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