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