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