1 /* -*- mode: c; c-basic-offset: 3 -*-
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
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:
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
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
28 * \file tdfx_context.c
29 * Context management functions for 3Dfx hardware.
31 * \author Gareth Hughes <gareth@valinux.com> (original rewrite 29 Sep - 1 Oct 2000)
32 * \author Brian Paul <brianp@valinux.com>
33 * \author Daniel Borca <dborca@users.sourceforge.net> (new fixes 19 Jul 2004)
37 #include "tdfx_context.h"
39 #include "tdfx_state.h"
42 #include "tdfx_tris.h"
43 #include "tdfx_render.h"
44 #include "tdfx_span.h"
45 #include "tdfx_texman.h"
46 #include "main/extensions.h"
47 #include "main/hash.h"
48 #include "main/texobj.h"
50 #include "swrast/swrast.h"
51 #include "swrast_setup/swrast_setup.h"
55 #include "tnl/t_pipeline.h"
57 #include "drivers/common/driverfuncs.h"
61 /* #define need_GL_ARB_point_parameters */
62 #define need_GL_ARB_occlusion_query
63 /* #define need_GL_ARB_vertex_program */
64 #define need_GL_EXT_blend_equation_separate
65 #define need_GL_EXT_blend_func_separate
66 #define need_GL_EXT_blend_minmax
67 #define need_GL_EXT_fog_coord
68 #define need_GL_EXT_paletted_texture
69 /* #define need_GL_EXT_secondary_color */
70 /* #define need_GL_MESA_program_debug */
71 /* #define need_GL_NV_vertex_program */
72 #include "extension_helper.h"
76 * Common extension strings exported by all cards
78 const struct dri_extension card_extensions
[] =
80 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
},
81 { "GL_ARB_texture_mirrored_repeat", NULL
},
83 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
84 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
85 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
86 { "GL_EXT_shared_texture_palette", NULL
},
87 { "GL_EXT_stencil_wrap", NULL
},
88 { "GL_EXT_texture_env_add", NULL
},
89 { "GL_EXT_texture_lod_bias", NULL
},
91 #ifdef need_GL_ARB_point_parameters
92 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
93 { "GL_ARB_point_sprite", NULL
},
95 #ifdef need_GL_EXT_secondary_color
96 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
98 #ifdef need_GL_ARB_vertex_program
99 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
}
101 #ifdef need_GL_NV_vertex_program
102 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
}
103 { "GL_NV_vertex_program1_1", NULL
},
105 #ifdef need_GL_MESA_program_debug
106 { "GL_MESA_program_debug", GL_MESA_program_debug_functions
},
112 * Extension strings exported only by Naplam (e.g., Voodoo4 & Voodoo5) cards.
114 const struct dri_extension napalm_extensions
[] =
116 { "GL_ARB_texture_env_combine", NULL
},
117 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
118 { "GL_EXT_blend_subtract", GL_EXT_blend_minmax_functions
},
119 { "GL_EXT_texture_compression_s3tc", NULL
},
120 { "GL_EXT_texture_env_combine", NULL
},
122 { "GL_3DFX_texture_compression_FXT1", NULL
},
123 { "GL_NV_blend_square", NULL
},
124 { "GL_S3_s3tc", NULL
},
129 * Enable/Disable the extensions for this context.
131 static void tdfxDDInitExtensions( GLcontext
*ctx
)
133 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
135 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
137 if ( fxMesa
->haveTwoTMUs
) {
138 _mesa_enable_extension( ctx
, "GL_ARB_multitexture" );
141 if ( TDFX_IS_NAPALM( fxMesa
) ) {
142 driInitExtensions( ctx
, napalm_extensions
, GL_FALSE
);
144 _mesa_enable_extension( ctx
, "GL_SGIS_generate_mipmap" );
150 static const struct tnl_pipeline_stage
*tdfx_pipeline
[] = {
151 &_tnl_vertex_transform_stage
,
152 &_tnl_normal_transform_stage
,
153 &_tnl_lighting_stage
,
154 &_tnl_fog_coordinate_stage
,
156 &_tnl_texture_transform_stage
,
157 &_tnl_point_attenuation_stage
,
162 static const struct dri_debug_control debug_control
[] =
164 { "dri", DEBUG_VERBOSE_DRI
},
165 { "sync", DEBUG_ALWAYS_SYNC
},
166 { "api", DEBUG_VERBOSE_API
},
167 { "fall", DEBUG_VERBOSE_FALL
},
171 GLboolean
tdfxCreateContext( const __GLcontextModes
*mesaVis
,
172 __DRIcontextPrivate
*driContextPriv
,
173 void *sharedContextPrivate
)
175 tdfxContextPtr fxMesa
;
176 GLcontext
*ctx
, *shareCtx
;
177 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
178 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
179 TDFXSAREAPriv
*saPriv
= (TDFXSAREAPriv
*) ((char *) sPriv
->pSAREA
+
180 sizeof(drm_sarea_t
));
181 struct dd_function_table functions
;
183 /* Allocate tdfx context */
184 fxMesa
= (tdfxContextPtr
) CALLOC( sizeof(tdfxContextRec
) );
188 /* Init default driver functions then plug in our tdfx-specific functions
189 * (the texture functions are especially important)
191 _mesa_init_driver_functions(&functions
);
192 tdfxDDInitDriverFuncs(mesaVis
, &functions
);
193 tdfxInitTextureFuncs(&functions
);
194 tdfxInitRenderFuncs(&functions
);
196 /* Allocate the Mesa context */
197 if (sharedContextPrivate
)
198 shareCtx
= ((tdfxContextPtr
) sharedContextPrivate
)->glCtx
;
202 fxMesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
203 &functions
, (void *) fxMesa
);
204 if (!fxMesa
->glCtx
) {
208 driContextPriv
->driverPrivate
= fxMesa
;
210 /* Mirror some important DRI state
212 fxMesa
->hHWContext
= driContextPriv
->hHWContext
;
213 fxMesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
214 fxMesa
->driFd
= sPriv
->fd
;
216 fxMesa
->driScreen
= sPriv
;
217 fxMesa
->driContext
= driContextPriv
;
218 fxMesa
->fxScreen
= fxScreen
;
219 fxMesa
->sarea
= saPriv
;
222 fxMesa
->haveHwAlpha
= ( mesaVis
->alphaBits
&&
223 ((mesaVis
->greenBits
== 8) ||
224 (mesaVis
->depthBits
== 0)) );
225 fxMesa
->haveHwStencil
= ( TDFX_IS_NAPALM( fxMesa
) &&
226 mesaVis
->stencilBits
&&
227 mesaVis
->depthBits
== 24 );
229 fxMesa
->screen_width
= fxScreen
->width
;
230 fxMesa
->screen_height
= fxScreen
->height
;
232 fxMesa
->new_gl_state
= ~0;
233 fxMesa
->new_state
= ~0;
236 /* Parse configuration files */
237 driParseConfigFiles (&fxMesa
->optionCache
, &fxScreen
->optionCache
,
238 fxMesa
->driScreen
->myNum
, "tdfx");
240 /* NOTE: This must be here before any Glide calls! */
241 if (!tdfxInitGlide( fxMesa
)) {
246 fxMesa
->Glide
.grDRIOpen( (char*) sPriv
->pFB
, fxScreen
->regs
.map
, fxScreen
->deviceID
,
247 fxScreen
->width
, fxScreen
->height
, fxScreen
->mem
, fxScreen
->cpp
,
248 fxScreen
->stride
, fxScreen
->fifoOffset
, fxScreen
->fifoSize
,
249 fxScreen
->fbOffset
, fxScreen
->backOffset
, fxScreen
->depthOffset
,
250 fxScreen
->textureOffset
, fxScreen
->textureSize
, &saPriv
->fifoPtr
,
253 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
254 fxMesa
->Glide
.SwapInterval
= atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
256 fxMesa
->Glide
.SwapInterval
= 0;
258 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
259 fxMesa
->Glide
.MaxPendingSwaps
= atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
261 fxMesa
->Glide
.MaxPendingSwaps
= 2;
264 fxMesa
->Glide
.Initialized
= GL_FALSE
;
265 fxMesa
->Glide
.Board
= 0;
268 if (getenv("FX_EMULATE_SINGLE_TMU")) {
269 fxMesa
->haveTwoTMUs
= GL_FALSE
;
272 if ( TDFX_IS_BANSHEE( fxMesa
) ) {
273 fxMesa
->haveTwoTMUs
= GL_FALSE
;
275 fxMesa
->haveTwoTMUs
= GL_TRUE
;
279 fxMesa
->stats
.swapBuffer
= 0;
280 fxMesa
->stats
.reqTexUpload
= 0;
281 fxMesa
->stats
.texUpload
= 0;
282 fxMesa
->stats
.memTexUpload
= 0;
284 fxMesa
->tmuSrc
= TDFX_TMU_NONE
;
287 if ( TDFX_IS_NAPALM( fxMesa
) ) {
288 ctx
->Const
.MaxTextureLevels
= 12;
290 ctx
->Const
.MaxTextureLevels
= 9;
292 ctx
->Const
.MaxTextureUnits
= TDFX_IS_BANSHEE( fxMesa
) ? 1 : 2;
293 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
294 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
298 ctx
->Const
.MinPointSize
= 1.0;
299 ctx
->Const
.MinPointSizeAA
= 1.0;
300 ctx
->Const
.MaxPointSize
= 1.0;
301 ctx
->Const
.MaxPointSizeAA
= 1.0;
303 /* Disable wide lines as we can't antialias them correctly in
306 ctx
->Const
.MinLineWidth
= 1.0;
307 ctx
->Const
.MinLineWidthAA
= 1.0;
308 ctx
->Const
.MaxLineWidth
= 1.0;
309 ctx
->Const
.MaxLineWidthAA
= 1.0;
310 ctx
->Const
.LineWidthGranularity
= 1.0;
312 ctx
->Const
.MaxDrawBuffers
= 1;
314 /* Initialize the software rasterizer and helper modules.
316 _swrast_CreateContext( ctx
);
317 _vbo_CreateContext( ctx
);
318 _tnl_CreateContext( ctx
);
319 _swsetup_CreateContext( ctx
);
321 /* Install the customized pipeline:
323 _tnl_destroy_pipeline( ctx
);
324 _tnl_install_pipeline( ctx
, tdfx_pipeline
);
326 /* Configure swrast and T&L to match hardware characteristics:
328 _swrast_allow_pixel_fog( ctx
, GL_TRUE
);
329 _swrast_allow_vertex_fog( ctx
, GL_FALSE
);
330 _tnl_allow_pixel_fog( ctx
, GL_TRUE
);
331 _tnl_allow_vertex_fog( ctx
, GL_FALSE
);
333 tdfxDDInitExtensions( ctx
);
334 /* XXX these should really go right after _mesa_init_driver_functions() */
335 tdfxDDInitSpanFuncs( ctx
);
336 tdfxDDInitStateFuncs( ctx
);
337 tdfxDDInitTriFuncs( ctx
);
339 tdfxInitState( fxMesa
);
342 TDFX_DEBUG
= driParseDebugString( getenv( "TDFX_DEBUG" ), debug_control
);
345 if (driQueryOptionb(&fxMesa
->optionCache
, "no_rast")) {
346 fprintf(stderr
, "disabling 3D acceleration\n");
347 FALLBACK(fxMesa
, TDFX_FALLBACK_DISABLE
, 1);
354 static GLboolean
tdfxInitVertexFormats( tdfxContextPtr fxMesa
)
359 LOCK_HARDWARE( fxMesa
);
361 fxMesa
->Glide
.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE
, sizeof(FxI32
), &result
);
362 for ( i
= 0 ; i
< TDFX_NUM_LAYOUTS
; i
++ ) {
363 fxMesa
->layout
[i
] = MALLOC( result
);
364 if ( !fxMesa
->layout
[i
] ) {
365 UNLOCK_HARDWARE( fxMesa
);
370 /* Tiny vertex format - 16 bytes.
372 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
373 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
374 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
375 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
376 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
377 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_TINY
] );
379 /* Non textured vertex format - 24 bytes (Need w for table fog)
381 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
382 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
383 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
384 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
385 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
386 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
387 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_NOTEX
] );
389 /* Single textured vertex format - 32 bytes.
391 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
392 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
393 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
394 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
395 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
396 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
397 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
398 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_SINGLE
] );
400 /* Multitextured vertex format - 40 bytes.
402 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
403 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
404 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
405 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
406 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
407 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
408 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
409 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
410 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_MULTI
] );
412 /* Projected texture vertex format - 36 bytes.
414 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
415 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
416 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
417 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
418 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
419 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
420 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
421 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
422 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJ1
] );
424 /* Projected multitexture vertex format - 48 bytes.
426 fxMesa
->Glide
.grReset( GR_VERTEX_PARAMETER
);
427 fxMesa
->Glide
.grCoordinateSpace( GR_WINDOW_COORDS
);
428 fxMesa
->Glide
.grVertexLayout( GR_PARAM_XY
, TDFX_XY_OFFSET
, GR_PARAM_ENABLE
);
429 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Z
, TDFX_Z_OFFSET
, GR_PARAM_ENABLE
);
430 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q
, TDFX_Q_OFFSET
, GR_PARAM_ENABLE
);
431 fxMesa
->Glide
.grVertexLayout( GR_PARAM_PARGB
, TDFX_ARGB_OFFSET
, GR_PARAM_ENABLE
);
432 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST0
, TDFX_ST0_OFFSET
, GR_PARAM_ENABLE
);
433 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q0
, TDFX_Q0_OFFSET
, GR_PARAM_ENABLE
);
434 fxMesa
->Glide
.grVertexLayout( GR_PARAM_ST1
, TDFX_ST1_OFFSET
, GR_PARAM_ENABLE
);
435 fxMesa
->Glide
.grVertexLayout( GR_PARAM_Q1
, TDFX_Q1_OFFSET
, GR_PARAM_ENABLE
);
436 fxMesa
->Glide
.grGlideGetVertexLayout( fxMesa
->layout
[TDFX_LAYOUT_PROJ2
] );
438 UNLOCK_HARDWARE( fxMesa
);
445 * Initialize the state in an tdfxContextPtr struct.
448 tdfxInitContext( __DRIdrawablePrivate
*driDrawPriv
, tdfxContextPtr fxMesa
)
450 /* KW: Would be nice to make one of these a member of the other.
455 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
456 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
460 fprintf(stderr
, "Debug locking enabled\n");
463 if ( fxMesa
->Glide
.Initialized
)
466 fxMesa
->width
= driDrawPriv
->w
;
467 fxMesa
->height
= driDrawPriv
->h
;
469 /* We have to use a light lock here, because we can't do any glide
470 * operations yet. No use of FX_* functions in this function.
472 DRM_LIGHT_LOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
474 fxMesa
->Glide
.grGlideInit();
475 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
477 fxMesa
->Glide
.Context
= fxMesa
->Glide
.grSstWinOpen( (FxU32
) -1,
480 fxMesa
->Glide
.ColorFormat
,
481 fxMesa
->Glide
.Origin
,
484 fxMesa
->Glide
.grDRIResetSAREA();
486 DRM_UNLOCK( fxMesa
->driFd
, fxMesa
->driHwLock
, fxMesa
->hHWContext
);
488 if ( !fxMesa
->Glide
.Context
)
492 /* Perform the Glide-dependant part of the context initialization.
494 FX_grColorMaskv( fxMesa
->glCtx
, true4
);
496 tdfxTMInit( fxMesa
);
498 LOCK_HARDWARE( fxMesa
);
500 /* JJJ - COMMAND_TRANSPORT, PALETTE6666 */
501 gext
= fxMesa
->Glide
.grGetString( GR_EXTENSION
);
502 fxMesa
->Glide
.HaveCombineExt
= strstr(gext
, "COMBINE") && !getenv("MESA_FX_IGNORE_CMBEXT");
503 fxMesa
->Glide
.HaveCommandTransportExt
= GL_FALSE
;
504 fxMesa
->Glide
.HaveFogCoordExt
= GL_TRUE
;
505 fxMesa
->Glide
.HavePixelExt
= strstr(gext
, "PIXEXT") && !getenv("MESA_FX_IGNORE_PIXEXT");
506 fxMesa
->Glide
.HaveTextureBufferExt
= GL_TRUE
;
507 fxMesa
->Glide
.HaveTexFmtExt
= strstr(gext
, "TEXFMT") && !getenv("MESA_FX_IGNORE_TEXFMT");
508 fxMesa
->Glide
.HaveTexUMAExt
= strstr(gext
, "TEXUMA") && !getenv("MESA_FX_IGNORE_TEXUMA");
509 fxMesa
->Glide
.HaveMirrorExt
= strstr(gext
, "TEXMIRROR") && !getenv("MESA_FX_IGNORE_MIREXT");
510 fxMesa
->Glide
.HaveTexus2
= GL_FALSE
;
512 if ( fxMesa
->glCtx
->Visual
.depthBits
> 0 ) {
513 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
515 fxMesa
->Glide
.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE
);
518 fxMesa
->Glide
.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR
);
520 fxMesa
->Glide
.grGet( GR_TEXTURE_ALIGN
, sizeof(FxI32
), result
);
521 fxMesa
->Glide
.TextureAlign
= result
[0];
523 fxMesa
->Glide
.State
= NULL
;
524 fxMesa
->Glide
.grGet( GR_GLIDE_STATE_SIZE
, sizeof(FxI32
), result
);
525 fxMesa
->Glide
.State
= MALLOC( result
[0] );
527 fxMesa
->Fog
.Table
= NULL
;
528 fxMesa
->Glide
.grGet( GR_FOG_TABLE_ENTRIES
, sizeof(FxI32
), result
);
529 fxMesa
->Fog
.Table
= MALLOC( result
[0] * sizeof(GrFog_t
) );
531 UNLOCK_HARDWARE( fxMesa
);
533 if ( !fxMesa
->Glide
.State
|| !fxMesa
->Fog
.Table
) {
534 if ( fxMesa
->Glide
.State
)
535 FREE( fxMesa
->Glide
.State
);
536 if ( fxMesa
->Fog
.Table
)
537 FREE( fxMesa
->Fog
.Table
);
541 if ( !tdfxInitVertexFormats( fxMesa
) ) {
545 LOCK_HARDWARE( fxMesa
);
547 fxMesa
->Glide
.grGlideGetState( fxMesa
->Glide
.State
);
549 if ( getenv( "FX_GLIDE_INFO" ) ) {
550 printf( "GR_RENDERER = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_RENDERER
) );
551 printf( "GR_VERSION = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VERSION
) );
552 printf( "GR_VENDOR = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_VENDOR
) );
553 printf( "GR_HARDWARE = %s\n", (char *) fxMesa
->Glide
.grGetString( GR_HARDWARE
) );
554 printf( "GR_EXTENSION = %s\n", (char *) gext
);
557 UNLOCK_HARDWARE( fxMesa
);
559 fxMesa
->numClipRects
= 0;
560 fxMesa
->pClipRects
= NULL
;
561 fxMesa
->scissoredClipRects
= GL_FALSE
;
563 fxMesa
->Glide
.Initialized
= GL_TRUE
;
570 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
)
572 tdfxContextPtr fxMesa
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
574 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
575 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)fxMesa
);
579 if (fxMesa
->glCtx
->Shared
->RefCount
== 1 && fxMesa
->driDrawable
) {
580 /* This share group is about to go away, free our private
581 * texture object data.
583 struct _mesa_HashTable
*textures
= fxMesa
->glCtx
->Shared
->TexObjects
;
585 for (id
= _mesa_HashFirstEntry(textures
);
587 id
= _mesa_HashNextEntry(textures
, id
)) {
588 struct gl_texture_object
*tObj
589 = _mesa_lookup_texture(fxMesa
->glCtx
, id
);
590 tdfxTMFreeTexture(fxMesa
, tObj
);
594 tdfxTMClose(fxMesa
); /* free texture memory */
596 _swsetup_DestroyContext( fxMesa
->glCtx
);
597 _tnl_DestroyContext( fxMesa
->glCtx
);
598 _vbo_DestroyContext( fxMesa
->glCtx
);
599 _swrast_DestroyContext( fxMesa
->glCtx
);
601 tdfxFreeVB( fxMesa
->glCtx
);
603 /* Free Mesa context */
604 fxMesa
->glCtx
->DriverCtx
= NULL
;
605 _mesa_destroy_context(fxMesa
->glCtx
);
607 /* free the tdfx context */
614 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
)
616 GET_CURRENT_CONTEXT(ctx
);
617 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
619 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
620 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
623 if ( driContextPriv
&& (tdfxContextPtr
) driContextPriv
== fxMesa
) {
624 LOCK_HARDWARE(fxMesa
);
625 fxMesa
->Glide
.grGlideGetState(fxMesa
->Glide
.State
);
626 UNLOCK_HARDWARE(fxMesa
);
633 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
634 __DRIdrawablePrivate
*driDrawPriv
,
635 __DRIdrawablePrivate
*driReadPriv
)
637 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
638 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driContextPriv
);
641 if ( driContextPriv
) {
642 tdfxContextPtr newFx
= (tdfxContextPtr
) driContextPriv
->driverPrivate
;
643 GLcontext
*newCtx
= newFx
->glCtx
;
644 GET_CURRENT_CONTEXT(curCtx
);
646 if ((newFx
->driDrawable
!= driDrawPriv
)
647 || (newFx
->driReadable
!= driReadPriv
)) {
648 newFx
->driDrawable
= driDrawPriv
;
649 newFx
->driReadable
= driReadPriv
;
653 if (curCtx
== newCtx
) {
654 /* same drawable, same context -> no-op */
655 /* Need to call _mesa_make_current2() in order to make sure API
656 * dispatch is set correctly.
658 _mesa_make_current( newCtx
,
659 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
660 (GLframebuffer
*) driReadPriv
->driverPrivate
);
663 /* [dBorca] tunnel2 requires this */
667 driUpdateFramebufferSize(newCtx
, driDrawPriv
);
668 if (driDrawPriv
!= driReadPriv
) {
669 driUpdateFramebufferSize(newCtx
, driReadPriv
);
672 if ( !newFx
->Glide
.Initialized
) {
673 if ( !tdfxInitContext( driDrawPriv
, newFx
) )
676 LOCK_HARDWARE( newFx
);
678 /* FIXME: Force loading of window information */
680 tdfxUpdateClipping(newCtx
);
681 tdfxUploadClipping(newFx
);
683 UNLOCK_HARDWARE( newFx
);
685 LOCK_HARDWARE( newFx
);
687 newFx
->Glide
.grSstSelect( newFx
->Glide
.Board
);
688 newFx
->Glide
.grGlideSetState( newFx
->Glide
.State
);
690 tdfxUpdateClipping(newCtx
);
691 tdfxUploadClipping(newFx
);
693 UNLOCK_HARDWARE( newFx
);
696 _mesa_make_current( newCtx
,
697 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
698 (GLframebuffer
*) driReadPriv
->driverPrivate
);
700 _mesa_make_current( NULL
, NULL
, NULL
);
708 * Enable this to trace calls to various Glide functions.
710 /*#define DEBUG_TRAP*/
712 static void (*real_grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
713 static void (*real_grDrawPoint
)( const void *a
);
714 static void (*real_grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
715 static void (*real_grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
716 void *pointers
, FxU32 stride
);
717 static void (*real_grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
719 static void (*real_grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
720 static void (*real_grGlideGetVertexLayout
)( void *layout
);
721 static void (*real_grGlideSetVertexLayout
)( const void *layout
);
723 static void (*real_grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
727 GrAspectRatio_t aspectRatio
,
728 GrTextureFormat_t format
,
733 static void debug_grDrawTriangle( const void *a
, const void *b
, const void *c
)
735 printf("%s\n", __FUNCTION__
);
736 (*real_grDrawTriangle
)(a
, b
, c
);
739 static void debug_grDrawPoint( const void *a
)
741 const float *f
= (const float *) a
;
742 printf("%s %g %g\n", __FUNCTION__
, f
[0], f
[1]);
743 (*real_grDrawPoint
)(a
);
746 static void debug_grDrawVertexArray(FxU32 mode
, FxU32 Count
, void *pointers
)
748 printf("%s count=%d\n", __FUNCTION__
, (int) Count
);
749 (*real_grDrawVertexArray
)(mode
, Count
, pointers
);
752 static void debug_grDrawVertexArrayContiguous(FxU32 mode
, FxU32 Count
,
753 void *pointers
, FxU32 stride
)
755 printf("%s mode=0x%x count=%d\n", __FUNCTION__
, (int) mode
, (int) Count
);
756 (*real_grDrawVertexArrayContiguous
)(mode
, Count
, pointers
, stride
);
759 static void debug_grClipWindow( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
)
761 printf("%s %d,%d .. %d,%d\n", __FUNCTION__
,
762 (int) minx
, (int) miny
, (int) maxx
, (int) maxy
);
763 (*real_grClipWindow
)(minx
, miny
, maxx
, maxy
);
766 static void debug_grVertexLayout(FxU32 param
, FxI32 offset
, FxU32 mode
)
768 (*real_grVertexLayout
)(param
, offset
, mode
);
771 static void debug_grGlideGetVertexLayout( void *layout
)
773 (*real_grGlideGetVertexLayout
)(layout
);
776 static void debug_grGlideSetVertexLayout( const void *layout
)
778 (*real_grGlideSetVertexLayout
)(layout
);
781 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu
,
785 GrAspectRatio_t aspectRatio
,
786 GrTextureFormat_t format
,
790 (*real_grTexDownloadMipMapLevel
)(tmu
, startAddress
, thisLod
, largeLod
,
791 aspectRatio
, format
, evenOdd
, data
);
798 * Examine the context's deviceID to determine what kind of 3dfx hardware
799 * is installed. dlopen() the appropriate Glide library and initialize
800 * this context's Glide function pointers.
801 * Return: true/false = success/failure
803 GLboolean
tdfxInitGlide(tdfxContextPtr tmesa
)
805 static const char *defaultGlide
= "libglide3.so";
810 * XXX this code which selects a Glide library filename given the
811 * deviceID may need to be cleaned up a bit.
812 * Non-Linux systems may have different filenames, for example.
814 switch (tmesa
->fxScreen
->deviceID
) {
815 case PCI_CHIP_BANSHEE
:
816 case PCI_CHIP_VOODOO3
:
817 libName
= "libglide3-v3.so";
819 case PCI_CHIP_VOODOO5
: /* same as PCI_CHIP_VOODOO4 */
820 libName
= "libglide3-v5.so";
824 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
825 tmesa
->fxScreen
->deviceID
);
830 libHandle
= dlopen(libName
, RTLD_NOW
);
832 /* The device-specific Glide library filename didn't work, try the
833 * old, generic libglide3.so library.
835 libHandle
= dlopen(defaultGlide
, RTLD_NOW
);
838 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
839 libName
, defaultGlide
);
840 __driUtilMessage("dlerror() message: %s", dlerror());
843 libName
= defaultGlide
;
847 const char *env
= getenv("LIBGL_DEBUG");
848 if (env
&& strstr(env
, "verbose")) {
849 fprintf(stderr
, "libGL: using Glide library %s\n", libName
);
853 #define GET_FUNCTION(PTR, NAME) \
854 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
855 if (!tmesa->Glide.PTR) { \
856 __driUtilMessage("couldn't find Glide function %s in %s.", \
860 GET_FUNCTION(grDrawPoint
, "grDrawPoint");
861 GET_FUNCTION(grDrawLine
, "grDrawLine");
862 GET_FUNCTION(grDrawTriangle
, "grDrawTriangle");
863 GET_FUNCTION(grVertexLayout
, "grVertexLayout");
864 GET_FUNCTION(grDrawVertexArray
, "grDrawVertexArray");
865 GET_FUNCTION(grDrawVertexArrayContiguous
, "grDrawVertexArrayContiguous");
866 GET_FUNCTION(grBufferClear
, "grBufferClear");
867 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
868 GET_FUNCTION(grRenderBuffer
, "grRenderBuffer");
869 GET_FUNCTION(grErrorSetCallback
, "grErrorSetCallback");
870 GET_FUNCTION(grFinish
, "grFinish");
871 GET_FUNCTION(grFlush
, "grFlush");
872 GET_FUNCTION(grSstWinOpen
, "grSstWinOpen");
873 GET_FUNCTION(grSstWinClose
, "grSstWinClose");
875 /* Not in V3 lib, and not used anyway. */
876 GET_FUNCTION(grSetNumPendingBuffers
, "grSetNumPendingBuffers");
878 GET_FUNCTION(grSelectContext
, "grSelectContext");
879 GET_FUNCTION(grSstOrigin
, "grSstOrigin");
880 GET_FUNCTION(grSstSelect
, "grSstSelect");
881 GET_FUNCTION(grAlphaBlendFunction
, "grAlphaBlendFunction");
882 GET_FUNCTION(grAlphaCombine
, "grAlphaCombine");
883 GET_FUNCTION(grAlphaControlsITRGBLighting
, "grAlphaControlsITRGBLighting");
884 GET_FUNCTION(grAlphaTestFunction
, "grAlphaTestFunction");
885 GET_FUNCTION(grAlphaTestReferenceValue
, "grAlphaTestReferenceValue");
886 GET_FUNCTION(grChromakeyMode
, "grChromakeyMode");
887 GET_FUNCTION(grChromakeyValue
, "grChromakeyValue");
888 GET_FUNCTION(grClipWindow
, "grClipWindow");
889 GET_FUNCTION(grColorCombine
, "grColorCombine");
890 GET_FUNCTION(grColorMask
, "grColorMask");
891 GET_FUNCTION(grCullMode
, "grCullMode");
892 GET_FUNCTION(grConstantColorValue
, "grConstantColorValue");
893 GET_FUNCTION(grDepthBiasLevel
, "grDepthBiasLevel");
894 GET_FUNCTION(grDepthBufferFunction
, "grDepthBufferFunction");
895 GET_FUNCTION(grDepthBufferMode
, "grDepthBufferMode");
896 GET_FUNCTION(grDepthMask
, "grDepthMask");
897 GET_FUNCTION(grDisableAllEffects
, "grDisableAllEffects");
898 GET_FUNCTION(grDitherMode
, "grDitherMode");
899 GET_FUNCTION(grFogColorValue
, "grFogColorValue");
900 GET_FUNCTION(grFogMode
, "grFogMode");
901 GET_FUNCTION(grFogTable
, "grFogTable");
902 GET_FUNCTION(grLoadGammaTable
, "grLoadGammaTable");
903 GET_FUNCTION(grSplash
, "grSplash");
904 GET_FUNCTION(grGet
, "grGet");
905 GET_FUNCTION(grGetString
, "grGetString");
906 GET_FUNCTION(grQueryResolutions
, "grQueryResolutions");
907 GET_FUNCTION(grReset
, "grReset");
908 GET_FUNCTION(grGetProcAddress
, "grGetProcAddress");
909 GET_FUNCTION(grEnable
, "grEnable");
910 GET_FUNCTION(grDisable
, "grDisable");
911 GET_FUNCTION(grCoordinateSpace
, "grCoordinateSpace");
912 GET_FUNCTION(grDepthRange
, "grDepthRange");
913 GET_FUNCTION(grStippleMode
, "grStippleMode");
914 GET_FUNCTION(grStipplePattern
, "grStipplePattern");
915 GET_FUNCTION(grViewport
, "grViewport");
916 GET_FUNCTION(grTexCalcMemRequired
, "grTexCalcMemRequired");
917 GET_FUNCTION(grTexTextureMemRequired
, "grTexTextureMemRequired");
918 GET_FUNCTION(grTexMinAddress
, "grTexMinAddress");
919 GET_FUNCTION(grTexMaxAddress
, "grTexMaxAddress");
920 GET_FUNCTION(grTexNCCTable
, "grTexNCCTable");
921 GET_FUNCTION(grTexSource
, "grTexSource");
922 GET_FUNCTION(grTexClampMode
, "grTexClampMode");
923 GET_FUNCTION(grTexCombine
, "grTexCombine");
924 GET_FUNCTION(grTexDetailControl
, "grTexDetailControl");
925 GET_FUNCTION(grTexFilterMode
, "grTexFilterMode");
926 GET_FUNCTION(grTexLodBiasValue
, "grTexLodBiasValue");
927 GET_FUNCTION(grTexDownloadMipMap
, "grTexDownloadMipMap");
928 GET_FUNCTION(grTexDownloadMipMapLevel
, "grTexDownloadMipMapLevel");
929 GET_FUNCTION(grTexDownloadMipMapLevelPartial
, "grTexDownloadMipMapLevelPartial");
930 GET_FUNCTION(grTexDownloadTable
, "grTexDownloadTable");
931 GET_FUNCTION(grTexDownloadTablePartial
, "grTexDownloadTablePartial");
932 GET_FUNCTION(grTexMipMapMode
, "grTexMipMapMode");
933 GET_FUNCTION(grTexMultibase
, "grTexMultibase");
934 GET_FUNCTION(grTexMultibaseAddress
, "grTexMultibaseAddress");
935 GET_FUNCTION(grLfbLock
, "grLfbLock");
936 GET_FUNCTION(grLfbUnlock
, "grLfbUnlock");
937 GET_FUNCTION(grLfbConstantAlpha
, "grLfbConstantAlpha");
938 GET_FUNCTION(grLfbConstantDepth
, "grLfbConstantDepth");
939 GET_FUNCTION(grLfbWriteColorSwizzle
, "grLfbWriteColorSwizzle");
940 GET_FUNCTION(grLfbWriteColorFormat
, "grLfbWriteColorFormat");
941 GET_FUNCTION(grLfbWriteRegion
, "grLfbWriteRegion");
942 GET_FUNCTION(grLfbReadRegion
, "grLfbReadRegion");
943 GET_FUNCTION(grGlideInit
, "grGlideInit");
944 GET_FUNCTION(grGlideShutdown
, "grGlideShutdown");
945 GET_FUNCTION(grGlideGetState
, "grGlideGetState");
946 GET_FUNCTION(grGlideSetState
, "grGlideSetState");
947 GET_FUNCTION(grGlideGetVertexLayout
, "grGlideGetVertexLayout");
948 GET_FUNCTION(grGlideSetVertexLayout
, "grGlideSetVertexLayout");
950 /* Glide utility functions */
951 GET_FUNCTION(guFogGenerateExp
, "guFogGenerateExp");
952 GET_FUNCTION(guFogGenerateExp2
, "guFogGenerateExp2");
953 GET_FUNCTION(guFogGenerateLinear
, "guFogGenerateLinear");
956 GET_FUNCTION(grDRIOpen
, "grDRIOpen");
957 GET_FUNCTION(grDRIPosition
, "grDRIPosition");
958 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
959 GET_FUNCTION(grDRIImportFifo
, "grDRIImportFifo");
960 GET_FUNCTION(grDRIInvalidateAll
, "grDRIInvalidateAll");
961 GET_FUNCTION(grDRIResetSAREA
, "grDRIResetSAREA");
962 GET_FUNCTION(grDRIBufferSwap
, "grDRIBufferSwap");
965 * Extension functions:
966 * Just use dlysm() because we want a NULL pointer if the function is
969 /* PIXEXT extension */
970 tmesa
->Glide
.grStencilFunc
= dlsym(libHandle
, "grStencilFunc");
971 tmesa
->Glide
.grStencilMask
= dlsym(libHandle
, "grStencilMask");
972 tmesa
->Glide
.grStencilOp
= dlsym(libHandle
, "grStencilOp");
973 tmesa
->Glide
.grBufferClearExt
= dlsym(libHandle
, "grBufferClearExt");
974 tmesa
->Glide
.grColorMaskExt
= dlsym(libHandle
, "grColorMaskExt");
975 /* COMBINE extension */
976 tmesa
->Glide
.grColorCombineExt
= dlsym(libHandle
, "grColorCombineExt");
977 tmesa
->Glide
.grTexColorCombineExt
= dlsym(libHandle
, "grTexColorCombineExt");
978 tmesa
->Glide
.grAlphaCombineExt
= dlsym(libHandle
, "grAlphaCombineExt");
979 tmesa
->Glide
.grTexAlphaCombineExt
= dlsym(libHandle
, "grTexAlphaCombineExt");
980 tmesa
->Glide
.grAlphaBlendFunctionExt
= dlsym(libHandle
, "grAlphaBlendFunctionExt");
981 tmesa
->Glide
.grConstantColorValueExt
= dlsym(libHandle
, "grConstantColorValueExt");
983 tmesa
->Glide
.txImgQuantize
= dlsym(libHandle
, "txImgQuantize");
984 tmesa
->Glide
.txImgDequantizeFXT1
= dlsym(libHandle
, "_txImgDequantizeFXT1");
985 tmesa
->Glide
.txErrorSetCallback
= dlsym(libHandle
, "txErrorSetCallback");
988 /* wrap the drawing functions so we can trap them */
989 real_grDrawTriangle
= tmesa
->Glide
.grDrawTriangle
;
990 tmesa
->Glide
.grDrawTriangle
= debug_grDrawTriangle
;
992 real_grDrawPoint
= tmesa
->Glide
.grDrawPoint
;
993 tmesa
->Glide
.grDrawPoint
= debug_grDrawPoint
;
995 real_grDrawVertexArray
= tmesa
->Glide
.grDrawVertexArray
;
996 tmesa
->Glide
.grDrawVertexArray
= debug_grDrawVertexArray
;
998 real_grDrawVertexArrayContiguous
= tmesa
->Glide
.grDrawVertexArrayContiguous
;
999 tmesa
->Glide
.grDrawVertexArrayContiguous
= debug_grDrawVertexArrayContiguous
;
1001 real_grClipWindow
= tmesa
->Glide
.grClipWindow
;
1002 tmesa
->Glide
.grClipWindow
= debug_grClipWindow
;
1004 real_grVertexLayout
= tmesa
->Glide
.grVertexLayout
;
1005 tmesa
->Glide
.grVertexLayout
= debug_grVertexLayout
;
1007 real_grGlideGetVertexLayout
= tmesa
->Glide
.grGlideGetVertexLayout
;
1008 tmesa
->Glide
.grGlideGetVertexLayout
= debug_grGlideGetVertexLayout
;
1010 real_grGlideSetVertexLayout
= tmesa
->Glide
.grGlideSetVertexLayout
;
1011 tmesa
->Glide
.grGlideSetVertexLayout
= debug_grGlideSetVertexLayout
;
1013 real_grTexDownloadMipMapLevel
= tmesa
->Glide
.grTexDownloadMipMapLevel
;
1014 tmesa
->Glide
.grTexDownloadMipMapLevel
= debug_grTexDownloadMipMapLevel
;