[Mesa-dev] [PATCH 15/18] gallium/u_blitter: don't pass GENERIC in VS if it's not needed

Marek Olšák maraeo at gmail.com
Thu Aug 17 18:31:36 UTC 2017


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

Now, depth-only clears and custom passes don't read memory in VS.
---
 src/gallium/auxiliary/util/u_blitter.c | 64 ++++++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 18 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 6827da8..786b232 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -62,21 +62,23 @@ struct blitter_context_priv
    struct blitter_context base;
 
    float vertices[4][2][4];   /**< {pos, color} or {pos, texcoord} */
    float vertices_nopos[4][4];     /**< {color} or {texcoord} only */
 
    /* Templates for various state objects. */
 
    /* Constant state objects. */
    /* Vertex shaders. */
    void *vs; /**< Vertex shader which passes {pos, generic} to the output.*/
-   void *vs_pos_only[4]; /**< Vertex shader which passes pos to the output.*/
+   void *vs_nogeneric;
+   void *vs_pos_only[4]; /**< Vertex shader which passes pos to the output
+                              for clear_buffer/copy_buffer.*/
    void *vs_layered; /**< Vertex shader which sets LAYER = INSTANCEID. */
 
    /* Fragment shaders. */
    void *fs_empty;
    void *fs_write_one_cbuf;
    void *fs_write_all_cbufs;
 
    /* FS which outputs a color from a texture where
     * the 1st index indicates the texture type / destination type,
     * the 2nd index is the PIPE_TEXTURE_* to be sampled,
@@ -343,39 +345,56 @@ static void bind_vs_pos_only(struct blitter_context_priv *ctx,
 
       ctx->vs_pos_only[index] =
          util_make_vertex_passthrough_shader_with_so(pipe, 1, semantic_names,
                                                      semantic_indices, FALSE,
                                                      false, &so);
    }
 
    pipe->bind_vs_state(pipe, ctx->vs_pos_only[index]);
 }
 
-static void bind_vs_passthrough(struct blitter_context_priv *ctx)
+static void bind_vs_passthrough_pos_generic(struct blitter_context_priv *ctx)
 {
    struct pipe_context *pipe = ctx->base.pipe;
 
    if (!ctx->vs) {
       const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
                                       TGSI_SEMANTIC_GENERIC };
       const uint semantic_indices[] = { 0, 0 };
       unsigned offset = ctx->has_vertex_id ? 1 : 0;
 
       ctx->vs =
          util_make_vertex_passthrough_shader(pipe, 2 - offset,
                                              semantic_names + offset,
                                              semantic_indices + offset, FALSE);
    }
 
    pipe->bind_vs_state(pipe, ctx->vs);
 }
 
+static void bind_vs_passthrough_pos(struct blitter_context_priv *ctx)
+{
+   struct pipe_context *pipe = ctx->base.pipe;
+
+   if (!ctx->vs_nogeneric) {
+      const uint semantic_names[] = { TGSI_SEMANTIC_POSITION };
+      const uint semantic_indices[] = { 0 };
+
+      ctx->vs_nogeneric =
+         util_make_vertex_passthrough_shader(pipe, !ctx->has_vertex_id,
+                                             semantic_names,
+                                             semantic_indices, FALSE);
+   }
+
+   pipe->bind_vs_state(pipe, ctx->vs_nogeneric);
+}
+
 static void bind_vs_layered(struct blitter_context_priv *ctx)
 {
    struct pipe_context *pipe = ctx->base.pipe;
 
    if (!ctx->vs_layered) {
       ctx->vs_layered =
          util_make_layered_clear_vertex_shader(pipe, !ctx->has_vertex_id);
    }
 
    pipe->bind_vs_state(pipe, ctx->vs_layered);
@@ -440,20 +459,22 @@ void util_blitter_destroy(struct blitter_context *blitter)
                                           ctx->dsa_write_depth_keep_stencil);
    pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil);
    pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_write_stencil);
 
    pipe->delete_rasterizer_state(pipe, ctx->rs_state);
    pipe->delete_rasterizer_state(pipe, ctx->rs_state_scissor);
    if (ctx->rs_discard_state)
       pipe->delete_rasterizer_state(pipe, ctx->rs_discard_state);
    if (ctx->vs)
       pipe->delete_vs_state(pipe, ctx->vs);
+   if (ctx->vs_nogeneric)
+      pipe->delete_vs_state(pipe, ctx->vs_nogeneric);
    for (i = 0; i < 4; i++)
       if (ctx->vs_pos_only[i])
          pipe->delete_vs_state(pipe, ctx->vs_pos_only[i]);
    if (ctx->vs_layered)
       pipe->delete_vs_state(pipe, ctx->vs_layered);
    pipe->delete_vertex_elements_state(pipe, ctx->velem_state);
    for (i = 0; i < 4; i++) {
       if (ctx->velem_state_readbuf[i]) {
          pipe->delete_vertex_elements_state(pipe, ctx->velem_state_readbuf[i]);
       }
@@ -1192,31 +1213,34 @@ void util_blitter_cache_all_shaders(struct blitter_context *blitter)
                                             TGSI_INTERPOLATE_CONSTANT, FALSE);
 
    ctx->fs_write_all_cbufs =
       util_make_fragment_passthrough_shader(pipe, TGSI_SEMANTIC_GENERIC,
                                             TGSI_INTERPOLATE_CONSTANT, TRUE);
 
    ctx->cached_all_shaders = TRUE;
 }
 
 static void blitter_set_common_draw_rect_state(struct blitter_context_priv *ctx,
-                                               boolean scissor,
-                                               boolean vs_layered)
+                                               bool scissor,
+                                               bool vs_layered,
+                                               bool vs_pass_generic)
 {
    struct pipe_context *pipe = ctx->base.pipe;
 
    pipe->bind_rasterizer_state(pipe, scissor ? ctx->rs_state_scissor
                                              : ctx->rs_state);
    if (vs_layered)
       bind_vs_layered(ctx);
+   else if (vs_pass_generic)
+      bind_vs_passthrough_pos_generic(ctx);
    else
-      bind_vs_passthrough(ctx);
+      bind_vs_passthrough_pos(ctx);
 
    if (ctx->has_geometry_shader)
       pipe->bind_gs_state(pipe, NULL);
    if (ctx->has_tessellation) {
       pipe->bind_tcs_state(pipe, NULL);
       pipe->bind_tes_state(pipe, NULL);
    }
    if (ctx->has_stream_out)
       pipe->set_stream_output_targets(pipe, 0, NULL, NULL);
 }
@@ -1382,28 +1406,32 @@ static void util_blitter_clear_custom(struct blitter_context *blitter,
 
    sr.ref_value[0] = stencil & 0xff;
    pipe->set_stencil_ref(pipe, &sr);
 
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    bind_fs_write_all_cbufs(ctx);
 
    union blitter_attrib attrib;
    memcpy(attrib.color, color->ui, sizeof(color->ui));
 
+   bool pass_generic = (clear_buffers & PIPE_CLEAR_COLOR) != 0;
+   enum blitter_attrib_type type = pass_generic ? UTIL_BLITTER_ATTRIB_COLOR :
+                                                  UTIL_BLITTER_ATTRIB_NONE;
+
    if (num_layers > 1 && ctx->has_layered) {
-      blitter_set_common_draw_rect_state(ctx, FALSE, TRUE);
+      blitter_set_common_draw_rect_state(ctx, false, true, pass_generic);
       blitter->draw_rectangle(blitter, 0, 0, width, height, (float) depth,
-                              num_layers, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
+                              num_layers, type, &attrib);
    } else {
-      blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
+      blitter_set_common_draw_rect_state(ctx, false, false, pass_generic);
       blitter->draw_rectangle(blitter, 0, 0, width, height, (float) depth,
-                              1, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
+                              1, type, &attrib);
    }
 
    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,
@@ -1944,21 +1972,21 @@ void util_blitter_blit_generic(struct blitter_context *blitter,
       pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1, &src);
       pipe->bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT,
                                 0, 1, &sampler_state);
    }
 
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    if (scissor) {
       pipe->set_scissor_states(pipe, 0, 1, scissor);
    }
 
-   blitter_set_common_draw_rect_state(ctx, scissor != NULL, FALSE);
+   blitter_set_common_draw_rect_state(ctx, scissor != NULL, false, true);
 
    do_blits(ctx, dst, dstbox, src, src_width0, src_height0,
             srcbox, blit_depth || blit_stencil, use_txf);
 
    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);
@@ -2051,21 +2079,21 @@ void util_blitter_generate_mipmap(struct blitter_context *blitter,
 
    if (target == PIPE_TEXTURE_RECT) {
       sampler_state = ctx->sampler_state_rect_linear;
    } else {
       sampler_state = ctx->sampler_state_linear;
    }
    pipe->bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT,
                              0, 1, &sampler_state);
 
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
-   blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
+   blitter_set_common_draw_rect_state(ctx, false, false, true);
 
    for (src_level = base_level; src_level < last_level; src_level++) {
       struct pipe_box dstbox = {0}, srcbox = {0};
       unsigned dst_level = src_level + 1;
 
       dstbox.width = u_minify(tex->width0, dst_level);
       dstbox.height = u_minify(tex->height0, dst_level);
 
       srcbox.width = u_minify(tex->width0, src_level);
       srcbox.height = u_minify(tex->height0, src_level);
@@ -2142,25 +2170,25 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
    fb_state.cbufs[0] = dstsurf;
    fb_state.zsbuf = 0;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
    union blitter_attrib attrib;
    memcpy(attrib.color, color->ui, sizeof(color->ui));
 
    num_layers = dstsurf->u.tex.last_layer - dstsurf->u.tex.first_layer + 1;
    if (num_layers > 1 && ctx->has_layered) {
-      blitter_set_common_draw_rect_state(ctx, FALSE, TRUE);
+      blitter_set_common_draw_rect_state(ctx, false, true, true);
       blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
                               num_layers, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
    } else {
-      blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
+      blitter_set_common_draw_rect_state(ctx, false, false, true);
       blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
                               1, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
    }
 
    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);
 }
@@ -2217,26 +2245,26 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
    fb_state.width = dstsurf->width;
    fb_state.height = dstsurf->height;
    fb_state.nr_cbufs = 0;
    fb_state.cbufs[0] = 0;
    fb_state.zsbuf = dstsurf;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
    num_layers = dstsurf->u.tex.last_layer - dstsurf->u.tex.first_layer + 1;
    if (num_layers > 1 && ctx->has_layered) {
-      blitter_set_common_draw_rect_state(ctx, FALSE, TRUE);
+      blitter_set_common_draw_rect_state(ctx, false, true, false);
       blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height,
                               depth, num_layers,
                               UTIL_BLITTER_ATTRIB_NONE, NULL);
    } else {
-      blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
+      blitter_set_common_draw_rect_state(ctx, false, false, false);
       blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height,
                               depth, 1,
                               UTIL_BLITTER_ATTRIB_NONE, NULL);
    }
 
    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);
@@ -2282,21 +2310,21 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
 	   fb_state.cbufs[0] = cbsurf;
 	   fb_state.nr_cbufs = 1;
    } else {
 	   fb_state.cbufs[0] = NULL;
 	   fb_state.nr_cbufs = 0;
    }
    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, FALSE);
+   blitter_set_common_draw_rect_state(ctx, false, false, false);
    blitter->draw_rectangle(blitter, 0, 0, zsurf->width, zsurf->height, depth,
                            1, UTIL_BLITTER_ATTRIB_NONE, NULL);
 
    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);
 }
 
@@ -2481,21 +2509,21 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
 
    /* set a framebuffer state */
    fb_state.width = src->width0;
    fb_state.height = src->height0;
    fb_state.nr_cbufs = 2;
    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, FALSE);
+   blitter_set_common_draw_rect_state(ctx, false, false, false);
    blitter->draw_rectangle(blitter, 0, 0, src->width0, src->height0,
                            0, 1, 0, NULL);
    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);
@@ -2530,20 +2558,20 @@ void util_blitter_custom_color(struct blitter_context *blitter,
 
    /* set a framebuffer state */
    fb_state.width = dstsurf->width;
    fb_state.height = dstsurf->height;
    fb_state.nr_cbufs = 1;
    fb_state.cbufs[0] = dstsurf;
    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, FALSE);
+   blitter_set_common_draw_rect_state(ctx, false, false, false);
    blitter->draw_rectangle(blitter, 0, 0, dstsurf->width, dstsurf->height,
                            0, 1, 0, NULL);
 
    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);
 }
-- 
2.7.4



More information about the mesa-dev mailing list