Merge branch 'master' into crestline
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.c
index c8ba26c425f5dc2f56456d8ce14f5267794ed43b..0daa0ecb7e11a4c7d38b8a2fa768a7b66103d038 100644 (file)
@@ -33,6 +33,7 @@
 #include "extensions.h"
 #include "framebuffer.h"
 #include "imports.h"
+#include "points.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -70,6 +71,7 @@ int INTEL_DEBUG = (0);
 #define need_GL_ARB_vertex_buffer_object
 #define need_GL_ARB_vertex_program
 #define need_GL_ARB_window_pos
+#define need_GL_ARB_occlusion_query
 #define need_GL_EXT_blend_color
 #define need_GL_EXT_blend_equation_separate
 #define need_GL_EXT_blend_func_separate
@@ -117,6 +119,9 @@ static const GLubyte *intelGetString( GLcontext *ctx, GLenum name )
       case PCI_CHIP_I946_GZ:
         chipset = "Intel(R) 946GZ"; break;
          break;
+      case PCI_CHIP_CRESTLINE:
+        chipset = "Intel(R) Crestline"; break;
+         break;
       default:
         chipset = "Unknown Intel Chipset"; break;
       }
@@ -182,7 +187,8 @@ const struct dri_extension card_extensions[] =
     { NULL,                                NULL }
 };
 
-
+static const struct dri_extension arb_oc_extension = 
+    { "GL_ARB_occlusion_query",            GL_ARB_occlusion_query_functions};
 
 static const struct dri_debug_control debug_control[] =
 {
@@ -241,6 +247,36 @@ void intelFinish( GLcontext *ctx )
    bmFinishFence(intel, bmLockAndFence(intel));
 }
 
+static void
+intelBeginQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+{
+       struct intel_context *intel = intel_context( ctx );
+       GLuint64EXT tmp = 0;    
+       drmI830MMIO io = {
+               .read_write = MMIO_WRITE,
+               .reg = MMIO_REGS_PS_DEPTH_COUNT,
+               .data = &tmp 
+       };
+       intel->stats_wm = GL_TRUE;
+       intelFinish(&intel->ctx);
+       drmCommandWrite(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
+}
+
+static void
+intelEndQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+{
+       struct intel_context *intel = intel_context( ctx );
+       drmI830MMIO io = {
+               .read_write = MMIO_READ,
+               .reg = MMIO_REGS_PS_DEPTH_COUNT,
+               .data = &q->Result
+       };
+       intelFinish(&intel->ctx);
+       drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
+       q->Ready = GL_TRUE;
+       intel->stats_wm = GL_FALSE;
+}
+
 
 void intelInitDriverFunctions( struct dd_function_table *functions )
 {
@@ -250,22 +286,16 @@ void intelInitDriverFunctions( struct dd_function_table *functions )
    functions->Finish = intelFinish;
    functions->GetString = intelGetString;
    functions->UpdateState = intelInvalidateState;
-   functions->CopyColorTable = _swrast_CopyColorTable;
-   functions->CopyColorSubTable = _swrast_CopyColorSubTable;
-   functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
-   functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
-
-   /* Pixel path fallbacks.
-    */
-   functions->Accum = _swrast_Accum;
-   functions->Bitmap = _swrast_Bitmap;
-   functions->ReadPixels = _swrast_ReadPixels;
-   functions->DrawPixels = _swrast_DrawPixels;
+   functions->BeginQuery = intelBeginQuery;
+   functions->EndQuery = intelEndQuery;
 
    /* CopyPixels can be accelerated even with the current memory
     * manager:
     */
-   functions->CopyPixels = intelCopyPixels;
+   if (!getenv("INTEL_NO_BLIT")) {
+      functions->CopyPixels = intelCopyPixels;
+      functions->Bitmap = intelBitmap;
+   }
 
    intelInitTextureFuncs( functions );
    intelInitStateFuncs( functions );
@@ -328,6 +358,11 @@ GLboolean intelInitContext( struct intel_context *intel,
    ctx->Const.MaxPointSizeAA = 3.0;
    ctx->Const.PointSizeGranularity = 1.0;
 
+   /* reinitialize the context point state.
+    * It depend on constants in __GLcontextRec::Const
+    */
+   _mesa_init_point(ctx);
+
    /* Initialize the software rasterizer and helper modules. */
    _swrast_CreateContext( ctx );
    _ac_CreateContext( ctx );
@@ -378,11 +413,12 @@ GLboolean intelInitContext( struct intel_context *intel,
       exit(1);
    }
  
-   _math_matrix_ctr (&intel->ViewportMatrix);
-
    driInitExtensions( ctx, card_extensions, 
                      GL_TRUE );
 
+   if (intel->intelScreen->drmMinor >= 8)
+      driInitSingleExtension (ctx, &arb_oc_extension);
+
    INTEL_DEBUG  = driParseDebugString( getenv( "INTEL_DEBUG" ),
                                       debug_control );
 
@@ -408,7 +444,7 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->front.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                GL_FALSE);
+                                intelScreen->front.tiled != 0); /* 0: LINEAR */
 
 
    intel->back_region = 
@@ -419,7 +455,7 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->back.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                (INTEL_DEBUG & DEBUG_TILE) ? 0 : 1);
+                                 intelScreen->back.tiled != 0);
 
    /* Still assuming front.cpp == depth.cpp
     *
@@ -435,7 +471,7 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->depth.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                (INTEL_DEBUG & DEBUG_TILE) ? 0 : 1);
+                                 intelScreen->depth.tiled != 0);
    
    intel_bufferobj_init( intel );
    intel->batch = intel_batchbuffer_alloc( intel );
@@ -587,12 +623,6 @@ static void intelContendedLock( struct intel_context *intel, GLuint flags )
    if (dPriv && intel->lastStamp != dPriv->lastStamp) {
       intelWindowMoved( intel );
       intel->lastStamp = dPriv->lastStamp;
-
-      /* This works because the lock is always grabbed before emitting
-       * commands and commands are always flushed prior to releasing
-       * the lock.
-       */
-      intel->NewGLState |= _NEW_WINDOW_POS; 
    }
 }