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