[Mesa-dev] [PATCH 1/4 v. 2] meta: Allow meta operations to pause/resume an active occlusion query

Carl Worth cworth at cworth.org
Thu Jan 3 15:24:43 PST 2013


This allows for avoiding the occlusion query erroneously accumulating results
during the meta operation. This functionality is made conditional on a new
MESA_META_OCCLUSION_QUERY bit so that meta-operations which should generate
fragments can continue to get the current behavior.

The implementation of glClear is specifically augmented to request the flag
since glClear is specified to not generate fragments.

This fixes the following es3conform tests:

	occlusion_query_draw_occluded.test
 	occlusion_query_clear
	occlusion_query_custom_framebuffer
	occlusion_query_stencil_test
	occlusion_query_discarded_fragments

As well as the recently proposed piglit test:

	occlusion_query_meta_no_fragments
---

Ian Romanick <idr at freedesktop.org> writes:
> I think we need a flag to select this behavior.  There are some meta ops 
> that *do* generate fragments (e.g., _mesa_meta_DrawPixels), and this 
> will prevent them from being counted.

Thanks, Ian.

As expected, writing some piglit tests for this series revealed exactly that
problem.

This updated patch adds the flag so that the "meta_no_fragments" test
will now pass and the "meta_fragments" test will not regress.

-Carl

PS. While I think this patch series is still good (with this update)
there's one remaining related issue with. My new meta_fragments test is
failing with mesa master. Occlusion queries over either of glCopyPixels
or glBitmap result in 0 samples whereas they should be generating
fragments. (This behavior is unchanged by my patch series here.)

Can anyone suggest to me what might be wrong here and how to fix it?

 src/mesa/drivers/common/meta.c |   28 +++++++++++++++++++++++++++-
 src/mesa/drivers/common/meta.h |    1 +
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index f95d207..b2087ab 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -54,6 +54,7 @@
 #include "main/pixel.h"
 #include "main/pbo.h"
 #include "main/polygon.h"
+#include "main/queryobj.h"
 #include "main/readpix.h"
 #include "main/scissor.h"
 #include "main/shaderapi.h"
@@ -89,6 +90,9 @@ struct save_state
 {
    GLbitfield SavedState;  /**< bitmask of MESA_META_* flags */
 
+   /** MESA_META_CLEAR (and others?) */
+   struct gl_query_object *CurrentOcclusionObject;
+   
    /** MESA_META_ALPHA_TEST */
    GLboolean AlphaEnabled;
    GLenum AlphaFunc;
@@ -479,6 +483,15 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
    if (save->TransformFeedbackNeedsResume)
       _mesa_PauseTransformFeedback();
 
+   /* After saving the current occlusion object, call EndQuery so that no
+    * occlusion querying will be active during the meta-operation.
+    */
+   if (state & MESA_META_OCCLUSION_QUERY) {
+      save->CurrentOcclusionObject = ctx->Query.CurrentOcclusionObject;
+      if (save->CurrentOcclusionObject)
+         _mesa_EndQuery(save->CurrentOcclusionObject->Target);
+   }
+
    if (state & MESA_META_ALPHA_TEST) {
       save->AlphaEnabled = ctx->Color.AlphaEnabled;
       save->AlphaFunc = ctx->Color.AlphaFunc;
@@ -807,6 +820,18 @@ _mesa_meta_end(struct gl_context *ctx)
    struct save_state *save = &ctx->Meta->Save[ctx->Meta->SaveStackDepth - 1];
    const GLbitfield state = save->SavedState;
 
+   /* After starting a new occlusion query, initialize the results to the
+    * values saved previously. The driver will then continue to increment
+    * these values.
+    */
+   if (state & MESA_META_OCCLUSION_QUERY) {
+      if (save->CurrentOcclusionObject) {
+         _mesa_BeginQuery(save->CurrentOcclusionObject->Target,
+                          save->CurrentOcclusionObject->Id);
+         ctx->Query.CurrentOcclusionObject->Result = save->CurrentOcclusionObject->Result;
+      }
+   }
+
    if (state & MESA_META_ALPHA_TEST) {
       if (ctx->Color.AlphaEnabled != save->AlphaEnabled)
          _mesa_set_enable(ctx, GL_ALPHA_TEST, save->AlphaEnabled);
@@ -1987,7 +2012,8 @@ _mesa_meta_glsl_Clear(struct gl_context *ctx, GLbitfield buffers)
 	       MESA_META_VIEWPORT |
 	       MESA_META_CLIP |
 	       MESA_META_CLAMP_FRAGMENT_COLOR |
-               MESA_META_MULTISAMPLE);
+               MESA_META_MULTISAMPLE |
+               MESA_META_OCCLUSION_QUERY);
 
    if (!(buffers & BUFFER_BITS_COLOR)) {
       /* We'll use colormask to disable color writes.  Otherwise,
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 6ffc5b5..a6bdd39 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -57,6 +57,7 @@
 #define MESA_META_SELECT_FEEDBACK       0x80000
 #define MESA_META_MULTISAMPLE          0x100000
 #define MESA_META_FRAMEBUFFER_SRGB     0x200000
+#define MESA_META_OCCLUSION_QUERY      0x400000
 /**\}*/
 
 extern void
-- 
1.7.10.4



More information about the mesa-dev mailing list