renderer: refactor draw time ubo binding

This refactors out the shader type code into a separate function,
makes it easier to add compute support later.

Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Dave Airlie 7 years ago
parent b624bc65ff
commit d7f23b2a1f
  1. 77
      src/vrend_renderer.c

@ -3033,51 +3033,56 @@ static void vrend_draw_bind_samplers(struct vrend_context *ctx)
ctx->sub->sampler_state_dirty = false; ctx->sub->sampler_state_dirty = false;
} }
static void vrend_draw_bind_ubo(struct vrend_context *ctx) static void vrend_draw_bind_ubo_shader(struct vrend_context *ctx,
int shader_type, int *ubo_id)
{ {
int i; uint32_t mask;
int ubo_id; int shader_ubo_idx;
int shader_type; struct pipe_constant_buffer *cb;
struct vrend_resource *res;
struct vrend_shader_info* sinfo;
ubo_id = 0; if (!ctx->sub->const_bufs_used_mask[shader_type])
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= ctx->sub->last_shader_idx; shader_type++) { return;
uint32_t mask;
int shader_ubo_idx;
struct pipe_constant_buffer *cb;
struct vrend_resource *res;
struct vrend_shader_info* sinfo;
if (!ctx->sub->const_bufs_used_mask[shader_type]) if (!ctx->sub->prog->ubo_locs[shader_type])
continue; return;
if (!ctx->sub->prog->ubo_locs[shader_type]) sinfo = &ctx->sub->prog->ss[shader_type]->sel->sinfo;
continue;
sinfo = &ctx->sub->prog->ss[shader_type]->sel->sinfo; mask = ctx->sub->const_bufs_used_mask[shader_type];
while (mask) {
/* The const_bufs_used_mask stores the gallium uniform buffer indices */
int i = u_bit_scan(&mask);
mask = ctx->sub->const_bufs_used_mask[shader_type]; /* The cbs array is indexed using the gallium uniform buffer index */
while (mask) { cb = &ctx->sub->cbs[shader_type][i];
/* The const_bufs_used_mask stores the gallium uniform buffer indices */ res = (struct vrend_resource *)cb->buffer;
i = u_bit_scan(&mask);
/* The cbs array is indexed using the gallium uniform buffer index */ /* Find the index of the uniform buffer in the array of shader ubo data */
cb = &ctx->sub->cbs[shader_type][i]; for (shader_ubo_idx = 0; shader_ubo_idx < sinfo->num_ubos; shader_ubo_idx++) {
res = (struct vrend_resource *)cb->buffer; if (sinfo->ubo_idx[shader_ubo_idx] == i)
break;
}
if (shader_ubo_idx == sinfo->num_ubos)
continue;
/* Find the index of the uniform buffer in the array of shader ubo data */ glBindBufferRange(GL_UNIFORM_BUFFER, *ubo_id, res->id,
for (shader_ubo_idx = 0; shader_ubo_idx < sinfo->num_ubos; shader_ubo_idx++) { cb->buffer_offset, cb->buffer_size);
if (sinfo->ubo_idx[shader_ubo_idx] == i) /* The ubo_locs array is indexed using the shader ubo index */
break; glUniformBlockBinding(ctx->sub->prog->id, ctx->sub->prog->ubo_locs[shader_type][shader_ubo_idx], *ubo_id);
} (*ubo_id)++;
if (shader_ubo_idx == sinfo->num_ubos) }
continue; }
glBindBufferRange(GL_UNIFORM_BUFFER, ubo_id, res->id, static void vrend_draw_bind_ubo(struct vrend_context *ctx)
cb->buffer_offset, cb->buffer_size); {
/* The ubo_locs array is indexed using the shader ubo index */ int ubo_id;
glUniformBlockBinding(ctx->sub->prog->id, ctx->sub->prog->ubo_locs[shader_type][shader_ubo_idx], ubo_id); int shader_type;
ubo_id++;
} ubo_id = 0;
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= ctx->sub->last_shader_idx; shader_type++) {
vrend_draw_bind_ubo_shader(ctx, shader_type, &ubo_id);
} }
} }

Loading…
Cancel
Save