r200_context.h revision f20917de5bd2b1fc152e74304d3649a1f6042422
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#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
52struct r200_context;
53typedef struct r200_context r200ContextRec;
54typedef 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
80typedef void (*r200_tri_func)( r200ContextPtr,
81				 r200Vertex *,
82				 r200Vertex *,
83				 r200Vertex * );
84
85typedef void (*r200_line_func)( r200ContextPtr,
86				  r200Vertex *,
87				  r200Vertex * );
88
89typedef void (*r200_point_func)( r200ContextPtr,
90				   r200Vertex * );
91
92
93struct r200_colorbuffer_state {
94   GLuint clear;
95#if 000
96   GLint drawOffset, drawPitch;
97#endif
98   int roundEnable;
99};
100
101
102struct r200_depthbuffer_state {
103   GLuint clear;
104   GLfloat scale;
105};
106
107#if 000
108struct r200_pixel_state {
109   GLint readOffset, readPitch;
110};
111#endif
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_2	0x4
136#define TEX_3	0x8
137#define TEX_4	0x10
138#define TEX_5	0x20
139#define TEX_ALL 0x3f
140
141typedef struct r200_tex_obj r200TexObj, *r200TexObjPtr;
142
143/* Texture object in locally shared texture space.
144 */
145struct 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
177struct r200_texture_env_state {
178   r200TexObjPtr texobj;
179   GLuint outputreg;
180   GLuint unitneeded;
181};
182
183#define R200_MAX_TEXTURE_UNITS 6
184
185struct r200_texture_state {
186   struct r200_texture_env_state unit[R200_MAX_TEXTURE_UNITS];
187};
188
189
190struct 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
401#define VTX_COLOR(v,n)   (((v)>>(R200_VTX_COLOR_0_SHIFT+(n)*2))&\
402                         R200_VTX_COLOR_MASK)
403
404/**
405 * Given the \c R200_SE_VTX_FMT_1 for the current vertex state, determine
406 * how many components are in texture coordinate \c n.
407 */
408#define VTX_TEXn_COUNT(v,n)   (((v) >> (3 * n)) & 0x07)
409
410#define MAT_CMD_0              0
411#define MAT_ELT_0              1
412#define MAT_STATE_SIZE         17
413
414#define GRD_CMD_0                  0
415#define GRD_VERT_GUARD_CLIP_ADJ    1
416#define GRD_VERT_GUARD_DISCARD_ADJ 2
417#define GRD_HORZ_GUARD_CLIP_ADJ    3
418#define GRD_HORZ_GUARD_DISCARD_ADJ 4
419#define GRD_STATE_SIZE             5
420
421/* position changes frequently when lighting in modelpos - separate
422 * out to new state item?
423 */
424#define LIT_CMD_0                  0
425#define LIT_AMBIENT_RED            1
426#define LIT_AMBIENT_GREEN          2
427#define LIT_AMBIENT_BLUE           3
428#define LIT_AMBIENT_ALPHA          4
429#define LIT_DIFFUSE_RED            5
430#define LIT_DIFFUSE_GREEN          6
431#define LIT_DIFFUSE_BLUE           7
432#define LIT_DIFFUSE_ALPHA          8
433#define LIT_SPECULAR_RED           9
434#define LIT_SPECULAR_GREEN         10
435#define LIT_SPECULAR_BLUE          11
436#define LIT_SPECULAR_ALPHA         12
437#define LIT_POSITION_X             13
438#define LIT_POSITION_Y             14
439#define LIT_POSITION_Z             15
440#define LIT_POSITION_W             16
441#define LIT_DIRECTION_X            17
442#define LIT_DIRECTION_Y            18
443#define LIT_DIRECTION_Z            19
444#define LIT_DIRECTION_W            20
445#define LIT_ATTEN_QUADRATIC        21
446#define LIT_ATTEN_LINEAR           22
447#define LIT_ATTEN_CONST            23
448#define LIT_ATTEN_XXX              24
449#define LIT_CMD_1                  25
450#define LIT_SPOT_DCD               26
451#define LIT_SPOT_DCM               27
452#define LIT_SPOT_EXPONENT          28
453#define LIT_SPOT_CUTOFF            29
454#define LIT_SPECULAR_THRESH        30
455#define LIT_RANGE_CUTOFF           31 /* ? */
456#define LIT_ATTEN_CONST_INV        32
457#define LIT_STATE_SIZE             33
458
459/* Fog
460 */
461#define FOG_CMD_0      0
462#define FOG_R          1
463#define FOG_C          2
464#define FOG_D          3
465#define FOG_PAD        4
466#define FOG_STATE_SIZE 5
467
468/* UCP
469 */
470#define UCP_CMD_0      0
471#define UCP_X          1
472#define UCP_Y          2
473#define UCP_Z          3
474#define UCP_W          4
475#define UCP_STATE_SIZE 5
476
477/* GLT - Global ambient
478 */
479#define GLT_CMD_0      0
480#define GLT_RED        1
481#define GLT_GREEN      2
482#define GLT_BLUE       3
483#define GLT_ALPHA      4
484#define GLT_STATE_SIZE 5
485
486/* EYE
487 */
488#define EYE_CMD_0          0
489#define EYE_X              1
490#define EYE_Y              2
491#define EYE_Z              3
492#define EYE_RESCALE_FACTOR 4
493#define EYE_STATE_SIZE     5
494
495/* CST - constant state
496 */
497#define CST_CMD_0                             0
498#define CST_PP_CNTL_X                         1
499#define CST_CMD_1                             2
500#define CST_RB3D_DEPTHXY_OFFSET               3
501#define CST_CMD_2                             4
502#define CST_RE_AUX_SCISSOR_CNTL               5
503#define CST_CMD_3                             6
504#define CST_RE_SCISSOR_TL_0                   7
505#define CST_RE_SCISSOR_BR_0                   8
506#define CST_CMD_4                             9
507#define CST_SE_VAP_CNTL_STATUS                10
508#define CST_CMD_5                             11
509#define CST_RE_POINTSIZE                      12
510#define CST_CMD_6                             13
511#define CST_SE_TCL_INPUT_VTX_0                14
512#define CST_SE_TCL_INPUT_VTX_1                15
513#define CST_SE_TCL_INPUT_VTX_2                16
514#define CST_SE_TCL_INPUT_VTX_3                17
515#define CST_STATE_SIZE                        18
516
517#define PRF_CMD_0         0
518#define PRF_PP_TRI_PERF   1
519#define PRF_PP_PERF_CNTL  2
520#define PRF_STATE_SIZE    3
521
522
523struct r200_hw_state {
524   /* Head of the linked list of state atoms. */
525   struct r200_state_atom atomlist;
526
527   /* Hardware state, stored as cmdbuf commands:
528    *   -- Need to doublebuffer for
529    *           - reviving state after loss of context
530    *           - eliding noop statechange loops? (except line stipple count)
531    */
532   struct r200_state_atom ctx;
533   struct r200_state_atom set;
534   struct r200_state_atom vte;
535   struct r200_state_atom lin;
536   struct r200_state_atom msk;
537   struct r200_state_atom vpt;
538   struct r200_state_atom vap;
539   struct r200_state_atom vtx;
540   struct r200_state_atom tcl;
541   struct r200_state_atom msl;
542   struct r200_state_atom tcg;
543   struct r200_state_atom msc;
544   struct r200_state_atom cst;
545   struct r200_state_atom tam;
546   struct r200_state_atom tf;
547   struct r200_state_atom tex[6];
548   struct r200_state_atom cube[6];
549   struct r200_state_atom zbs;
550   struct r200_state_atom mtl[2];
551   struct r200_state_atom mat[9];
552   struct r200_state_atom lit[8]; /* includes vec, scl commands */
553   struct r200_state_atom ucp[6];
554   struct r200_state_atom pix[6]; /* pixshader stages */
555   struct r200_state_atom eye; /* eye pos */
556   struct r200_state_atom grd; /* guard band clipping */
557   struct r200_state_atom fog;
558   struct r200_state_atom glt;
559   struct r200_state_atom prf;
560   struct r200_state_atom afs[2];
561   struct r200_state_atom atf;
562
563   int max_state_size;	/* Number of bytes necessary for a full state emit. */
564   GLboolean is_dirty, all_dirty;
565};
566
567struct r200_state {
568   /* Derived state for internal purposes:
569    */
570   struct r200_colorbuffer_state color;
571   struct r200_depthbuffer_state depth;
572#if 00
573   struct r200_pixel_state pixel;
574#endif
575   struct r200_scissor_state scissor;
576   struct r200_stencilbuffer_state stencil;
577   struct r200_stipple_state stipple;
578   struct r200_texture_state texture;
579   GLuint envneeded;
580};
581
582/* Need refcounting on dma buffers:
583 */
584struct r200_dma_buffer {
585   int refcount;		/* the number of retained regions in buf */
586   drmBufPtr buf;
587};
588
589#define GET_START(rvb) (rmesa->r200Screen->gart_buffer_offset +		\
590			(rvb)->address - rmesa->dma.buf0_address +	\
591			(rvb)->start)
592
593/* A retained region, eg vertices for indexed vertices.
594 */
595struct r200_dma_region {
596   struct r200_dma_buffer *buf;
597   char *address;		/* == buf->address */
598   int start, end, ptr;		/* offsets from start of buf */
599   int aos_start;
600   int aos_stride;
601   int aos_size;
602};
603
604
605struct r200_dma {
606   /* Active dma region.  Allocations for vertices and retained
607    * regions come from here.  Also used for emitting random vertices,
608    * these may be flushed by calling flush_current();
609    */
610   struct r200_dma_region current;
611
612   void (*flush)( r200ContextPtr );
613
614   char *buf0_address;		/* start of buf[0], for index calcs */
615   GLuint nr_released_bufs;	/* flush after so many buffers released */
616};
617
618struct r200_dri_mirror {
619   __DRIcontextPrivate	*context;	/* DRI context */
620   __DRIscreenPrivate	*screen;	/* DRI screen */
621   __DRIdrawablePrivate	*drawable;	/* DRI drawable bound to this ctx */
622
623   drm_context_t hwContext;
624   drm_hw_lock_t *hwLock;
625   int fd;
626   int drmMinor;
627};
628
629
630#define R200_CMD_BUF_SZ  (8*1024)
631
632struct r200_store {
633   GLuint statenr;
634   GLuint primnr;
635   char cmd_buf[R200_CMD_BUF_SZ];
636   int cmd_used;
637   int elts_start;
638};
639
640
641/* r200_tcl.c
642 */
643struct r200_tcl_info {
644   GLuint vertex_format;
645   GLint last_offset;
646   GLuint hw_primitive;
647
648   struct r200_dma_region *aos_components[8];
649   GLuint nr_aos_components;
650
651   GLuint *Elts;
652
653   struct r200_dma_region indexed_verts;
654   struct r200_dma_region obj;
655   struct r200_dma_region rgba;
656   struct r200_dma_region spec;
657   struct r200_dma_region fog;
658   struct r200_dma_region tex[R200_MAX_TEXTURE_UNITS];
659   struct r200_dma_region norm;
660};
661
662
663/* r200_swtcl.c
664 */
665struct r200_swtcl_info {
666   GLuint RenderIndex;
667
668   /**
669    * Size of a hardware vertex.  This is calculated when \c ::vertex_attrs is
670    * installed in the Mesa state vector.
671    */
672   GLuint vertex_size;
673
674   /**
675    * Attributes instructing the Mesa TCL pipeline where / how to put vertex
676    * data in the hardware buffer.
677    */
678   struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
679
680   /**
681    * Number of elements of \c ::vertex_attrs that are actually used.
682    */
683   GLuint vertex_attr_count;
684
685   /**
686    * Cached pointer to the buffer where Mesa will store vertex data.
687    */
688   GLubyte *verts;
689
690   /* Fallback rasterization functions
691    */
692   r200_point_func draw_point;
693   r200_line_func draw_line;
694   r200_tri_func draw_tri;
695
696   GLuint hw_primitive;
697   GLenum render_primitive;
698   GLuint numverts;
699
700   /**
701    * Offset of the 4UB color data within a hardware (swtcl) vertex.
702    */
703   GLuint coloroffset;
704
705   /**
706    * Offset of the 3UB specular color data within a hardware (swtcl) vertex.
707    */
708   GLuint specoffset;
709
710   /**
711    * Should Mesa project vertex data or will the hardware do it?
712    */
713   GLboolean needproj;
714
715   struct r200_dma_region indexed_verts;
716};
717
718
719struct r200_ioctl {
720   GLuint vertex_offset;
721   GLuint vertex_size;
722};
723
724
725
726#define R200_MAX_PRIMS 64
727
728
729/* Want to keep a cache of these around.  Each is parameterized by
730 * only a single value which has only a small range.  Only expect a
731 * few, so just rescan the list each time?
732 */
733struct dynfn {
734   struct dynfn *next, *prev;
735   int key[2];
736   char *code;
737};
738
739struct dfn_lists {
740   struct dynfn Vertex2f;
741   struct dynfn Vertex2fv;
742   struct dynfn Vertex3f;
743   struct dynfn Vertex3fv;
744   struct dynfn Color4ub;
745   struct dynfn Color4ubv;
746   struct dynfn Color3ub;
747   struct dynfn Color3ubv;
748   struct dynfn Color4f;
749   struct dynfn Color4fv;
750   struct dynfn Color3f;
751   struct dynfn Color3fv;
752   struct dynfn SecondaryColor3ubEXT;
753   struct dynfn SecondaryColor3ubvEXT;
754   struct dynfn SecondaryColor3fEXT;
755   struct dynfn SecondaryColor3fvEXT;
756   struct dynfn Normal3f;
757   struct dynfn Normal3fv;
758   struct dynfn TexCoord3f;
759   struct dynfn TexCoord3fv;
760   struct dynfn TexCoord2f;
761   struct dynfn TexCoord2fv;
762   struct dynfn TexCoord1f;
763   struct dynfn TexCoord1fv;
764   struct dynfn MultiTexCoord3fARB;
765   struct dynfn MultiTexCoord3fvARB;
766   struct dynfn MultiTexCoord2fARB;
767   struct dynfn MultiTexCoord2fvARB;
768   struct dynfn MultiTexCoord1fARB;
769   struct dynfn MultiTexCoord1fvARB;
770   struct dynfn FogCoordfEXT;
771   struct dynfn FogCoordfvEXT;
772};
773
774struct dfn_generators {
775   struct dynfn *(*Vertex2f)( GLcontext *, const int * );
776   struct dynfn *(*Vertex2fv)( GLcontext *, const int * );
777   struct dynfn *(*Vertex3f)( GLcontext *, const int * );
778   struct dynfn *(*Vertex3fv)( GLcontext *, const int * );
779   struct dynfn *(*Color4ub)( GLcontext *, const int * );
780   struct dynfn *(*Color4ubv)( GLcontext *, const int * );
781   struct dynfn *(*Color3ub)( GLcontext *, const int * );
782   struct dynfn *(*Color3ubv)( GLcontext *, const int * );
783   struct dynfn *(*Color4f)( GLcontext *, const int * );
784   struct dynfn *(*Color4fv)( GLcontext *, const int * );
785   struct dynfn *(*Color3f)( GLcontext *, const int * );
786   struct dynfn *(*Color3fv)( GLcontext *, const int * );
787   struct dynfn *(*SecondaryColor3ubEXT)( GLcontext *, const int * );
788   struct dynfn *(*SecondaryColor3ubvEXT)( GLcontext *, const int * );
789   struct dynfn *(*SecondaryColor3fEXT)( GLcontext *, const int * );
790   struct dynfn *(*SecondaryColor3fvEXT)( GLcontext *, const int * );
791   struct dynfn *(*Normal3f)( GLcontext *, const int * );
792   struct dynfn *(*Normal3fv)( GLcontext *, const int * );
793   struct dynfn *(*TexCoord3f)( GLcontext *, const int * );
794   struct dynfn *(*TexCoord3fv)( GLcontext *, const int * );
795   struct dynfn *(*TexCoord2f)( GLcontext *, const int * );
796   struct dynfn *(*TexCoord2fv)( GLcontext *, const int * );
797   struct dynfn *(*TexCoord1f)( GLcontext *, const int * );
798   struct dynfn *(*TexCoord1fv)( GLcontext *, const int * );
799   struct dynfn *(*MultiTexCoord3fARB)( GLcontext *, const int * );
800   struct dynfn *(*MultiTexCoord3fvARB)( GLcontext *, const int * );
801   struct dynfn *(*MultiTexCoord2fARB)( GLcontext *, const int * );
802   struct dynfn *(*MultiTexCoord2fvARB)( GLcontext *, const int * );
803   struct dynfn *(*MultiTexCoord1fARB)( GLcontext *, const int * );
804   struct dynfn *(*MultiTexCoord1fvARB)( GLcontext *, const int * );
805   struct dynfn *(*FogCoordfEXT)( GLcontext *, const int * );
806   struct dynfn *(*FogCoordfvEXT)( GLcontext *, const int * );
807};
808
809
810
811struct r200_prim {
812   GLuint start;
813   GLuint end;
814   GLuint prim;
815};
816
817   /* A maximum total of 29 elements per vertex:  3 floats for position, 3
818    * floats for normal, 4 floats for color, 4 bytes for secondary color,
819    * 3 floats for each texture unit (18 floats total).
820    *
821    * we maybe need add. 4 to prevent segfault if someone specifies
822    * GL_TEXTURE6/GL_TEXTURE7 (esp. for the codegen-path) (FIXME: )
823    *
824    * The position data is never actually stored here, so 3 elements could be
825    * trimmed out of the buffer.
826    */
827
828#define R200_MAX_VERTEX_SIZE ((3*6)+11)
829
830struct r200_vbinfo {
831   GLint counter, initial_counter;
832   GLint *dmaptr;
833   void (*notify)( void );
834   GLint vertex_size;
835
836   union { float f; int i; r200_color_t color; } vertex[R200_MAX_VERTEX_SIZE];
837
838   GLfloat *normalptr;
839   GLfloat *floatcolorptr;
840   GLfloat *fogptr;
841   r200_color_t *colorptr;
842   GLfloat *floatspecptr;
843   r200_color_t *specptr;
844   GLfloat *texcoordptr[8];	/* 6 (TMU) + 2 for r200_vtxfmt_c.c when GL_TEXTURE6/7 */
845
846
847   GLenum *prim;		/* &ctx->Driver.CurrentExecPrimitive */
848   GLuint primflags;
849   GLboolean enabled;		/* *_NO_VTXFMT / *_NO_TCL env vars */
850   GLboolean installed;
851   GLboolean fell_back;
852   GLboolean recheck;
853   GLint nrverts;
854   GLuint vtxfmt_0, vtxfmt_1;
855
856   GLuint installed_vertex_format;
857   GLuint installed_color_3f_sz;
858
859   struct r200_prim primlist[R200_MAX_PRIMS];
860   int nrprims;
861
862   struct dfn_lists dfn_cache;
863   struct dfn_generators codegen;
864   GLvertexformat vtxfmt;
865};
866
867
868struct r200_context {
869   GLcontext *glCtx;			/* Mesa context */
870
871   /* Driver and hardware state management
872    */
873   struct r200_hw_state hw;
874   struct r200_state state;
875
876   /* Texture object bookkeeping
877    */
878   unsigned              nr_heaps;
879   driTexHeap          * texture_heaps[ R200_NR_TEX_HEAPS ];
880   driTextureObject      swapped;
881   int                   texture_depth;
882   float                 initialMaxAnisotropy;
883
884   /* Rasterization and vertex state:
885    */
886   GLuint TclFallback;
887   GLuint Fallback;
888   GLuint NewGLState;
889   GLuint tnl_index;	/* index of bits for last tnl_install_attrs */
890
891   /* Vertex buffers
892    */
893   struct r200_ioctl ioctl;
894   struct r200_dma dma;
895   struct r200_store store;
896   /* A full state emit as of the first state emit in the main store, in case
897    * the context is lost.
898    */
899   struct r200_store backup_store;
900
901   /* Page flipping
902    */
903   GLuint doPageFlip;
904
905   /* Busy waiting
906    */
907   GLuint do_usleeps;
908   GLuint do_irqs;
909   GLuint irqsEmitted;
910   drm_radeon_irq_wait_t iw;
911
912   /* Clientdata textures;
913    */
914   GLuint prefer_gart_client_texturing;
915
916   /* Drawable, cliprect and scissor information
917    */
918   GLuint numClipRects;			/* Cliprects for the draw buffer */
919   drm_clip_rect_t *pClipRects;
920   unsigned int lastStamp;
921   GLboolean lost_context;
922   GLboolean save_on_next_emit;
923   r200ScreenPtr r200Screen;	/* Screen private DRI data */
924   drm_radeon_sarea_t *sarea;		/* Private SAREA data */
925
926   /* TCL stuff
927    */
928   GLmatrix TexGenMatrix[R200_MAX_TEXTURE_UNITS];
929   GLboolean recheck_texgen[R200_MAX_TEXTURE_UNITS];
930   GLboolean TexGenNeedNormals[R200_MAX_TEXTURE_UNITS];
931   GLuint TexMatEnabled;
932   GLuint TexMatCompSel;
933   GLuint TexGenEnabled;
934   GLuint TexGenCompSel;
935   GLmatrix tmpmat;
936
937   /* VBI / buffer swap
938    */
939   GLuint vbl_seq;
940   GLuint vblank_flags;
941
942   int64_t swap_ust;
943   int64_t swap_missed_ust;
944
945   GLuint swap_count;
946   GLuint swap_missed_count;
947
948
949   /* r200_tcl.c
950    */
951   struct r200_tcl_info tcl;
952
953   /* r200_swtcl.c
954    */
955   struct r200_swtcl_info swtcl;
956
957   /* r200_vtxfmt.c
958    */
959   struct r200_vbinfo vb;
960
961   /* Mirrors of some DRI state
962    */
963   struct r200_dri_mirror dri;
964
965   /* Configuration cache
966    */
967   driOptionCache optionCache;
968
969   GLboolean using_hyperz;
970   GLboolean texmicrotile;
971
972  struct ati_fragment_shader *afs_loaded;
973};
974
975#define R200_CONTEXT(ctx)		((r200ContextPtr)(ctx->DriverCtx))
976
977
978static __inline GLuint r200PackColor( GLuint cpp,
979					GLubyte r, GLubyte g,
980					GLubyte b, GLubyte a )
981{
982   switch ( cpp ) {
983   case 2:
984      return PACK_COLOR_565( r, g, b );
985   case 4:
986      return PACK_COLOR_8888( a, r, g, b );
987   default:
988      return 0;
989   }
990}
991
992
993extern void r200DestroyContext( __DRIcontextPrivate *driContextPriv );
994extern GLboolean r200CreateContext( const __GLcontextModes *glVisual,
995				    __DRIcontextPrivate *driContextPriv,
996				    void *sharedContextPrivate);
997extern void r200SwapBuffers( __DRIdrawablePrivate *dPriv );
998extern GLboolean r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
999				  __DRIdrawablePrivate *driDrawPriv,
1000				  __DRIdrawablePrivate *driReadPriv );
1001extern GLboolean r200UnbindContext( __DRIcontextPrivate *driContextPriv );
1002
1003/* ================================================================
1004 * Debugging:
1005 */
1006#define DO_DEBUG		1
1007
1008#if DO_DEBUG
1009extern int R200_DEBUG;
1010#else
1011#define R200_DEBUG		0
1012#endif
1013
1014#define DEBUG_TEXTURE	0x001
1015#define DEBUG_STATE	0x002
1016#define DEBUG_IOCTL	0x004
1017#define DEBUG_PRIMS	0x008
1018#define DEBUG_VERTS	0x010
1019#define DEBUG_FALLBACKS	0x020
1020#define DEBUG_VFMT	0x040
1021#define DEBUG_CODEGEN	0x080
1022#define DEBUG_VERBOSE	0x100
1023#define DEBUG_DRI       0x200
1024#define DEBUG_DMA       0x400
1025#define DEBUG_SANITY    0x800
1026#define DEBUG_SYNC      0x1000
1027#define DEBUG_PIXEL     0x2000
1028#define DEBUG_MEMORY    0x4000
1029
1030#endif /* __R200_CONTEXT_H__ */
1031