gallium/u_blitter: let drivers set the vertex elements state
authorMarek Olšák <marek.olsak@amd.com>
Thu, 5 Oct 2017 00:38:35 +0000 (02:38 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 7 Oct 2017 16:26:35 +0000 (18:26 +0200)
radeonsi won't set it.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_blitter.h
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r600/r600_pipe_common.c
src/gallium/drivers/r600/r600_pipe_common.h
src/gallium/drivers/radeonsi/si_state.h
src/gallium/drivers/radeonsi/si_state_draw.c

index 9153ae139b2f18b1e4b9f768201c5064c4d95046..ec03e5f7d128997290d79378ea69fcbc581f4f7c 100644 (file)
@@ -1237,6 +1237,7 @@ static void blitter_set_common_draw_rect_state(struct blitter_context_priv *ctx,
 }
 
 static void blitter_draw(struct blitter_context_priv *ctx,
+                         void *vertex_elements_cso,
                          int x1, int y1, int x2, int y2, float depth,
                          unsigned num_instances)
 {
@@ -1254,12 +1255,14 @@ static void blitter_draw(struct blitter_context_priv *ctx,
    u_upload_unmap(pipe->stream_uploader);
 
    pipe->set_vertex_buffers(pipe, ctx->base.vb_slot, 1, &vb);
+   pipe->bind_vertex_elements_state(pipe, vertex_elements_cso);
    util_draw_arrays_instanced(pipe, PIPE_PRIM_TRIANGLE_FAN, 0, 4,
                               0, num_instances);
    pipe_resource_reference(&vb.buffer.resource, NULL);
 }
 
 void util_blitter_draw_rectangle(struct blitter_context *blitter,
+                                 void *vertex_elements_cso,
                                  int x1, int y1, int x2, int y2,
                                  float depth, unsigned num_instances,
                                  enum blitter_attrib_type type,
@@ -1286,7 +1289,7 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter,
       default:;
    }
 
-   blitter_draw(ctx, x1, y1, x2, y2, depth, num_instances);
+   blitter_draw(ctx, vertex_elements_cso, x1, y1, x2, y2, depth, num_instances);
 }
 
 static void *get_clear_blend_state(struct blitter_context_priv *ctx,
@@ -1380,7 +1383,6 @@ 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;
@@ -1392,12 +1394,12 @@ static void util_blitter_clear_custom(struct blitter_context *blitter,
 
    if (num_layers > 1 && ctx->has_layered) {
       blitter_set_common_draw_rect_state(ctx, false, true, pass_generic);
-      blitter->draw_rectangle(blitter, 0, 0, width, height, (float) depth,
-                              num_layers, type, &attrib);
+      blitter->draw_rectangle(blitter, ctx->velem_state, 0, 0, width, height,
+                              (float) depth, num_layers, type, &attrib);
    } else {
       blitter_set_common_draw_rect_state(ctx, false, false, pass_generic);
-      blitter->draw_rectangle(blitter, 0, 0, width, height, (float) depth,
-                              1, type, &attrib);
+      blitter->draw_rectangle(blitter, ctx->velem_state, 0, 0, width, height,
+                              (float) depth, 1, type, &attrib);
    }
 
    util_blitter_restore_vertex_states(blitter);
@@ -1629,10 +1631,12 @@ blitter_draw_tex(struct blitter_context_priv *ctx,
          ctx->vertices[i][1][3] = coord.texcoord.w;
 
       /* Cubemaps don't use draw_rectangle. */
-      blitter_draw(ctx, dst_x1, dst_y1, dst_x2, dst_y2, 0, 1);
+      blitter_draw(ctx, ctx->velem_state,
+                   dst_x1, dst_y1, dst_x2, dst_y2, 0, 1);
    } else {
-      ctx->base.draw_rectangle(&ctx->base, dst_x1, dst_y1, dst_x2, dst_y2, 0,
-                               1, type, &coord);
+      ctx->base.draw_rectangle(&ctx->base, ctx->velem_state,
+                               dst_x1, dst_y1, dst_x2, dst_y2,
+                               0, 1, type, &coord);
    }
 }
 
@@ -1938,7 +1942,6 @@ void util_blitter_blit_generic(struct blitter_context *blitter,
                                 0, 1, &sampler_state);
    }
 
-   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    if (scissor) {
       pipe->set_scissor_states(pipe, 0, 1, scissor);
    }
@@ -2049,7 +2052,6 @@ void util_blitter_generate_mipmap(struct blitter_context *blitter,
    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, true);
 
    for (src_level = base_level; src_level < last_level; src_level++) {
@@ -2125,7 +2127,6 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
    pipe->bind_blend_state(pipe, ctx->blend[PIPE_MASK_RGBA][0]);
    pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
    bind_fs_write_one_cbuf(ctx);
-   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
 
    /* set a framebuffer state */
    fb_state.width = dstsurf->width;
@@ -2144,11 +2145,13 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
    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, true);
-      blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
+      blitter->draw_rectangle(blitter, ctx->velem_state,
+                              dstx, dsty, dstx+width, dsty+height, 0,
                               num_layers, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
    } else {
       blitter_set_common_draw_rect_state(ctx, false, false, true);
-      blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
+      blitter->draw_rectangle(blitter, ctx->velem_state,
+                              dstx, dsty, dstx+width, dsty+height, 0,
                               1, UTIL_BLITTER_ATTRIB_COLOR, &attrib);
    }
 
@@ -2205,7 +2208,6 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
       pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
 
    bind_fs_empty(ctx);
-   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
 
    /* set a framebuffer state */
    fb_state.width = dstsurf->width;
@@ -2221,13 +2223,13 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
    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, false);
-      blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height,
-                              depth, num_layers,
-                              UTIL_BLITTER_ATTRIB_NONE, NULL);
+      blitter->draw_rectangle(blitter, ctx->velem_state,
+                              dstx, dsty, dstx+width, dsty+height, depth,
+                              num_layers, UTIL_BLITTER_ATTRIB_NONE, NULL);
    } else {
       blitter_set_common_draw_rect_state(ctx, false, false, false);
-      blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height,
-                              depth, 1,
+      blitter->draw_rectangle(blitter, ctx->velem_state,
+                              dstx, dsty, dstx+width, dsty+height, depth, 1,
                               UTIL_BLITTER_ATTRIB_NONE, NULL);
    }
 
@@ -2268,7 +2270,6 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
       bind_fs_write_one_cbuf(ctx);
    else
       bind_fs_empty(ctx);
-   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
 
    /* set a framebuffer state */
    fb_state.width = zsurf->width;
@@ -2287,7 +2288,8 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
 
    blitter_set_common_draw_rect_state(ctx, false, false, false);
    blitter_set_dst_dimensions(ctx, zsurf->width, zsurf->height);
-   blitter->draw_rectangle(blitter, 0, 0, zsurf->width, zsurf->height, depth,
+   blitter->draw_rectangle(blitter, ctx->velem_state, 0, 0,
+                           zsurf->width, zsurf->height, depth,
                            1, UTIL_BLITTER_ATTRIB_NONE, NULL);
 
    util_blitter_restore_vertex_states(blitter);
@@ -2458,7 +2460,6 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
    /* bind states */
    pipe->bind_blend_state(pipe, custom_blend);
    pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
-   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    bind_fs_write_one_cbuf(ctx);
    pipe->set_sample_mask(pipe, sample_mask);
 
@@ -2487,7 +2488,8 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
 
    blitter_set_common_draw_rect_state(ctx, false, false, false);
    blitter_set_dst_dimensions(ctx, src->width0, src->height0);
-   blitter->draw_rectangle(blitter, 0, 0, src->width0, src->height0,
+   blitter->draw_rectangle(blitter, ctx->velem_state,
+                           0, 0, src->width0, src->height0,
                            0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_vertex_states(blitter);
@@ -2523,7 +2525,6 @@ void util_blitter_custom_color(struct blitter_context *blitter,
                                              : ctx->blend[PIPE_MASK_RGBA][0]);
    pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
    bind_fs_write_one_cbuf(ctx);
-   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    pipe->set_sample_mask(pipe, (1ull << MAX2(1, dstsurf->texture->nr_samples)) - 1);
 
    /* set a framebuffer state */
@@ -2537,7 +2538,8 @@ void util_blitter_custom_color(struct blitter_context *blitter,
 
    blitter_set_common_draw_rect_state(ctx, false, false, false);
    blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
-   blitter->draw_rectangle(blitter, 0, 0, dstsurf->width, dstsurf->height,
+   blitter->draw_rectangle(blitter, ctx->velem_state,
+                           0, 0, dstsurf->width, dstsurf->height,
                            0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL);
 
    util_blitter_restore_vertex_states(blitter);
index 626d46aae47935ce4dccfa3ff3f6312efff734b5..868f1da5c9c5394e5593e798c2f86021546b890b 100644 (file)
@@ -81,6 +81,7 @@ struct blitter_context
     *       a rectangular point sprite.
     */
    void (*draw_rectangle)(struct blitter_context *blitter,
+                          void *vertex_elements_cso,
                           int x1, int y1, int x2, int y2,
                           float depth, unsigned num_instances,
                           enum blitter_attrib_type type,
@@ -155,6 +156,7 @@ void util_blitter_set_texture_multisample(struct blitter_context *blitter,
 /* The default function to draw a rectangle. This can only be used
  * inside of the draw_rectangle callback if the driver overrides it. */
 void util_blitter_draw_rectangle(struct blitter_context *blitter,
+                                 void *vertex_elements_cso,
                                  int x1, int y1, int x2, int y2,
                                  float depth, unsigned num_instances,
                                  enum blitter_attrib_type type,
index 84b8748b4c137c14e986d2062a7e45c076dbfd36..b2d7f6da30e13eb7cc7b614646b9f51f299d01aa 100644 (file)
@@ -743,6 +743,7 @@ void r300_plug_in_stencil_ref_fallback(struct r300_context *r300);
 /* r300_render.c */
 void r500_emit_index_bias(struct r300_context *r300, int index_bias);
 void r300_blitter_draw_rectangle(struct blitter_context *blitter,
+                                 void *vertex_elements_cso,
                                  int x1, int y1, int x2, int y2,
                                  float depth, unsigned num_instances,
                                  enum blitter_attrib_type type,
index ddd24523ca67dac43e3b76ffb2d647598305629f..7808669e25300102047e22562b0e04f96f6cfe8f 100644 (file)
@@ -1113,6 +1113,7 @@ struct draw_stage* r300_draw_stage(struct r300_context* r300)
  * would be computed and stored twice, which makes the clear/copy codepaths
  * somewhat inefficient. Instead we use a rectangular point sprite. */
 void r300_blitter_draw_rectangle(struct blitter_context *blitter,
+                                 void *vertex_elements_cso,
                                  int x1, int y1, int x2, int y2,
                                  float depth, unsigned num_instances,
                                  enum blitter_attrib_type type,
@@ -1134,14 +1135,16 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter,
     if ((!r300->screen->caps.has_tcl && type == UTIL_BLITTER_ATTRIB_NONE) ||
         type == UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW ||
         num_instances > 1) {
-        util_blitter_draw_rectangle(blitter, x1, y1, x2, y2, depth,
-                                    num_instances, type, attrib);
+        util_blitter_draw_rectangle(blitter, vertex_elements_cso, x1, y1, x2, y2,
+                                    depth, num_instances, type, attrib);
         return;
     }
 
     if (r300->skip_rendering)
         return;
 
+    r300->context.bind_vertex_elements_state(&r300->context, vertex_elements_cso);
+
     if (type == UTIL_BLITTER_ATTRIB_TEXCOORD_XY)
         r300->sprite_coord_enable = 1;
 
index 4fbcd3a65723d66cccaa7512589e335e0492f396..0e8a12a1b64cb4f21d0783dcd8975797f25ab5ab 100644 (file)
@@ -211,6 +211,7 @@ void r600_gfx_wait_fence(struct r600_common_context *ctx,
 }
 
 void r600_draw_rectangle(struct blitter_context *blitter,
+                        void *vertex_elements_cso,
                         int x1, int y1, int x2, int y2,
                         float depth, unsigned num_instances,
                         enum blitter_attrib_type type,
@@ -223,6 +224,8 @@ void r600_draw_rectangle(struct blitter_context *blitter,
        unsigned offset = 0;
        float *vb;
 
+       rctx->b.bind_vertex_elements_state(&rctx->b, vertex_elements_cso);
+
        /* Some operations (like color resolve on r6xx) don't work
         * with the conventional primitive types.
         * One that works is PT_RECTLIST, which we use here. */
index 719efb9bbab16ee090356b9995e475639e02d5cf..37dcbd3d31691a7c4bf9c9fb1997d25a0021bdeb 100644 (file)
@@ -762,6 +762,7 @@ unsigned r600_gfx_write_fence_dwords(struct r600_common_screen *screen);
 void r600_gfx_wait_fence(struct r600_common_context *ctx,
                         uint64_t va, uint32_t ref, uint32_t mask);
 void r600_draw_rectangle(struct blitter_context *blitter,
+                        void *vertex_elements_cso,
                         int x1, int y1, int x2, int y2,
                         float depth, unsigned num_instances,
                         enum blitter_attrib_type type,
index eccc87ea8a0d95ab0f983de6c122d10ce5d55bb0..c9745a58cb7bd2a98b314b409db12bb3b2cb446c 100644 (file)
@@ -408,6 +408,7 @@ void si_init_ia_multi_vgt_param_table(struct si_context *sctx);
 void si_emit_cache_flush(struct si_context *sctx);
 void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo);
 void si_draw_rectangle(struct blitter_context *blitter,
+                      void *vertex_elements_cso,
                       int x1, int y1, int x2, int y2,
                       float depth, unsigned num_instances,
                       enum blitter_attrib_type type,
index adebba645d4a7f3397ca5f464734ce65c9c1ecb0..ceb90d287f5c3a9208cf8b087d138f742c8055c8 100644 (file)
@@ -1491,6 +1491,7 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 }
 
 void si_draw_rectangle(struct blitter_context *blitter,
+                      void *vertex_elements_cso,
                       int x1, int y1, int x2, int y2,
                       float depth, unsigned num_instances,
                       enum blitter_attrib_type type,
@@ -1565,6 +1566,9 @@ void si_draw_rectangle(struct blitter_context *blitter,
 
        pipe->set_vertex_buffers(pipe, blitter->vb_slot, 1, &vbuffer);
 
+       if (sctx->vertex_elements != vertex_elements_cso)
+               pipe->bind_vertex_elements_state(pipe, vertex_elements_cso);
+
        struct pipe_draw_info info = {};
        info.mode = R600_PRIM_RECTANGLE_LIST;
        info.count = 3;