i965: ARB_occlusion_query support
authorWang Zhenyu <zhenyu.z.wang@intel.com>
Mon, 11 Dec 2006 08:01:56 +0000 (00:01 -0800)
committerKeith Packard <keithp@neko.keithp.com>
Sat, 6 Jan 2007 23:18:23 +0000 (15:18 -0800)
Signed-off-by: Keith Packard <keithp@neko.keithp.com>
src/mesa/drivers/dri/i965/brw_wm_state.c
src/mesa/drivers/dri/i965/intel_context.c
src/mesa/drivers/dri/i965/intel_context.h
src/mesa/drivers/dri/i965/server/i830_common.h

index 4707a709e779815818224ae3e7f6366286c913f9..e41042d6d27345d95950d49b4ad3546e219bc53f 100644 (file)
@@ -168,7 +168,7 @@ static void upload_wm_unit(struct brw_context *brw )
       wm.wm5.line_stipple = 1;
    }
 
-   if (INTEL_DEBUG & DEBUG_STATS)
+   if (INTEL_DEBUG & DEBUG_STATS || intel->stats_wm)
       wm.wm4.stats_enable = 1;
 
    brw->wm.state_gs_offset = brw_cache_data( &brw->cache[BRW_WM_UNIT], &wm );
index 5e97e4d609849e92ffd3be99d01285d291ebd3be..9acafe5310e17774c3f7fbf1b7fd27b0c1f6326a 100644 (file)
@@ -70,6 +70,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
@@ -157,6 +158,7 @@ const struct dri_extension card_extensions[] =
     { "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 },
@@ -241,6 +243,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,6 +282,8 @@ void intelInitDriverFunctions( struct dd_function_table *functions )
    functions->Finish = intelFinish;
    functions->GetString = intelGetString;
    functions->UpdateState = intelInvalidateState;
+   functions->BeginQuery = intelBeginQuery;
+   functions->EndQuery = intelEndQuery;
 
    /* CopyPixels can be accelerated even with the current memory
     * manager:
index 8367a957109bf2320e4f3f492754ecbc8243881d..fe7ee382a195751436a6613346a06502cc2746fb 100644 (file)
@@ -177,6 +177,7 @@ struct intel_context
    GLuint second_last_swap_fence;
    
    GLboolean aub_wrap;
+   GLboolean stats_wm;
 
    struct intel_batchbuffer *batch;
 
index e3bbdc79070590e0ad87c0601a96a1f2c32ecb6c..f320378c2a5674f86f1c0f07038a07bddb088808 100644 (file)
@@ -52,6 +52,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define DRM_I830_INIT_HEAP                0x0a
 #define DRM_I830_CMDBUFFER                0x0b
 #define DRM_I830_DESTROY_HEAP             0x0c
+#define DRM_I830_MMIO                    0x10
 
 typedef struct {
    enum {
@@ -199,5 +200,23 @@ typedef struct {
        int region;
 } drmI830MemDestroyHeap;
 
+#define MMIO_READ  0
+#define MMIO_WRITE 1
+
+#define MMIO_REGS_IA_PRIMATIVES_COUNT           0
+#define MMIO_REGS_IA_VERTICES_COUNT             1
+#define MMIO_REGS_VS_INVOCATION_COUNT           2
+#define MMIO_REGS_GS_PRIMITIVES_COUNT           3
+#define MMIO_REGS_GS_INVOCATION_COUNT           4
+#define MMIO_REGS_CL_PRIMITIVES_COUNT           5
+#define MMIO_REGS_CL_INVOCATION_COUNT           6
+#define MMIO_REGS_PS_INVOCATION_COUNT           7
+#define MMIO_REGS_PS_DEPTH_COUNT                8
+
+typedef struct {
+        unsigned int read_write:1;
+        unsigned int reg:31;
+        void __user *data;
+} drmI830MMIO;
 
 #endif /* _I830_DRM_H_ */