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