[Mesa-dev] [PATCH 2/6] gallium: manage render condition in cso_context and fix postprocessing w/ it

Marek Olšák maraeo at gmail.com
Sat Dec 8 06:40:18 PST 2012


---
 src/gallium/auxiliary/cso_cache/cso_context.c |   26 +++++++++++++++++++++++++
 src/gallium/auxiliary/cso_cache/cso_context.h |    5 +++++
 src/gallium/auxiliary/postprocess/pp_run.c    |    3 +++
 src/gallium/auxiliary/util/u_blit.c           |    3 +++
 src/gallium/auxiliary/util/u_gen_mipmap.c     |    3 +++
 src/mesa/state_tracker/st_cb_condrender.c     |   11 +++--------
 src/mesa/state_tracker/st_cb_texture.c        |   12 ------------
 src/mesa/state_tracker/st_context.h           |    4 ----
 src/mesa/state_tracker/st_gen_mipmap.c        |    9 ---------
 9 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index b3decc5..b4ffac6 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -106,6 +106,8 @@ struct cso_context {
    void *vertex_shader, *vertex_shader_saved;
    void *geometry_shader, *geometry_shader_saved;
    void *velements, *velements_saved;
+   struct pipe_query *render_condition, *render_condition_saved;
+   uint render_condition_mode, render_condition_mode_saved;
 
    struct pipe_clip_state clip;
    struct pipe_clip_state clip_saved;
@@ -723,6 +725,30 @@ void cso_restore_stencil_ref(struct cso_context *ctx)
    }
 }
 
+void cso_set_render_condition(struct cso_context *ctx,
+                              struct pipe_query *query, uint mode)
+{
+   struct pipe_context *pipe = ctx->pipe;
+
+   if (ctx->render_condition != query || ctx->render_condition_mode != mode) {
+      pipe->render_condition(pipe, query, mode);
+      ctx->render_condition = query;
+      ctx->render_condition_mode = mode;
+   }
+}
+
+void cso_save_render_condition(struct cso_context *ctx)
+{
+   ctx->render_condition_saved = ctx->render_condition;
+   ctx->render_condition_mode_saved = ctx->render_condition_mode;
+}
+
+void cso_restore_render_condition(struct cso_context *ctx)
+{
+   cso_set_render_condition(ctx, ctx->render_condition_saved,
+                            ctx->render_condition_mode_saved);
+}
+
 enum pipe_error cso_set_geometry_shader_handle(struct cso_context *ctx,
                                                void *handle)
 {
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
index 16158ed..b991eb9 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.h
+++ b/src/gallium/auxiliary/cso_cache/cso_context.h
@@ -173,6 +173,11 @@ enum pipe_error cso_set_stencil_ref(struct cso_context *cso,
 void cso_save_stencil_ref(struct cso_context *cso);
 void cso_restore_stencil_ref(struct cso_context *cso);
 
+void cso_set_render_condition(struct cso_context *cso,
+                              struct pipe_query *query, uint mode);
+void cso_save_render_condition(struct cso_context *cso);
+void cso_restore_render_condition(struct cso_context *cso);
+
 
 /* clip state */
 
diff --git a/src/gallium/auxiliary/postprocess/pp_run.c b/src/gallium/auxiliary/postprocess/pp_run.c
index 6f06324..112458f 100644
--- a/src/gallium/auxiliary/postprocess/pp_run.c
+++ b/src/gallium/auxiliary/postprocess/pp_run.c
@@ -82,11 +82,13 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    cso_save_vertex_shader(cso);
    cso_save_viewport(cso);
    cso_save_aux_vertex_buffer_slot(cso);
+   cso_save_render_condition(cso);
 
    /* set default state */
    cso_set_sample_mask(cso, ~0);
    cso_set_stream_outputs(cso, 0, NULL, 0);
    cso_set_geometry_shader_handle(cso, NULL);
+   cso_set_render_condition(cso, NULL, 0);
 
    // Kept only for this frame.
    pipe_resource_reference(&ppq->depth, indepth);
@@ -139,6 +141,7 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    cso_restore_vertex_shader(cso);
    cso_restore_viewport(cso);
    cso_restore_aux_vertex_buffer_slot(cso);
+   cso_restore_render_condition(cso);
 
    pipe_resource_reference(&ppq->depth, NULL);
    pipe_resource_reference(&refin, NULL);
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index ab1549e..9fe15b8 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -666,6 +666,7 @@ util_blit_pixels(struct blit_state *ctx,
    cso_save_geometry_shader(ctx->cso);
    cso_save_vertex_elements(ctx->cso);
    cso_save_aux_vertex_buffer_slot(ctx->cso);
+   cso_save_render_condition(ctx->cso);
 
    /* set misc state we care about */
    if (writemask)
@@ -677,6 +678,7 @@ util_blit_pixels(struct blit_state *ctx,
    cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
    cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
    cso_set_stream_outputs(ctx->cso, 0, NULL, 0);
+   cso_set_render_condition(ctx->cso, NULL, 0);
 
    /* default sampler state */
    ctx->sampler.normalized_coords = normalized;
@@ -799,6 +801,7 @@ util_blit_pixels(struct blit_state *ctx,
    cso_restore_vertex_elements(ctx->cso);
    cso_restore_aux_vertex_buffer_slot(ctx->cso);
    cso_restore_stream_outputs(ctx->cso);
+   cso_restore_render_condition(ctx->cso);
 
    pipe_sampler_view_reference(&sampler_view, NULL);
    if (dst_surface != dst)
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 48ebdb9..90588a0 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -1566,6 +1566,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_save_viewport(ctx->cso);
    cso_save_vertex_elements(ctx->cso);
    cso_save_aux_vertex_buffer_slot(ctx->cso);
+   cso_save_render_condition(ctx->cso);
 
    /* bind our state */
    cso_set_blend(ctx->cso, is_depth ? &ctx->blend_keep_color :
@@ -1576,6 +1577,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_set_sample_mask(ctx->cso, ~0);
    cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
    cso_set_stream_outputs(ctx->cso, 0, NULL, 0);
+   cso_set_render_condition(ctx->cso, NULL, 0);
 
    set_fragment_shader(ctx, type, is_depth);
    set_vertex_shader(ctx);
@@ -1699,4 +1701,5 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_restore_vertex_elements(ctx->cso);
    cso_restore_stream_outputs(ctx->cso);
    cso_restore_aux_vertex_buffer_slot(ctx->cso);
+   cso_restore_render_condition(ctx->cso);
 }
diff --git a/src/mesa/state_tracker/st_cb_condrender.c b/src/mesa/state_tracker/st_cb_condrender.c
index 1ced560..3a5835e 100644
--- a/src/mesa/state_tracker/st_cb_condrender.c
+++ b/src/mesa/state_tracker/st_cb_condrender.c
@@ -38,6 +38,7 @@
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
+#include "cso_cache/cso_context.h"
 #include "st_context.h"
 #include "st_cb_queryobj.h"
 #include "st_cb_condrender.h"
@@ -53,7 +54,6 @@ st_BeginConditionalRender(struct gl_context *ctx, struct gl_query_object *q,
 {
    struct st_query_object *stq = st_query_object(q);
    struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
    uint m;
 
    st_flush_bitmap_cache(st);
@@ -76,10 +76,7 @@ st_BeginConditionalRender(struct gl_context *ctx, struct gl_query_object *q,
       m = PIPE_RENDER_COND_WAIT;
    }
 
-   st->render_condition = stq->pq;
-   st->condition_mode = m;
-
-   pipe->render_condition(pipe, stq->pq, m);
+   cso_set_render_condition(st->cso_context, stq->pq, m);
 }
 
 
@@ -90,13 +87,11 @@ static void
 st_EndConditionalRender(struct gl_context *ctx, struct gl_query_object *q)
 {
    struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
    (void) q;
 
    st_flush_bitmap_cache(st);
 
-   pipe->render_condition(pipe, NULL, 0);
-   st->render_condition = NULL;
+   cso_set_render_condition(st->cso_context, NULL, 0);
 }
 
 
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index ae069eb..1ddb695 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -1089,11 +1089,6 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
       goto fallback;
    }
 
-   /* Disable conditional rendering. */
-   if (st->render_condition) {
-      pipe->render_condition(pipe, NULL, 0);
-   }
-
    memset(&surf_tmpl, 0, sizeof(surf_tmpl));
    surf_tmpl.format = util_format_linear(stImage->pt->format);
    surf_tmpl.usage = dst_usage;
@@ -1115,13 +1110,6 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims,
                     0.0, PIPE_TEX_MIPFILTER_NEAREST,
                     color_writemask, 0);
    pipe_surface_reference(&dest_surface, NULL);
-
-   /* Restore conditional rendering state. */
-   if (st->render_condition) {
-      pipe->render_condition(pipe, st->render_condition,
-                             st->condition_mode);
-   }
-
    return;
 
 fallback:
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 8e6f28b..eeb7f0c 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -190,10 +190,6 @@ struct st_context
    /* The number of vertex buffers from the last call of validate_arrays. */
    unsigned last_num_vbuffers;
 
-   /* Active render condition. */
-   struct pipe_query *render_condition;
-   unsigned condition_mode;
-
    int32_t draw_stamp;
    int32_t read_stamp;
 
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index c092613..8ce2e06 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -93,18 +93,9 @@ st_render_mipmap(struct st_context *st,
 
    psv = st_create_texture_sampler_view(pipe, stObj->pt);
 
-   /* Disable conditional rendering. */
-   if (st->render_condition) {
-      pipe->render_condition(pipe, NULL, 0);
-   }
-
    util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel,
                    PIPE_TEX_FILTER_LINEAR);
 
-   if (st->render_condition) {
-      pipe->render_condition(pipe, st->render_condition, st->condition_mode);
-   }
-
    pipe_sampler_view_reference(&psv, NULL);
 
    return TRUE;
-- 
1.7.10.4



More information about the mesa-dev mailing list