r200_context.h revision ae4a1cc0666860bf5cc37a5cb549afc9aa5448b0
1/* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.h,v 1.2 2002/12/16 16:18:54 dawes Exp $ */
2/*
3Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
4
5The Weather Channel (TM) funded Tungsten Graphics to develop the
6initial release of the Radeon 8500 driver under the XFree86 license.
7This notice must be preserved.
8
9Permission is hereby granted, free of charge, to any person obtaining
10a copy of this software and associated documentation files (the
11"Software"), to deal in the Software without restriction, including
12without limitation the rights to use, copy, modify, merge, publish,
13distribute, sublicense, and/or sell copies of the Software, and to
14permit persons to whom the Software is furnished to do so, subject to
15the following conditions:
16
17The above copyright notice and this permission notice (including the
18next paragraph) shall be included in all copies or substantial
19portions of the Software.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27WITH 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 <inttypes.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 0  /* XXX this is temporary! */
53
54struct r200_context;
55typedef struct r200_context r200ContextRec;
56typedef 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
84typedef void (*r200_tri_func)( r200ContextPtr,
85				 r200Vertex *,
86				 r200Vertex *,
87				 r200Vertex * );
88
89typedef void (*r200_line_func)( r200ContextPtr,
90				  r200Vertex *,
91				  r200Vertex * );
92
93typedef void (*r200_point_func)( r200ContextPtr,
94				   r200Vertex * );
95
96
97struct r200_colorbuffer_state {
98   GLuint clear;
99   GLint drawOffset, drawPitch;
100   int roundEnable;
101};
102
103
104struct r200_depthbuffer_state {
105   GLfloat scale;
106};
107
108struct r200_pixel_state {
109   GLint readOffset, readPitch;
110};
111
112struct 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
121struct r200_stencilbuffer_state {
122   GLboolean hwBuffer;
123   GLuint clear;			/* rb3d_stencilrefmask value */
124};
125
126struct 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
136typedef struct r200_tex_obj r200TexObj, *r200TexObjPtr;
137
138/* Texture object in locally shared texture space.
139 */
140struct 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
170struct r200_texture_env_state {
171   r200TexObjPtr texobj;
172   GLenum format;
173   GLenum envMode;
174};
175
176#define R200_MAX_TEXTURE_UNITS 3
177
178struct r200_texture_state {
179   struct r200_texture_env_state unit[R200_MAX_TEXTURE_UNITS];
180};
181
182
183struct 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        14
217
218#define SET_CMD_0               0
219#define SET_SE_CNTL             1
220#define SET_RE_CNTL             2 /* replace se_coord_fmt */
221#define SET_STATE_SIZE          3
222
223#define VTE_CMD_0               0
224#define VTE_SE_VTE_CNTL         1
225#define VTE_STATE_SIZE          2
226
227#define LIN_CMD_0               0
228#define LIN_RE_LINE_PATTERN     1
229#define LIN_RE_LINE_STATE       2
230#define LIN_CMD_1               3
231#define LIN_SE_LINE_WIDTH       4
232#define LIN_STATE_SIZE          5
233
234#define MSK_CMD_0               0
235#define MSK_RB3D_STENCILREFMASK 1
236#define MSK_RB3D_ROPCNTL        2
237#define MSK_RB3D_PLANEMASK      3
238#define MSK_STATE_SIZE          4
239
240#define VPT_CMD_0           0
241#define VPT_SE_VPORT_XSCALE          1
242#define VPT_SE_VPORT_XOFFSET         2
243#define VPT_SE_VPORT_YSCALE          3
244#define VPT_SE_VPORT_YOFFSET         4
245#define VPT_SE_VPORT_ZSCALE          5
246#define VPT_SE_VPORT_ZOFFSET         6
247#define VPT_STATE_SIZE      7
248
249#define ZBS_CMD_0               0
250#define ZBS_SE_ZBIAS_FACTOR     1
251#define ZBS_SE_ZBIAS_CONSTANT   2
252#define ZBS_STATE_SIZE          3
253
254#define MSC_CMD_0               0
255#define MSC_RE_MISC             1
256#define MSC_STATE_SIZE          2
257
258#define TAM_CMD_0               0
259#define TAM_DEBUG3              1
260#define TAM_STATE_SIZE          2
261
262#define TEX_CMD_0                   0
263#define TEX_PP_TXFILTER             1  /*2c00*/
264#define TEX_PP_TXFORMAT             2  /*2c04*/
265#define TEX_PP_TXFORMAT_X           3  /*2c08*/
266#define TEX_PP_TXSIZE               4  /*2c0c*/
267#define TEX_PP_TXPITCH              5  /*2c10*/
268#define TEX_PP_BORDER_COLOR         6  /*2c14*/
269#define TEX_CMD_1                   7
270#define TEX_PP_TXOFFSET             8  /*2d00 */
271#define TEX_STATE_SIZE              9
272
273#define CUBE_CMD_0                  0  /* 1 register follows */
274#define CUBE_PP_CUBIC_FACES         1  /* 0x2c18 */
275#define CUBE_CMD_1                  2  /* 5 registers follow */
276#define CUBE_PP_CUBIC_OFFSET_F1     3  /* 0x2d04 */
277#define CUBE_PP_CUBIC_OFFSET_F2     4  /* 0x2d08 */
278#define CUBE_PP_CUBIC_OFFSET_F3     5  /* 0x2d0c */
279#define CUBE_PP_CUBIC_OFFSET_F4     6  /* 0x2d10 */
280#define CUBE_PP_CUBIC_OFFSET_F5     7  /* 0x2d14 */
281#define CUBE_STATE_SIZE             8
282
283#define PIX_CMD_0                   0
284#define PIX_PP_TXCBLEND             1
285#define PIX_PP_TXCBLEND2            2
286#define PIX_PP_TXABLEND             3
287#define PIX_PP_TXABLEND2            4
288#define PIX_STATE_SIZE              5
289
290#define TF_CMD_0                    0
291#define TF_TFACTOR_0                1
292#define TF_TFACTOR_1                2
293#define TF_TFACTOR_2                3
294#define TF_TFACTOR_3                4
295#define TF_TFACTOR_4                5
296#define TF_TFACTOR_5                6
297#define TF_STATE_SIZE               7
298
299#define TCL_CMD_0                 0
300#define TCL_LIGHT_MODEL_CTL_0     1
301#define TCL_LIGHT_MODEL_CTL_1     2
302#define TCL_PER_LIGHT_CTL_0       3
303#define TCL_PER_LIGHT_CTL_1       4
304#define TCL_PER_LIGHT_CTL_2       5
305#define TCL_PER_LIGHT_CTL_3       6
306#define TCL_CMD_1                 7
307#define TCL_UCP_VERT_BLEND_CTL    8
308#define TCL_STATE_SIZE            9
309
310#define MSL_CMD_0                     0
311#define MSL_MATRIX_SELECT_0           1
312#define MSL_MATRIX_SELECT_1           2
313#define MSL_MATRIX_SELECT_2           3
314#define MSL_MATRIX_SELECT_3           4
315#define MSL_MATRIX_SELECT_4           5
316#define MSL_STATE_SIZE                6
317
318#define TCG_CMD_0                 0
319#define TCG_TEX_PROC_CTL_2            1
320#define TCG_TEX_PROC_CTL_3            2
321#define TCG_TEX_PROC_CTL_0            3
322#define TCG_TEX_PROC_CTL_1            4
323#define TCG_TEX_CYL_WRAP_CTL      5
324#define TCG_STATE_SIZE            6
325
326#define MTL_CMD_0            0
327#define MTL_EMMISSIVE_RED    1
328#define MTL_EMMISSIVE_GREEN  2
329#define MTL_EMMISSIVE_BLUE   3
330#define MTL_EMMISSIVE_ALPHA  4
331#define MTL_AMBIENT_RED      5
332#define MTL_AMBIENT_GREEN    6
333#define MTL_AMBIENT_BLUE     7
334#define MTL_AMBIENT_ALPHA    8
335#define MTL_DIFFUSE_RED      9
336#define MTL_DIFFUSE_GREEN    10
337#define MTL_DIFFUSE_BLUE     11
338#define MTL_DIFFUSE_ALPHA    12
339#define MTL_SPECULAR_RED     13
340#define MTL_SPECULAR_GREEN   14
341#define MTL_SPECULAR_BLUE    15
342#define MTL_SPECULAR_ALPHA   16
343#define MTL_CMD_1            17
344#define MTL_SHININESS        18
345#define MTL_STATE_SIZE       19
346
347#define VAP_CMD_0                   0
348#define VAP_SE_VAP_CNTL             1
349#define VAP_STATE_SIZE              2
350
351/* Replaces a lot of packet info from radeon
352 */
353#define VTX_CMD_0                   0
354#define VTX_VTXFMT_0            1
355#define VTX_VTXFMT_1            2
356#define VTX_TCL_OUTPUT_VTXFMT_0 3
357#define VTX_TCL_OUTPUT_VTXFMT_1 4
358#define VTX_CMD_1               5
359#define VTX_TCL_OUTPUT_COMPSEL  6
360#define VTX_CMD_2               7
361#define VTX_STATE_CNTL          8
362#define VTX_STATE_SIZE          9
363
364
365#define VTX_COLOR(v,n)   (((v)>>(R200_VTX_COLOR_0_SHIFT+(n)*2))&\
366                         R200_VTX_COLOR_MASK)
367
368#define MAT_CMD_0              0
369#define MAT_ELT_0              1
370#define MAT_STATE_SIZE         17
371
372#define GRD_CMD_0                  0
373#define GRD_VERT_GUARD_CLIP_ADJ    1
374#define GRD_VERT_GUARD_DISCARD_ADJ 2
375#define GRD_HORZ_GUARD_CLIP_ADJ    3
376#define GRD_HORZ_GUARD_DISCARD_ADJ 4
377#define GRD_STATE_SIZE             5
378
379/* position changes frequently when lighting in modelpos - separate
380 * out to new state item?
381 */
382#define LIT_CMD_0                  0
383#define LIT_AMBIENT_RED            1
384#define LIT_AMBIENT_GREEN          2
385#define LIT_AMBIENT_BLUE           3
386#define LIT_AMBIENT_ALPHA          4
387#define LIT_DIFFUSE_RED            5
388#define LIT_DIFFUSE_GREEN          6
389#define LIT_DIFFUSE_BLUE           7
390#define LIT_DIFFUSE_ALPHA          8
391#define LIT_SPECULAR_RED           9
392#define LIT_SPECULAR_GREEN         10
393#define LIT_SPECULAR_BLUE          11
394#define LIT_SPECULAR_ALPHA         12
395#define LIT_POSITION_X             13
396#define LIT_POSITION_Y             14
397#define LIT_POSITION_Z             15
398#define LIT_POSITION_W             16
399#define LIT_DIRECTION_X            17
400#define LIT_DIRECTION_Y            18
401#define LIT_DIRECTION_Z            19
402#define LIT_DIRECTION_W            20
403#define LIT_ATTEN_QUADRATIC        21
404#define LIT_ATTEN_LINEAR           22
405#define LIT_ATTEN_CONST            23
406#define LIT_ATTEN_XXX              24
407#define LIT_CMD_1                  25
408#define LIT_SPOT_DCD               26
409#define LIT_SPOT_DCM               27
410#define LIT_SPOT_EXPONENT          28
411#define LIT_SPOT_CUTOFF            29
412#define LIT_SPECULAR_THRESH        30
413#define LIT_RANGE_CUTOFF           31 /* ? */
414#define LIT_ATTEN_CONST_INV        32
415#define LIT_STATE_SIZE             33
416
417/* Fog
418 */
419#define FOG_CMD_0      0
420#define FOG_R          1
421#define FOG_C          2
422#define FOG_D          3
423#define FOG_PAD        4
424#define FOG_STATE_SIZE 5
425
426/* UCP
427 */
428#define UCP_CMD_0      0
429#define UCP_X          1
430#define UCP_Y          2
431#define UCP_Z          3
432#define UCP_W          4
433#define UCP_STATE_SIZE 5
434
435/* GLT - Global ambient
436 */
437#define GLT_CMD_0      0
438#define GLT_RED        1
439#define GLT_GREEN      2
440#define GLT_BLUE       3
441#define GLT_ALPHA      4
442#define GLT_STATE_SIZE 5
443
444/* EYE
445 */
446#define EYE_CMD_0          0
447#define EYE_X              1
448#define EYE_Y              2
449#define EYE_Z              3
450#define EYE_RESCALE_FACTOR 4
451#define EYE_STATE_SIZE     5
452
453/* CST - constant state
454 */
455#define CST_CMD_0                             0
456#define CST_PP_CNTL_X                         1
457#define CST_CMD_1                             2
458#define CST_RB3D_DEPTHXY_OFFSET               3
459#define CST_CMD_2                             4
460#define CST_RE_AUX_SCISSOR_CNTL               5
461#define CST_CMD_3                             6
462#define CST_RE_SCISSOR_TL_0                   7
463#define CST_RE_SCISSOR_BR_0                   8
464#define CST_CMD_4                             9
465#define CST_SE_VAP_CNTL_STATUS                10
466#define CST_CMD_5                             11
467#define CST_RE_POINTSIZE                      12
468#define CST_CMD_6                             13
469#define CST_SE_TCL_INPUT_VTX_0                14
470#define CST_SE_TCL_INPUT_VTX_1                15
471#define CST_SE_TCL_INPUT_VTX_2                16
472#define CST_SE_TCL_INPUT_VTX_3                17
473#define CST_STATE_SIZE                        18
474
475
476
477
478struct r200_hw_state {
479   /* All state should be on one of these lists:
480    */
481   struct r200_state_atom dirty; /* dirty list head placeholder */
482   struct r200_state_atom clean; /* clean list head placeholder */
483
484   /* Hardware state, stored as cmdbuf commands:
485    *   -- Need to doublebuffer for
486    *           - reviving state after loss of context
487    *           - eliding noop statechange loops? (except line stipple count)
488    */
489   struct r200_state_atom ctx;
490   struct r200_state_atom set;
491   struct r200_state_atom vte;
492   struct r200_state_atom lin;
493   struct r200_state_atom msk;
494   struct r200_state_atom vpt;
495   struct r200_state_atom vap;
496   struct r200_state_atom vtx;
497   struct r200_state_atom tcl;
498   struct r200_state_atom msl;
499   struct r200_state_atom tcg;
500   struct r200_state_atom msc;
501   struct r200_state_atom cst;
502   struct r200_state_atom tam;
503   struct r200_state_atom tf;
504   struct r200_state_atom tex[2];
505   struct r200_state_atom cube[2];
506   struct r200_state_atom zbs;
507   struct r200_state_atom mtl[2];
508   struct r200_state_atom mat[5];
509   struct r200_state_atom lit[8]; /* includes vec, scl commands */
510   struct r200_state_atom ucp[6];
511   struct r200_state_atom pix[6]; /* pixshader stages */
512   struct r200_state_atom eye; /* eye pos */
513   struct r200_state_atom grd; /* guard band clipping */
514   struct r200_state_atom fog;
515   struct r200_state_atom glt;
516};
517
518struct r200_state {
519   /* Derived state for internal purposes:
520    */
521   struct r200_colorbuffer_state color;
522   struct r200_depthbuffer_state depth;
523   struct r200_pixel_state pixel;
524   struct r200_scissor_state scissor;
525   struct r200_stencilbuffer_state stencil;
526   struct r200_stipple_state stipple;
527   struct r200_texture_state texture;
528};
529
530/* Need refcounting on dma buffers:
531 */
532struct r200_dma_buffer {
533   int refcount;		/* the number of retained regions in buf */
534   drmBufPtr buf;
535};
536
537#define GET_START(rvb) (rmesa->r200Screen->gart_buffer_offset +		\
538			(rvb)->address - rmesa->dma.buf0_address +	\
539			(rvb)->start)
540
541/* A retained region, eg vertices for indexed vertices.
542 */
543struct r200_dma_region {
544   struct r200_dma_buffer *buf;
545   char *address;		/* == buf->address */
546   int start, end, ptr;		/* offsets from start of buf */
547   int aos_start;
548   int aos_stride;
549   int aos_size;
550};
551
552
553struct r200_dma {
554   /* Active dma region.  Allocations for vertices and retained
555    * regions come from here.  Also used for emitting random vertices,
556    * these may be flushed by calling flush_current();
557    */
558   struct r200_dma_region current;
559
560   void (*flush)( r200ContextPtr );
561
562   char *buf0_address;		/* start of buf[0], for index calcs */
563   GLuint nr_released_bufs;	/* flush after so many buffers released */
564};
565
566struct r200_dri_mirror {
567   __DRIcontextPrivate	*context;	/* DRI context */
568   __DRIscreenPrivate	*screen;	/* DRI screen */
569   __DRIdrawablePrivate	*drawable;	/* DRI drawable bound to this ctx */
570
571   drmContext hwContext;
572   drm_hw_lock_t *hwLock;
573   int fd;
574   int drmMinor;
575};
576
577
578#define R200_CMD_BUF_SZ  (8*1024)
579
580struct r200_store {
581   GLuint statenr;
582   GLuint primnr;
583   char cmd_buf[R200_CMD_BUF_SZ];
584   int cmd_used;
585   int elts_start;
586};
587
588
589/* r200_tcl.c
590 */
591struct r200_tcl_info {
592   GLuint vertex_format;
593   GLint last_offset;
594   GLuint hw_primitive;
595
596   struct r200_dma_region *aos_components[8];
597   GLuint nr_aos_components;
598
599   GLuint *Elts;
600
601   struct r200_dma_region indexed_verts;
602   struct r200_dma_region obj;
603   struct r200_dma_region rgba;
604   struct r200_dma_region spec;
605   struct r200_dma_region fog;
606   struct r200_dma_region tex[R200_MAX_TEXTURE_UNITS];
607   struct r200_dma_region norm;
608};
609
610
611/* r200_swtcl.c
612 */
613struct r200_swtcl_info {
614   GLuint SetupIndex;
615   GLuint SetupNewInputs;
616   GLuint RenderIndex;
617   GLuint vertex_size;
618   GLuint vertex_stride_shift;
619   GLuint vertex_format;
620   GLubyte *verts;
621
622   /* Fallback rasterization functions
623    */
624   r200_point_func draw_point;
625   r200_line_func draw_line;
626   r200_tri_func draw_tri;
627
628   GLuint hw_primitive;
629   GLenum render_primitive;
630   GLuint numverts;
631
632   struct r200_dma_region indexed_verts;
633};
634
635
636struct r200_ioctl {
637   GLuint vertex_offset;
638   GLuint vertex_size;
639};
640
641
642
643#define R200_MAX_PRIMS 64
644
645
646/* Want to keep a cache of these around.  Each is parameterized by
647 * only a single value which has only a small range.  Only expect a
648 * few, so just rescan the list each time?
649 */
650struct dynfn {
651   struct dynfn *next, *prev;
652   int key[2];
653   char *code;
654};
655
656struct dfn_lists {
657   struct dynfn Vertex2f;
658   struct dynfn Vertex2fv;
659   struct dynfn Vertex3f;
660   struct dynfn Vertex3fv;
661   struct dynfn Color4ub;
662   struct dynfn Color4ubv;
663   struct dynfn Color3ub;
664   struct dynfn Color3ubv;
665   struct dynfn Color4f;
666   struct dynfn Color4fv;
667   struct dynfn Color3f;
668   struct dynfn Color3fv;
669   struct dynfn SecondaryColor3ubEXT;
670   struct dynfn SecondaryColor3ubvEXT;
671   struct dynfn SecondaryColor3fEXT;
672   struct dynfn SecondaryColor3fvEXT;
673   struct dynfn Normal3f;
674   struct dynfn Normal3fv;
675   struct dynfn TexCoord2f;
676   struct dynfn TexCoord2fv;
677   struct dynfn TexCoord1f;
678   struct dynfn TexCoord1fv;
679   struct dynfn MultiTexCoord2fARB;
680   struct dynfn MultiTexCoord2fvARB;
681   struct dynfn MultiTexCoord1fARB;
682   struct dynfn MultiTexCoord1fvARB;
683};
684
685struct dfn_generators {
686   struct dynfn *(*Vertex2f)( GLcontext *, const int * );
687   struct dynfn *(*Vertex2fv)( GLcontext *, const int * );
688   struct dynfn *(*Vertex3f)( GLcontext *, const int * );
689   struct dynfn *(*Vertex3fv)( GLcontext *, const int * );
690   struct dynfn *(*Color4ub)( GLcontext *, const int * );
691   struct dynfn *(*Color4ubv)( GLcontext *, const int * );
692   struct dynfn *(*Color3ub)( GLcontext *, const int * );
693   struct dynfn *(*Color3ubv)( GLcontext *, const int * );
694   struct dynfn *(*Color4f)( GLcontext *, const int * );
695   struct dynfn *(*Color4fv)( GLcontext *, const int * );
696   struct dynfn *(*Color3f)( GLcontext *, const int * );
697   struct dynfn *(*Color3fv)( GLcontext *, const int * );
698   struct dynfn *(*SecondaryColor3ubEXT)( GLcontext *, const int * );
699   struct dynfn *(*SecondaryColor3ubvEXT)( GLcontext *, const int * );
700   struct dynfn *(*SecondaryColor3fEXT)( GLcontext *, const int * );
701   struct dynfn *(*SecondaryColor3fvEXT)( GLcontext *, const int * );
702   struct dynfn *(*Normal3f)( GLcontext *, const int * );
703   struct dynfn *(*Normal3fv)( GLcontext *, const int * );
704   struct dynfn *(*TexCoord2f)( GLcontext *, const int * );
705   struct dynfn *(*TexCoord2fv)( GLcontext *, const int * );
706   struct dynfn *(*TexCoord1f)( GLcontext *, const int * );
707   struct dynfn *(*TexCoord1fv)( GLcontext *, const int * );
708   struct dynfn *(*MultiTexCoord2fARB)( GLcontext *, const int * );
709   struct dynfn *(*MultiTexCoord2fvARB)( GLcontext *, const int * );
710   struct dynfn *(*MultiTexCoord1fARB)( GLcontext *, const int * );
711   struct dynfn *(*MultiTexCoord1fvARB)( GLcontext *, const int * );
712};
713
714
715
716struct r200_prim {
717   GLuint start;
718   GLuint end;
719   GLuint prim;
720};
721
722struct r200_vbinfo {
723   GLint counter, initial_counter;
724   GLint *dmaptr;
725   void (*notify)( void );
726   GLint vertex_size;
727
728   /* A maximum total of 15 elements per vertex:  3 floats for position, 3
729    * floats for normal, 4 floats for color, 4 bytes for secondary color,
730    * 2 floats for each texture unit (4 floats total).
731    *
732    * As soon as the 3rd TMU is supported or cube maps (or 3D textures) are
733    * supported, this value will grow.
734    *
735    * The position data is never actually stored here, so 3 elements could be
736    * trimmed out of the buffer.
737    */
738   union { float f; int i; r200_color_t color; } vertex[15];
739
740   GLfloat *normalptr;
741   GLfloat *floatcolorptr;
742   r200_color_t *colorptr;
743   GLfloat *floatspecptr;
744   r200_color_t *specptr;
745   GLfloat *texcoordptr[2];
746
747
748   GLenum *prim;		/* &ctx->Driver.CurrentExecPrimitive */
749   GLuint primflags;
750   GLboolean enabled;		/* *_NO_VTXFMT / *_NO_TCL env vars */
751   GLboolean installed;
752   GLboolean fell_back;
753   GLboolean recheck;
754   GLint nrverts;
755   GLuint vtxfmt_0, vtxfmt_1;
756
757   GLuint installed_vertex_format;
758   GLuint installed_color_3f_sz;
759
760   struct r200_prim primlist[R200_MAX_PRIMS];
761   int nrprims;
762
763   struct dfn_lists dfn_cache;
764   struct dfn_generators codegen;
765   GLvertexformat vtxfmt;
766};
767
768
769
770
771struct r200_context {
772   GLcontext *glCtx;			/* Mesa context */
773
774   /* Driver and hardware state management
775    */
776   struct r200_hw_state hw;
777   struct r200_state state;
778
779   /* Texture object bookkeeping
780    */
781   unsigned              nr_heaps;
782   driTexHeap          * texture_heaps[ R200_NR_TEX_HEAPS ];
783   driTextureObject      swapped;
784   int                   texture_depth;
785   float                 initialMaxAnisotropy;
786
787   /* Rasterization and vertex state:
788    */
789   GLuint TclFallback;
790   GLuint Fallback;
791   GLuint NewGLState;
792
793   /* Vertex buffers
794    */
795   struct r200_ioctl ioctl;
796   struct r200_dma dma;
797   struct r200_store store;
798
799   /* Page flipping
800    */
801   GLuint doPageFlip;
802
803   /* Busy waiting
804    */
805   GLuint do_usleeps;
806   GLuint do_irqs;
807   GLuint irqsEmitted;
808   drm_radeon_irq_wait_t iw;
809
810   /* Clientdata textures;
811    */
812   GLuint prefer_gart_client_texturing;
813
814   /* Drawable, cliprect and scissor information
815    */
816   GLuint numClipRects;			/* Cliprects for the draw buffer */
817   drm_clip_rect_t *pClipRects;
818   unsigned int lastStamp;
819   GLboolean lost_context;
820   r200ScreenPtr r200Screen;	/* Screen private DRI data */
821   drm_radeon_sarea_t *sarea;		/* Private SAREA data */
822
823   /* TCL stuff
824    */
825   GLmatrix TexGenMatrix[R200_MAX_TEXTURE_UNITS];
826   GLboolean recheck_texgen[R200_MAX_TEXTURE_UNITS];
827   GLboolean TexGenNeedNormals[R200_MAX_TEXTURE_UNITS];
828   GLuint TexMatEnabled;
829   GLuint TexMatCompSel;
830   GLuint TexGenEnabled;
831   GLuint TexGenInputs;
832   GLuint TexGenCompSel;
833   GLmatrix tmpmat;
834
835   /* VBI / buffer swap
836    */
837   GLuint vbl_seq;
838   GLuint vblank_flags;
839
840   int64_t swap_ust;
841   int64_t swap_missed_ust;
842
843   GLuint swap_count;
844   GLuint swap_missed_count;
845
846   PFNGLXGETUSTPROC get_ust;
847
848   /* r200_tcl.c
849    */
850   struct r200_tcl_info tcl;
851
852   /* r200_swtcl.c
853    */
854   struct r200_swtcl_info swtcl;
855
856   /* r200_vtxfmt.c
857    */
858   struct r200_vbinfo vb;
859
860   /* Mirrors of some DRI state
861    */
862   struct r200_dri_mirror dri;
863
864   /* Configuration cache
865    */
866   driOptionCache optionCache;
867};
868
869#define R200_CONTEXT(ctx)		((r200ContextPtr)(ctx->DriverCtx))
870
871
872static __inline GLuint r200PackColor( GLuint cpp,
873					GLubyte r, GLubyte g,
874					GLubyte b, GLubyte a )
875{
876   switch ( cpp ) {
877   case 2:
878      return PACK_COLOR_565( r, g, b );
879   case 4:
880      return PACK_COLOR_8888( a, r, g, b );
881   default:
882      return 0;
883   }
884}
885
886#define R200_OLD_PACKETS 0
887
888
889extern void r200DestroyContext( __DRIcontextPrivate *driContextPriv );
890extern GLboolean r200CreateContext( const __GLcontextModes *glVisual,
891				    __DRIcontextPrivate *driContextPriv,
892				    void *sharedContextPrivate);
893extern void r200SwapBuffers( __DRIdrawablePrivate *dPriv );
894extern GLboolean r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
895				  __DRIdrawablePrivate *driDrawPriv,
896				  __DRIdrawablePrivate *driReadPriv );
897extern GLboolean r200UnbindContext( __DRIcontextPrivate *driContextPriv );
898
899/* ================================================================
900 * Debugging:
901 */
902#define DO_DEBUG		1
903
904#if DO_DEBUG
905extern int R200_DEBUG;
906#else
907#define R200_DEBUG		0
908#endif
909
910#define DEBUG_TEXTURE	0x001
911#define DEBUG_STATE	0x002
912#define DEBUG_IOCTL	0x004
913#define DEBUG_PRIMS	0x008
914#define DEBUG_VERTS	0x010
915#define DEBUG_FALLBACKS	0x020
916#define DEBUG_VFMT	0x040
917#define DEBUG_CODEGEN	0x080
918#define DEBUG_VERBOSE	0x100
919#define DEBUG_DRI       0x200
920#define DEBUG_DMA       0x400
921#define DEBUG_SANITY    0x800
922#define DEBUG_SYNC      0x1000
923#define DEBUG_PIXEL     0x2000
924#define DEBUG_MEMORY    0x4000
925
926#endif
927#endif /* __R200_CONTEXT_H__ */
928