b7ee33aa6c988d2d83e0c0a3523420fd60060d23
[mesa.git] / src / mesa / drivers / dri / r200 / r200_context.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.h,v 1.2 2002/12/16 16:18:54 dawes Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #ifndef __R200_CONTEXT_H__
37 #define __R200_CONTEXT_H__
38
39 #include "tnl/t_vertex.h"
40 #include "drm.h"
41 #include "radeon_drm.h"
42 #include "dri_util.h"
43 #include "texmem.h"
44
45 #include "macros.h"
46 #include "mtypes.h"
47 #include "colormac.h"
48 #include "r200_reg.h"
49 #include "r200_vertprog.h"
50
51 #define ENABLE_HW_3D_TEXTURE 1 /* XXX this is temporary! */
52
53 #ifndef R200_EMIT_VAP_PVS_CNTL
54 #error This driver requires a newer libdrm to compile
55 #endif
56
57 struct r200_context;
58 typedef struct r200_context r200ContextRec;
59 typedef struct r200_context *r200ContextPtr;
60
61 /* This union is used to avoid warnings/miscompilation
62 with float to uint32_t casts due to strict-aliasing */
63 typedef union { GLfloat f; uint32_t ui32; } float_ui32_type;
64
65 #include "r200_lock.h"
66 #include "radeon_screen.h"
67 #include "mm.h"
68
69 /* Flags for software fallback cases */
70 /* See correponding strings in r200_swtcl.c */
71 #define R200_FALLBACK_TEXTURE 0x01
72 #define R200_FALLBACK_DRAW_BUFFER 0x02
73 #define R200_FALLBACK_STENCIL 0x04
74 #define R200_FALLBACK_RENDER_MODE 0x08
75 #define R200_FALLBACK_DISABLE 0x10
76 #define R200_FALLBACK_BORDER_MODE 0x20
77
78 /* The blit width for texture uploads
79 */
80 #define BLIT_WIDTH_BYTES 1024
81
82 /* Use the templated vertex format:
83 */
84 #define COLOR_IS_RGBA
85 #define TAG(x) r200##x
86 #include "tnl_dd/t_dd_vertex.h"
87 #undef TAG
88
89 typedef void (*r200_tri_func)( r200ContextPtr,
90 r200Vertex *,
91 r200Vertex *,
92 r200Vertex * );
93
94 typedef void (*r200_line_func)( r200ContextPtr,
95 r200Vertex *,
96 r200Vertex * );
97
98 typedef void (*r200_point_func)( r200ContextPtr,
99 r200Vertex * );
100
101
102 struct r200_vertex_program {
103 struct gl_vertex_program mesa_program; /* Must be first */
104 int translated;
105 VERTEX_SHADER_INSTRUCTION instr[R200_VSF_MAX_INST + 3];
106 int pos_end;
107 int inputs[VERT_ATTRIB_MAX];
108 int native;
109 };
110
111 struct r200_colorbuffer_state {
112 GLuint clear;
113 #if 000
114 GLint drawOffset, drawPitch;
115 #endif
116 int roundEnable;
117 };
118
119
120 struct r200_depthbuffer_state {
121 GLuint clear;
122 GLfloat scale;
123 };
124
125 #if 000
126 struct r200_pixel_state {
127 GLint readOffset, readPitch;
128 };
129 #endif
130
131 struct r200_scissor_state {
132 drm_clip_rect_t rect;
133 GLboolean enabled;
134
135 GLuint numClipRects; /* Cliprects active */
136 GLuint numAllocedClipRects; /* Cliprects available */
137 drm_clip_rect_t *pClipRects;
138 };
139
140 struct r200_stencilbuffer_state {
141 GLboolean hwBuffer;
142 GLuint clear; /* rb3d_stencilrefmask value */
143 };
144
145 struct r200_stipple_state {
146 GLuint mask[32];
147 };
148
149
150
151 #define TEX_0 0x1
152 #define TEX_1 0x2
153 #define TEX_2 0x4
154 #define TEX_3 0x8
155 #define TEX_4 0x10
156 #define TEX_5 0x20
157 #define TEX_ALL 0x3f
158
159 typedef struct r200_tex_obj r200TexObj, *r200TexObjPtr;
160
161 /* Texture object in locally shared texture space.
162 */
163 struct r200_tex_obj {
164 driTextureObject base;
165
166 GLuint bufAddr; /* Offset to start of locally
167 shared texture block */
168
169 GLuint dirty_state; /* Flags (1 per texunit) for
170 whether or not this texobj
171 has dirty hardware state
172 (pp_*) that needs to be
173 brought into the
174 texunit. */
175
176 drm_radeon_tex_image_t image[6][RADEON_MAX_TEXTURE_LEVELS];
177 /* Six, for the cube faces */
178
179 GLuint pp_txfilter; /* hardware register values */
180 GLuint pp_txformat;
181 GLuint pp_txformat_x;
182 GLuint pp_txoffset; /* Image location in texmem.
183 All cube faces follow. */
184 GLuint pp_txsize; /* npot only */
185 GLuint pp_txpitch; /* npot only */
186 GLuint pp_border_color;
187 GLuint pp_cubic_faces; /* cube face 1,2,3,4 log2 sizes */
188
189 GLboolean border_fallback;
190
191 GLuint tile_bits; /* hw texture tile bits used on this texture */
192 };
193
194
195 struct r200_texture_env_state {
196 r200TexObjPtr texobj;
197 GLuint outputreg;
198 GLuint unitneeded;
199 };
200
201 #define R200_MAX_TEXTURE_UNITS 6
202
203 struct r200_texture_state {
204 struct r200_texture_env_state unit[R200_MAX_TEXTURE_UNITS];
205 };
206
207
208 struct r200_state_atom {
209 struct r200_state_atom *next, *prev;
210 const char *name; /* for debug */
211 int cmd_size; /* size in bytes */
212 GLuint idx;
213 int *cmd; /* one or more cmd's */
214 int *lastcmd; /* one or more cmd's */
215 GLboolean dirty;
216 GLboolean (*check)( GLcontext *, int ); /* is this state active? */
217 };
218
219
220
221 /* Trying to keep these relatively short as the variables are becoming
222 * extravagently long. Drop the driver name prefix off the front of
223 * everything - I think we know which driver we're in by now, and keep the
224 * prefix to 3 letters unless absolutely impossible.
225 */
226
227 #define CTX_CMD_0 0
228 #define CTX_PP_MISC 1
229 #define CTX_PP_FOG_COLOR 2
230 #define CTX_RE_SOLID_COLOR 3
231 #define CTX_RB3D_BLENDCNTL 4
232 #define CTX_RB3D_DEPTHOFFSET 5
233 #define CTX_RB3D_DEPTHPITCH 6
234 #define CTX_RB3D_ZSTENCILCNTL 7
235 #define CTX_CMD_1 8
236 #define CTX_PP_CNTL 9
237 #define CTX_RB3D_CNTL 10
238 #define CTX_RB3D_COLOROFFSET 11
239 #define CTX_CMD_2 12 /* why */
240 #define CTX_RB3D_COLORPITCH 13 /* why */
241 #define CTX_STATE_SIZE_OLDDRM 14
242 #define CTX_CMD_3 14
243 #define CTX_RB3D_BLENDCOLOR 15
244 #define CTX_RB3D_ABLENDCNTL 16
245 #define CTX_RB3D_CBLENDCNTL 17
246 #define CTX_STATE_SIZE_NEWDRM 18
247
248 #define SET_CMD_0 0
249 #define SET_SE_CNTL 1
250 #define SET_RE_CNTL 2 /* replace se_coord_fmt */
251 #define SET_STATE_SIZE 3
252
253 #define VTE_CMD_0 0
254 #define VTE_SE_VTE_CNTL 1
255 #define VTE_STATE_SIZE 2
256
257 #define LIN_CMD_0 0
258 #define LIN_RE_LINE_PATTERN 1
259 #define LIN_RE_LINE_STATE 2
260 #define LIN_CMD_1 3
261 #define LIN_SE_LINE_WIDTH 4
262 #define LIN_STATE_SIZE 5
263
264 #define MSK_CMD_0 0
265 #define MSK_RB3D_STENCILREFMASK 1
266 #define MSK_RB3D_ROPCNTL 2
267 #define MSK_RB3D_PLANEMASK 3
268 #define MSK_STATE_SIZE 4
269
270 #define VPT_CMD_0 0
271 #define VPT_SE_VPORT_XSCALE 1
272 #define VPT_SE_VPORT_XOFFSET 2
273 #define VPT_SE_VPORT_YSCALE 3
274 #define VPT_SE_VPORT_YOFFSET 4
275 #define VPT_SE_VPORT_ZSCALE 5
276 #define VPT_SE_VPORT_ZOFFSET 6
277 #define VPT_STATE_SIZE 7
278
279 #define ZBS_CMD_0 0
280 #define ZBS_SE_ZBIAS_FACTOR 1
281 #define ZBS_SE_ZBIAS_CONSTANT 2
282 #define ZBS_STATE_SIZE 3
283
284 #define MSC_CMD_0 0
285 #define MSC_RE_MISC 1
286 #define MSC_STATE_SIZE 2
287
288 #define TAM_CMD_0 0
289 #define TAM_DEBUG3 1
290 #define TAM_STATE_SIZE 2
291
292 #define TEX_CMD_0 0
293 #define TEX_PP_TXFILTER 1 /*2c00*/
294 #define TEX_PP_TXFORMAT 2 /*2c04*/
295 #define TEX_PP_TXFORMAT_X 3 /*2c08*/
296 #define TEX_PP_TXSIZE 4 /*2c0c*/
297 #define TEX_PP_TXPITCH 5 /*2c10*/
298 #define TEX_PP_BORDER_COLOR 6 /*2c14*/
299 #define TEX_CMD_1_OLDDRM 7
300 #define TEX_PP_TXOFFSET_OLDDRM 8 /*2d00 */
301 #define TEX_STATE_SIZE_OLDDRM 9
302 #define TEX_PP_CUBIC_FACES 7
303 #define TEX_PP_TXMULTI_CTL 8
304 #define TEX_CMD_1_NEWDRM 9
305 #define TEX_PP_TXOFFSET_NEWDRM 10
306 #define TEX_STATE_SIZE_NEWDRM 11
307
308 #define CUBE_CMD_0 0 /* 1 register follows */ /* this command unnecessary */
309 #define CUBE_PP_CUBIC_FACES 1 /* 0x2c18 */ /* with new enough drm */
310 #define CUBE_CMD_1 2 /* 5 registers follow */
311 #define CUBE_PP_CUBIC_OFFSET_F1 3 /* 0x2d04 */
312 #define CUBE_PP_CUBIC_OFFSET_F2 4 /* 0x2d08 */
313 #define CUBE_PP_CUBIC_OFFSET_F3 5 /* 0x2d0c */
314 #define CUBE_PP_CUBIC_OFFSET_F4 6 /* 0x2d10 */
315 #define CUBE_PP_CUBIC_OFFSET_F5 7 /* 0x2d14 */
316 #define CUBE_STATE_SIZE 8
317
318 #define PIX_CMD_0 0
319 #define PIX_PP_TXCBLEND 1
320 #define PIX_PP_TXCBLEND2 2
321 #define PIX_PP_TXABLEND 3
322 #define PIX_PP_TXABLEND2 4
323 #define PIX_STATE_SIZE 5
324
325 #define TF_CMD_0 0
326 #define TF_TFACTOR_0 1
327 #define TF_TFACTOR_1 2
328 #define TF_TFACTOR_2 3
329 #define TF_TFACTOR_3 4
330 #define TF_TFACTOR_4 5
331 #define TF_TFACTOR_5 6
332 #define TF_STATE_SIZE 7
333
334 #define ATF_CMD_0 0
335 #define ATF_TFACTOR_0 1
336 #define ATF_TFACTOR_1 2
337 #define ATF_TFACTOR_2 3
338 #define ATF_TFACTOR_3 4
339 #define ATF_TFACTOR_4 5
340 #define ATF_TFACTOR_5 6
341 #define ATF_TFACTOR_6 7
342 #define ATF_TFACTOR_7 8
343 #define ATF_STATE_SIZE 9
344
345 /* ATI_FRAGMENT_SHADER */
346 #define AFS_CMD_0 0
347 #define AFS_IC0 1 /* 2f00 */
348 #define AFS_IC1 2 /* 2f04 */
349 #define AFS_IA0 3 /* 2f08 */
350 #define AFS_IA1 4 /* 2f0c */
351 #define AFS_STATE_SIZE 33
352
353 #define PVS_CMD_0 0
354 #define PVS_CNTL_1 1
355 #define PVS_CNTL_2 2
356 #define PVS_STATE_SIZE 3
357
358 /* those are quite big... */
359 #define VPI_CMD_0 0
360 #define VPI_OPDST_0 1
361 #define VPI_SRC0_0 2
362 #define VPI_SRC1_0 3
363 #define VPI_SRC2_0 4
364 #define VPI_OPDST_63 253
365 #define VPI_SRC0_63 254
366 #define VPI_SRC1_63 255
367 #define VPI_SRC2_63 256
368 #define VPI_STATE_SIZE 257
369
370 #define VPP_CMD_0 0
371 #define VPP_PARAM0_0 1
372 #define VPP_PARAM1_0 2
373 #define VPP_PARAM2_0 3
374 #define VPP_PARAM3_0 4
375 #define VPP_PARAM0_95 381
376 #define VPP_PARAM1_95 382
377 #define VPP_PARAM2_95 383
378 #define VPP_PARAM3_95 384
379 #define VPP_STATE_SIZE 385
380
381 #define TCL_CMD_0 0
382 #define TCL_LIGHT_MODEL_CTL_0 1
383 #define TCL_LIGHT_MODEL_CTL_1 2
384 #define TCL_PER_LIGHT_CTL_0 3
385 #define TCL_PER_LIGHT_CTL_1 4
386 #define TCL_PER_LIGHT_CTL_2 5
387 #define TCL_PER_LIGHT_CTL_3 6
388 #define TCL_CMD_1 7
389 #define TCL_UCP_VERT_BLEND_CTL 8
390 #define TCL_STATE_SIZE 9
391
392 #define MSL_CMD_0 0
393 #define MSL_MATRIX_SELECT_0 1
394 #define MSL_MATRIX_SELECT_1 2
395 #define MSL_MATRIX_SELECT_2 3
396 #define MSL_MATRIX_SELECT_3 4
397 #define MSL_MATRIX_SELECT_4 5
398 #define MSL_STATE_SIZE 6
399
400 #define TCG_CMD_0 0
401 #define TCG_TEX_PROC_CTL_2 1
402 #define TCG_TEX_PROC_CTL_3 2
403 #define TCG_TEX_PROC_CTL_0 3
404 #define TCG_TEX_PROC_CTL_1 4
405 #define TCG_TEX_CYL_WRAP_CTL 5
406 #define TCG_STATE_SIZE 6
407
408 #define MTL_CMD_0 0
409 #define MTL_EMMISSIVE_RED 1
410 #define MTL_EMMISSIVE_GREEN 2
411 #define MTL_EMMISSIVE_BLUE 3
412 #define MTL_EMMISSIVE_ALPHA 4
413 #define MTL_AMBIENT_RED 5
414 #define MTL_AMBIENT_GREEN 6
415 #define MTL_AMBIENT_BLUE 7
416 #define MTL_AMBIENT_ALPHA 8
417 #define MTL_DIFFUSE_RED 9
418 #define MTL_DIFFUSE_GREEN 10
419 #define MTL_DIFFUSE_BLUE 11
420 #define MTL_DIFFUSE_ALPHA 12
421 #define MTL_SPECULAR_RED 13
422 #define MTL_SPECULAR_GREEN 14
423 #define MTL_SPECULAR_BLUE 15
424 #define MTL_SPECULAR_ALPHA 16
425 #define MTL_CMD_1 17
426 #define MTL_SHININESS 18
427 #define MTL_STATE_SIZE 19
428
429 #define VAP_CMD_0 0
430 #define VAP_SE_VAP_CNTL 1
431 #define VAP_STATE_SIZE 2
432
433 /* Replaces a lot of packet info from radeon
434 */
435 #define VTX_CMD_0 0
436 #define VTX_VTXFMT_0 1
437 #define VTX_VTXFMT_1 2
438 #define VTX_TCL_OUTPUT_VTXFMT_0 3
439 #define VTX_TCL_OUTPUT_VTXFMT_1 4
440 #define VTX_CMD_1 5
441 #define VTX_TCL_OUTPUT_COMPSEL 6
442 #define VTX_CMD_2 7
443 #define VTX_STATE_CNTL 8
444 #define VTX_STATE_SIZE 9
445
446 /* SPR - point sprite state
447 */
448 #define SPR_CMD_0 0
449 #define SPR_POINT_SPRITE_CNTL 1
450 #define SPR_STATE_SIZE 2
451
452 #define VTX_COLOR(v,n) (((v)>>(R200_VTX_COLOR_0_SHIFT+(n)*2))&\
453 R200_VTX_COLOR_MASK)
454
455 /**
456 * Given the \c R200_SE_VTX_FMT_1 for the current vertex state, determine
457 * how many components are in texture coordinate \c n.
458 */
459 #define VTX_TEXn_COUNT(v,n) (((v) >> (3 * n)) & 0x07)
460
461 #define MAT_CMD_0 0
462 #define MAT_ELT_0 1
463 #define MAT_STATE_SIZE 17
464
465 #define GRD_CMD_0 0
466 #define GRD_VERT_GUARD_CLIP_ADJ 1
467 #define GRD_VERT_GUARD_DISCARD_ADJ 2
468 #define GRD_HORZ_GUARD_CLIP_ADJ 3
469 #define GRD_HORZ_GUARD_DISCARD_ADJ 4
470 #define GRD_STATE_SIZE 5
471
472 /* position changes frequently when lighting in modelpos - separate
473 * out to new state item?
474 */
475 #define LIT_CMD_0 0
476 #define LIT_AMBIENT_RED 1
477 #define LIT_AMBIENT_GREEN 2
478 #define LIT_AMBIENT_BLUE 3
479 #define LIT_AMBIENT_ALPHA 4
480 #define LIT_DIFFUSE_RED 5
481 #define LIT_DIFFUSE_GREEN 6
482 #define LIT_DIFFUSE_BLUE 7
483 #define LIT_DIFFUSE_ALPHA 8
484 #define LIT_SPECULAR_RED 9
485 #define LIT_SPECULAR_GREEN 10
486 #define LIT_SPECULAR_BLUE 11
487 #define LIT_SPECULAR_ALPHA 12
488 #define LIT_POSITION_X 13
489 #define LIT_POSITION_Y 14
490 #define LIT_POSITION_Z 15
491 #define LIT_POSITION_W 16
492 #define LIT_DIRECTION_X 17
493 #define LIT_DIRECTION_Y 18
494 #define LIT_DIRECTION_Z 19
495 #define LIT_DIRECTION_W 20
496 #define LIT_ATTEN_QUADRATIC 21
497 #define LIT_ATTEN_LINEAR 22
498 #define LIT_ATTEN_CONST 23
499 #define LIT_ATTEN_XXX 24
500 #define LIT_CMD_1 25
501 #define LIT_SPOT_DCD 26
502 #define LIT_SPOT_DCM 27
503 #define LIT_SPOT_EXPONENT 28
504 #define LIT_SPOT_CUTOFF 29
505 #define LIT_SPECULAR_THRESH 30
506 #define LIT_RANGE_CUTOFF 31 /* ? */
507 #define LIT_ATTEN_CONST_INV 32
508 #define LIT_STATE_SIZE 33
509
510 /* Fog
511 */
512 #define FOG_CMD_0 0
513 #define FOG_R 1
514 #define FOG_C 2
515 #define FOG_D 3
516 #define FOG_PAD 4
517 #define FOG_STATE_SIZE 5
518
519 /* UCP
520 */
521 #define UCP_CMD_0 0
522 #define UCP_X 1
523 #define UCP_Y 2
524 #define UCP_Z 3
525 #define UCP_W 4
526 #define UCP_STATE_SIZE 5
527
528 /* GLT - Global ambient
529 */
530 #define GLT_CMD_0 0
531 #define GLT_RED 1
532 #define GLT_GREEN 2
533 #define GLT_BLUE 3
534 #define GLT_ALPHA 4
535 #define GLT_STATE_SIZE 5
536
537 /* EYE
538 */
539 #define EYE_CMD_0 0
540 #define EYE_X 1
541 #define EYE_Y 2
542 #define EYE_Z 3
543 #define EYE_RESCALE_FACTOR 4
544 #define EYE_STATE_SIZE 5
545
546 /* CST - constant state
547 */
548 #define CST_CMD_0 0
549 #define CST_PP_CNTL_X 1
550 #define CST_CMD_1 2
551 #define CST_RB3D_DEPTHXY_OFFSET 3
552 #define CST_CMD_2 4
553 #define CST_RE_AUX_SCISSOR_CNTL 5
554 #define CST_CMD_3 6
555 #define CST_RE_SCISSOR_TL_0 7
556 #define CST_RE_SCISSOR_BR_0 8
557 #define CST_CMD_4 9
558 #define CST_SE_VAP_CNTL_STATUS 10
559 #define CST_CMD_5 11
560 #define CST_RE_POINTSIZE 12
561 #define CST_CMD_6 13
562 #define CST_SE_TCL_INPUT_VTX_0 14
563 #define CST_SE_TCL_INPUT_VTX_1 15
564 #define CST_SE_TCL_INPUT_VTX_2 16
565 #define CST_SE_TCL_INPUT_VTX_3 17
566 #define CST_STATE_SIZE 18
567
568 #define PRF_CMD_0 0
569 #define PRF_PP_TRI_PERF 1
570 #define PRF_PP_PERF_CNTL 2
571 #define PRF_STATE_SIZE 3
572
573
574 struct r200_hw_state {
575 /* Head of the linked list of state atoms. */
576 struct r200_state_atom atomlist;
577
578 /* Hardware state, stored as cmdbuf commands:
579 * -- Need to doublebuffer for
580 * - reviving state after loss of context
581 * - eliding noop statechange loops? (except line stipple count)
582 */
583 struct r200_state_atom ctx;
584 struct r200_state_atom set;
585 struct r200_state_atom vte;
586 struct r200_state_atom lin;
587 struct r200_state_atom msk;
588 struct r200_state_atom vpt;
589 struct r200_state_atom vap;
590 struct r200_state_atom vtx;
591 struct r200_state_atom tcl;
592 struct r200_state_atom msl;
593 struct r200_state_atom tcg;
594 struct r200_state_atom msc;
595 struct r200_state_atom cst;
596 struct r200_state_atom tam;
597 struct r200_state_atom tf;
598 struct r200_state_atom tex[6];
599 struct r200_state_atom cube[6];
600 struct r200_state_atom zbs;
601 struct r200_state_atom mtl[2];
602 struct r200_state_atom mat[9];
603 struct r200_state_atom lit[8]; /* includes vec, scl commands */
604 struct r200_state_atom ucp[6];
605 struct r200_state_atom pix[6]; /* pixshader stages */
606 struct r200_state_atom eye; /* eye pos */
607 struct r200_state_atom grd; /* guard band clipping */
608 struct r200_state_atom fog;
609 struct r200_state_atom glt;
610 struct r200_state_atom prf;
611 struct r200_state_atom afs[2];
612 struct r200_state_atom pvs;
613 struct r200_state_atom vpi[2];
614 struct r200_state_atom vpp[2];
615 struct r200_state_atom atf;
616 struct r200_state_atom spr;
617
618 int max_state_size; /* Number of bytes necessary for a full state emit. */
619 GLboolean is_dirty, all_dirty;
620 };
621
622 struct r200_state {
623 /* Derived state for internal purposes:
624 */
625 struct r200_colorbuffer_state color;
626 struct r200_depthbuffer_state depth;
627 #if 00
628 struct r200_pixel_state pixel;
629 #endif
630 struct r200_scissor_state scissor;
631 struct r200_stencilbuffer_state stencil;
632 struct r200_stipple_state stipple;
633 struct r200_texture_state texture;
634 GLuint envneeded;
635 };
636
637 /* Need refcounting on dma buffers:
638 */
639 struct r200_dma_buffer {
640 int refcount; /* the number of retained regions in buf */
641 drmBufPtr buf;
642 };
643
644 #define GET_START(rvb) (rmesa->r200Screen->gart_buffer_offset + \
645 (rvb)->address - rmesa->dma.buf0_address + \
646 (rvb)->start)
647
648 /* A retained region, eg vertices for indexed vertices.
649 */
650 struct r200_dma_region {
651 struct r200_dma_buffer *buf;
652 char *address; /* == buf->address */
653 int start, end, ptr; /* offsets from start of buf */
654 int aos_start;
655 int aos_stride;
656 int aos_size;
657 };
658
659
660 struct r200_dma {
661 /* Active dma region. Allocations for vertices and retained
662 * regions come from here. Also used for emitting random vertices,
663 * these may be flushed by calling flush_current();
664 */
665 struct r200_dma_region current;
666
667 void (*flush)( r200ContextPtr );
668
669 char *buf0_address; /* start of buf[0], for index calcs */
670 GLuint nr_released_bufs; /* flush after so many buffers released */
671 };
672
673 struct r200_dri_mirror {
674 __DRIcontextPrivate *context; /* DRI context */
675 __DRIscreenPrivate *screen; /* DRI screen */
676 __DRIdrawablePrivate *drawable; /* DRI drawable bound to this ctx */
677
678 drm_context_t hwContext;
679 drm_hw_lock_t *hwLock;
680 int fd;
681 int drmMinor;
682 };
683
684
685 #define R200_CMD_BUF_SZ (16*1024)
686
687 struct r200_store {
688 GLuint statenr;
689 GLuint primnr;
690 char cmd_buf[R200_CMD_BUF_SZ];
691 int cmd_used;
692 int elts_start;
693 };
694
695
696 /* r200_tcl.c
697 */
698 struct r200_tcl_info {
699 GLuint vertex_format;
700 GLint last_offset;
701 GLuint hw_primitive;
702
703 /* FIXME: what's the maximum number of components? */
704 struct r200_dma_region *aos_components[11];
705 GLuint nr_aos_components;
706
707 GLuint *Elts;
708
709 struct r200_dma_region indexed_verts;
710 struct r200_dma_region obj;
711 struct r200_dma_region rgba;
712 struct r200_dma_region spec;
713 struct r200_dma_region fog;
714 struct r200_dma_region tex[R200_MAX_TEXTURE_UNITS];
715 struct r200_dma_region norm;
716 };
717
718
719 /* r200_swtcl.c
720 */
721 struct r200_swtcl_info {
722 GLuint RenderIndex;
723
724 /**
725 * Size of a hardware vertex. This is calculated when \c ::vertex_attrs is
726 * installed in the Mesa state vector.
727 */
728 GLuint vertex_size;
729
730 /**
731 * Attributes instructing the Mesa TCL pipeline where / how to put vertex
732 * data in the hardware buffer.
733 */
734 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
735
736 /**
737 * Number of elements of \c ::vertex_attrs that are actually used.
738 */
739 GLuint vertex_attr_count;
740
741 /**
742 * Cached pointer to the buffer where Mesa will store vertex data.
743 */
744 GLubyte *verts;
745
746 /* Fallback rasterization functions
747 */
748 r200_point_func draw_point;
749 r200_line_func draw_line;
750 r200_tri_func draw_tri;
751
752 GLuint hw_primitive;
753 GLenum render_primitive;
754 GLuint numverts;
755
756 /**
757 * Offset of the 4UB color data within a hardware (swtcl) vertex.
758 */
759 GLuint coloroffset;
760
761 /**
762 * Offset of the 3UB specular color data within a hardware (swtcl) vertex.
763 */
764 GLuint specoffset;
765
766 /**
767 * Should Mesa project vertex data or will the hardware do it?
768 */
769 GLboolean needproj;
770
771 struct r200_dma_region indexed_verts;
772 };
773
774
775 struct r200_ioctl {
776 GLuint vertex_offset;
777 GLuint vertex_size;
778 };
779
780
781
782 #define R200_MAX_PRIMS 64
783
784
785 /* Want to keep a cache of these around. Each is parameterized by
786 * only a single value which has only a small range. Only expect a
787 * few, so just rescan the list each time?
788 */
789 struct dynfn {
790 struct dynfn *next, *prev;
791 int key[2];
792 char *code;
793 };
794
795 struct dfn_lists {
796 struct dynfn Vertex2f;
797 struct dynfn Vertex2fv;
798 struct dynfn Vertex3f;
799 struct dynfn Vertex3fv;
800 struct dynfn Color4ub;
801 struct dynfn Color4ubv;
802 struct dynfn Color3ub;
803 struct dynfn Color3ubv;
804 struct dynfn Color4f;
805 struct dynfn Color4fv;
806 struct dynfn Color3f;
807 struct dynfn Color3fv;
808 struct dynfn SecondaryColor3ubEXT;
809 struct dynfn SecondaryColor3ubvEXT;
810 struct dynfn SecondaryColor3fEXT;
811 struct dynfn SecondaryColor3fvEXT;
812 struct dynfn Normal3f;
813 struct dynfn Normal3fv;
814 struct dynfn TexCoord3f;
815 struct dynfn TexCoord3fv;
816 struct dynfn TexCoord2f;
817 struct dynfn TexCoord2fv;
818 struct dynfn TexCoord1f;
819 struct dynfn TexCoord1fv;
820 struct dynfn MultiTexCoord3fARB;
821 struct dynfn MultiTexCoord3fvARB;
822 struct dynfn MultiTexCoord2fARB;
823 struct dynfn MultiTexCoord2fvARB;
824 struct dynfn MultiTexCoord1fARB;
825 struct dynfn MultiTexCoord1fvARB;
826 struct dynfn FogCoordfEXT;
827 struct dynfn FogCoordfvEXT;
828 };
829
830 struct dfn_generators {
831 struct dynfn *(*Vertex2f)( GLcontext *, const int * );
832 struct dynfn *(*Vertex2fv)( GLcontext *, const int * );
833 struct dynfn *(*Vertex3f)( GLcontext *, const int * );
834 struct dynfn *(*Vertex3fv)( GLcontext *, const int * );
835 struct dynfn *(*Color4ub)( GLcontext *, const int * );
836 struct dynfn *(*Color4ubv)( GLcontext *, const int * );
837 struct dynfn *(*Color3ub)( GLcontext *, const int * );
838 struct dynfn *(*Color3ubv)( GLcontext *, const int * );
839 struct dynfn *(*Color4f)( GLcontext *, const int * );
840 struct dynfn *(*Color4fv)( GLcontext *, const int * );
841 struct dynfn *(*Color3f)( GLcontext *, const int * );
842 struct dynfn *(*Color3fv)( GLcontext *, const int * );
843 struct dynfn *(*SecondaryColor3ubEXT)( GLcontext *, const int * );
844 struct dynfn *(*SecondaryColor3ubvEXT)( GLcontext *, const int * );
845 struct dynfn *(*SecondaryColor3fEXT)( GLcontext *, const int * );
846 struct dynfn *(*SecondaryColor3fvEXT)( GLcontext *, const int * );
847 struct dynfn *(*Normal3f)( GLcontext *, const int * );
848 struct dynfn *(*Normal3fv)( GLcontext *, const int * );
849 struct dynfn *(*TexCoord3f)( GLcontext *, const int * );
850 struct dynfn *(*TexCoord3fv)( GLcontext *, const int * );
851 struct dynfn *(*TexCoord2f)( GLcontext *, const int * );
852 struct dynfn *(*TexCoord2fv)( GLcontext *, const int * );
853 struct dynfn *(*TexCoord1f)( GLcontext *, const int * );
854 struct dynfn *(*TexCoord1fv)( GLcontext *, const int * );
855 struct dynfn *(*MultiTexCoord3fARB)( GLcontext *, const int * );
856 struct dynfn *(*MultiTexCoord3fvARB)( GLcontext *, const int * );
857 struct dynfn *(*MultiTexCoord2fARB)( GLcontext *, const int * );
858 struct dynfn *(*MultiTexCoord2fvARB)( GLcontext *, const int * );
859 struct dynfn *(*MultiTexCoord1fARB)( GLcontext *, const int * );
860 struct dynfn *(*MultiTexCoord1fvARB)( GLcontext *, const int * );
861 struct dynfn *(*FogCoordfEXT)( GLcontext *, const int * );
862 struct dynfn *(*FogCoordfvEXT)( GLcontext *, const int * );
863 };
864
865
866
867 struct r200_prim {
868 GLuint start;
869 GLuint end;
870 GLuint prim;
871 };
872
873 /* A maximum total of 29 elements per vertex: 3 floats for position, 3
874 * floats for normal, 4 floats for color, 4 bytes for secondary color,
875 * 3 floats for each texture unit (18 floats total).
876 *
877 * we maybe need add. 4 to prevent segfault if someone specifies
878 * GL_TEXTURE6/GL_TEXTURE7 (esp. for the codegen-path) (FIXME: )
879 *
880 * The position data is never actually stored here, so 3 elements could be
881 * trimmed out of the buffer.
882 */
883
884 #define R200_MAX_VERTEX_SIZE ((3*6)+11)
885
886 struct r200_vbinfo {
887 GLint counter, initial_counter;
888 GLint *dmaptr;
889 void (*notify)( void );
890 GLint vertex_size;
891
892 union { float f; int i; r200_color_t color; } vertex[R200_MAX_VERTEX_SIZE];
893
894 GLfloat *normalptr;
895 GLfloat *floatcolorptr;
896 GLfloat *fogptr;
897 r200_color_t *colorptr;
898 GLfloat *floatspecptr;
899 r200_color_t *specptr;
900 GLfloat *texcoordptr[8]; /* 6 (TMU) + 2 for r200_vtxfmt_c.c when GL_TEXTURE6/7 */
901
902
903 GLenum *prim; /* &ctx->Driver.CurrentExecPrimitive */
904 GLuint primflags;
905 GLboolean enabled; /* *_NO_VTXFMT / *_NO_TCL env vars */
906 GLboolean installed;
907 GLboolean fell_back;
908 GLboolean recheck;
909 GLint nrverts;
910 GLuint vtxfmt_0, vtxfmt_1;
911
912 GLuint installed_vertex_format;
913 GLuint installed_color_3f_sz;
914
915 struct r200_prim primlist[R200_MAX_PRIMS];
916 int nrprims;
917
918 struct dfn_lists dfn_cache;
919 struct dfn_generators codegen;
920 GLvertexformat vtxfmt;
921 };
922
923
924 struct r200_context {
925 GLcontext *glCtx; /* Mesa context */
926
927 /* Driver and hardware state management
928 */
929 struct r200_hw_state hw;
930 struct r200_state state;
931 struct r200_vertex_program *curr_vp_hw;
932
933 /* Texture object bookkeeping
934 */
935 unsigned nr_heaps;
936 driTexHeap * texture_heaps[ RADEON_NR_TEX_HEAPS ];
937 driTextureObject swapped;
938 int texture_depth;
939 float initialMaxAnisotropy;
940
941 /* Rasterization and vertex state:
942 */
943 GLuint TclFallback;
944 GLuint Fallback;
945 GLuint NewGLState;
946 DECLARE_RENDERINPUTS(tnl_index_bitset); /* index of bits for last tnl_install_attrs */
947
948 /* Vertex buffers
949 */
950 struct r200_ioctl ioctl;
951 struct r200_dma dma;
952 struct r200_store store;
953 /* A full state emit as of the first state emit in the main store, in case
954 * the context is lost.
955 */
956 struct r200_store backup_store;
957
958 /* Page flipping
959 */
960 GLuint doPageFlip;
961
962 /* Busy waiting
963 */
964 GLuint do_usleeps;
965 GLuint do_irqs;
966 GLuint irqsEmitted;
967 drm_radeon_irq_wait_t iw;
968
969 /* Clientdata textures;
970 */
971 GLuint prefer_gart_client_texturing;
972
973 /* Drawable, cliprect and scissor information
974 */
975 GLuint numClipRects; /* Cliprects for the draw buffer */
976 drm_clip_rect_t *pClipRects;
977 unsigned int lastStamp;
978 GLboolean lost_context;
979 GLboolean save_on_next_emit;
980 radeonScreenPtr r200Screen; /* Screen private DRI data */
981 drm_radeon_sarea_t *sarea; /* Private SAREA data */
982
983 /* TCL stuff
984 */
985 GLmatrix TexGenMatrix[R200_MAX_TEXTURE_UNITS];
986 GLboolean recheck_texgen[R200_MAX_TEXTURE_UNITS];
987 GLboolean TexGenNeedNormals[R200_MAX_TEXTURE_UNITS];
988 GLuint TexMatEnabled;
989 GLuint TexMatCompSel;
990 GLuint TexGenEnabled;
991 GLuint TexGenCompSel;
992 GLmatrix tmpmat;
993
994 /* VBI / buffer swap
995 */
996 GLuint vbl_seq;
997 GLuint vblank_flags;
998
999 int64_t swap_ust;
1000 int64_t swap_missed_ust;
1001
1002 GLuint swap_count;
1003 GLuint swap_missed_count;
1004
1005
1006 /* r200_tcl.c
1007 */
1008 struct r200_tcl_info tcl;
1009
1010 /* r200_swtcl.c
1011 */
1012 struct r200_swtcl_info swtcl;
1013
1014 /* r200_vtxfmt.c
1015 */
1016 struct r200_vbinfo vb;
1017
1018 /* Mirrors of some DRI state
1019 */
1020 struct r200_dri_mirror dri;
1021
1022 /* Configuration cache
1023 */
1024 driOptionCache optionCache;
1025
1026 GLboolean using_hyperz;
1027 GLboolean texmicrotile;
1028
1029 struct ati_fragment_shader *afs_loaded;
1030 };
1031
1032 #define R200_CONTEXT(ctx) ((r200ContextPtr)(ctx->DriverCtx))
1033
1034
1035 static __inline GLuint r200PackColor( GLuint cpp,
1036 GLubyte r, GLubyte g,
1037 GLubyte b, GLubyte a )
1038 {
1039 switch ( cpp ) {
1040 case 2:
1041 return PACK_COLOR_565( r, g, b );
1042 case 4:
1043 return PACK_COLOR_8888( a, r, g, b );
1044 default:
1045 return 0;
1046 }
1047 }
1048
1049
1050 extern void r200DestroyContext( __DRIcontextPrivate *driContextPriv );
1051 extern GLboolean r200CreateContext( const __GLcontextModes *glVisual,
1052 __DRIcontextPrivate *driContextPriv,
1053 void *sharedContextPrivate);
1054 extern void r200SwapBuffers( __DRIdrawablePrivate *dPriv );
1055 extern void r200CopySubBuffer( __DRIdrawablePrivate * dPriv,
1056 int x, int y, int w, int h );
1057 extern GLboolean r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
1058 __DRIdrawablePrivate *driDrawPriv,
1059 __DRIdrawablePrivate *driReadPriv );
1060 extern GLboolean r200UnbindContext( __DRIcontextPrivate *driContextPriv );
1061
1062 /* ================================================================
1063 * Debugging:
1064 */
1065 #define DO_DEBUG 1
1066
1067 #if DO_DEBUG
1068 extern int R200_DEBUG;
1069 #else
1070 #define R200_DEBUG 0
1071 #endif
1072
1073 #define DEBUG_TEXTURE 0x001
1074 #define DEBUG_STATE 0x002
1075 #define DEBUG_IOCTL 0x004
1076 #define DEBUG_PRIMS 0x008
1077 #define DEBUG_VERTS 0x010
1078 #define DEBUG_FALLBACKS 0x020
1079 #define DEBUG_VFMT 0x040
1080 #define DEBUG_CODEGEN 0x080
1081 #define DEBUG_VERBOSE 0x100
1082 #define DEBUG_DRI 0x200
1083 #define DEBUG_DMA 0x400
1084 #define DEBUG_SANITY 0x800
1085 #define DEBUG_SYNC 0x1000
1086 #define DEBUG_PIXEL 0x2000
1087 #define DEBUG_MEMORY 0x4000
1088
1089 #endif /* __R200_CONTEXT_H__ */