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
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.c,v 1.12 2003/05/08 09:25:35 herrb Exp $ */
30 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
33 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
36 * Gareth Hughes <gareth@valinux.com>
37 * Brian Paul <brianp@valinux.com>
42 #include "tdfx_context.h"
44 #include "tdfx_state.h"
47 #include "tdfx_tris.h"
48 #include "tdfx_render.h"
49 #include "tdfx_span.h"
50 #include "tdfx_texman.h"
51 #include "extensions.h"
54 #include "swrast/swrast.h"
55 #include "swrast_setup/swrast_setup.h"
56 #include "array_cache/acache.h"
59 #include "tnl/t_pipeline.h"
61 #include "drivers/common/driverfuncs.h"
65 PUBLIC const char __driConfigOptions[] = { 0 };
66 const GLuint __driNConfigOptions = 0;
69 * Common extension strings exported by all cards
71 static const char * const card_extensions[] =
73 "GL_ARB_texture_mirrored_repeat",
74 "GL_ARB_vertex_buffer_object",
75 "GL_EXT_blend_func_separate",
77 "GL_EXT_multi_draw_arrays",
78 "GL_EXT_paletted_texture",
79 "GL_EXT_shared_texture_palette",
80 "GL_EXT_stencil_wrap",
81 "GL_EXT_texture_env_add",
82 "GL_EXT_texture_lod_bias",
83 "GL_HP_occlusion_test",
84 "GL_IBM_multimode_draw_arrays",
87 "GL_ARB_point_sprite",
88 "GL_EXT_point_parameters",
89 "GL_EXT_secondary_color",
93 "GL_ARB_vertex_program",
94 "GL_NV_vertex_program",
95 "GL_NV_vertex_program1_1",
96 "GL_MESA_program_debug",
102 * Extension strings exported only by Naplam (e.g., Voodoo4 & Voodoo5) cards.
104 static const char * const napalm_extensions[] =
106 "GL_ARB_texture_compression",
107 "GL_ARB_texture_env_combine",
108 "GL_EXT_blend_equation_separate",
109 "GL_EXT_blend_subtract",
110 "GL_EXT_texture_compression_s3tc",
111 "GL_EXT_texture_env_combine",
113 "GL_3DFX_texture_compression_FXT1",
114 "GL_NV_blend_square",
120 * Enable/Disable the extensions for this context.
122 static void tdfxDDInitExtensions( GLcontext *ctx )
124 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
126 driInitExtensions( ctx, card_extensions, GL_FALSE );
128 if ( fxMesa->haveTwoTMUs ) {
129 _mesa_enable_extension( ctx, "GL_ARB_multitexture" );
132 if ( TDFX_IS_NAPALM( fxMesa ) ) {
133 driInitExtensions( ctx, napalm_extensions, GL_FALSE );
135 _mesa_enable_extension( ctx, "GL_SGIS_generate_mipmap" );
141 static const struct tnl_pipeline_stage *tdfx_pipeline[] = {
142 &_tnl_vertex_transform_stage,
143 &_tnl_normal_transform_stage,
144 &_tnl_lighting_stage,
145 &_tnl_fog_coordinate_stage,
147 &_tnl_texture_transform_stage,
148 &_tnl_point_attenuation_stage,
150 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
151 &_tnl_vertex_program_stage,
159 GLboolean tdfxCreateContext( const __GLcontextModes *mesaVis,
160 __DRIcontextPrivate *driContextPriv,
161 void *sharedContextPrivate )
163 tdfxContextPtr fxMesa;
164 GLcontext *ctx, *shareCtx;
165 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
166 tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private;
167 TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) ((char *) sPriv->pSAREA +
168 sizeof(drm_sarea_t));
169 struct dd_function_table functions;
171 /* Allocate tdfx context */
172 fxMesa = (tdfxContextPtr) CALLOC( sizeof(tdfxContextRec) );
176 /* Init default driver functions then plug in our tdfx-specific functions
177 * (the texture functions are especially important)
179 _mesa_init_driver_functions(&functions);
180 tdfxDDInitDriverFuncs(mesaVis, &functions);
181 tdfxInitTextureFuncs(&functions);
182 tdfxInitRenderFuncs(&functions);
184 /* Allocate the Mesa context */
185 if (sharedContextPrivate)
186 shareCtx = ((tdfxContextPtr) sharedContextPrivate)->glCtx;
190 fxMesa->glCtx = _mesa_create_context(mesaVis, shareCtx,
191 &functions, (void *) fxMesa);
192 if (!fxMesa->glCtx) {
196 driContextPriv->driverPrivate = fxMesa;
198 /* Mirror some important DRI state
200 fxMesa->hHWContext = driContextPriv->hHWContext;
201 fxMesa->driHwLock = &sPriv->pSAREA->lock;
202 fxMesa->driFd = sPriv->fd;
204 fxMesa->driScreen = sPriv;
205 fxMesa->driContext = driContextPriv;
206 fxMesa->fxScreen = fxScreen;
207 fxMesa->sarea = saPriv;
210 fxMesa->haveHwAlpha = ( mesaVis->alphaBits &&
211 ((mesaVis->greenBits == 8) ||
212 (mesaVis->depthBits == 0)) );
213 fxMesa->haveHwStencil = ( TDFX_IS_NAPALM( fxMesa ) &&
214 mesaVis->stencilBits &&
215 mesaVis->depthBits == 24 );
217 fxMesa->screen_width = fxScreen->width;
218 fxMesa->screen_height = fxScreen->height;
220 fxMesa->new_gl_state = ~0;
221 fxMesa->new_state = ~0;
224 /* NOTE: This must be here before any Glide calls! */
225 if (!tdfxInitGlide( fxMesa )) {
230 fxMesa->Glide.grDRIOpen( (char*) sPriv->pFB, fxScreen->regs.map, fxScreen->deviceID,
231 fxScreen->width, fxScreen->height, fxScreen->mem, fxScreen->cpp,
232 fxScreen->stride, fxScreen->fifoOffset, fxScreen->fifoSize,
233 fxScreen->fbOffset, fxScreen->backOffset, fxScreen->depthOffset,
234 fxScreen->textureOffset, fxScreen->textureSize, &saPriv->fifoPtr,
237 if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) {
238 fxMesa->Glide.SwapInterval = atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) );
240 fxMesa->Glide.SwapInterval = 0;
242 if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) {
243 fxMesa->Glide.MaxPendingSwaps = atoi( getenv( "FX_MAX_PENDING_SWAPS" ) );
245 fxMesa->Glide.MaxPendingSwaps = 2;
248 fxMesa->Glide.Initialized = GL_FALSE;
249 fxMesa->Glide.Board = 0;
252 if (getenv("FX_EMULATE_SINGLE_TMU")) {
253 fxMesa->haveTwoTMUs = GL_FALSE;
256 if ( TDFX_IS_BANSHEE( fxMesa ) ) {
257 fxMesa->haveTwoTMUs = GL_FALSE;
259 fxMesa->haveTwoTMUs = GL_TRUE;
263 fxMesa->stats.swapBuffer = 0;
264 fxMesa->stats.reqTexUpload = 0;
265 fxMesa->stats.texUpload = 0;
266 fxMesa->stats.memTexUpload = 0;
268 fxMesa->tmuSrc = TDFX_TMU_NONE;
271 if ( TDFX_IS_NAPALM( fxMesa ) ) {
272 ctx->Const.MaxTextureLevels = 12;
274 ctx->Const.MaxTextureLevels = 9;
276 ctx->Const.MaxTextureUnits = TDFX_IS_BANSHEE( fxMesa ) ? 1 : 2;
277 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
278 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
282 ctx->Const.MinPointSize = 1.0;
283 ctx->Const.MinPointSizeAA = 1.0;
284 ctx->Const.MaxPointSize = 1.0;
285 ctx->Const.MaxPointSizeAA = 1.0;
287 /* Disable wide lines as we can't antialias them correctly in
290 ctx->Const.MinLineWidth = 1.0;
291 ctx->Const.MinLineWidthAA = 1.0;
292 ctx->Const.MaxLineWidth = 1.0;
293 ctx->Const.MaxLineWidthAA = 1.0;
294 ctx->Const.LineWidthGranularity = 1.0;
296 /* Initialize the software rasterizer and helper modules.
298 _swrast_CreateContext( ctx );
299 _ac_CreateContext( ctx );
300 _tnl_CreateContext( ctx );
301 _swsetup_CreateContext( ctx );
303 /* Install the customized pipeline:
305 _tnl_destroy_pipeline( ctx );
306 _tnl_install_pipeline( ctx, tdfx_pipeline );
308 /* Configure swrast and T&L to match hardware characteristics:
310 _swrast_allow_pixel_fog( ctx, GL_TRUE );
311 _swrast_allow_vertex_fog( ctx, GL_FALSE );
312 _tnl_allow_pixel_fog( ctx, GL_TRUE );
313 _tnl_allow_vertex_fog( ctx, GL_FALSE );
315 tdfxDDInitExtensions( ctx );
316 /* XXX these should really go right after _mesa_init_driver_functions() */
317 tdfxDDInitSpanFuncs( ctx );
318 tdfxDDInitStateFuncs( ctx );
319 tdfxDDInitTriFuncs( ctx );
321 tdfxInitState( fxMesa );
327 static GLboolean tdfxInitVertexFormats( tdfxContextPtr fxMesa )
332 LOCK_HARDWARE( fxMesa );
334 fxMesa->Glide.grGet( GR_GLIDE_VERTEXLAYOUT_SIZE, sizeof(FxI32), &result );
335 for ( i = 0 ; i < TDFX_NUM_LAYOUTS ; i++ ) {
336 fxMesa->layout[i] = MALLOC( result );
337 if ( !fxMesa->layout[i] ) {
338 UNLOCK_HARDWARE( fxMesa );
343 /* Tiny vertex format - 16 bytes.
345 fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
346 fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
347 fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
348 fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
349 fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
350 fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_TINY] );
352 /* Non textured vertex format - 24 bytes (Need w for table fog)
354 fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
355 fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
356 fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
357 fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
358 fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
359 fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
360 fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_NOTEX] );
362 /* Single textured vertex format - 32 bytes.
364 fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
365 fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
366 fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
367 fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
368 fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
369 fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
370 fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
371 fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_SINGLE] );
373 /* Multitextured vertex format - 40 bytes.
375 fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
376 fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
377 fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
378 fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
379 fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
380 fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
381 fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
382 fxMesa->Glide.grVertexLayout( GR_PARAM_ST1, TDFX_ST1_OFFSET, GR_PARAM_ENABLE );
383 fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_MULTI] );
385 /* Projected texture vertex format - 36 bytes.
387 fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
388 fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
389 fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
390 fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
391 fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
392 fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
393 fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
394 fxMesa->Glide.grVertexLayout( GR_PARAM_Q0, TDFX_Q0_OFFSET, GR_PARAM_ENABLE );
395 fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_PROJ1] );
397 /* Projected multitexture vertex format - 48 bytes.
399 fxMesa->Glide.grReset( GR_VERTEX_PARAMETER );
400 fxMesa->Glide.grCoordinateSpace( GR_WINDOW_COORDS );
401 fxMesa->Glide.grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE );
402 fxMesa->Glide.grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE );
403 fxMesa->Glide.grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE );
404 fxMesa->Glide.grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE );
405 fxMesa->Glide.grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE );
406 fxMesa->Glide.grVertexLayout( GR_PARAM_Q0, TDFX_Q0_OFFSET, GR_PARAM_ENABLE );
407 fxMesa->Glide.grVertexLayout( GR_PARAM_ST1, TDFX_ST1_OFFSET, GR_PARAM_ENABLE );
408 fxMesa->Glide.grVertexLayout( GR_PARAM_Q1, TDFX_Q1_OFFSET, GR_PARAM_ENABLE );
409 fxMesa->Glide.grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_PROJ2] );
411 UNLOCK_HARDWARE( fxMesa );
418 * Initialize the state in an tdfxContextPtr struct.
421 tdfxInitContext( __DRIdrawablePrivate *driDrawPriv, tdfxContextPtr fxMesa )
423 /* KW: Would be nice to make one of these a member of the other.
428 if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
429 fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)fxMesa );
433 fprintf(stderr, "Debug locking enabled\n");
436 if ( fxMesa->Glide.Initialized )
439 fxMesa->width = driDrawPriv->w;
440 fxMesa->height = driDrawPriv->h;
442 /* We have to use a light lock here, because we can't do any glide
443 * operations yet. No use of FX_* functions in this function.
445 DRM_LIGHT_LOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext );
447 fxMesa->Glide.grGlideInit();
448 fxMesa->Glide.grSstSelect( fxMesa->Glide.Board );
450 fxMesa->Glide.Context = fxMesa->Glide.grSstWinOpen( (FxU32) -1,
453 fxMesa->Glide.ColorFormat,
454 fxMesa->Glide.Origin,
457 fxMesa->Glide.grDRIResetSAREA();
459 DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext );
461 if ( !fxMesa->Glide.Context )
465 /* Perform the Glide-dependant part of the context initialization.
467 FX_grColorMaskv( fxMesa->glCtx, true4 );
469 tdfxTMInit( fxMesa );
471 LOCK_HARDWARE( fxMesa );
473 /* JJJ - COMMAND_TRANSPORT, PALETTE6666 */
474 gext = fxMesa->Glide.grGetString( GR_EXTENSION );
475 fxMesa->Glide.HaveCombineExt = strstr(gext, "COMBINE") && !getenv("MESA_FX_IGNORE_CMBEXT");
476 fxMesa->Glide.HaveCommandTransportExt = GL_FALSE;
477 fxMesa->Glide.HaveFogCoordExt = GL_TRUE;
478 fxMesa->Glide.HavePixelExt = strstr(gext, "PIXEXT") && !getenv("MESA_FX_IGNORE_PIXEXT");
479 fxMesa->Glide.HaveTextureBufferExt = GL_TRUE;
480 fxMesa->Glide.HaveTexFmtExt = strstr(gext, "TEXFMT") && !getenv("MESA_FX_IGNORE_TEXFMT");
481 fxMesa->Glide.HaveTexUMAExt = strstr(gext, "TEXUMA") && !getenv("MESA_FX_IGNORE_TEXUMA");
482 fxMesa->Glide.HaveMirrorExt = strstr(gext, "TEXMIRROR") && !getenv("MESA_FX_IGNORE_MIREXT");
483 fxMesa->Glide.HaveTexus2 = GL_FALSE;
485 if ( fxMesa->glCtx->Visual.depthBits > 0 ) {
486 fxMesa->Glide.grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER);
488 fxMesa->Glide.grDepthBufferMode(GR_DEPTHBUFFER_DISABLE);
491 fxMesa->Glide.grLfbWriteColorFormat( GR_COLORFORMAT_ABGR );
493 fxMesa->Glide.grGet( GR_TEXTURE_ALIGN, sizeof(FxI32), result );
494 fxMesa->Glide.TextureAlign = result[0];
496 fxMesa->Glide.State = NULL;
497 fxMesa->Glide.grGet( GR_GLIDE_STATE_SIZE, sizeof(FxI32), result );
498 fxMesa->Glide.State = MALLOC( result[0] );
500 fxMesa->Fog.Table = NULL;
501 fxMesa->Glide.grGet( GR_FOG_TABLE_ENTRIES, sizeof(FxI32), result );
502 fxMesa->Fog.Table = MALLOC( result[0] * sizeof(GrFog_t) );
504 UNLOCK_HARDWARE( fxMesa );
506 if ( !fxMesa->Glide.State || !fxMesa->Fog.Table ) {
507 if ( fxMesa->Glide.State )
508 FREE( fxMesa->Glide.State );
509 if ( fxMesa->Fog.Table )
510 FREE( fxMesa->Fog.Table );
514 if ( !tdfxInitVertexFormats( fxMesa ) ) {
518 LOCK_HARDWARE( fxMesa );
520 fxMesa->Glide.grGlideGetState( fxMesa->Glide.State );
522 if ( getenv( "FX_GLIDE_INFO" ) ) {
523 printf( "GR_RENDERER = %s\n", (char *) fxMesa->Glide.grGetString( GR_RENDERER ) );
524 printf( "GR_VERSION = %s\n", (char *) fxMesa->Glide.grGetString( GR_VERSION ) );
525 printf( "GR_VENDOR = %s\n", (char *) fxMesa->Glide.grGetString( GR_VENDOR ) );
526 printf( "GR_HARDWARE = %s\n", (char *) fxMesa->Glide.grGetString( GR_HARDWARE ) );
527 printf( "GR_EXTENSION = %s\n", (char *) gext );
530 UNLOCK_HARDWARE( fxMesa );
533 const char *debug = getenv("LIBGL_DEBUG");
534 if (debug && strstr(debug, "fallbacks")) {
535 fxMesa->debugFallbacks = GL_TRUE;
540 fxMesa->numClipRects = 0;
541 fxMesa->pClipRects = NULL;
542 fxMesa->scissoredClipRects = GL_FALSE;
544 fxMesa->Glide.Initialized = GL_TRUE;
551 tdfxDestroyContext( __DRIcontextPrivate *driContextPriv )
553 tdfxContextPtr fxMesa = (tdfxContextPtr) driContextPriv->driverPrivate;
555 if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
556 fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)fxMesa );
560 if (fxMesa->glCtx->Shared->RefCount == 1 && fxMesa->driDrawable) {
561 /* This share group is about to go away, free our private
562 * texture object data.
565 struct gl_texture_object *tObj;
566 tObj = fxMesa->glCtx->Shared->TexObjectList;
568 tdfxTMFreeTexture(fxMesa, tObj);
572 struct _mesa_HashTable *textures = fxMesa->glCtx->Shared->TexObjects;
574 for (id = _mesa_HashFirstEntry(textures);
576 id = _mesa_HashNextEntry(textures, id)) {
577 struct gl_texture_object *tObj
578 = (struct gl_texture_object *) _mesa_HashLookup(textures, id);
579 tdfxTMFreeTexture(fxMesa, tObj);
584 tdfxTMClose(fxMesa); /* free texture memory */
586 _swsetup_DestroyContext( fxMesa->glCtx );
587 _tnl_DestroyContext( fxMesa->glCtx );
588 _ac_DestroyContext( fxMesa->glCtx );
589 _swrast_DestroyContext( fxMesa->glCtx );
591 tdfxFreeVB( fxMesa->glCtx );
593 /* Free Mesa context */
594 fxMesa->glCtx->DriverCtx = NULL;
595 _mesa_destroy_context(fxMesa->glCtx);
597 /* free the tdfx context */
604 tdfxUnbindContext( __DRIcontextPrivate *driContextPriv )
606 GET_CURRENT_CONTEXT(ctx);
607 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
609 if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
610 fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)driContextPriv );
613 if ( driContextPriv && (tdfxContextPtr) driContextPriv == fxMesa ) {
614 LOCK_HARDWARE(fxMesa);
615 fxMesa->Glide.grGlideGetState(fxMesa->Glide.State);
616 UNLOCK_HARDWARE(fxMesa);
623 tdfxMakeCurrent( __DRIcontextPrivate *driContextPriv,
624 __DRIdrawablePrivate *driDrawPriv,
625 __DRIdrawablePrivate *driReadPriv )
627 if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
628 fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)driContextPriv );
631 if ( driContextPriv ) {
632 tdfxContextPtr newFx = (tdfxContextPtr) driContextPriv->driverPrivate;
633 GLcontext *newCtx = newFx->glCtx;
634 GET_CURRENT_CONTEXT(curCtx);
636 if ( newFx->driDrawable != driDrawPriv ) {
637 newFx->driDrawable = driDrawPriv;
641 if (curCtx == newCtx) {
642 /* same drawable, same context -> no-op */
643 /* Need to call _mesa_make_current2() in order to make sure API
644 * dispatch is set correctly.
646 _mesa_make_current2( newCtx,
647 (GLframebuffer *) driDrawPriv->driverPrivate,
648 (GLframebuffer *) driReadPriv->driverPrivate );
651 /* [dBorca] tunnel2 requires this */
655 if ( !newFx->Glide.Initialized ) {
656 if ( !tdfxInitContext( driDrawPriv, newFx ) )
659 LOCK_HARDWARE( newFx );
661 /* FIXME: Force loading of window information */
663 tdfxUpdateClipping(newCtx);
664 tdfxUploadClipping(newFx);
666 UNLOCK_HARDWARE( newFx );
668 LOCK_HARDWARE( newFx );
670 newFx->Glide.grSstSelect( newFx->Glide.Board );
671 newFx->Glide.grGlideSetState( newFx->Glide.State );
673 tdfxUpdateClipping(newCtx);
674 tdfxUploadClipping(newFx);
676 UNLOCK_HARDWARE( newFx );
679 _mesa_make_current2( newCtx,
680 (GLframebuffer *) driDrawPriv->driverPrivate,
681 (GLframebuffer *) driReadPriv->driverPrivate );
683 _mesa_make_current( 0, 0 );
691 * Enable this to trace calls to various Glide functions.
693 /*#define DEBUG_TRAP*/
695 static void (*real_grDrawTriangle)( const void *a, const void *b, const void *c );
696 static void (*real_grDrawPoint)( const void *a );
697 static void (*real_grDrawVertexArray)(FxU32 mode, FxU32 Count, void *pointers);
698 static void (*real_grDrawVertexArrayContiguous)(FxU32 mode, FxU32 Count,
699 void *pointers, FxU32 stride);
700 static void (*real_grClipWindow)( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy );
702 static void (*real_grVertexLayout)(FxU32 param, FxI32 offset, FxU32 mode);
703 static void (*real_grGlideGetVertexLayout)( void *layout );
704 static void (*real_grGlideSetVertexLayout)( const void *layout );
706 static void (*real_grTexDownloadMipMapLevel)( GrChipID_t tmu,
710 GrAspectRatio_t aspectRatio,
711 GrTextureFormat_t format,
716 static void debug_grDrawTriangle( const void *a, const void *b, const void *c )
718 printf("%s\n", __FUNCTION__);
719 (*real_grDrawTriangle)(a, b, c);
722 static void debug_grDrawPoint( const void *a )
724 const float *f = (const float *) a;
725 printf("%s %g %g\n", __FUNCTION__, f[0], f[1]);
726 (*real_grDrawPoint)(a);
729 static void debug_grDrawVertexArray(FxU32 mode, FxU32 Count, void *pointers)
731 printf("%s count=%d\n", __FUNCTION__, (int) Count);
732 (*real_grDrawVertexArray)(mode, Count, pointers);
735 static void debug_grDrawVertexArrayContiguous(FxU32 mode, FxU32 Count,
736 void *pointers, FxU32 stride)
738 printf("%s mode=0x%x count=%d\n", __FUNCTION__, (int) mode, (int) Count);
739 (*real_grDrawVertexArrayContiguous)(mode, Count, pointers, stride);
742 static void debug_grClipWindow( FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy )
744 printf("%s %d,%d .. %d,%d\n", __FUNCTION__,
745 (int) minx, (int) miny, (int) maxx, (int) maxy);
746 (*real_grClipWindow)(minx, miny, maxx, maxy);
749 static void debug_grVertexLayout(FxU32 param, FxI32 offset, FxU32 mode)
751 (*real_grVertexLayout)(param, offset, mode);
754 static void debug_grGlideGetVertexLayout( void *layout )
756 (*real_grGlideGetVertexLayout)(layout);
759 static void debug_grGlideSetVertexLayout( const void *layout )
761 (*real_grGlideSetVertexLayout)(layout);
764 static void debug_grTexDownloadMipMapLevel( GrChipID_t tmu,
768 GrAspectRatio_t aspectRatio,
769 GrTextureFormat_t format,
773 (*real_grTexDownloadMipMapLevel)(tmu, startAddress, thisLod, largeLod,
774 aspectRatio, format, evenOdd, data);
781 * Examine the context's deviceID to determine what kind of 3dfx hardware
782 * is installed. dlopen() the appropriate Glide library and initialize
783 * this context's Glide function pointers.
784 * Return: true/false = success/failure
786 GLboolean tdfxInitGlide(tdfxContextPtr tmesa)
788 static const char *defaultGlide = "libglide3.so";
793 * XXX this code which selects a Glide library filename given the
794 * deviceID may need to be cleaned up a bit.
795 * Non-Linux systems may have different filenames, for example.
797 switch (tmesa->fxScreen->deviceID) {
798 case PCI_CHIP_BANSHEE:
799 case PCI_CHIP_VOODOO3:
800 libName = "libglide3-v3.so";
802 case PCI_CHIP_VOODOO5: /* same as PCI_CHIP_VOODOO4 */
803 libName = "libglide3-v5.so";
807 __driUtilMessage("unrecognized 3dfx deviceID: 0x%x",
808 tmesa->fxScreen->deviceID);
813 libHandle = dlopen(libName, RTLD_NOW);
815 /* The device-specific Glide library filename didn't work, try the
816 * old, generic libglide3.so library.
818 libHandle = dlopen(defaultGlide, RTLD_NOW);
821 "can't find Glide library, dlopen(%s) and dlopen(%s) both failed.",
822 libName, defaultGlide);
823 __driUtilMessage("dlerror() message: %s", dlerror());
826 libName = defaultGlide;
830 const char *env = getenv("LIBGL_DEBUG");
831 if (env && strstr(env, "verbose")) {
832 fprintf(stderr, "libGL: using Glide library %s\n", libName);
836 #define GET_FUNCTION(PTR, NAME) \
837 tmesa->Glide.PTR = dlsym(libHandle, NAME); \
838 if (!tmesa->Glide.PTR) { \
839 __driUtilMessage("couldn't find Glide function %s in %s.", \
843 GET_FUNCTION(grDrawPoint, "grDrawPoint");
844 GET_FUNCTION(grDrawLine, "grDrawLine");
845 GET_FUNCTION(grDrawTriangle, "grDrawTriangle");
846 GET_FUNCTION(grVertexLayout, "grVertexLayout");
847 GET_FUNCTION(grDrawVertexArray, "grDrawVertexArray");
848 GET_FUNCTION(grDrawVertexArrayContiguous, "grDrawVertexArrayContiguous");
849 GET_FUNCTION(grBufferClear, "grBufferClear");
850 /*GET_FUNCTION(grBufferSwap, "grBufferSwap");*/
851 GET_FUNCTION(grRenderBuffer, "grRenderBuffer");
852 GET_FUNCTION(grErrorSetCallback, "grErrorSetCallback");
853 GET_FUNCTION(grFinish, "grFinish");
854 GET_FUNCTION(grFlush, "grFlush");
855 GET_FUNCTION(grSstWinOpen, "grSstWinOpen");
856 GET_FUNCTION(grSstWinClose, "grSstWinClose");
858 /* Not in V3 lib, and not used anyway. */
859 GET_FUNCTION(grSetNumPendingBuffers, "grSetNumPendingBuffers");
861 GET_FUNCTION(grSelectContext, "grSelectContext");
862 GET_FUNCTION(grSstOrigin, "grSstOrigin");
863 GET_FUNCTION(grSstSelect, "grSstSelect");
864 GET_FUNCTION(grAlphaBlendFunction, "grAlphaBlendFunction");
865 GET_FUNCTION(grAlphaCombine, "grAlphaCombine");
866 GET_FUNCTION(grAlphaControlsITRGBLighting, "grAlphaControlsITRGBLighting");
867 GET_FUNCTION(grAlphaTestFunction, "grAlphaTestFunction");
868 GET_FUNCTION(grAlphaTestReferenceValue, "grAlphaTestReferenceValue");
869 GET_FUNCTION(grChromakeyMode, "grChromakeyMode");
870 GET_FUNCTION(grChromakeyValue, "grChromakeyValue");
871 GET_FUNCTION(grClipWindow, "grClipWindow");
872 GET_FUNCTION(grColorCombine, "grColorCombine");
873 GET_FUNCTION(grColorMask, "grColorMask");
874 GET_FUNCTION(grCullMode, "grCullMode");
875 GET_FUNCTION(grConstantColorValue, "grConstantColorValue");
876 GET_FUNCTION(grDepthBiasLevel, "grDepthBiasLevel");
877 GET_FUNCTION(grDepthBufferFunction, "grDepthBufferFunction");
878 GET_FUNCTION(grDepthBufferMode, "grDepthBufferMode");
879 GET_FUNCTION(grDepthMask, "grDepthMask");
880 GET_FUNCTION(grDisableAllEffects, "grDisableAllEffects");
881 GET_FUNCTION(grDitherMode, "grDitherMode");
882 GET_FUNCTION(grFogColorValue, "grFogColorValue");
883 GET_FUNCTION(grFogMode, "grFogMode");
884 GET_FUNCTION(grFogTable, "grFogTable");
885 GET_FUNCTION(grLoadGammaTable, "grLoadGammaTable");
886 GET_FUNCTION(grSplash, "grSplash");
887 GET_FUNCTION(grGet, "grGet");
888 GET_FUNCTION(grGetString, "grGetString");
889 GET_FUNCTION(grQueryResolutions, "grQueryResolutions");
890 GET_FUNCTION(grReset, "grReset");
891 GET_FUNCTION(grGetProcAddress, "grGetProcAddress");
892 GET_FUNCTION(grEnable, "grEnable");
893 GET_FUNCTION(grDisable, "grDisable");
894 GET_FUNCTION(grCoordinateSpace, "grCoordinateSpace");
895 GET_FUNCTION(grDepthRange, "grDepthRange");
896 GET_FUNCTION(grStippleMode, "grStippleMode");
897 GET_FUNCTION(grStipplePattern, "grStipplePattern");
898 GET_FUNCTION(grViewport, "grViewport");
899 GET_FUNCTION(grTexCalcMemRequired, "grTexCalcMemRequired");
900 GET_FUNCTION(grTexTextureMemRequired, "grTexTextureMemRequired");
901 GET_FUNCTION(grTexMinAddress, "grTexMinAddress");
902 GET_FUNCTION(grTexMaxAddress, "grTexMaxAddress");
903 GET_FUNCTION(grTexNCCTable, "grTexNCCTable");
904 GET_FUNCTION(grTexSource, "grTexSource");
905 GET_FUNCTION(grTexClampMode, "grTexClampMode");
906 GET_FUNCTION(grTexCombine, "grTexCombine");
907 GET_FUNCTION(grTexDetailControl, "grTexDetailControl");
908 GET_FUNCTION(grTexFilterMode, "grTexFilterMode");
909 GET_FUNCTION(grTexLodBiasValue, "grTexLodBiasValue");
910 GET_FUNCTION(grTexDownloadMipMap, "grTexDownloadMipMap");
911 GET_FUNCTION(grTexDownloadMipMapLevel, "grTexDownloadMipMapLevel");
912 GET_FUNCTION(grTexDownloadMipMapLevelPartial, "grTexDownloadMipMapLevelPartial");
913 GET_FUNCTION(grTexDownloadTable, "grTexDownloadTable");
914 GET_FUNCTION(grTexDownloadTablePartial, "grTexDownloadTablePartial");
915 GET_FUNCTION(grTexMipMapMode, "grTexMipMapMode");
916 GET_FUNCTION(grTexMultibase, "grTexMultibase");
917 GET_FUNCTION(grTexMultibaseAddress, "grTexMultibaseAddress");
918 GET_FUNCTION(grLfbLock, "grLfbLock");
919 GET_FUNCTION(grLfbUnlock, "grLfbUnlock");
920 GET_FUNCTION(grLfbConstantAlpha, "grLfbConstantAlpha");
921 GET_FUNCTION(grLfbConstantDepth, "grLfbConstantDepth");
922 GET_FUNCTION(grLfbWriteColorSwizzle, "grLfbWriteColorSwizzle");
923 GET_FUNCTION(grLfbWriteColorFormat, "grLfbWriteColorFormat");
924 GET_FUNCTION(grLfbWriteRegion, "grLfbWriteRegion");
925 GET_FUNCTION(grLfbReadRegion, "grLfbReadRegion");
926 GET_FUNCTION(grGlideInit, "grGlideInit");
927 GET_FUNCTION(grGlideShutdown, "grGlideShutdown");
928 GET_FUNCTION(grGlideGetState, "grGlideGetState");
929 GET_FUNCTION(grGlideSetState, "grGlideSetState");
930 GET_FUNCTION(grGlideGetVertexLayout, "grGlideGetVertexLayout");
931 GET_FUNCTION(grGlideSetVertexLayout, "grGlideSetVertexLayout");
933 /* Glide utility functions */
934 GET_FUNCTION(guFogGenerateExp, "guFogGenerateExp");
935 GET_FUNCTION(guFogGenerateExp2, "guFogGenerateExp2");
936 GET_FUNCTION(guFogGenerateLinear, "guFogGenerateLinear");
939 GET_FUNCTION(grDRIOpen, "grDRIOpen");
940 GET_FUNCTION(grDRIPosition, "grDRIPosition");
941 /*GET_FUNCTION(grDRILostContext, "grDRILostContext");*/
942 GET_FUNCTION(grDRIImportFifo, "grDRIImportFifo");
943 GET_FUNCTION(grDRIInvalidateAll, "grDRIInvalidateAll");
944 GET_FUNCTION(grDRIResetSAREA, "grDRIResetSAREA");
945 GET_FUNCTION(grDRIBufferSwap, "grDRIBufferSwap");
948 * Extension functions:
949 * Just use dlysm() because we want a NULL pointer if the function is
952 /* PIXEXT extension */
953 tmesa->Glide.grStencilFunc = dlsym(libHandle, "grStencilFunc");
954 tmesa->Glide.grStencilMask = dlsym(libHandle, "grStencilMask");
955 tmesa->Glide.grStencilOp = dlsym(libHandle, "grStencilOp");
956 tmesa->Glide.grBufferClearExt = dlsym(libHandle, "grBufferClearExt");
957 tmesa->Glide.grColorMaskExt = dlsym(libHandle, "grColorMaskExt");
958 /* COMBINE extension */
959 tmesa->Glide.grColorCombineExt = dlsym(libHandle, "grColorCombineExt");
960 tmesa->Glide.grTexColorCombineExt = dlsym(libHandle, "grTexColorCombineExt");
961 tmesa->Glide.grAlphaCombineExt = dlsym(libHandle, "grAlphaCombineExt");
962 tmesa->Glide.grTexAlphaCombineExt = dlsym(libHandle, "grTexAlphaCombineExt");
963 tmesa->Glide.grAlphaBlendFunctionExt = dlsym(libHandle, "grAlphaBlendFunctionExt");
964 tmesa->Glide.grConstantColorValueExt = dlsym(libHandle, "grConstantColorValueExt");
966 tmesa->Glide.txImgQuantize = dlsym(libHandle, "txImgQuantize");
967 tmesa->Glide.txImgDequantizeFXT1 = dlsym(libHandle, "_txImgDequantizeFXT1");
968 tmesa->Glide.txErrorSetCallback = dlsym(libHandle, "txErrorSetCallback");
971 /* wrap the drawing functions so we can trap them */
972 real_grDrawTriangle = tmesa->Glide.grDrawTriangle;
973 tmesa->Glide.grDrawTriangle = debug_grDrawTriangle;
975 real_grDrawPoint = tmesa->Glide.grDrawPoint;
976 tmesa->Glide.grDrawPoint = debug_grDrawPoint;
978 real_grDrawVertexArray = tmesa->Glide.grDrawVertexArray;
979 tmesa->Glide.grDrawVertexArray = debug_grDrawVertexArray;
981 real_grDrawVertexArrayContiguous = tmesa->Glide.grDrawVertexArrayContiguous;
982 tmesa->Glide.grDrawVertexArrayContiguous = debug_grDrawVertexArrayContiguous;
984 real_grClipWindow = tmesa->Glide.grClipWindow;
985 tmesa->Glide.grClipWindow = debug_grClipWindow;
987 real_grVertexLayout = tmesa->Glide.grVertexLayout;
988 tmesa->Glide.grVertexLayout = debug_grVertexLayout;
990 real_grGlideGetVertexLayout = tmesa->Glide.grGlideGetVertexLayout;
991 tmesa->Glide.grGlideGetVertexLayout = debug_grGlideGetVertexLayout;
993 real_grGlideSetVertexLayout = tmesa->Glide.grGlideSetVertexLayout;
994 tmesa->Glide.grGlideSetVertexLayout = debug_grGlideSetVertexLayout;
996 real_grTexDownloadMipMapLevel = tmesa->Glide.grTexDownloadMipMapLevel;
997 tmesa->Glide.grTexDownloadMipMapLevel = debug_grTexDownloadMipMapLevel;