[i915] Include header to pick up intel_ttm_bo_create_from_handle() proto.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.c
index 1546b33108c7879dd410b3d0e964dc978d5e24dd..d654d2d30dea089e703330853c29e2f14415443f 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"
@@ -45,6 +46,7 @@
 #include "drivers/common/driverfuncs.h"
 
 #include "intel_screen.h"
+#include "intel_chipset.h"
 
 #include "i830_dri.h"
 #include "i830_common.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
@@ -79,17 +83,18 @@ 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
+#define need_GL_VERSION_2_0
+#define need_GL_VERSION_2_1
+#define need_GL_ARB_shader_objects
+#define need_GL_ARB_vertex_shader
+
 #include "extension_helper.h"
 
 #ifndef VERBOSE
 int VERBOSE = 0;
 #endif
 
-#if DEBUG_LOCKING
-char *prevLockFile;
-int prevLockLine;
-#endif
-
 /***************************************
  * Mesa's Driver Functions
  ***************************************/
@@ -109,20 +114,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_CRESTLINE:
-        chipset = "Intel(R) Crestline"; 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 );
@@ -146,6 +154,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 },
@@ -158,10 +167,11 @@ const struct dri_extension card_extensions[] =
     { "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 },
-    { "GL_ARB_occlusion_query",            GL_ARB_occlusion_query_functions},
     { "GL_EXT_blend_color",                GL_EXT_blend_color_functions },
     { "GL_EXT_blend_equation_separate",    GL_EXT_blend_equation_separate_functions },
     { "GL_EXT_blend_func_separate",        GL_EXT_blend_func_separate_functions },
@@ -178,16 +188,33 @@ 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 },
     { "GL_MESA_ycbcr_texture",             NULL },
     { "GL_NV_blend_square",                NULL },
     { "GL_SGIS_generate_mipmap",           NULL },
+    { "GL_ARB_shading_language_100",       GL_VERSION_2_0_functions},
+    { "GL_ARB_shading_language_120",       GL_VERSION_2_1_functions},
+    { "GL_ARB_shader_objects",             GL_ARB_shader_objects_functions},
+    { "GL_ARB_vertex_shader",              GL_ARB_vertex_shader_functions},
+    { "GL_ARB_fragment_shader",            NULL },
+    /* XXX not implement yet, to compile builtin glsl lib */
+    { "GL_ARB_draw_buffers",               NULL },
     { 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[] =
 {
@@ -211,6 +238,7 @@ static const struct dri_debug_control debug_control[] =
     { "thre",  DEBUG_SINGLE_THREAD },
     { "wm",    DEBUG_WM },
     { "vs",    DEBUG_VS },
+    { "bat",   DEBUG_BATCH },
     { NULL,    0 }
 };
 
@@ -221,7 +249,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 );
    
@@ -250,13 +278,12 @@ 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,
+               .read_write = MMIO_READ,
                .reg = MMIO_REGS_PS_DEPTH_COUNT,
-               .data = &tmp 
+               .data = &q->Result 
        };
-       intel->stats_wm = GL_TRUE;
+       intel->stats_wm++;
        intelFinish(&intel->ctx);
        drmCommandWrite(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
 }
@@ -265,15 +292,17 @@ 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 = &q->Result
+               .data = &tmp
        };
        intelFinish(&intel->ctx);
-       drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
+       drmCommandWrite(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
+       q->Result = tmp - q->Result;
        q->Ready = GL_TRUE;
-       intel->stats_wm = GL_FALSE;
+       intel->stats_wm--;
 }
 
 
@@ -313,8 +342,8 @@ GLboolean intelInitContext( struct intel_context *intel,
    GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
    __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
    intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
-   volatile drmI830Sarea *saPriv = (volatile drmI830Sarea *)
-      (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
+   volatile drmI830Sarea *saPriv = (drmI830Sarea *)
+     (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
 
    if (!_mesa_initialize_context(&intel->ctx,
                                 mesaVis, shareCtx, 
@@ -329,6 +358,8 @@ GLboolean intelInitContext( struct intel_context *intel,
    intel->driScreen = sPriv;
    intel->sarea = saPriv;
 
+   driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
+                  intel->driScreen->myNum, "i965");
 
    ctx->Const.MaxTextureMaxAnisotropy = 2.0;
 
@@ -364,7 +395,7 @@ GLboolean intelInitContext( struct intel_context *intel,
 
    /* Initialize the software rasterizer and helper modules. */
    _swrast_CreateContext( ctx );
-   _ac_CreateContext( ctx );
+   _vbo_CreateContext( ctx );
    _tnl_CreateContext( ctx );
    _swsetup_CreateContext( ctx );
 
@@ -411,9 +442,7 @@ GLboolean intelInitContext( struct intel_context *intel,
       _mesa_printf("IRQs not active.  Exiting\n");
       exit(1);
    }
-   driInitExtensions( ctx, card_extensions, 
-                     GL_TRUE );
+   intelInitExtensions(ctx, GL_TRUE); 
 
    INTEL_DEBUG  = driParseDebugString( getenv( "INTEL_DEBUG" ),
                                       debug_control );
@@ -440,8 +469,8 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->front.pitch / intelScreen->cpp,
                                 intelScreen->height,
-                                intelScreen->front.tiled != 0); /* 0: LINEAR */
-
+                                intelScreen->front.size,
+                                intelScreen->front.tiled != 0);
 
    intel->back_region = 
       intel_region_create_static(intel,
@@ -451,6 +480,7 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->back.pitch / intelScreen->cpp,
                                 intelScreen->height,
+                                intelScreen->back.size,
                                  intelScreen->back.tiled != 0);
 
    /* Still assuming front.cpp == depth.cpp
@@ -467,6 +497,7 @@ GLboolean intelInitContext( struct intel_context *intel,
                                 intelScreen->cpp,
                                 intelScreen->depth.pitch / intelScreen->cpp,
                                 intelScreen->height,
+                                intelScreen->depth.size,
                                  intelScreen->depth.tiled != 0);
    
    intel_bufferobj_init( intel );
@@ -476,7 +507,7 @@ GLboolean intelInitContext( struct intel_context *intel,
       _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
       _mesa_enable_extension( ctx, "GL_S3_s3tc" );
    }
-   else if (driQueryOptionb (&intelScreen->optionCache, "force_s3tc_enable")) {
+   else if (driQueryOptionb (&intel->optionCache, "force_s3tc_enable")) {
       _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
    }
 
@@ -509,7 +540,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 */
@@ -537,6 +568,8 @@ void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
 #endif
 
       /* free the Mesa context */
+      intel->ctx.VertexProgram.Current = NULL;
+      intel->ctx.FragmentProgram.Current = NULL;
       _mesa_destroy_context(&intel->ctx);
    }
 
@@ -556,10 +589,19 @@ GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
    if (driContextPriv) {
       struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
 
+      driDrawPriv->vblFlags = (intel->intelScreen->irq_active != 0)
+         ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
+
+
+      if (intel->driReadDrawable != driReadPriv) {
+          intel->driReadDrawable = driReadPriv;
+      }
+
       if ( intel->driDrawable != driDrawPriv ) {
-        /* Shouldn't the readbuffer be stored also? */
         intel->driDrawable = driDrawPriv;
         intelWindowMoved( intel );
+        /* Shouldn't the readbuffer be stored also? */
+        driDrawableInitVBlank( driDrawPriv );
       }
 
       _mesa_make_current(&intel->ctx,
@@ -641,19 +683,12 @@ void LOCK_HARDWARE( struct intel_context *intel )
 
    intel->locked = 1;
 
-   if (intel->aub_wrap) {
-      bm_fake_NotifyContendedLockTake( intel ); 
-      intel->vtbl.lost_hardware( intel );
-      intel->vtbl.aub_wrap(intel);
-      intel->aub_wrap = 0;
-   }
-
    if (bmError(intel)) {
       bmEvictAll(intel);
       intel->vtbl.lost_hardware( intel );
    }
 
-   /* Make sure nothing has been emitted prior to getting the lock: 
+   /* Make sure nothing has been emitted prior to getting the lock:
     */
    assert(intel->batch->map == 0);
 
@@ -686,9 +721,8 @@ void UNLOCK_HARDWARE( struct intel_context *intel )
    intel->vtbl.note_unlock( intel );
    intel->locked = 0;
 
-
-
    DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
    _glthread_UNLOCK_MUTEX(lockMutex); 
 }
 
+