From: Marek Olšák Date: Wed, 27 Nov 2019 22:26:51 +0000 (-0500) Subject: st/mesa: support SSBOs for Selection/Feedback/RasterPos X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b7393f1115f5cc240f4ba389c56d50606143854a;p=mesa.git st/mesa: support SSBOs for Selection/Feedback/RasterPos Reviewed-by: Dave Airlie --- 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,