gallium/u_blitter: add ability to disable and restore the render condition
authorMarek Olšák <maraeo@gmail.com>
Wed, 12 Sep 2012 21:33:50 +0000 (23:33 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 30 Sep 2012 16:57:56 +0000 (18:57 +0200)
Tested-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_blitter.h
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_pipe.h

index 3f0d1b17d01633176f795c23e3a45fc93ee29719..a47fba6e1eb18efa6e633e0d8cec7f40726aa387 100644 (file)
@@ -467,6 +467,26 @@ static void blitter_check_saved_fb_state(struct blitter_context_priv *ctx)
    assert(ctx->base.saved_fb_state.nr_cbufs != ~0);
 }
 
+static void blitter_disable_render_cond(struct blitter_context_priv *ctx)
+{
+   struct pipe_context *pipe = ctx->base.pipe;
+
+   if (ctx->base.saved_render_cond_query) {
+      pipe->render_condition(pipe, NULL, 0);
+   }
+}
+
+static void blitter_restore_render_cond(struct blitter_context_priv *ctx)
+{
+   struct pipe_context *pipe = ctx->base.pipe;
+
+   if (ctx->base.saved_render_cond_query) {
+      pipe->render_condition(pipe, ctx->base.saved_render_cond_query,
+                             ctx->base.saved_render_cond_mode);
+      ctx->base.saved_render_cond_query = NULL;
+   }
+}
+
 static void blitter_restore_fb_state(struct blitter_context_priv *ctx)
 {
    struct pipe_context *pipe = ctx->base.pipe;
@@ -947,6 +967,7 @@ static void util_blitter_clear_custom(struct blitter_context *blitter,
    blitter_set_running_flag(ctx);
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* bind states */
    if (custom_blend) {
@@ -989,6 +1010,7 @@ static void util_blitter_clear_custom(struct blitter_context *blitter,
 
    blitter_restore_vertex_states(ctx);
    blitter_restore_fragment_states(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 }
 
@@ -1212,6 +1234,7 @@ void util_blitter_copy_texture_view(struct blitter_context *blitter,
    blitter_check_saved_fragment_states(ctx);
    blitter_check_saved_textures(ctx);
    blitter_check_saved_fb_state(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* Initialize framebuffer state. */
    fb_state.width = dst->width;
@@ -1329,6 +1352,7 @@ void util_blitter_copy_texture_view(struct blitter_context *blitter,
    blitter_restore_fragment_states(ctx);
    blitter_restore_textures(ctx);
    blitter_restore_fb_state(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 }
 
@@ -1352,6 +1376,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
    blitter_check_saved_fb_state(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* bind states */
    pipe->bind_blend_state(pipe, ctx->blend_write_color);
@@ -1376,6 +1401,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
    blitter_restore_vertex_states(ctx);
    blitter_restore_fragment_states(ctx);
    blitter_restore_fb_state(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 }
 
@@ -1402,6 +1428,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
    blitter_check_saved_fb_state(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* bind states */
    pipe->bind_blend_state(pipe, ctx->blend_keep_color);
@@ -1442,6 +1469,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
    blitter_restore_vertex_states(ctx);
    blitter_restore_fragment_states(ctx);
    blitter_restore_fb_state(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 }
 
@@ -1465,6 +1493,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
    blitter_check_saved_fb_state(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* bind states */
    pipe->bind_blend_state(pipe, ctx->blend_write_color);
@@ -1495,6 +1524,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
    blitter_restore_vertex_states(ctx);
    blitter_restore_fragment_states(ctx);
    blitter_restore_fb_state(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 }
 
@@ -1536,6 +1566,7 @@ void util_blitter_copy_buffer(struct blitter_context *blitter,
 
    blitter_set_running_flag(ctx);
    blitter_check_saved_vertex_states(ctx);
+   blitter_disable_render_cond(ctx);
 
    vb.buffer = src;
    vb.buffer_offset = srcx;
@@ -1554,6 +1585,7 @@ void util_blitter_copy_buffer(struct blitter_context *blitter,
    util_draw_arrays(pipe, PIPE_PRIM_POINTS, 0, size / 4);
 
    blitter_restore_vertex_states(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
    pipe_so_target_reference(&so_target, NULL);
 }
@@ -1576,6 +1608,7 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
    blitter_set_running_flag(ctx);
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* bind states */
    pipe->bind_blend_state(pipe, custom_blend);
@@ -1615,6 +1648,7 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
    blitter_restore_fb_state(ctx);
    blitter_restore_vertex_states(ctx);
    blitter_restore_fragment_states(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 
    pipe_surface_reference(&srcsurf, NULL);
@@ -1638,6 +1672,7 @@ void util_blitter_custom_color(struct blitter_context *blitter,
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
    blitter_check_saved_fb_state(ctx);
+   blitter_disable_render_cond(ctx);
 
    /* bind states */
    pipe->bind_blend_state(pipe, custom_blend);
@@ -1663,5 +1698,6 @@ void util_blitter_custom_color(struct blitter_context *blitter,
    blitter_restore_vertex_states(ctx);
    blitter_restore_fragment_states(ctx);
    blitter_restore_fb_state(ctx);
+   blitter_restore_render_cond(ctx);
    blitter_unset_running_flag(ctx);
 }
index d458f6927023fd236763d7c3c663cdd49671ae47..43b732699e3a4a1484b0ad32a68b9691b5933705 100644 (file)
@@ -108,6 +108,9 @@ struct blitter_context
 
    int saved_num_so_targets;
    struct pipe_stream_output_target *saved_so_targets[PIPE_MAX_SO_BUFFERS];
+
+   struct pipe_query *saved_render_cond_query;
+   uint saved_render_cond_mode;
 };
 
 /**
@@ -475,6 +478,15 @@ util_blitter_save_sample_mask(struct blitter_context *blitter,
    blitter->saved_sample_mask = sample_mask;
 }
 
+static INLINE void
+util_blitter_save_render_condition(struct blitter_context *blitter,
+                                   struct pipe_query *query,
+                                   uint mode)
+{
+   blitter->saved_render_cond_query = query;
+   blitter->saved_render_cond_mode = mode;
+}
+
 #ifdef __cplusplus
 }
 #endif
index 09fb6239221433550b3efed3108a1a8b4ca623f5..3da583c5d09c0515637cdaee4a5ee2badc75ade7 100644 (file)
@@ -84,23 +84,16 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
        }
 
        if ((op & R600_DISABLE_RENDER_COND) && rctx->current_render_cond) {
-               rctx->saved_render_cond = rctx->current_render_cond;
-               rctx->saved_render_cond_mode = rctx->current_render_cond_mode;
-               rctx->context.render_condition(&rctx->context, NULL, 0);
-       }
-
+           util_blitter_save_render_condition(rctx->blitter,
+                                              rctx->current_render_cond,
+                                              rctx->current_render_cond_mode);
+        }
 }
 
 static void r600_blitter_end(struct pipe_context *ctx)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
-       if (rctx->saved_render_cond) {
-               rctx->context.render_condition(&rctx->context,
-                                              rctx->saved_render_cond,
-                                              rctx->saved_render_cond_mode);
-               rctx->saved_render_cond = NULL;
-       }
-       r600_resume_nontimer_queries(rctx);
+        r600_resume_nontimer_queries(rctx);
 }
 
 static unsigned u_max_layer(struct pipe_resource *r, unsigned level)
index 6880060997977795d539b434f1893c788f884484..e66766a984429f986b62572034ce6a4aec8b13ef 100644 (file)
@@ -385,8 +385,6 @@ struct r600_context {
        struct r600_pipe_state          spi;
        struct pipe_query               *current_render_cond;
        unsigned                        current_render_cond_mode;
-       struct pipe_query               *saved_render_cond;
-       unsigned                        saved_render_cond_mode;
        /* shader information */
        boolean                         two_side;
        boolean                         spi_dirty;