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

Author: Kenneth Graunke <kenn...@whitecape.org>
Date:   Mon Sep  9 15:36:16 2019 -0700

st/mesa: Only pause queries if there are any active queries to pause.

Previously, ReadPixels, PBO upload/download, and clears would call
cso_save_state with CSO_PAUSE_QUERIES, causing cso_context to call
pipe->set_active_query_state() twice for each operation.  This can
potentially cause driver work to enable/disable statistics counters.

But often, there are no queries happening which need to be paused.
By keeping a simple tally of active queries, we can skip this work.

Reviewed-by: Tapani Pälli <tapani.pa...@intel.com>
Reviewed-by: Marek Olšák <marek.ol...@amd.com>

---

 src/mesa/state_tracker/st_cb_clear.c      | 2 +-
 src/mesa/state_tracker/st_cb_queryobj.c   | 9 ++++++++-
 src/mesa/state_tracker/st_cb_readpixels.c | 2 +-
 src/mesa/state_tracker/st_cb_texture.c    | 2 +-
 src/mesa/state_tracker/st_context.h       | 6 ++++++
 5 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_clear.c 
b/src/mesa/state_tracker/st_cb_clear.c
index 593d15331fd..06fb9798c68 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -267,7 +267,7 @@ clear_with_quad(struct gl_context *ctx, unsigned 
clear_buffers)
                         CSO_BIT_STREAM_OUTPUTS |
                         CSO_BIT_VERTEX_ELEMENTS |
                         CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
-                        CSO_BIT_PAUSE_QUERIES |
+                        (st->active_queries ? CSO_BIT_PAUSE_QUERIES : 0) |
                         CSO_BITS_ALL_SHADERS));
 
    /* blend state: RGBA masking */
diff --git a/src/mesa/state_tracker/st_cb_queryobj.c 
b/src/mesa/state_tracker/st_cb_queryobj.c
index 14de2431d64..bce56e200c3 100644
--- a/src/mesa/state_tracker/st_cb_queryobj.c
+++ b/src/mesa/state_tracker/st_cb_queryobj.c
@@ -221,6 +221,9 @@ st_BeginQuery(struct gl_context *ctx, struct 
gl_query_object *q)
       return;
    }
 
+   if (stq->type != PIPE_QUERY_TIMESTAMP)
+      st->active_queries++;
+
    assert(stq->type == type);
 }
 
@@ -228,7 +231,8 @@ st_BeginQuery(struct gl_context *ctx, struct 
gl_query_object *q)
 static void
 st_EndQuery(struct gl_context *ctx, struct gl_query_object *q)
 {
-   struct pipe_context *pipe = st_context(ctx)->pipe;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
    struct st_query_object *stq = st_query_object(q);
    bool ret = false;
 
@@ -248,6 +252,9 @@ st_EndQuery(struct gl_context *ctx, struct gl_query_object 
*q)
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEndQuery");
       return;
    }
+
+   if (stq->type != PIPE_QUERY_TIMESTAMP)
+      st->active_queries--;
 }
 
 
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c 
b/src/mesa/state_tracker/st_cb_readpixels.c
index e887d8de6d7..71a11be03f3 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -141,7 +141,7 @@ try_pbo_readpixels(struct st_context *st, struct 
st_renderbuffer *strb,
                         CSO_BIT_RASTERIZER |
                         CSO_BIT_DEPTH_STENCIL_ALPHA |
                         CSO_BIT_STREAM_OUTPUTS |
-                        CSO_BIT_PAUSE_QUERIES |
+                        (st->active_queries ? CSO_BIT_PAUSE_QUERIES : 0) |
                         CSO_BIT_SAMPLE_MASK |
                         CSO_BIT_MIN_SAMPLES |
                         CSO_BIT_RENDER_CONDITION |
diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index 3f1c73fe66d..d189d7c1762 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -1233,7 +1233,7 @@ try_pbo_upload_common(struct gl_context *ctx,
                         CSO_BIT_DEPTH_STENCIL_ALPHA |
                         CSO_BIT_RASTERIZER |
                         CSO_BIT_STREAM_OUTPUTS |
-                        CSO_BIT_PAUSE_QUERIES |
+                        (st->active_queries ? CSO_BIT_PAUSE_QUERIES : 0) |
                         CSO_BIT_SAMPLE_MASK |
                         CSO_BIT_MIN_SAMPLES |
                         CSO_BIT_RENDER_CONDITION |
diff --git a/src/mesa/state_tracker/st_context.h 
b/src/mesa/state_tracker/st_context.h
index 50c4a1f28b2..f79b7af1088 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -222,6 +222,12 @@ struct st_context
    GLboolean vertdata_edgeflags;
    GLboolean edgeflag_culls_prims;
 
+   /**
+    * The number of currently active queries (excluding timer queries).
+    * This is used to know if we need to pause any queries for meta ops.
+    */
+   unsigned active_queries;
+
    struct st_vertex_program *vp;    /**< Currently bound vertex program */
    struct st_fragment_program *fp;  /**< Currently bound fragment program */
    struct st_common_program *gp;  /**< Currently bound geometry program */

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to