From b7393f1115f5cc240f4ba389c56d50606143854a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 27 Nov 2019 17:26:51 -0500 Subject: [PATCH] st/mesa: support SSBOs for Selection/Feedback/RasterPos Reviewed-by: Dave Airlie --- src/mesa/state_tracker/st_draw_feedback.c | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index fccb3dbdc4a..89651c0d76b 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -257,6 +257,38 @@ st_feedback_draw_vbo(struct gl_context *ctx, size); } + /* shader buffers */ + /* TODO: atomic counter buffers */ + struct pipe_transfer *ssbo_transfer[PIPE_MAX_SHADER_BUFFERS] = {0}; + unsigned ssbo_first_slot = st->has_hw_atomics ? 0 : + st->ctx->Const.Program[MESA_SHADER_VERTEX].MaxAtomicBuffers; + + for (unsigned i = 0; i < prog->info.num_ssbos; i++) { + struct gl_buffer_binding *binding = + &st->ctx->ShaderStorageBufferBindings[ + prog->sh.ShaderStorageBlocks[i]->Binding]; + struct st_buffer_object *st_obj = st_buffer_object(binding->BufferObject); + struct pipe_resource *buf = st_obj->buffer; + + if (!buf) + continue; + + unsigned offset = binding->Offset; + unsigned size = buf->width0 - binding->Offset; + + /* AutomaticSize is FALSE if the buffer was set with BindBufferRange. + * Take the minimum just to be sure. + */ + if (!binding->AutomaticSize) + size = MIN2(size, (unsigned) binding->Size); + + void *ptr = pipe_buffer_map_range(pipe, buf, offset, size, + PIPE_TRANSFER_READ, &ssbo_transfer[i]); + + draw_set_mapped_shader_buffer(draw, PIPE_SHADER_VERTEX, + ssbo_first_slot + i, ptr, size); + } + /* samplers */ struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; for (unsigned i = 0; i < st->state.num_vert_samplers; i++) @@ -384,6 +416,14 @@ st_feedback_draw_vbo(struct gl_context *ctx, draw_set_samplers(draw, PIPE_SHADER_VERTEX, NULL, 0); draw_set_sampler_views(draw, PIPE_SHADER_VERTEX, NULL, 0); + for (unsigned i = 0; i < prog->info.num_ssbos; i++) { + if (ssbo_transfer[i]) { + draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 1 + i, + NULL, 0); + pipe_buffer_unmap(pipe, ssbo_transfer[i]); + } + } + for (unsigned i = 0; i < prog->info.num_ubos; i++) { if (ubo_transfer[i]) { draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 1 + i, -- 2.30.2