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