zink: flag ssbo buffer resources as having pending writes on batch
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 4 Aug 2020 18:57:06 +0000 (14:57 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 14 Jan 2021 18:13:28 +0000 (18:13 +0000)
ssbos are the only descriptor type we support (so far) that allows writes
during the draw, so we have to ensure that we set the right flag on the batch
reference to handle sync if the buffer is later read from

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8330>

src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_context.h
src/gallium/drivers/zink/zink_draw.c

index 42d8829..e5a502f 100644 (file)
@@ -583,6 +583,10 @@ zink_set_shader_buffers(struct pipe_context *pctx,
 {
    struct zink_context *ctx = zink_context(pctx);
 
+   unsigned modified_bits = u_bit_consecutive(start_slot, count);
+   ctx->writable_ssbos &= ~modified_bits;
+   ctx->writable_ssbos |= writable_bitmask << start_slot;
+
    for (unsigned i = 0; i < count; i++) {
       struct pipe_shader_buffer *ssbo = &ctx->ssbos[p_stage][start_slot + i];
       if (buffers && buffers[i].buffer) {
index a1879d3..e63875b 100644 (file)
@@ -92,6 +92,7 @@ struct zink_context {
 
    struct pipe_constant_buffer ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
    struct pipe_shader_buffer ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
+   uint32_t writable_ssbos;
    struct pipe_framebuffer_state fb_state;
 
    struct zink_vertex_elements_state *element_state;
index 81d0d40..c2e7f1a 100644 (file)
@@ -356,7 +356,10 @@ zink_draw_vbo(struct pipe_context *pctx,
             assert(ctx->ssbos[i][index].buffer_size <= screen->info.props.limits.maxStorageBufferRange);
             assert(ctx->ssbos[i][index].buffer);
             struct zink_resource *res = zink_resource(ctx->ssbos[i][index].buffer);
-            write_desc_resources[num_wds] = res;
+            if (ctx->writable_ssbos & (1 << index))
+               write_desc_resources[num_wds] = res;
+            else
+               read_desc_resources[num_wds] = res;
             buffer_infos[num_buffer_info].buffer = res->buffer;
             buffer_infos[num_buffer_info].offset = ctx->ssbos[i][index].buffer_offset;
             buffer_infos[num_buffer_info].range  = ctx->ssbos[i][index].buffer_size;