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