mesa: improved driver query interface
authorKeith Whitwell <keith@tungstengraphics.com>
Sat, 20 Sep 2008 13:34:23 +0000 (06:34 -0700)
committerKeith Whitwell <keith@tungstengraphics.com>
Sun, 21 Sep 2008 16:44:25 +0000 (09:44 -0700)
Brought over from gallium-0.2 branch.

src/mesa/drivers/common/driverfuncs.c
src/mesa/drivers/dri/intel/intel_context.c
src/mesa/drivers/x11/xm_dd.c
src/mesa/main/dd.h
src/mesa/main/mtypes.h
src/mesa/main/queryobj.c
src/mesa/main/queryobj.h

index f6411f3..9e2cce5 100644 (file)
@@ -228,8 +228,10 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
 
    /* query objects */
    driver->NewQueryObject = _mesa_new_query_object;
-   driver->BeginQuery = NULL;
-   driver->EndQuery = NULL;
+   driver->DeleteQuery = _mesa_delete_query;
+   driver->BeginQuery = _mesa_begin_query;
+   driver->EndQuery = _mesa_end_query;
+   driver->WaitQuery = _mesa_wait_query;
 
    /* APPLE_vertex_array_object */
    driver->NewArrayObject = _mesa_new_array_object;
index eee03d0..57e5744 100644 (file)
@@ -550,7 +550,7 @@ intelFinish(GLcontext * ctx)
 
 #ifdef I915_MMIO_READ
 static void
-intelBeginQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+intelBeginQuery(GLcontext *ctx, struct gl_query_object *q)
 {
        struct intel_context *intel = intel_context( ctx );
        struct drm_i915_mmio io = {
@@ -564,7 +564,7 @@ intelBeginQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
 }
 
 static void
-intelEndQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+intelEndQuery(GLcontext *ctx, struct gl_query_object *q)
 {
        struct intel_context *intel = intel_context( ctx );
        GLuint64EXT tmp;        
index 0a978e5..305df54 100644 (file)
@@ -1086,9 +1086,9 @@ xmesa_new_query_object(GLcontext *ctx, GLuint id)
 
 
 static void
-xmesa_begin_query(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+xmesa_begin_query(GLcontext *ctx, struct gl_query_object *q)
 {
-   if (target == GL_TIME_ELAPSED_EXT) {
+   if (q->Target == GL_TIME_ELAPSED_EXT) {
       struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
       (void) gettimeofday(&xq->StartTime, NULL);
    }
@@ -1113,9 +1113,9 @@ time_diff(const struct timeval *t0, const struct timeval *t1)
 
 
 static void
-xmesa_end_query(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+xmesa_end_query(GLcontext *ctx, struct gl_query_object *q)
 {
-   if (target == GL_TIME_ELAPSED_EXT) {
+   if (q->Target == GL_TIME_ELAPSED_EXT) {
       struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
       struct timeval endTime;
       (void) gettimeofday(&endTime, NULL);
index 8edcfaf..fc9a77d 100644 (file)
@@ -817,9 +817,11 @@ struct dd_function_table {
     */
    /*@{*/
    struct gl_query_object * (*NewQueryObject)(GLcontext *ctx, GLuint id);
-   void (*BeginQuery)(GLcontext *ctx, GLenum target,
-                      struct gl_query_object *q);
-   void (*EndQuery)(GLcontext *ctx, GLenum target, struct gl_query_object *q);
+   void (*DeleteQuery)(GLcontext *ctx, struct gl_query_object *q);
+   void (*BeginQuery)(GLcontext *ctx, struct gl_query_object *q);
+   void (*EndQuery)(GLcontext *ctx, struct gl_query_object *q);
+   void (*CheckQuery)(GLcontext *ctx, struct gl_query_object *q);
+   void (*WaitQuery)(GLcontext *ctx, struct gl_query_object *q);
    /*@}*/
 
 
index f06e4a4..e1abcf4 100644 (file)
@@ -2074,10 +2074,11 @@ struct gl_ati_fragment_shader_state
  */
 struct gl_query_object
 {
-   GLuint Id;
-   GLuint64EXT Result; /* the counter */
-   GLboolean Active;   /* inside Begin/EndQuery */
-   GLboolean Ready;    /* result is ready */
+   GLenum Target;      /**< The query target, when active */
+   GLuint Id;          /**< hash table ID/name */
+   GLuint64EXT Result; /**< the counter */
+   GLboolean Active;   /**< inside Begin/EndQuery */
+   GLboolean Ready;    /**< result is ready? */
 };
 
 
index 0e59ba6..a1e32e7 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  7.1
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -54,14 +54,50 @@ _mesa_new_query_object(GLcontext *ctx, GLuint id)
 
 
 /**
+ * Begin a query.  Software driver fallback.
+ * Called via ctx->Driver.BeginQuery().
+ */
+void
+_mesa_begin_query(GLcontext *ctx, struct gl_query_object *q)
+{
+   /* no-op */
+}
+
+
+/**
+ * End a query.  Software driver fallback.
+ * Called via ctx->Driver.EndQuery().
+ */
+void
+_mesa_end_query(GLcontext *ctx, struct gl_query_object *q)
+{
+   q->Ready = GL_TRUE;
+}
+
+
+/**
+ * Wait for query to complete.  Software driver fallback.
+ * Called via ctx->Driver.WaitQuery().
+ */
+void
+_mesa_wait_query(GLcontext *ctx, struct gl_query_object *q)
+{
+   /* For software drivers, _mesa_end_query() should have completed the query.
+    * For real hardware, implement a proper WaitQuery() driver function.
+    */
+   assert(q->Ready);
+}
+
+
+/**
  * Delete an occlusion query object.
  * Not removed from hash table here.
  * XXX maybe add Delete() method to gl_query_object class and call that instead
  */
-static void
-delete_query_object(struct gl_query_object *q)
+void
+_mesa_delete_query(struct gl_query_object *q)
 {
-   FREE(q);
+   _mesa_free(q);
 }
 
 
@@ -135,7 +171,7 @@ _mesa_DeleteQueriesARB(GLsizei n, const GLuint *ids)
          if (q) {
             ASSERT(!q->Active); /* should be caught earlier */
             _mesa_HashRemove(ctx->Query.QueryObjects, ids[i]);
-            delete_query_object(q);
+            ctx->Driver.DeleteQuery(ctx, q);
          }
       }
    }
@@ -216,6 +252,7 @@ _mesa_BeginQueryARB(GLenum target, GLuint id)
       }
    }
 
+   q->Target = target;
    q->Active = GL_TRUE;
    q->Result = 0;
    q->Ready = GL_FALSE;
@@ -229,9 +266,7 @@ _mesa_BeginQueryARB(GLenum target, GLuint id)
    }
 #endif
 
-   if (ctx->Driver.BeginQuery) {
-      ctx->Driver.BeginQuery(ctx, target, q);
-   }
+   ctx->Driver.BeginQuery(ctx, q);
 }
 
 
@@ -275,13 +310,7 @@ _mesa_EndQueryARB(GLenum target)
    }
 
    q->Active = GL_FALSE;
-   if (ctx->Driver.EndQuery) {
-      ctx->Driver.EndQuery(ctx, target, q);
-   }
-   else {
-      /* if we're using software rendering/querying */
-      q->Ready = GL_TRUE;
-   }
+   ctx->Driver.EndQuery(ctx, q);
 }
 
 
@@ -346,23 +375,19 @@ _mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          /* if result is too large for returned type, clamp to max value */
          if (q->Result > 0x7fffffff) {
             *params = 0x7fffffff;
          }
          else {
-            *params = q->Result;
+            *params = (GLint)q->Result;
          }
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -390,23 +415,19 @@ _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          /* if result is too large for returned type, clamp to max value */
          if (q->Result > 0xffffffff) {
             *params = 0xffffffff;
          }
          else {
-            *params = q->Result;
+            *params = (GLuint)q->Result;
          }
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -439,17 +460,13 @@ _mesa_GetQueryObjecti64vEXT(GLuint id, GLenum pname, GLint64EXT *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          *params = q->Result;
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -480,17 +497,13 @@ _mesa_GetQueryObjectui64vEXT(GLuint id, GLenum pname, GLuint64EXT *params)
 
    switch (pname) {
       case GL_QUERY_RESULT_ARB:
-         while (!q->Ready) {
-            /* Wait for the query to finish! */
-            /* If using software rendering, the result will always be ready
-             * by time we get here.  Otherwise, we must be using hardware!
-             */
-            ASSERT(ctx->Driver.EndQuery);
-         }
+         if (!q->Ready)
+            ctx->Driver.WaitQuery(ctx, q);
          *params = q->Result;
          break;
       case GL_QUERY_RESULT_AVAILABLE_ARB:
-         /* XXX revisit when we have a hardware implementation! */
+        if (!q->Ready)
+           ctx->Driver.CheckQuery( ctx, q );
          *params = q->Ready;
          break;
       default:
@@ -522,8 +535,8 @@ static void
 delete_queryobj_cb(GLuint id, void *data, void *userData)
 {
    struct gl_query_object *q= (struct gl_query_object *) data;
-   (void) userData;
-   delete_query_object(q);
+   GLcontext *ctx = (GLcontext *)userData;
+   ctx->Driver.DeleteQuery(ctx, q);
 }
 
 
index ada8cf8..c05a1f3 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  7.1
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -36,6 +36,19 @@ _mesa_init_query(GLcontext *ctx);
 extern void
 _mesa_free_query_data(GLcontext *ctx);
 
+extern void
+_mesa_delete_query(struct gl_query_object *q);
+
+extern void
+_mesa_begin_query(GLcontext *ctx, struct gl_query_object *q);
+
+extern void
+_mesa_end_query(GLcontext *ctx, struct gl_query_object *q);
+
+extern void
+_mesa_wait_query(GLcontext *ctx, struct gl_query_object *q);
+
+
 extern void GLAPIENTRY
 _mesa_GenQueriesARB(GLsizei n, GLuint *ids);