aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/r600/r600_context.h
blob: 74e34e3684d0a0d1e786287d9446fb43039341f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.

The Weather Channel (TM) funded Tungsten Graphics to develop the
initial release of the Radeon 8500 driver under the XFree86 license.
This notice must be preserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

**************************************************************************/

/**
 * \file
 *
 * \author Keith Whitwell <keith@tungstengraphics.com>
 * \author Nicolai Haehnle <prefect_@gmx.net>
 */

#ifndef __R600_CONTEXT_H__
#define __R600_CONTEXT_H__

#include "tnl/t_vertex.h"
#include "drm.h"
#include "radeon_drm.h"
#include "dri_util.h"
#include "texmem.h"
#include "radeon_common.h"

#include "main/macros.h"
#include "main/mtypes.h"
#include "main/colormac.h"

struct r600_context;
typedef struct r600_context r600ContextRec;
typedef struct r600_context *r600ContextPtr;

typedef struct r600_context context_t;

#include "main/mm.h"

/* From http://gcc. gnu.org/onlinedocs/gcc-3.2.3/gcc/Variadic-Macros.html .
   I suppose we could inline this and use macro to fetch out __LINE__ and stuff in case we run into trouble
   with other compilers ... GLUE!
*/
#define WARN_ONCE(a, ...)	{ \
	static int warn##__LINE__=1; \
	if(warn##__LINE__){ \
		fprintf(stderr, "*********************************WARN_ONCE*********************************\n"); \
		fprintf(stderr, "File %s function %s line %d\n", \
			__FILE__, __FUNCTION__, __LINE__); \
		fprintf(stderr,  a, ## __VA_ARGS__);\
		fprintf(stderr, "***************************************************************************\n"); \
		warn##__LINE__=0;\
		} \
	}

/************ DMA BUFFERS **************/

/* The blit width for texture uploads
 */
#define R600_BLIT_WIDTH_BYTES 1024
#define R600_MAX_TEXTURE_UNITS 8

struct r600_texture_state {
	int tc_count;		/* number of incoming texture coordinates from VAP */
};

/* Perhaps more if we store programs in vmem? */
/* drm_r600_cmd_header_t->vpu->count is unsigned char */
#define VSF_MAX_FRAGMENT_LENGTH (255*4)

/* Can be tested with colormat currently. */
#define VSF_MAX_FRAGMENT_TEMPS (14)

#define STATE_R600_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)
#define STATE_R600_TEXRECT_FACTOR (STATE_INTERNAL_DRIVER+1)

extern int hw_tcl_on;

#define COLOR_IS_RGBA
#define TAG(x) r600##x
#include "tnl_dd/t_dd_vertex.h"
#undef TAG

#define PFS_MAX_ALU_INST	64
#define PFS_MAX_TEX_INST	64
#define PFS_MAX_TEX_INDIRECT 4
#define PFS_NUM_TEMP_REGS	32
#define PFS_NUM_CONST_REGS	16

#define R600_MAX_AOS_ARRAYS		16

#define REG_COORDS	0
#define REG_COLOR0	1
#define REG_TEX0	2

#define R600_FALLBACK_NONE 0
#define R600_FALLBACK_TCL 1
#define R600_FALLBACK_RAST 2

/* r600_swtcl.c
 */
struct r600_swtcl_info {
  /*
    * Offset of the 4UB color data within a hardware (swtcl) vertex.
    */
   GLuint coloroffset;

   /**
    * Offset of the 3UB specular color data within a hardware (swtcl) vertex.
    */
   GLuint specoffset;

   struct vertex_attribute{
       GLuint attr;
       GLubyte format;
       GLubyte dst_loc;
       GLuint swizzle;
       GLubyte write_mask;
   } vert_attrs[VERT_ATTRIB_MAX];

   GLubyte vertex_attr_count;
};

/* to be enabled */ /* DELETE FOLLOWING 2 SRTUCTS */
struct r600_dma_buffer 
{
    int         refcount;       /* the number of retained regions in buf */
    drmBufPtr   buf;
    int         id;
};
struct r600_dma_region 
{
    struct r600_dma_buffer  *buf;
    char        *address;       /* == buf->address */
    int         start;
    int         end;
    int         ptr;            /* offsets from start of buf */

    int         aos_offset;     /* address in GART memory */
    int         aos_stride;     /* distance between elements, in dwords */
    int         aos_size;       /* number of components (1-4) */
};
/* ----------------------- */

typedef struct chip_object
{
    void      *pvChipObj;

    /* ------------  OUT ------------------- */
    GLboolean (*DestroyChipObj)(void* pvChipObj);

    void      (*InitFuncs)(struct dd_function_table *functions);

    void      (*InitState)(GLcontext * ctx);

    GLuint    (*GetTexObjSize)(void);

    /* ------------  IN  ------------------- */
    void      (*EmitShader)( GLcontext * ctx, 
                             struct r600_dma_region *rvb,
			                 GLvoid * data, 
                             int sizeinDWORD);
    void      (*FreeDmaRegion)( GLcontext * ctx, 
                                struct r600_dma_region *region);
    void      (*EmitVec)(GLcontext * ctx, 
                         struct r600_dma_region *rvb,
			             GLvoid * data, 
                         int size, 
                         int stride, 
                         int count);
    void      (*MemUse)(context_t *context, int id);
    void      (*ReleaseArrays)(GLcontext * ctx);
    int       (*FlushCmdBuffer)(GLcontext * ctx);
    GLboolean (*LoadMemSurf)(context_t *context,
                               GLuint     dst_offset, /* gpu addr */
                               GLuint     dst_pitch_in_pixel,                               
                               GLuint     src_width_in_pixel,
                               GLuint     height,
                               GLuint     byte_per_pixel,
                               unsigned char* pSrc); /* source data */    
    GLboolean (*AllocMemSurf)(context_t   *context,
                           void  **ppmemBlock,
                           void  **ppheap,
                           GLuint      *prefered_heap, 
                           GLuint       totalSize);
    
    struct tnl_pipeline_stage **stages;
} chip_object;

/**
 * \brief R600 context structure.
 */
struct r600_context {
	struct radeon_context radeon;	/* parent class, must be first */

    /* ------ */
    chip_object chipobj;

	/* Vertex buffers
	 */
	GLvector4f dummy_attrib[_TNL_ATTRIB_MAX];
	GLvector4f *temp_attrib[_TNL_ATTRIB_MAX];

	GLboolean disable_lowimpact_fallback;

	struct r600_swtcl_info swtcl;
	GLboolean vap_flush_needed;
};

#define R600_CONTEXT(ctx)		((r600ContextPtr)(ctx->DriverCtx))
#define R700_CONTEXT(ctx)		((context_t *)(ctx->DriverCtx))
#define GL_CONTEXT(context)     ((GLcontext *)(context->radeon.glCtx))

extern void r600DestroyContext(__DRIcontextPrivate * driContextPriv);
extern GLboolean r600CreateContext(const __GLcontextModes * glVisual,
				   __DRIcontextPrivate * driContextPriv,
				   void *sharedContextPrivate);

#define RADEON_D_CAPTURE 0
#define RADEON_D_PLAYBACK 1
#define RADEON_D_PLAYBACK_RAW 2
#define RADEON_D_T 3

#define r600PackFloat32 radeonPackFloat32
#define r600PackFloat24 radeonPackFloat24

#endif				/* __R600_CONTEXT_H__ */