zink: Store zink_vertex_elements_hw_state::b.strides by binding id
authorSviatoslav Peleshko <sviatoslav.peleshko@globallogic.com>
Wed, 20 Sep 2023 13:31:57 +0000 (16:31 +0300)
committerMarge Bot <emma+marge@anholt.net>
Wed, 20 Sep 2023 13:44:28 +0000 (13:44 +0000)
Currently, we store strides by vertex buffer id, which means that we have
to map the binding index to the vertex buffer index every time we want to
get a stride for a given binding. This also creates an order mismatch when
we pass strides directly to CmdBindVertexBuffers2EXT. Instead of converting
strides for CmdBindVertexBuffers2EXT too, we can just store strides by
binding id, and drop the mapping in other places.

Fixes: 76725452 ("gallium: move vertex stride to CSO")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9817
Signed-off-by: Sviatoslav Peleshko <sviatoslav.peleshko@globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25305>

src/gallium/drivers/zink/zink_draw.cpp
src/gallium/drivers/zink/zink_program_state.hpp
src/gallium/drivers/zink/zink_state.c

index 304cbb5..2946e26 100644 (file)
@@ -132,7 +132,7 @@ bind_vertex_buffers_dgc(struct zink_context *ctx)
          assert(res->obj->bda);
          ptr->bufferAddress = res->obj->bda + vb->buffer_offset;
          ptr->size = res->base.b.width0;
-         ptr->stride = ctx->element_state->hw_state.b.strides[ctx->element_state->hw_state.binding_map[i]];
+         ptr->stride = ctx->element_state->hw_state.b.strides[i];
       } else {
          ptr->bufferAddress = 0;
          ptr->size = 0;
@@ -151,7 +151,7 @@ zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
    struct zink_screen *screen = zink_screen(ctx->base.screen);
 
    for (unsigned i = 0; i < elems->hw_state.num_bindings; i++) {
-      struct pipe_vertex_buffer *vb = ctx->vertex_buffers + ctx->element_state->hw_state.binding_map[i];
+      struct pipe_vertex_buffer *vb = ctx->vertex_buffers + elems->hw_state.binding_map[i];
       assert(vb);
       if (vb->buffer.resource) {
          struct zink_resource *res = zink_resource(vb->buffer.resource);
index eb2af70..4f05f13 100644 (file)
@@ -84,7 +84,7 @@ check_vertex_strides(struct zink_context *ctx)
    const struct zink_vertex_elements_state *ves = ctx->element_state;
    for (unsigned i = 0; i < ves->hw_state.num_bindings; i++) {
       const struct pipe_vertex_buffer *vb = ctx->vertex_buffers + ves->hw_state.binding_map[i];
-      unsigned stride = vb->buffer.resource ? ves->hw_state.b.strides[ves->hw_state.binding_map[i]] : 0;
+      unsigned stride = vb->buffer.resource ? ves->hw_state.b.strides[i] : 0;
       if (stride && stride < ves->min_stride[i])
          return false;
    }
@@ -148,7 +148,7 @@ zink_get_gfx_pipeline(struct zink_context *ctx,
          for (unsigned i = 0; i < state->element_state->num_bindings; i++) {
             const unsigned buffer_id = ctx->element_state->hw_state.binding_map[i];
             struct pipe_vertex_buffer *vb = ctx->vertex_buffers + buffer_id;
-            state->vertex_strides[buffer_id] = vb->buffer.resource ? state->element_state->b.strides[buffer_id] : 0;
+            state->vertex_strides[buffer_id] = vb->buffer.resource ? state->element_state->b.strides[i] : 0;
             hash = XXH32(&state->vertex_strides[buffer_id], sizeof(uint32_t), hash);
          }
          state->vertex_hash = hash ^ state->element_state->hash;
index 0d94f5a..1f671cb 100644 (file)
@@ -120,7 +120,7 @@ zink_create_vertex_elements_state(struct pipe_context *pctx,
          ves->hw_state.attribs[i].binding = binding;
          ves->hw_state.attribs[i].location = i;
          ves->hw_state.attribs[i].format = format;
-         ves->hw_state.b.strides[elem->vertex_buffer_index] = elem->src_stride;
+         ves->hw_state.b.strides[binding] = elem->src_stride;
          assert(ves->hw_state.attribs[i].format != VK_FORMAT_UNDEFINED);
          ves->hw_state.attribs[i].offset = elem->src_offset;
          ves->min_stride[binding] = MAX2(ves->min_stride[binding], elem->src_offset + vk_format_get_blocksize(format));