i965: Fix all non-snb regression in the snb attribute interpolation commit.
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_dd.c
index 367b0d241ef590819e9037d8cc5a8ac67e144f55..2cbbeb811415eaeccfa8665d798ed6e4556bdb2f 100644 (file)
  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c,v 1.10 2002/10/30 12:52:00 alanh Exp $ */
 
-/*
- * Original rewrite:
- *     Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
- *
- * Authors:
- *     Gareth Hughes <gareth@valinux.com>
- *     Brian Paul <brianp@valinux.com>
- *
+/**
+ * \file tdfx_dd.c
+ * Device driver interface functions for 3Dfx based cards.
+ * 
+ * \author Gareth Hughes <gareth@valinux.com> (Original rewrite 29 Sep - 1 Oct 2000)
+ * \author Brian Paul <brianp@valinux.com>
  */
 
 #include "tdfx_context.h"
 #include "tdfx_dd.h"
 #include "tdfx_lock.h"
-#include "tdfx_vb.h"
 #include "tdfx_pixels.h"
 
-#include "context.h"
-#include "enums.h"
-#include "swrast/swrast.h"
-#if defined(USE_X86_ASM)
-#include "x86/common_x86_asm.h"
-#endif
+#include "utils.h"
+#include "main/context.h"
 
 
-#define TDFX_DATE      "20021125"
+#define DRIVER_DATE    "20061113"
 
 
 /* These are used in calls to FX_grColorMaskv() */
@@ -66,67 +58,40 @@ static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
 {
    tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx;
 
-   switch ( name ) {
+   switch (name) {
    case GL_RENDERER:
    {
       /* The renderer string must be per-context state to handle
        * multihead correctly.
        */
-      char *buffer = fxMesa->rendererString;
-      char hardware[100];
+      char *const buffer = fxMesa->rendererString;
+      char hardware[64];
 
       LOCK_HARDWARE(fxMesa);
-      strcpy( hardware, fxMesa->Glide.grGetString(GR_HARDWARE) );
+      strncpy(hardware, fxMesa->Glide.grGetString(GR_HARDWARE),
+             sizeof(hardware));
+      hardware[sizeof(hardware) - 1] = '\0';
       UNLOCK_HARDWARE(fxMesa);
 
-      strcpy( buffer, "Mesa DRI " );
-      strcat( buffer, TDFX_DATE );
-      strcat( buffer, " " );
-
-      if ( strcmp( hardware, "Voodoo3 (tm)" ) == 0 ) {
-        strcat( buffer, "Voodoo3" );
-      }
-      else if ( strcmp( hardware, "Voodoo Banshee (tm)" ) == 0 ) {
-        strcat( buffer, "VoodooBanshee" );
-      }
-      else if ( strcmp( hardware, "Voodoo4 (tm)" ) == 0 ) {
-        strcat( buffer, "Voodoo4" );
+      if ((strncmp(hardware, "Voodoo3", 7) == 0)
+         || (strncmp(hardware, "Voodoo4", 7) == 0)
+         || (strncmp(hardware, "Voodoo5", 7) == 0)) {
+        hardware[7] = '\0';
       }
-      else if ( strcmp( hardware, "Voodoo5 (tm)" ) == 0 ) {
-        strcat( buffer, "Voodoo5" );
+      else if (strncmp(hardware, "Voodoo Banshee", 14) == 0) {
+        strcpy(&hardware[6], "Banshee");
       }
       else {
         /* unexpected result: replace spaces with hyphens */
         int i;
-        for ( i = 0 ; hardware[i] && i < 60 ; i++ ) {
-           if ( hardware[i] == ' ' || hardware[i] == '\t' )
+        for (i = 0; i < sizeof(hardware) && hardware[i]; i++) {
+           if (hardware[i] == ' ' || hardware[i] == '\t') {
               hardware[i] = '-';
+           }
         }
-         strcat( buffer, hardware );
       }
 
-      /* Append any CPU-specific information.
-       */
-#ifdef USE_X86_ASM
-      if ( _mesa_x86_cpu_features ) {
-        strncat( buffer, " x86", 4 );
-      }
-#endif
-#ifdef USE_MMX_ASM
-      if ( cpu_has_mmx ) {
-        strncat( buffer, "/MMX", 4 );
-      }
-#endif
-#ifdef USE_3DNOW_ASM
-      if ( cpu_has_3dnow ) {
-        strncat( buffer, "/3DNow!", 7 );
-      }
-#endif
-#ifdef USE_SSE_ASM
-      if ( cpu_has_xmm ) {
-        strncat( buffer, "/SSE", 4 );
-      }
-#endif
+      (void) driGetRendererString(buffer, hardware, DRIVER_DATE, 0);
       return (const GLubyte *) buffer;
    }
    case GL_VENDOR:
@@ -137,111 +102,55 @@ static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name )
 }
 
 
-/* Return uptodate buffer size information.
- */
-static void tdfxDDGetBufferSize( GLframebuffer *buffer,
-                                GLuint *width, GLuint *height )
+static void
+tdfxBeginQuery(GLcontext *ctx, struct gl_query_object *q)
 {
-   GET_CURRENT_CONTEXT(ctx);
    tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
 
-   LOCK_HARDWARE( fxMesa );
-   *width = fxMesa->width;
-   *height = fxMesa->height;
-   UNLOCK_HARDWARE( fxMesa );
-}
+   (void) q;
 
+   if (q->Target == GL_SAMPLES_PASSED_ARB) {
+      LOCK_HARDWARE(fxMesa);
+      fxMesa->Glide.grFinish();
+      fxMesa->Glide.grReset(GR_STATS_PIXELS);
+      UNLOCK_HARDWARE(fxMesa);
+   }
+}
 
 
-/*
- * Return the current value of the occlusion test flag and
- * reset the flag (hardware counters) to false.
- */
-static GLboolean get_occlusion_result( GLcontext *ctx )
+static void
+tdfxEndQuery(GLcontext *ctx, struct gl_query_object *q)
 {
    tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
-   GLboolean result;
-
-   LOCK_HARDWARE( fxMesa );
-   fxMesa->Glide.grFinish(); /* required to flush the FIFO - FB 21-01-2002 */ 
-
-   if (ctx->Depth.OcclusionTest) {
-      if (ctx->OcclusionResult) {
-        result = GL_TRUE;  /* result of software rendering */
-      }
-      else {
-        FxI32 zfail, in;
-         fxMesa->Glide.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &zfail);
-         fxMesa->Glide.grGet(GR_STATS_PIXELS_IN, 4, &in);
-         /* Geometry is occluded if there is no input (in == 0) */
-         /* or if all pixels failed the depth test (zfail == in) */
-         /* The < 1 is there because I have empirically seen cases where */
-         /* zfail > in.... go figure.  FB - 21-01-2002. */
-         result = ((in - zfail) < 1 || in == 0) ? GL_FALSE : GL_TRUE;
-      }
-   }
-   else {
-      result = ctx->OcclusionResultSaved;
-   }
+   FxI32 total_pixels;
+   FxI32 z_fail_pixels;
 
-   /* reset results now */
-   fxMesa->Glide.grReset(GR_STATS_PIXELS);
-   ctx->OcclusionResult = GL_FALSE;
-   ctx->OcclusionResultSaved = GL_FALSE;
-
-   UNLOCK_HARDWARE( fxMesa );
-
-   return result;
-}
 
+   if (q->Target == GL_SAMPLES_PASSED_ARB) {
+      LOCK_HARDWARE(fxMesa);
+      fxMesa->Glide.grFinish();
 
-/*
- * We're only implementing this function to handle the
- * GL_OCCLUSTION_TEST_RESULT_HP case.  It's special because it
- * has a side-effect: resetting the occlustion result flag.
- */
-static GLboolean tdfxDDGetBooleanv( GLcontext *ctx, GLenum pname,
-                                   GLboolean *result )
-{
-   if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
-      *result = get_occlusion_result( ctx );
-      return GL_TRUE;
-   }
-   return GL_FALSE;
-}
+      fxMesa->Glide.grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, sizeof(FxI32),
+                         &z_fail_pixels);
+      fxMesa->Glide.grGet(GR_STATS_PIXELS_IN, sizeof(FxI32), &total_pixels);
 
-static GLboolean tdfxDDGetDoublev( GLcontext *ctx, GLenum pname,
-                                  GLdouble *result )
-{
-   if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
-      *result = (GLdouble) get_occlusion_result( ctx );
-      return GL_TRUE;
-   }
-   return GL_FALSE;
-}
+      q->Result = total_pixels - z_fail_pixels;
+      
+      /* Apparently, people have seen z_fail_pixels > total_pixels under
+       * some conditions on some 3Dfx hardware.  The occlusion query spec
+       * requires that we clamp to 0.
+       */
+      if (q->Result < 0) {
+        q->Result = 0;
+      }
 
-static GLboolean tdfxDDGetFloatv( GLcontext *ctx, GLenum pname,
-                                 GLfloat *result )
-{
-   if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
-      *result = (GLfloat) get_occlusion_result( ctx );
-      return GL_TRUE;
-   }
-   return GL_FALSE;
-}
+      q->Ready = GL_TRUE;
 
-static GLboolean tdfxDDGetIntegerv( GLcontext *ctx, GLenum pname,
-                                   GLint *result )
-{
-   if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) {
-      *result = (GLint) get_occlusion_result( ctx );
-      return GL_TRUE;
+      UNLOCK_HARDWARE(fxMesa);
    }
-   return GL_FALSE;
 }
 
 
-
 #define VISUAL_EQUALS_RGBA(vis, r, g, b, a)        \
    ((vis->redBits == r) &&                         \
     (vis->greenBits == g) &&                       \
@@ -255,9 +164,9 @@ void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
       fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ );
    }
 
-   functions->GetString                = tdfxDDGetString;
-   functions->GetBufferSize    = tdfxDDGetBufferSize;
-   functions->ResizeBuffers     = _swrast_alloc_buffers;
+   functions->GetString         = tdfxDDGetString;
+   functions->BeginQuery        = tdfxBeginQuery;
+   functions->EndQuery          = tdfxEndQuery;
 
    /* Accelerated paths
     */
@@ -270,11 +179,6 @@ void tdfxDDInitDriverFuncs( const __GLcontextModes *visual,
    {
       functions->ReadPixels    = tdfx_readpixels_R5G6B5;
    }
-
-   functions->GetBooleanv      = tdfxDDGetBooleanv;
-   functions->GetDoublev       = tdfxDDGetDoublev;
-   functions->GetFloatv                = tdfxDDGetFloatv;
-   functions->GetIntegerv      = tdfxDDGetIntegerv;
 }