[Mesa-dev] [PATCH 4/5] gallium/u_blitter: add bool u_blitter::leaving

Marek Olšák maraeo at gmail.com
Sun Mar 11 18:11:12 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/util/u_blitter.c | 14 ++++++++++++++
 src/gallium/auxiliary/util/u_blitter.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 4748627..87fb33b 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -532,31 +532,33 @@ void util_blitter_set_texture_multisample(struct blitter_context *blitter,
    ctx->has_texture_multisample = supported;
 }
 
 void util_blitter_set_running_flag(struct blitter_context *blitter)
 {
    if (blitter->running) {
       _debug_printf("u_blitter:%i: Caught recursion. This is a driver bug.\n",
                     __LINE__);
    }
    blitter->running = true;
+   blitter->leaving = false;
 
    blitter->pipe->set_active_query_state(blitter->pipe, false);
 }
 
 void util_blitter_unset_running_flag(struct blitter_context *blitter)
 {
    if (!blitter->running) {
       _debug_printf("u_blitter:%i: Caught recursion. This is a driver bug.\n",
                     __LINE__);
    }
    blitter->running = false;
+   blitter->leaving = false;
 
    blitter->pipe->set_active_query_state(blitter->pipe, true);
 }
 
 static void blitter_check_saved_vertex_states(MAYBE_UNUSED struct blitter_context_priv *ctx)
 {
    assert(ctx->base.saved_vs != INVALID_PTR);
    assert(!ctx->has_geometry_shader || ctx->base.saved_gs != INVALID_PTR);
    assert(!ctx->has_tessellation || ctx->base.saved_tcs != INVALID_PTR);
    assert(!ctx->has_tessellation || ctx->base.saved_tes != INVALID_PTR);
@@ -1410,20 +1412,21 @@ static void util_blitter_clear_custom(struct blitter_context *blitter,
          get_vs = get_vs_passthrough_pos_generic;
       else
          get_vs = get_vs_passthrough_pos;
 
       blitter_set_common_draw_rect_state(ctx, false);
       blitter->draw_rectangle(blitter, ctx->velem_state, get_vs,
                               0, 0, width, height,
                               (float) depth, 1, type, &attrib);
    }
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
 void util_blitter_clear(struct blitter_context *blitter,
                         unsigned width, unsigned height, unsigned num_layers,
                         unsigned clear_buffers,
                         const union pipe_color_union *color,
@@ -1960,20 +1963,21 @@ void util_blitter_blit_generic(struct blitter_context *blitter,
 
    if (scissor) {
       pipe->set_scissor_states(pipe, 0, 1, scissor);
    }
 
    blitter_set_common_draw_rect_state(ctx, scissor != NULL);
 
    do_blits(ctx, dst, dstbox, src, src_width0, src_height0,
             srcbox, blit_depth || blit_stencil, use_txf);
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_textures(blitter);
    util_blitter_restore_fb_state(blitter);
    if (scissor) {
       pipe->set_scissor_states(pipe, 0, 1, &ctx->base.saved_scissor);
    }
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
@@ -2101,20 +2105,21 @@ void util_blitter_generate_mipmap(struct blitter_context *blitter,
 
       pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1, &src_view);
 
       do_blits(ctx, dst_view, &dstbox, src_view, tex->width0, tex->height0,
                &srcbox, is_depth, false);
 
       pipe_surface_reference(&dst_view, NULL);
       pipe_sampler_view_reference(&src_view, NULL);
    }
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_textures(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
 /* Clear a region of a color surface to a constant value. */
 void util_blitter_clear_render_target(struct blitter_context *blitter,
@@ -2165,20 +2170,21 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
                               dstx, dsty, dstx+width, dsty+height, 0,
                               num_layers, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
    } else {
       blitter_set_common_draw_rect_state(ctx, false);
       blitter->draw_rectangle(blitter, ctx->velem_state,
                               get_vs_passthrough_pos_generic,
                               dstx, dsty, dstx+width, dsty+height, 0,
                               1, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
    }
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
 /* Clear a region of a depth stencil surface. */
 void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
                                       struct pipe_surface *dstsurf,
@@ -2244,20 +2250,21 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
                               dstx, dsty, dstx+width, dsty+height, depth,
                               num_layers, UTIL_BLITTER_ATTRIB_NONE, NULL);
    } else {
       blitter_set_common_draw_rect_state(ctx, false);
       blitter->draw_rectangle(blitter, ctx->velem_state,
                               get_vs_passthrough_pos,
                               dstx, dsty, dstx+width, dsty+height, depth, 1,
                               UTIL_BLITTER_ATTRIB_NONE, NULL);
    }
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
 /* draw a rectangle across a region using a custom dsa stage - for r600g */
 void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
                                        struct pipe_surface *zsurf,
@@ -2303,20 +2310,21 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
    fb_state.zsbuf = zsurf;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, sample_mask);
 
    blitter_set_common_draw_rect_state(ctx, false);
    blitter_set_dst_dimensions(ctx, zsurf->width, zsurf->height);
    blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_passthrough_pos,
                            0, 0, zsurf->width, zsurf->height, depth,
                            1, UTIL_BLITTER_ATTRIB_NONE, NULL);
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
 void util_blitter_copy_buffer(struct blitter_context *blitter,
                               struct pipe_resource *dst,
                               unsigned dstx,
@@ -2372,20 +2380,21 @@ void util_blitter_copy_buffer(struct blitter_context *blitter,
       pipe->bind_tcs_state(pipe, NULL);
       pipe->bind_tes_state(pipe, NULL);
    }
    pipe->bind_rasterizer_state(pipe, ctx->rs_discard_state);
 
    so_target = pipe->create_stream_output_target(pipe, dst, dstx, size);
    pipe->set_stream_output_targets(pipe, 1, &so_target, offsets);
 
    util_draw_arrays(pipe, PIPE_PRIM_POINTS, 0, size / 4);
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
    pipe_so_target_reference(&so_target, NULL);
 }
 
 void util_blitter_clear_buffer(struct blitter_context *blitter,
                                struct pipe_resource *dst,
                                unsigned offset, unsigned size,
                                unsigned num_channels,
@@ -2440,20 +2449,21 @@ void util_blitter_clear_buffer(struct blitter_context *blitter,
       pipe->bind_tes_state(pipe, NULL);
    }
    pipe->bind_rasterizer_state(pipe, ctx->rs_discard_state);
 
    so_target = pipe->create_stream_output_target(pipe, dst, offset, size);
    pipe->set_stream_output_targets(pipe, 1, &so_target, offsets);
 
    util_draw_arrays(pipe, PIPE_PRIM_POINTS, 0, size / 4);
 
 out:
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
    pipe_so_target_reference(&so_target, NULL);
    pipe_resource_reference(&vb.buffer.resource, NULL);
 }
 
 /* probably radeon specific */
 void util_blitter_custom_resolve_color(struct blitter_context *blitter,
                                        struct pipe_resource *dst,
@@ -2502,20 +2512,22 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
    fb_state.cbufs[0] = srcsurf;
    fb_state.cbufs[1] = dstsurf;
    fb_state.zsbuf = NULL;
    pipe->set_framebuffer_state(pipe, &fb_state);
 
    blitter_set_common_draw_rect_state(ctx, false);
    blitter_set_dst_dimensions(ctx, src->width0, src->height0);
    blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_passthrough_pos,
                            0, 0, src->width0, src->height0,
                            0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL);
+
+   blitter->leaving = true;
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 
    pipe_surface_reference(&srcsurf, NULL);
    pipe_surface_reference(&dstsurf, NULL);
 }
 
@@ -2553,20 +2565,21 @@ void util_blitter_custom_color(struct blitter_context *blitter,
    fb_state.zsbuf = 0;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
    blitter_set_common_draw_rect_state(ctx, false);
    blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
    blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_passthrough_pos,
                            0, 0, dstsurf->width, dstsurf->height,
                            0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL);
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
 static void *get_custom_vs(struct blitter_context *blitter)
 {
    struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
@@ -2615,16 +2628,17 @@ void util_blitter_custom_shader(struct blitter_context *blitter,
    fb_state.zsbuf = 0;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
    blitter_set_common_draw_rect_state(ctx, false);
    blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
    blitter->draw_rectangle(blitter, ctx->velem_state, get_custom_vs,
                            0, 0, dstsurf->width, dstsurf->height,
                            0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL);
 
+   blitter->leaving = true;
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index 9e94598..89813e5 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -92,20 +92,22 @@ struct blitter_context
    void (*draw_rectangle)(struct blitter_context *blitter,
                           void *vertex_elements_cso,
                           blitter_get_vs_func get_vs,
                           int x1, int y1, int x2, int y2,
                           float depth, unsigned num_instances,
                           enum blitter_attrib_type type,
                           const union blitter_attrib *attrib);
 
    /* Whether the blitter is running. */
    bool running;
+   /* Whether the blitter is done and restoring states. */
+   bool leaving;
 
    /* Private members, really. */
    struct pipe_context *pipe; /**< pipe context */
 
    void *saved_blend_state;   /**< blend state */
    void *saved_dsa_state;     /**< depth stencil alpha state */
    void *saved_velem_state;   /**< vertex elements state */
    void *saved_rs_state;      /**< rasterizer state */
    void *saved_fs, *saved_vs, *saved_gs, *saved_tcs, *saved_tes; /**< shaders */
 
-- 
2.7.4



More information about the mesa-dev mailing list