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