Merge remote branch 'origin/gallium-0.2' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_context.h
1 /* -*- mode: c; c-basic-offset: 3 -*-
2 *
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27 /*
28 * New fixes:
29 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
30 *
31 * Original rewrite:
32 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
33 *
34 * Authors:
35 * Gareth Hughes <gareth@valinux.com>
36 *
37 */
38
39 #ifndef __TDFX_CONTEXT_H__
40 #define __TDFX_CONTEXT_H__
41
42 #include <sys/time.h>
43 #include "dri_util.h"
44 #ifdef XFree86Server
45 #include "GL/xf86glx.h"
46 #else
47 #include "main/glheader.h"
48 #endif
49 #if defined(__linux__)
50 #include <signal.h>
51 #endif
52
53 #include "drm.h"
54 #include "drm_sarea.h"
55 #include "tdfx_glide.h"
56 #include "xmlconfig.h"
57
58 #include "main/clip.h"
59 #include "main/context.h"
60 #include "main/macros.h"
61 #include "main/matrix.h"
62 #include "main/imports.h"
63 #include "main/mtypes.h"
64
65 #include "tdfx_screen.h"
66
67
68
69
70 #define TDFX_TMU0 GR_TMU0
71 #define TDFX_TMU1 GR_TMU1
72 #define TDFX_TMU_SPLIT 98
73 #define TDFX_TMU_BOTH 99
74 #define TDFX_TMU_NONE 100
75
76
77
78 /* Flags for fxMesa->new_state
79 */
80 #define TDFX_NEW_COLOR 0x0001
81 #define TDFX_NEW_ALPHA 0x0002
82 #define TDFX_NEW_DEPTH 0x0004
83 #define TDFX_NEW_FOG 0x0008
84 #define TDFX_NEW_STENCIL 0x0010
85 #define TDFX_NEW_CLIP 0x0020
86 #define TDFX_NEW_VIEWPORT 0x0040
87 #define TDFX_NEW_CULL 0x0080
88 #define TDFX_NEW_GLIDE 0x0100
89 #define TDFX_NEW_TEXTURE 0x0200
90 #define TDFX_NEW_CONTEXT 0x0400
91 #define TDFX_NEW_LINE 0x0800
92 #define TDFX_NEW_RENDER 0x1000
93 #define TDFX_NEW_STIPPLE 0x2000
94 #define TDFX_NEW_TEXTURE_BIND 0x4000 /* experimental */
95
96
97 /* Flags for fxMesa->dirty
98 */
99 #define TDFX_UPLOAD_COLOR_COMBINE 0x00000001
100 #define TDFX_UPLOAD_ALPHA_COMBINE 0x00000002
101 #define TDFX_UPLOAD_RENDER_BUFFER 0x00000004
102 #define TDFX_UPLOAD_ALPHA_TEST 0x00000008
103 #define TDFX_UPLOAD_ALPHA_REF 0x00000010
104 #define TDFX_UPLOAD_BLEND_FUNC 0x00000020
105 #define TDFX_UPLOAD_DEPTH_MODE 0x00000040
106 #define TDFX_UPLOAD_DEPTH_BIAS 0x00000080
107 #define TDFX_UPLOAD_DEPTH_FUNC 0x00000100
108 #define TDFX_UPLOAD_DEPTH_MASK 0x00000200
109 #define TDFX_UPLOAD_FOG_MODE 0x00000400
110 #define TDFX_UPLOAD_FOG_COLOR 0x00000800
111 #define TDFX_UPLOAD_FOG_TABLE 0x00001000
112 #define TDFX_UPLOAD_CONSTANT_COLOR 0x00002000
113
114 #define TDFX_UPLOAD_CLIP 0x00002000
115 #define TDFX_UPLOAD_CULL 0x00004000
116 #define TDFX_UPLOAD_VERTEX_LAYOUT 0x00008000
117 #define TDFX_UPLOAD_COLOR_MASK 0x00010000
118 #define TDFX_UPLOAD_DITHER 0x00040000
119 #define TDFX_UPLOAD_STENCIL 0x00080000
120
121 #define TDFX_UPLOAD_TEXTURE_SOURCE 0x00100000
122 #define TDFX_UPLOAD_TEXTURE_PARAMS 0x00200000
123 #define TDFX_UPLOAD_TEXTURE_PALETTE 0x00400000
124 #define TDFX_UPLOAD_TEXTURE_ENV 0x00800000
125 #define TDFX_UPLOAD_TEXTURE_IMAGES 0x01000000
126
127 #define TDFX_UPLOAD_LINE 0x02000000
128
129 #define TDFX_UPLOAD_STIPPLE 0x04000000
130
131 /* Flags for software fallback cases */
132 /* See correponding strings in tdfx_tris.c */
133 #define TDFX_FALLBACK_TEXTURE_MAP 0x0001
134 #define TDFX_FALLBACK_DRAW_BUFFER 0x0002
135 #define TDFX_FALLBACK_SPECULAR 0x0004
136 #define TDFX_FALLBACK_STENCIL 0x0008
137 #define TDFX_FALLBACK_RENDER_MODE 0x0010
138 #define TDFX_FALLBACK_LOGICOP 0x0020
139 #define TDFX_FALLBACK_TEXTURE_ENV 0x0040
140 #define TDFX_FALLBACK_TEXTURE_BORDER 0x0080
141 #define TDFX_FALLBACK_COLORMASK 0x0100
142 #define TDFX_FALLBACK_BLEND 0x0200
143 #define TDFX_FALLBACK_LINE_STIPPLE 0x0400
144 #define TDFX_FALLBACK_DISABLE 0x0800
145
146 /* Different Glide vertex layouts
147 */
148 #define TDFX_LAYOUT_TINY 0
149 #define TDFX_LAYOUT_NOTEX 1
150 #define TDFX_LAYOUT_SINGLE 2
151 #define TDFX_LAYOUT_MULTI 3
152 #define TDFX_LAYOUT_PROJ1 4
153 #define TDFX_LAYOUT_PROJ2 5
154 #define TDFX_NUM_LAYOUTS 6
155
156 #define TDFX_XY_OFFSET 0
157 #define TDFX_Z_OFFSET 8
158 #define TDFX_Q_OFFSET 12
159 #define TDFX_ARGB_OFFSET 16
160 #define TDFX_FOG_OFFSET 20
161 #define TDFX_ST0_OFFSET 24
162 #define TDFX_ST1_OFFSET 32
163 #define TDFX_Q0_OFFSET 40
164 #define TDFX_Q1_OFFSET 44
165
166
167 /* Flags for buffer clears
168 */
169 #define TDFX_FRONT 0x1
170 #define TDFX_BACK 0x2
171 #define TDFX_DEPTH 0x4
172 #define TDFX_STENCIL 0x8
173
174 /*
175 * Subpixel offsets to adjust Mesa's (true) window coordinates to
176 * Glide coordinates. We need these to ensure precise rasterization.
177 * Otherwise, we'll fail a bunch of conformance tests.
178 */
179 #define TRI_X_OFFSET ( 0.0F)
180 #define TRI_Y_OFFSET ( 0.0F)
181 #define LINE_X_OFFSET ( 0.0F)
182 #define LINE_Y_OFFSET ( 0.125F)
183 #define PNT_X_OFFSET ( 0.375F)
184 #define PNT_Y_OFFSET ( 0.375F)
185
186
187 #define TDFX_DEPTH_BIAS_SCALE 128
188
189 /* Including xf86PciInfo.h causes a bunch of errors
190 */
191 #ifndef PCI_CHIP_BANSHEE
192 #define PCI_CHIP_BANSHEE 0x0003
193 #define PCI_CHIP_VOODOO3 0x0005
194 #define PCI_CHIP_VOODOO4 0x0009
195 #define PCI_CHIP_VOODOO5 0x0009
196 #endif
197
198 #define TDFX_IS_BANSHEE( fxMesa ) \
199 ( fxMesa->fxScreen->deviceID == PCI_CHIP_BANSHEE )
200 #define TDFX_IS_VOODOO3( fxMesa ) \
201 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO3 )
202 #define TDFX_IS_VOODOO4( fxMesa ) \
203 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4 )
204 #define TDFX_IS_VOODOO5( fxMesa ) \
205 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5 )
206 #define TDFX_IS_NAPALM( fxMesa ) \
207 ( (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4) || \
208 (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5) )
209
210
211 #define PACK_BGRA32(R, G, B, A) \
212 ( (((GLuint) (R)) << 16) | \
213 (((GLuint) (G)) << 8) | \
214 (((GLuint) (B)) ) | \
215 (((GLuint) (A)) << 24) )
216
217 #define PACK_RGBA32(R, G, B, A) \
218 ( (((GLuint) (R)) ) | \
219 (((GLuint) (G)) << 8) | \
220 (((GLuint) (B)) << 16) | \
221 (((GLuint) (A)) << 24) )
222
223 /*
224 * The first two macros are to pack 8 bit color
225 * channel values into a 565 format.
226 */
227 #define PACK_RGB16(R, G, B) \
228 ((((GLuint) (R) & 0xF8) << 8) | \
229 (((GLuint) (G) & 0xFC) << 3) | \
230 (((GLuint) (B) & 0xFF) >> 3))
231 #define PACK_BGR16(R, G, B) \
232 ((((GLuint) (B) & 0xF8) << 8) | \
233 (((GLuint) (G) & 0xFC) << 3) | \
234 (((GLuint) (R) & 0xFF) >> 3))
235 /*
236 * The second two macros pack 8 bit color channel values
237 * into 1555 values.
238 */
239 #define PACK_RGBA16(R, G, B, A) \
240 (((((GLuint) (A) & 0xFF) > 0) << 15)| \
241 (((GLuint) (R) & 0xF8) << 7) | \
242 (((GLuint) (G) & 0xF8) << 2) | \
243 (((GLuint) (B) & 0xF8) >> 3))
244 #define PACK_BGRA16(R, G, B, A) \
245 (((((GLuint) (A) & 0xFF) > 0) << 15)| \
246 (((GLuint) (B) & 0xF8) << 7) | \
247 (((GLuint) (G) & 0xF8) << 2) | \
248 (((GLuint) (R) & 0xF8) >> 3))
249
250 /* Used in calls to grColorMaskv()...
251 */
252 extern const GLboolean false4[4];
253 extern const GLboolean true4[4];
254
255
256 typedef struct tdfx_context tdfxContextRec;
257 typedef struct tdfx_context *tdfxContextPtr;
258
259
260 typedef struct {
261 volatile int fifoPtr;
262 volatile int fifoRead;
263 volatile int fifoOwner;
264 volatile int ctxOwner;
265 volatile int texOwner;
266 }
267 TDFXSAREAPriv;
268
269
270 typedef struct {
271 GLuint swapBuffer;
272 GLuint reqTexUpload;
273 GLuint texUpload;
274 GLuint memTexUpload;
275 GLuint texSwaps;
276 } tdfxStats;
277
278
279
280 /*
281 * Memory range from startAddr to endAddr-1
282 */
283 typedef struct mem_range {
284 struct mem_range *next;
285 FxU32 startAddr, endAddr;
286 }
287 tdfxMemRange;
288
289
290 typedef struct {
291 GLsizei width, height; /* image size */
292 GLint wScale, hScale; /* scale factors */
293 GrTextureFormat_t glideFormat; /* Glide image format */
294 }
295 tdfxMipMapLevel;
296
297
298 #define TDFX_NUM_TMU 2
299
300
301 typedef struct tdfxTexInfo_t
302 {
303 GLboolean isInTM;
304 GLboolean reloadImages; /* if true, resend images to Glide */
305 GLuint lastTimeUsed;
306 FxU32 whichTMU;
307
308 GrTexInfo info;
309 GrAspectRatio_t aspectRatio;
310 tdfxMemRange *tm[TDFX_NUM_TMU];
311
312 GLint minLevel, maxLevel;
313 GrTextureFilterMode_t minFilt;
314 GrTextureFilterMode_t magFilt;
315 GrTextureClampMode_t sClamp;
316 GrTextureClampMode_t tClamp;
317 FxBool LODblend;
318 GrMipMapMode_t mmMode;
319
320 GLfloat sScale, tScale; /* texcoord scale factor */
321
322 GrTexTable_t paltype;
323 GuTexPalette palette;
324
325 GLboolean padded;
326 }
327 tdfxTexInfo;
328
329
330 #define TDFX_TEXTURE_DATA(mesaObj) ((tdfxTexInfo *)((mesaObj)->DriverData))
331
332 #define TDFX_TEXIMAGE_DATA(mesaImg) ((tdfxMipMapLevel *)((mesaImg)->DriverData))
333
334
335
336 /*
337 * This is state which may be shared by several tdfx contexts.
338 * It hangs off of Mesa's gl_shared_state object (ctx->Shared->DriverData).
339 */
340 struct tdfxSharedState {
341 GLboolean umaTexMemory;
342 GLuint totalTexMem[TDFX_NUM_TMU]; /* constant */
343 GLuint freeTexMem[TDFX_NUM_TMU]; /* changes as we go */
344 tdfxMemRange *tmPool;
345 tdfxMemRange *tmFree[TDFX_NUM_TMU];
346 };
347
348
349
350 /* ================================================================
351 * The vertex structures.
352 */
353 /* The size of this union is not of relevence:
354 */
355 typedef struct tdfx_vertex_t {
356 GLfloat x, y, z; /* Coordinates in screen space */
357 GLfloat rhw; /* Reciprocal homogeneous w */
358 GLubyte color[4]; /* Diffuse color */
359 GLfloat fog;
360 GLfloat tu0, tv0; /* Texture 0 coordinates */
361 GLfloat tu1, tv1; /* Texture 1 coordinates */
362 GLfloat tq0, tq1; /* Texture 0/1 q coords */
363 unsigned char pspec[4]; /* B, G, R, A [0..255] */
364 float psize; /* point size */
365 long pad[16 - 14]; /* ensure 64b structure */
366 } tdfxVertex, *tdfxVertexPtr;
367
368
369 /* ================================================================
370 *
371 * We want to keep a mirror of the Glide function call parameters so we
372 * can avoid updating our state too often.
373 *
374 * Each of these broad groups will typically have a new state flag
375 * associated with it, and will be updated together. The individual
376 * Glide function calls each have a dirty flag and will only be called
377 * when absolutely necessary.
378 */
379
380 /* for grTexSource() */
381 struct tdfx_texsource {
382 FxU32 StartAddress;
383 FxU32 EvenOdd;
384 GrTexInfo *Info;
385 };
386
387 /* Texture object params */
388 struct tdfx_texparams {
389 GrTextureClampMode_t sClamp;
390 GrTextureClampMode_t tClamp;
391 GrTextureFilterMode_t minFilt;
392 GrTextureFilterMode_t magFilt;
393 GrMipMapMode_t mmMode;
394 FxBool LODblend;
395 GLfloat LodBias;
396 };
397
398 /* for grTexDownloadTable() texture palettes */
399 struct tdfx_texpalette {
400 GrTexTable_t Type;
401 void *Data;
402 };
403
404 /* for Voodoo3/Banshee's grColorCombine() and grAlphaCombine() */
405 struct tdfx_combine {
406 GrCombineFunction_t Function; /* Combine function */
407 GrCombineFactor_t Factor; /* Combine scale factor */
408 GrCombineLocal_t Local; /* Local combine source */
409 GrCombineOther_t Other; /* Other combine source */
410 FxBool Invert; /* Combine result inversion flag */
411 };
412
413 /* for Voodoo3's grTexCombine() */
414 struct tdfx_texcombine {
415 GrCombineFunction_t FunctionRGB;
416 GrCombineFactor_t FactorRGB;
417 GrCombineFunction_t FunctionAlpha;
418 GrCombineFactor_t FactorAlpha;
419 FxBool InvertRGB;
420 FxBool InvertAlpha;
421 };
422
423
424 /* for Voodoo5's grColorCombineExt() */
425 struct tdfx_combine_color_ext {
426 GrCCUColor_t SourceA;
427 GrCombineMode_t ModeA;
428 GrCCUColor_t SourceB;
429 GrCombineMode_t ModeB;
430 GrCCUColor_t SourceC;
431 FxBool InvertC;
432 GrCCUColor_t SourceD;
433 FxBool InvertD;
434 FxU32 Shift;
435 FxBool Invert;
436 };
437
438 /* for Voodoo5's grAlphaCombineExt() */
439 struct tdfx_combine_alpha_ext {
440 GrACUColor_t SourceA;
441 GrCombineMode_t ModeA;
442 GrACUColor_t SourceB;
443 GrCombineMode_t ModeB;
444 GrACUColor_t SourceC;
445 FxBool InvertC;
446 GrACUColor_t SourceD;
447 FxBool InvertD;
448 FxU32 Shift;
449 FxBool Invert;
450 };
451
452 /* for Voodoo5's grTexColorCombineExt() */
453 struct tdfx_color_texenv {
454 GrTCCUColor_t SourceA;
455 GrCombineMode_t ModeA;
456 GrTCCUColor_t SourceB;
457 GrCombineMode_t ModeB;
458 GrTCCUColor_t SourceC;
459 FxBool InvertC;
460 GrTCCUColor_t SourceD;
461 FxBool InvertD;
462 FxU32 Shift;
463 FxBool Invert;
464 };
465
466 /* for Voodoo5's grTexAlphaCombineExt() */
467 struct tdfx_alpha_texenv {
468 GrTACUColor_t SourceA;
469 GrCombineMode_t ModeA;
470 GrTACUColor_t SourceB;
471 GrCombineMode_t ModeB;
472 GrTACUColor_t SourceC;
473 FxBool InvertC;
474 GrTCCUColor_t SourceD;
475 FxBool InvertD;
476 FxU32 Shift;
477 FxBool Invert;
478 };
479
480 /* Voodoo5's texture combine environment */
481 struct tdfx_texcombine_ext {
482 struct tdfx_alpha_texenv Alpha;
483 struct tdfx_color_texenv Color;
484 GrColor_t EnvColor;
485 };
486
487 /* Used to track changes between Glide's state and Mesa's */
488 struct tdfx_texstate {
489 GLuint Enabled[2]; /* values ala ctx->Texture.Unit[i]._ReallyEnabled */
490 GLenum EnvMode[TDFX_NUM_TMU]; /* index is Glide index, not OpenGL */
491 GLenum TexFormat[TDFX_NUM_TMU]; /* index is Glide index, not OpenGL */
492 };
493
494 struct tdfx_color {
495 GrColor_t ClearColor; /* Buffer clear color value */
496 GrAlpha_t ClearAlpha; /* Buffer clear alpha value */
497 FxBool ColorMask[4]; /* Per-channel write enable flags */
498
499 GrColor_t MonoColor; /* Constant color value */
500
501 /* Alpha testing */
502 GrCmpFnc_t AlphaFunc; /* Alpha test function */
503 GrAlpha_t AlphaRef; /* Alpha ref value in range [0,255] */
504
505 /* Blending */
506 GrAlphaBlendFnc_t BlendSrcRGB; /* Blend source RGB factor */
507 GrAlphaBlendFnc_t BlendDstRGB; /* Blend destination RGB factor */
508 GrAlphaBlendOp_t BlendEqRGB; /* Blend source RGB op */
509 GrAlphaBlendFnc_t BlendSrcA; /* Blend source alpha factor */
510 GrAlphaBlendFnc_t BlendDstA; /* Blend destination alpha factor */
511 GrAlphaBlendOp_t BlendEqA; /* Blend source alpha op */
512
513 GrDitherMode_t Dither; /* Dither enable */
514 };
515
516 struct tdfx_depth {
517 GrDepthBufferMode_t Mode; /* Fixed-point Z or floating-point W */
518 FxI32 Bias; /* Polygon offset factor */
519 GrCmpFnc_t Func; /* Depth test function */
520 FxU32 Clear; /* Buffer clear value */
521 FxBool Mask; /* Write enable flag */
522 };
523
524 struct tdfx_stipple {
525 GrStippleMode_t Mode; /* Stipple enable/disable */
526 FxU32 Pattern; /* 8x4 Stipple Pattern */
527 };
528
529 struct tdfx_fog {
530 GrFogMode_t Mode; /* Glide fog mode */
531 GrColor_t Color; /* Fog color value */
532 GLenum TableMode; /* GL fog mode currently in table */
533 GrFog_t *Table; /* Fog value table */
534 FxFloat Density; /* Density >= 0 */
535 FxFloat Near; /* Start distance in eye coords */
536 FxFloat Far; /* End distance in eye coords */
537 };
538
539 struct tdfx_stencil {
540 GrCmpFnc_t Function; /* Stencil function */
541 GrStencil_t RefValue; /* Stencil reference value */
542 GrStencil_t ValueMask; /* Value mask */
543 GrStencil_t WriteMask; /* Write mask */
544 GrStencil_t FailFunc; /* Stencil fail function */
545 GrStencil_t ZFailFunc; /* Stencil pass, depth fail function */
546 GrStencil_t ZPassFunc; /* Stencil pass, depth pass function */
547 GrStencil_t Clear; /* Buffer clear value */
548 };
549
550 struct tdfx_scissor {
551 FxU32 minX, minY; /* Lower left corner */
552 FxU32 maxX, maxY; /* Upper right corner */
553 };
554
555 struct tdfx_viewport {
556 GrCoordinateSpaceMode_t Mode; /* Coordinate space */
557 FxI32 X, Y; /* Position */
558 FxI32 Width, Height; /* Size */
559 FxFloat Near, Far; /* Depth buffer range */
560 };
561
562 struct tdfx_glide {
563 void *State; /* Mirror of internal Glide state */
564 GrContext_t Context; /* Glide context identifier */
565 FxI32 Board; /* Current graphics subsystem */
566 GrColorFormat_t ColorFormat; /* Framebuffer format */
567 GrOriginLocation_t Origin; /* Location of screen space origin */
568
569 FxBool Initialized; /* Glide initialization done? */
570
571 FxI32 SwapInterval; /* SwapBuffers interval */
572 FxI32 MaxPendingSwaps; /* Maximum outstanding SwapBuffers */
573 FxI32 TextureAlign;
574
575 /* Extensions */
576 FxBool HaveCombineExt; /* COMBINE */
577 FxBool HaveCommandTransportExt; /* COMMAND_TRANSPORT */
578 FxBool HaveFogCoordExt; /* FOGCOORD */
579 FxBool HavePixelExt; /* PIXEXT */
580 FxBool HaveTextureBufferExt; /* TEXTUREBUFFER */
581 FxBool HaveTexFmtExt; /* TEXFMT */
582 FxBool HaveTexUMAExt; /* TEXUMA */
583 FxBool HaveMirrorExt; /* MIRROR */
584 FxBool HaveTexus2; /* Texus 2 - FXT1 */
585
586 /* Glide library function pointers */
587 void (*grDrawPoint)( const void *pt );
588 void (*grDrawLine)( const void *v1, const void *v2 );
589 void (*grDrawTriangle)( const void *a, const void *b, const void *c );
590 void (*grVertexLayout)(FxU32 param, FxI32 offset, FxU32 mode);
591 void (*grDrawVertexArray)(FxU32 mode, FxU32 Count, void *pointers);
592 void (*grDrawVertexArrayContiguous)(FxU32 mode, FxU32 Count,
593 void *pointers, FxU32 stride);
594 void (*grBufferClear)( GrColor_t color, GrAlpha_t alpha, FxU32 depth );
595 void (*grBufferSwap)( FxU32 swap_interval );
596 void (*grRenderBuffer)( GrBuffer_t buffer );
597 void (*grErrorSetCallback)( GrErrorCallbackFnc_t fnc );
598 void (*grFinish)(void);
599 void (*grFlush)(void);
600 GrContext_t (*grSstWinOpen)(FxU32 hWnd,
601 GrScreenResolution_t screen_resolution,
602 GrScreenRefresh_t refresh_rate,
603 GrColorFormat_t color_format,
604 GrOriginLocation_t origin_location,
605 int nColBuffers,
606 int nAuxBuffers);
607 void (*grSstWinClose)( GrContext_t context );
608 /* Not used */
609 #if 0
610 void (*grSetNumPendingBuffers)(FxI32 NumPendingBuffers);
611 #endif
612 void (*grSelectContext)( GrContext_t context );
613 void (*grSstOrigin)(GrOriginLocation_t origin);
614 void (*grSstSelect)( int which_sst );
615 void (*grAlphaBlendFunction)(GrAlphaBlendFnc_t rgb_sf,
616 GrAlphaBlendFnc_t rgb_df,
617 GrAlphaBlendFnc_t alpha_sf,
618 GrAlphaBlendFnc_t alpha_df);
619 void (*grAlphaCombine)(GrCombineFunction_t function,
620 GrCombineFactor_t factor,
621 GrCombineLocal_t local, GrCombineOther_t other,
622 FxBool invert);
623 void (*grAlphaControlsITRGBLighting)( FxBool enable );
624 void (*grAlphaTestFunction)( GrCmpFnc_t function );
625 void (*grAlphaTestReferenceValue)( GrAlpha_t value );
626 void (*grChromakeyMode)( GrChromakeyMode_t mode );
627 void (*grChromakeyValue)( GrColor_t value );
628 void (*grClipWindow)( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy );
629 void (*grColorCombine)( GrCombineFunction_t function,
630 GrCombineFactor_t factor,
631 GrCombineLocal_t local,
632 GrCombineOther_t other,
633 FxBool invert );
634 void (*grColorMask)( FxBool rgb, FxBool a );
635 void (*grCullMode)( GrCullMode_t mode );
636 void (*grConstantColorValue)( GrColor_t value );
637 void (*grDepthBiasLevel)( FxI32 level );
638 void (*grDepthBufferFunction)( GrCmpFnc_t function );
639 void (*grDepthBufferMode)( GrDepthBufferMode_t mode );
640 void (*grDepthMask)( FxBool mask );
641 void (*grDisableAllEffects)( void );
642 void (*grDitherMode)( GrDitherMode_t mode );
643 void (*grFogColorValue)( GrColor_t fogcolor );
644 void (*grFogMode)( GrFogMode_t mode );
645 void (*grFogTable)( const GrFog_t ft[] );
646 void (*grLoadGammaTable)( FxU32 nentries, FxU32 *red, FxU32 *green, FxU32 *blue);
647 void (*grSplash)(float x, float y, float width, float height, FxU32 frame);
648 FxU32 (*grGet)( FxU32 pname, FxU32 plength, FxI32 *params );
649 const char * (*grGetString)( FxU32 pname );
650 FxI32 (*grQueryResolutions)( const GrResolution *resTemplate,
651 GrResolution *output );
652 FxBool (*grReset)( FxU32 what );
653 GrProc (*grGetProcAddress)( char *procName );
654 void (*grEnable)( GrEnableMode_t mode );
655 void (*grDisable)( GrEnableMode_t mode );
656 void (*grCoordinateSpace)( GrCoordinateSpaceMode_t mode );
657 void (*grDepthRange)( FxFloat n, FxFloat f );
658 void (*grStippleMode)( GrStippleMode_t mode );
659 void (*grStipplePattern)( GrStipplePattern_t mode );
660 void (*grViewport)( FxI32 x, FxI32 y, FxI32 width, FxI32 height );
661 FxU32 (*grTexCalcMemRequired)(GrLOD_t lodmin, GrLOD_t lodmax,
662 GrAspectRatio_t aspect, GrTextureFormat_t fmt);
663 FxU32 (*grTexTextureMemRequired)( FxU32 evenOdd, GrTexInfo *info );
664 FxU32 (*grTexMinAddress)( GrChipID_t tmu );
665 FxU32 (*grTexMaxAddress)( GrChipID_t tmu );
666 void (*grTexNCCTable)( GrNCCTable_t table );
667 void (*grTexSource)( GrChipID_t tmu, FxU32 startAddress,
668 FxU32 evenOdd, GrTexInfo *info );
669 void (*grTexClampMode)( GrChipID_t tmu,
670 GrTextureClampMode_t s_clampmode,
671 GrTextureClampMode_t t_clampmode );
672 void (*grTexCombine)( GrChipID_t tmu,
673 GrCombineFunction_t rgb_function,
674 GrCombineFactor_t rgb_factor,
675 GrCombineFunction_t alpha_function,
676 GrCombineFactor_t alpha_factor,
677 FxBool rgb_invert,
678 FxBool alpha_invert);
679 void (*grTexDetailControl)( GrChipID_t tmu, int lod_bias,
680 FxU8 detail_scale, float detail_max );
681 void (*grTexFilterMode)( GrChipID_t tmu,
682 GrTextureFilterMode_t minfilter_mode,
683 GrTextureFilterMode_t magfilter_mode );
684 void (*grTexLodBiasValue)(GrChipID_t tmu, float bias );
685 void (*grTexDownloadMipMap)( GrChipID_t tmu, FxU32 startAddress,
686 FxU32 evenOdd, GrTexInfo *info );
687 void (*grTexDownloadMipMapLevel)( GrChipID_t tmu,
688 FxU32 startAddress,
689 GrLOD_t thisLod,
690 GrLOD_t largeLod,
691 GrAspectRatio_t aspectRatio,
692 GrTextureFormat_t format,
693 FxU32 evenOdd,
694 void *data );
695 FxBool (*grTexDownloadMipMapLevelPartial)( GrChipID_t tmu,
696 FxU32 startAddress,
697 GrLOD_t thisLod,
698 GrLOD_t largeLod,
699 GrAspectRatio_t aspectRatio,
700 GrTextureFormat_t format,
701 FxU32 evenOdd,
702 void *data,
703 int start,
704 int end );
705 void (*grTexDownloadTable)( GrTexTable_t type, void *data );
706 void (*grTexDownloadTablePartial)( GrTexTable_t type,
707 void *data, int start, int end );
708 void (*grTexMipMapMode)( GrChipID_t tmu, GrMipMapMode_t mode,
709 FxBool lodBlend );
710 void (*grTexMultibase)( GrChipID_t tmu, FxBool enable );
711 void (*grTexMultibaseAddress)( GrChipID_t tmu,
712 GrTexBaseRange_t range,
713 FxU32 startAddress,
714 FxU32 evenOdd,
715 GrTexInfo *info );
716 FxBool (*grLfbLock)( GrLock_t type, GrBuffer_t buffer,
717 GrLfbWriteMode_t writeMode,
718 GrOriginLocation_t origin, FxBool pixelPipeline,
719 GrLfbInfo_t *info );
720 FxBool (*grLfbUnlock)( GrLock_t type, GrBuffer_t buffer );
721 void (*grLfbConstantAlpha)( GrAlpha_t alpha );
722 void (*grLfbConstantDepth)( FxU32 depth );
723 void (*grLfbWriteColorSwizzle)(FxBool swizzleBytes, FxBool swapWords);
724 void (*grLfbWriteColorFormat)(GrColorFormat_t colorFormat);
725 FxBool (*grLfbWriteRegion)( GrBuffer_t dst_buffer,
726 FxU32 dst_x, FxU32 dst_y,
727 GrLfbSrcFmt_t src_format,
728 FxU32 src_width, FxU32 src_height,
729 FxBool pixelPipeline,
730 FxI32 src_stride, void *src_data );
731 FxBool (*grLfbReadRegion)( GrBuffer_t src_buffer,
732 FxU32 src_x, FxU32 src_y,
733 FxU32 src_width, FxU32 src_height,
734 FxU32 dst_stride, void *dst_data );
735 void (*grGlideInit)( void );
736 void (*grGlideShutdown)( void );
737 void (*grGlideGetState)( void *state );
738 void (*grGlideSetState)( const void *state );
739 void (*grGlideGetVertexLayout)( void *layout );
740 void (*grGlideSetVertexLayout)( const void *layout );
741 /* Glide utility functions */
742 void (*guFogGenerateExp)( GrFog_t *fogtable, float density );
743 void (*guFogGenerateExp2)( GrFog_t *fogtable, float density );
744 void (*guFogGenerateLinear)(GrFog_t *fogtable, float nearZ, float farZ );
745 /* DRI functions */
746 void (*grDRIOpen)( char *pFB, char *pRegs, int deviceID,
747 int width, int height,
748 int mem, int cpp, int stride,
749 int fifoOffset, int fifoSize,
750 int fbOffset, int backOffset, int depthOffset,
751 int textureOffset, int textureSize,
752 volatile int *fifoPtr, volatile int *fifoRead );
753 void (*grDRIPosition)( int x, int y, int w, int h,
754 int numClip, drm_clip_rect_t *pClip );
755 void (*grDRILostContext)( void );
756 void (*grDRIImportFifo)( int fifoPtr, int fifoRead );
757 void (*grDRIInvalidateAll)( void );
758 void (*grDRIResetSAREA)( void );
759 void (*grDRIBufferSwap)( FxU32 swapInterval );
760 /* Glide extensions */
761 /* PIXEXT extension */
762 void (*grStencilFunc)( GrCmpFnc_t func, GrStencil_t ref, GrStencil_t mask );
763 void (*grStencilMask)( GrStencil_t mask );
764 void (*grStencilOp)( GrStencilOp_t fail, GrStencilOp_t zfail,
765 GrStencilOp_t zpass );
766 void (*grBufferClearExt)( GrColor_t color, GrAlpha_t alpha,
767 FxU32 depth, GrStencil_t stencil );
768 void (*grColorMaskExt)( FxBool r, FxBool g, FxBool b, FxBool a );
769 /* COMBINE extension */
770 void (*grColorCombineExt)( GrCCUColor_t a, GrCombineMode_t a_mode,
771 GrCCUColor_t b, GrCombineMode_t b_mode,
772 GrCCUColor_t c, FxBool c_invert,
773 GrCCUColor_t d, FxBool d_invert,
774 FxU32 shift, FxBool invert );
775 void (*grTexColorCombineExt)( FxU32 tmu,
776 GrTCCUColor_t a, GrCombineMode_t a_mode,
777 GrTCCUColor_t b, GrCombineMode_t b_mode,
778 GrTCCUColor_t c, FxBool c_invert,
779 GrTCCUColor_t d, FxBool d_invert,
780 FxU32 shift, FxBool invert );
781 void (*grAlphaCombineExt)( GrACUColor_t a, GrCombineMode_t a_mode,
782 GrACUColor_t b, GrCombineMode_t b_mode,
783 GrACUColor_t c, FxBool c_invert,
784 GrACUColor_t d, FxBool d_invert,
785 FxU32 shift, FxBool invert );
786 void (*grTexAlphaCombineExt)( FxU32 tmu,
787 GrTACUColor_t a, GrCombineMode_t a_mode,
788 GrTACUColor_t b, GrCombineMode_t b_mode,
789 GrTACUColor_t c, FxBool c_invert,
790 GrTACUColor_t d, FxBool d_invert,
791 FxU32 shift, FxBool invert );
792 void (*grAlphaBlendFunctionExt)( GrAlphaBlendFnc_t rgb_sf,
793 GrAlphaBlendFnc_t rgb_df,
794 GrAlphaBlendOp_t rgb_op,
795 GrAlphaBlendFnc_t alpha_sf,
796 GrAlphaBlendFnc_t alpha_df,
797 GrAlphaBlendOp_t alpha_op );
798 void (*grConstantColorValueExt)( FxU32 tmu, GrColor_t value );
799 /* Texus 2 */
800 void (*txImgQuantize)( void *xxx_unknown_arguments );
801 void (*txImgDequantizeFXT1)( void *txMip, void *pxMip );
802 void (*txErrorSetCallback)( void *fnc );
803 };
804
805 typedef void (*tdfx_tri_func)( tdfxContextPtr, tdfxVertex *, tdfxVertex *,
806 tdfxVertex * );
807 typedef void (*tdfx_line_func)( tdfxContextPtr, tdfxVertex *, tdfxVertex * );
808 typedef void (*tdfx_point_func)( tdfxContextPtr, tdfxVertex * );
809
810 struct tdfx_context {
811 /* Set once and never changed:
812 */
813 GLcontext *glCtx; /* The core Mesa context */
814
815 GLuint new_gl_state;
816 GLuint new_state;
817 GLuint dirty;
818
819 /* Mirror of hardware state, Glide parameters
820 */
821 GLuint tmu_source[TDFX_NUM_TMU];
822 struct tdfx_texsource TexSource[TDFX_NUM_TMU];
823 struct tdfx_texparams TexParams[TDFX_NUM_TMU];
824 struct tdfx_texpalette TexPalette;
825
826 /* Voodoo3 texture/color combine state */
827 struct tdfx_combine ColorCombine;
828 struct tdfx_combine AlphaCombine;
829 struct tdfx_texcombine TexCombine[TDFX_NUM_TMU];
830
831 /* Voodoo5 texture/color combine state */
832 struct tdfx_combine_color_ext ColorCombineExt;
833 struct tdfx_combine_alpha_ext AlphaCombineExt;
834 struct tdfx_texcombine_ext TexCombineExt[TDFX_NUM_TMU];
835
836 /* Tracks tex state difference between Glide and Mesa */
837 struct tdfx_texstate TexState;
838
839 GrBuffer_t DrawBuffer; /* Current draw buffer */
840 GrBuffer_t ReadBuffer; /* Current read buffer */
841
842 struct tdfx_color Color;
843 struct tdfx_depth Depth;
844 struct tdfx_fog Fog;
845 struct tdfx_stencil Stencil;
846 struct tdfx_scissor Scissor;
847 struct tdfx_viewport Viewport;
848 struct tdfx_stipple Stipple;
849
850 GrCullMode_t CullMode;
851
852 struct tdfx_glide Glide;
853
854 /* Fallback rasterization functions
855 */
856 tdfx_point_func draw_point;
857 tdfx_line_func draw_line;
858 tdfx_tri_func draw_triangle;
859
860
861 /* Variable-size Glide vertex formats
862 */
863 GLuint vertexFormat; /* the current format */
864 void *layout[TDFX_NUM_LAYOUTS];
865 tdfxVertex *verts;
866
867 GLfloat hw_viewport[16];
868
869 GLuint SetupIndex;
870 GLuint SetupNewInputs;
871 GLuint RenderIndex;
872 GLuint Fallback;
873 GLenum render_primitive; /* what GL thinks */
874 GLenum raster_primitive; /* what the hardware thinks */
875
876 GLfloat sScale0, tScale0;
877 GLfloat sScale1, tScale1;
878
879 GLuint texBindNumber;
880 GLint tmuSrc;
881
882 int screen_width;
883 int screen_height;
884
885 GLboolean haveTwoTMUs; /* True if we have 2 tmu's */
886 GLboolean haveHwAlpha;
887 GLboolean haveHwStencil;
888 GLboolean haveHwStipple;
889
890 GLint maxPendingSwapBuffers;
891
892 char rendererString[100];
893
894 /* stuff added for DRI */
895 __DRIscreenPrivate *driScreen;
896 __DRIcontextPrivate *driContext;
897
898 /**
899 * DRI drawable bound to this context for drawing.
900 */
901 __DRIdrawablePrivate *driDrawable;
902
903 /**
904 * DRI drawable bound to this context for reading.
905 */
906 __DRIdrawablePrivate *driReadable;
907
908 drm_context_t hHWContext;
909 drm_hw_lock_t *driHwLock;
910 int driFd;
911 tdfxScreenPrivate *fxScreen;
912 TDFXSAREAPriv *sarea;
913
914
915 /*
916 * Changes during execution:
917 */
918 int width, height; /* size of window */
919 int x_offset; /* distance from window left to screen left */
920 int y_offset; /* distance from window top to screen top */
921 int y_delta; /* distance from window bottom to screen bottom */
922
923 int numClipRects;
924 drm_clip_rect_t *pClipRects;
925 GLboolean scissoredClipRects; /* if true, pClipRects is private storage */
926
927 GuTexPalette glbPalette; /* global texture palette */
928
929 tdfxStats stats;
930
931 /* Configuration cache
932 */
933 driOptionCache optionCache;
934 };
935
936 #define TDFX_CONTEXT(ctx) ((tdfxContextPtr)((ctx)->DriverCtx))
937
938
939 extern GLboolean
940 tdfxCreateContext( const __GLcontextModes *mesaVis,
941 __DRIcontextPrivate *driContextPriv,
942 void *sharedContextPrivate );
943
944 extern void
945 tdfxDestroyContext( __DRIcontextPrivate *driContextPriv );
946
947 extern GLboolean
948 tdfxUnbindContext( __DRIcontextPrivate *driContextPriv );
949
950 extern GLboolean
951 tdfxMakeCurrent( __DRIcontextPrivate *driContextPriv,
952 __DRIdrawablePrivate *driDrawPriv,
953 __DRIdrawablePrivate *driReadPriv );
954
955 extern GLboolean
956 tdfxInitGlide( tdfxContextPtr tmesa );
957
958 extern void
959 FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4]);
960
961 extern void
962 FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4]);
963
964
965 /* Color packing utilities
966 */
967 #define TDFXPACKCOLOR332( r, g, b ) \
968 (((b) & 0xe0) | (((g) & 0xe0) >> 3) | (((r) & 0xc0) >> 6))
969
970 #define TDFXPACKCOLOR1555( r, g, b, a ) \
971 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
972 ((a) ? 0x8000 : 0))
973
974 #define TDFXPACKCOLOR565( r, g, b ) \
975 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
976
977 #define TDFXPACKCOLOR888( r, g, b ) \
978 (((b) << 16) | ((g) << 8) | (r))
979
980 #define TDFXPACKCOLOR8888( r, g, b, a ) \
981 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
982
983 #define TDFXPACKCOLOR4444( r, g, b, a ) \
984 ((((a) & 0xf0) << 8) | (((b) & 0xf0) << 4) | ((g) & 0xf0) | ((r) >> 4))
985
986 static INLINE GrColor_t tdfxPackColor( GLuint cpp,
987 GLubyte r, GLubyte g,
988 GLubyte b, GLubyte a )
989 {
990 switch ( cpp ) {
991 case 2:
992 return TDFXPACKCOLOR565( r, g, b );
993 case 4:
994 return TDFXPACKCOLOR8888( r, g, b, a );
995 default:
996 return 0;
997 }
998 }
999
1000 #define DO_DEBUG 1
1001 #if DO_DEBUG
1002 extern int TDFX_DEBUG;
1003 #else
1004 #define TDFX_DEBUG 0
1005 #endif
1006
1007 #define DEBUG_ALWAYS_SYNC 0x01
1008 #define DEBUG_VERBOSE_API 0x02
1009 #define DEBUG_VERBOSE_DRI 0x04
1010 #define DEBUG_VERBOSE_FALL 0x08
1011
1012 /* conf */
1013 #define FX_COMPRESS_S3TC_AS_FXT1_HACK 1
1014 #define FX_TC_NAPALM 0
1015
1016 #endif /* __TDFX_CONTEXT_H__ */