Mesa (master): mesa: Add constants for the GL_QUERY_COUNTER_BITS per target .

Eric Anholt anholt at kemper.freedesktop.org
Sun Aug 26 19:08:29 UTC 2012


Module: Mesa
Branch: master
Commit: b765119c5d2cd41a7f47cce10fd1fdbcf162b03d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b765119c5d2cd41a7f47cce10fd1fdbcf162b03d

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Aug 23 10:18:47 2012 -0700

mesa: Add constants for the GL_QUERY_COUNTER_BITS per target.

Drivers need to be able to communicate their actual number of bits populated
in the field in order for applications to be able to properly handle rollover.

There's a small behavior change here: Instead of reporting the
GL_SAMPLES_PASSED bits for GL_ANY_SAMPLES_PASSED (which would also be valid),
just return 1, because more bits don't make any sense.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/main/mtypes.h   |    8 ++++++++
 src/mesa/main/queryobj.c |   37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 552c1cf..58111a7 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2820,6 +2820,14 @@ struct gl_constants
    GLuint MaxProgramMatrices;
    GLuint MaxProgramMatrixStackDepth;
 
+   struct {
+      GLuint SamplesPassed;
+      GLuint TimeElapsed;
+      GLuint Timestamp;
+      GLuint PrimitivesGenerated;
+      GLuint PrimitivesWritten;
+   } QueryCounterBits;
+
    /** vertex array / buffer object bounds checking */
    GLboolean CheckArrayBounds;
 
diff --git a/src/mesa/main/queryobj.c b/src/mesa/main/queryobj.c
index 4492a17..407a761 100644
--- a/src/mesa/main/queryobj.c
+++ b/src/mesa/main/queryobj.c
@@ -482,7 +482,36 @@ _mesa_GetQueryIndexediv(GLenum target, GLuint index, GLenum pname,
 
    switch (pname) {
       case GL_QUERY_COUNTER_BITS_ARB:
-         *params = 8 * sizeof(q->Result);
+         switch (target) {
+         case GL_SAMPLES_PASSED:
+            *params = ctx->Const.QueryCounterBits.SamplesPassed;
+            break;
+         case GL_ANY_SAMPLES_PASSED:
+            /* The minimum value of this is 1 if it's nonzero, and the value
+             * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
+             * bits.
+             */
+            *params = 1;
+            break;
+         case GL_TIME_ELAPSED:
+            *params = ctx->Const.QueryCounterBits.TimeElapsed;
+            break;
+         case GL_TIMESTAMP:
+            *params = ctx->Const.QueryCounterBits.Timestamp;
+            break;
+         case GL_PRIMITIVES_GENERATED:
+            *params = ctx->Const.QueryCounterBits.PrimitivesGenerated;
+            break;
+         case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+            *params = ctx->Const.QueryCounterBits.PrimitivesWritten;
+            break;
+         default:
+            _mesa_problem(ctx,
+                          "Unknown target in glGetQueryIndexediv(target = %s)",
+                          _mesa_lookup_enum_by_nr(target));
+            *params = 0;
+            break;
+         }
          break;
       case GL_CURRENT_QUERY_ARB:
          *params = q ? q->Id : 0;
@@ -716,6 +745,12 @@ _mesa_init_queryobj(struct gl_context *ctx)
 {
    ctx->Query.QueryObjects = _mesa_NewHashTable();
    ctx->Query.CurrentOcclusionObject = NULL;
+
+   ctx->Const.QueryCounterBits.SamplesPassed = 64;
+   ctx->Const.QueryCounterBits.TimeElapsed = 64;
+   ctx->Const.QueryCounterBits.Timestamp = 64;
+   ctx->Const.QueryCounterBits.PrimitivesGenerated = 64;
+   ctx->Const.QueryCounterBits.PrimitivesWritten = 64;
 }
 
 




More information about the mesa-commit mailing list