renderer: do glUniform1f at link-time

This means less needless work per frame, as this binding will never
change.

Signed-off-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
macos/master
Erik Faye-Lund 6 years ago
parent 23ea840f08
commit 20cba1d469
  1. 35
      src/vrend_renderer.c

@ -281,7 +281,6 @@ struct vrend_linked_shader_program {
struct vrend_shader *ss[PIPE_SHADER_TYPES];
uint32_t samplers_used_mask[PIPE_SHADER_TYPES];
GLuint *samp_locs[PIPE_SHADER_TYPES];
GLuint *shadow_samp_mask_locs[PIPE_SHADER_TYPES];
GLuint *shadow_samp_add_locs[PIPE_SHADER_TYPES];
@ -1090,7 +1089,7 @@ static void set_stream_out_varyings(struct vrend_context *ctx, int prog_id,
}
static void bind_sampler_locs(struct vrend_linked_shader_program *sprog,
int id)
int id, int *sampler_id)
{
if (sprog->ss[id]->sel->sinfo.samplers_used_mask) {
uint32_t mask = sprog->ss[id]->sel->sinfo.samplers_used_mask;
@ -1103,8 +1102,6 @@ static void bind_sampler_locs(struct vrend_linked_shader_program *sprog,
} else {
sprog->shadow_samp_mask_locs[id] = sprog->shadow_samp_add_locs[id] = NULL;
}
sprog->samp_locs[id] = calloc(nsamp, sizeof(uint32_t));
if (sprog->samp_locs[id]) {
const char *prefix = pipe_shader_to_prefix(id);
index = 0;
while(mask) {
@ -1115,7 +1112,9 @@ static void bind_sampler_locs(struct vrend_linked_shader_program *sprog,
snprintf(name, 32, "%ssamp%d[%d]", prefix, arr_idx, i - arr_idx);
} else
snprintf(name, 32, "%ssamp%d", prefix, i);
sprog->samp_locs[id][index] = glGetUniformLocation(sprog->id, name);
glUniform1i(glGetUniformLocation(sprog->id, name), *sampler_id);
if (sprog->ss[id]->sel->sinfo.shadow_samp_mask & (1 << i)) {
snprintf(name, 32, "%sshadmask%d", prefix, i);
sprog->shadow_samp_mask_locs[id][index] = glGetUniformLocation(sprog->id, name);
@ -1123,10 +1122,9 @@ static void bind_sampler_locs(struct vrend_linked_shader_program *sprog,
sprog->shadow_samp_add_locs[id][index] = glGetUniformLocation(sprog->id, name);
}
index++;
}
(*sampler_id)++;
}
} else {
sprog->samp_locs[id] = NULL;
sprog->shadow_samp_mask_locs[id] = NULL;
sprog->shadow_samp_add_locs[id] = NULL;
sprog->shadow_samp_mask[id] = 0;
@ -1267,8 +1265,10 @@ static struct vrend_linked_shader_program *add_cs_shader_program(struct vrend_co
sprog->id = prog_id;
list_addtail(&sprog->head, &ctx->sub->programs);
bind_sampler_locs(sprog, PIPE_SHADER_COMPUTE);
int ubo_id = 0;
vrend_use_program(ctx, prog_id);
int sampler_id = 0, ubo_id = 0;
bind_sampler_locs(sprog, PIPE_SHADER_COMPUTE, &sampler_id);
bind_ubo_locs(sprog, PIPE_SHADER_COMPUTE, &ubo_id);
bind_ssbo_locs(sprog, PIPE_SHADER_COMPUTE);
bind_const_locs(sprog, PIPE_SHADER_COMPUTE);
@ -1415,12 +1415,14 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_conte
sprog->fs_stipple_loc = -1;
sprog->vs_ws_adjust_loc = glGetUniformLocation(prog_id, "winsys_adjust_y");
int ubo_id = 0;
vrend_use_program(ctx, prog_id);
int ubo_id = 0, sampler_id = 0;
for (id = PIPE_SHADER_VERTEX; id <= last_shader; id++) {
if (!sprog->ss[id])
continue;
bind_sampler_locs(sprog, id);
bind_sampler_locs(sprog, id, &sampler_id);
bind_const_locs(sprog, id);
bind_ubo_locs(sprog, id, &ubo_id);
bind_image_locs(sprog, id);
@ -1508,7 +1510,6 @@ static void vrend_destroy_program(struct vrend_linked_shader_program *ent)
list_del(&ent->sl[i]);
free(ent->shadow_samp_mask_locs[i]);
free(ent->shadow_samp_add_locs[i]);
free(ent->samp_locs[i]);
free(ent->ssbo_locs[i]);
free(ent->img_locs[i]);
}
@ -3625,12 +3626,7 @@ static void vrend_draw_bind_samplers_shader(struct vrend_context *ctx,
int i = u_bit_scan(&mask);
struct vrend_sampler_view *tview = ctx->sub->views[shader_type].views[i];
if (!tview)
continue;
if (ctx->sub->prog->samp_locs[shader_type])
glUniform1i(ctx->sub->prog->samp_locs[shader_type][index], *sampler_id);
if (tview) {
if (ctx->sub->prog->shadow_samp_mask[shader_type] & (1 << i)) {
glUniform4f(ctx->sub->prog->shadow_samp_mask_locs[shader_type][index],
(tview->gl_swizzle_r == GL_ZERO || tview->gl_swizzle_r == GL_ONE) ? 0.0 : 1.0,
@ -3663,8 +3659,9 @@ static void vrend_draw_bind_samplers_shader(struct vrend_context *ctx,
vrend_apply_sampler_state(ctx, texture, shader_type, i, *sampler_id, tview);
ctx->sub->views[shader_type].old_ids[i] = id;
}
(*sampler_id)++;
}
}
(*sampler_id)++;
index++;
}
}

Loading…
Cancel
Save