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