i965: Correct build_lighting in i965 driver according to
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.c
index 47c8510ad39ecea049fe7a22a4282ba20a1e4580..1fbf571184e092643820685165f6dda65c8c872b 100644 (file)
 #include "extensions.h"
 #include "framebuffer.h"
 #include "imports.h"
+#include "points.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "tnl/tnl.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 
 #include "tnl/t_pipeline.h"
 #include "tnl/t_vertex.h"
 #include "bufmgr.h"
 
 #include "utils.h"
+#include "vblank.h"
 #ifndef INTEL_DEBUG
 int INTEL_DEBUG = (0);
 #endif
 
+#define need_GL_NV_point_sprite
 #define need_GL_ARB_multisample
 #define need_GL_ARB_point_parameters
 #define need_GL_ARB_texture_compression
 #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
@@ -78,17 +82,13 @@ int INTEL_DEBUG = (0);
 #define need_GL_EXT_fog_coord
 #define need_GL_EXT_multi_draw_arrays
 #define need_GL_EXT_secondary_color
+#define need_GL_EXT_point_parameters
 #include "extension_helper.h"
 
 #ifndef VERBOSE
 int VERBOSE = 0;
 #endif
 
-#if DEBUG_LOCKING
-char *prevLockFile;
-int prevLockLine;
-#endif
-
 /***************************************
  * Mesa's Driver Functions
  ***************************************/
@@ -108,17 +108,23 @@ static const GLubyte *intelGetString( GLcontext *ctx, GLenum name )
    case GL_RENDERER:
       switch (intel_context(ctx)->intelScreen->deviceID) {
       case PCI_CHIP_I965_Q:
-        chipset = "Intel(R) 965Q"; break;
+        chipset = "Intel(R) 965Q";
          break;
       case PCI_CHIP_I965_G:
       case PCI_CHIP_I965_G_1:
-        chipset = "Intel(R) 965G"; break;
+        chipset = "Intel(R) 965G";
          break;
       case PCI_CHIP_I946_GZ:
-        chipset = "Intel(R) 946GZ"; break;
+        chipset = "Intel(R) 946GZ";
+         break;
+      case PCI_CHIP_I965_GM:
+        chipset = "Intel(R) 965GM";
+         break;
+      case PCI_CHIP_I965_GME:
+        chipset = "Intel(R) 965GME/GLE";
          break;
       default:
-        chipset = "Unknown Intel Chipset"; break;
+        chipset = "Unknown Intel Chipset";
       }
 
       (void) driGetRendererString( buffer, chipset, DRIVER_VERSION, 0 );
@@ -142,6 +148,7 @@ const struct dri_extension card_extensions[] =
     { "GL_ARB_multisample",                GL_ARB_multisample_functions },
     { "GL_ARB_multitexture",               NULL },
     { "GL_ARB_point_parameters",           GL_ARB_point_parameters_functions },
+    { "GL_NV_point_sprite",                GL_NV_point_sprite_functions },
     { "GL_ARB_texture_border_clamp",       NULL },
     { "GL_ARB_texture_compression",        GL_ARB_texture_compression_functions },
     { "GL_ARB_texture_cube_map",           NULL },
@@ -149,7 +156,13 @@ const struct dri_extension card_extensions[] =
     { "GL_ARB_texture_env_combine",        NULL },
     { "GL_ARB_texture_env_dot3",           NULL },
     { "GL_ARB_texture_mirrored_repeat",    NULL },
+    { "GL_ARB_texture_non_power_of_two",   NULL },
     { "GL_ARB_texture_rectangle",          NULL },
+    { "GL_NV_texture_rectangle",           NULL },
+    { "GL_EXT_texture_rectangle",          NULL },
+    { "GL_ARB_texture_rectangle",          NULL },
+    { "GL_ARB_point_sprite",               NULL},
+    { "GL_ARB_point_parameters",          NULL }, 
     { "GL_ARB_vertex_buffer_object",       GL_ARB_vertex_buffer_object_functions },
     { "GL_ARB_vertex_program",             GL_ARB_vertex_program_functions },
     { "GL_ARB_window_pos",                 GL_ARB_window_pos_functions },
@@ -169,6 +182,7 @@ const struct dri_extension card_extensions[] =
     { "GL_EXT_texture_env_dot3",           NULL },
     { "GL_EXT_texture_filter_anisotropic", NULL },
     { "GL_EXT_texture_lod_bias",           NULL },
+    { "GL_EXT_texture_sRGB",               NULL },
     { "GL_3DFX_texture_compression_FXT1",  NULL },
     { "GL_APPLE_client_storage",           NULL },
     { "GL_MESA_pack_invert",               NULL },
@@ -178,7 +192,16 @@ const struct dri_extension card_extensions[] =
     { NULL,                                NULL }
 };
 
+const struct dri_extension arb_oc_extension = 
+    { "GL_ARB_occlusion_query",            GL_ARB_occlusion_query_functions};
 
+void intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging)
+{           
+       struct intel_context *intel = ctx?intel_context(ctx):NULL;
+       driInitExtensions(ctx, card_extensions, enable_imaging);
+       if (!ctx || intel->intelScreen->drmMinor >= 8)
+               driInitSingleExtension (ctx, &arb_oc_extension);
+}
 
 static const struct dri_debug_control debug_control[] =
 {
@@ -212,7 +235,7 @@ static void intelInvalidateState( GLcontext *ctx, GLuint new_state )
 
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
-   _ac_InvalidateState( ctx, new_state );
+   _vbo_InvalidateState( ctx, new_state );
    _tnl_InvalidateState( ctx, new_state );
    _tnl_invalidate_vertex_state( ctx, new_state );
    
@@ -237,6 +260,37 @@ 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 );
+       drmI830MMIO io = {
+               .read_write = MMIO_READ,
+               .reg = MMIO_REGS_PS_DEPTH_COUNT,
+               .data = &q->Result 
+       };
+       intel->stats_wm++;
+       intelFinish(&intel->ctx);
+       drmCommandRead(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 );
+       GLuint64EXT tmp;        
+       drmI830MMIO io = {
+               .read_write = MMIO_READ,
+               .reg = MMIO_REGS_PS_DEPTH_COUNT,
+               .data = &tmp
+       };
+       intelFinish(&intel->ctx);
+       drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
+       q->Result = tmp - q->Result;
+       q->Ready = GL_TRUE;
+       intel->stats_wm--;
+}
+
 
 void intelInitDriverFunctions( struct dd_function_table *functions )
 {
@@ -246,22 +300,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 );
@@ -296,6 +344,11 @@ GLboolean intelInitContext( struct intel_context *intel,
    intel->driScreen = sPriv;
    intel->sarea = saPriv;
 
+   driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
+                  intel->driScreen->myNum, "i965");
+
+   intel->vblank_flags = (intel->intelScreen->irq_active != 0)
+          ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
 
    ctx->Const.MaxTextureMaxAnisotropy = 2.0;
 
@@ -324,9 +377,14 @@ 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 );
+   _vbo_CreateContext( ctx );
    _tnl_CreateContext( ctx );
    _swsetup_CreateContext( ctx );
 
@@ -373,11 +431,7 @@ GLboolean intelInitContext( struct intel_context *intel,
       _mesa_printf("IRQs not active.  Exiting\n");
       exit(1);
    }
-   _math_matrix_ctr (&intel->ViewportMatrix);
-
-   driInitExtensions( ctx, card_extensions, 
-                     GL_TRUE );
+   intelInitExtensions(ctx, GL_TRUE); 
 
    INTEL_DEBUG  = driParseDebugString( getenv( "INTEL_DEBUG" ),
                                       debug_control );
@@ -404,8 +458,8 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->front.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                GL_FALSE);
-
+                                intelScreen->front.size,
+                                intelScreen->front.tiled != 0);
 
    intel->back_region = 
       intel_region_create_static(intel,
@@ -415,7 +469,8 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->back.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                (INTEL_DEBUG & DEBUG_TILE) ? 0 : 1);
+                                intelScreen->back.size,
+                                 intelScreen->back.tiled != 0);
 
    /* Still assuming front.cpp == depth.cpp
     *
@@ -431,7 +486,8 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->depth.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                (INTEL_DEBUG & DEBUG_TILE) ? 0 : 1);
+                                intelScreen->depth.size,
+                                 intelScreen->depth.tiled != 0);
    
    intel_bufferobj_init( intel );
    intel->batch = intel_batchbuffer_alloc( intel );
@@ -473,7 +529,7 @@ void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
       release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
       _swsetup_DestroyContext (&intel->ctx);
       _tnl_DestroyContext (&intel->ctx);
-      _ac_DestroyContext (&intel->ctx);
+      _vbo_DestroyContext (&intel->ctx);
 
       _swrast_DestroyContext (&intel->ctx);
       intel->Fallback = 0;     /* don't call _swrast_Flush later */
@@ -520,8 +576,15 @@ GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
    if (driContextPriv) {
       struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
 
+      if (intel->driReadDrawable != driReadPriv) {
+          intel->driReadDrawable = driReadPriv;
+      }
+
       if ( intel->driDrawable != driDrawPriv ) {
         /* Shouldn't the readbuffer be stored also? */
+        driDrawableInitVBlank( driDrawPriv, intel->vblank_flags,
+                     &intel->vbl_seq );
+
         intel->driDrawable = driDrawPriv;
         intelWindowMoved( intel );
       }
@@ -583,12 +646,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; 
    }
 }
 
@@ -662,3 +719,4 @@ void UNLOCK_HARDWARE( struct intel_context *intel )
    _glthread_UNLOCK_MUTEX(lockMutex); 
 }
 
+