vrend/shader: handle uniforms as array

In the shaders the uniforms are allocated as arrays, and they are also
passed from the guest as arrays, so let's also upload them to the host
driver as arrays.

Performance improvement (both measurements used Gurchetan's mesa/virgl
patches to improve transfers):

Measurements on r600 (AMD 6870 HD)
  Unigine Valley (1024x768, Q:High, AA:2x)
  Unigine Heaven (1024x768, Q:High, Tess: Disabled, AA:2x)

                 Unigine Valley   Unigine Heaven
without              20.2             26.1
with this patch      22.0             31.5

Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Signed-off-by: Jakob Bornecrantz <jakob@collabora.com>
macos/master
Gert Wollny 6 years ago committed by Jakob Bornecrantz
parent c1b6c98589
commit 172c9679b4
  1. 28
      src/vrend_renderer.c

@ -278,7 +278,7 @@ struct vrend_linked_shader_program {
GLuint *shadow_samp_mask_locs[PIPE_SHADER_TYPES]; GLuint *shadow_samp_mask_locs[PIPE_SHADER_TYPES];
GLuint *shadow_samp_add_locs[PIPE_SHADER_TYPES]; GLuint *shadow_samp_add_locs[PIPE_SHADER_TYPES];
GLint *const_locs[PIPE_SHADER_TYPES]; GLint const_location[PIPE_SHADER_TYPES];
GLuint *attrib_locs; GLuint *attrib_locs;
uint32_t shadow_samp_mask[PIPE_SHADER_TYPES]; uint32_t shadow_samp_mask[PIPE_SHADER_TYPES];
@ -1107,17 +1107,11 @@ static void bind_const_locs(struct vrend_linked_shader_program *sprog,
int id) int id)
{ {
if (sprog->ss[id]->sel->sinfo.num_consts) { if (sprog->ss[id]->sel->sinfo.num_consts) {
sprog->const_locs[id] = calloc(sprog->ss[id]->sel->sinfo.num_consts, sizeof(uint32_t)); char name[32];
if (sprog->const_locs[id]) { snprintf(name, 32, "%sconst0", pipe_shader_to_prefix(id));
const char *prefix = pipe_shader_to_prefix(id); sprog->const_location[id] = glGetUniformLocation(sprog->id, name);
for (int i = 0; i < sprog->ss[id]->sel->sinfo.num_consts; i++) { } else
char name[32]; sprog->const_location[id] = -1;
snprintf(name, 32, "%sconst0[%d]", prefix, i);
sprog->const_locs[id][i] = glGetUniformLocation(sprog->id, name);
}
}
} else
sprog->const_locs[id] = NULL;
} }
static void bind_ubo_locs(struct vrend_linked_shader_program *sprog, static void bind_ubo_locs(struct vrend_linked_shader_program *sprog,
@ -1479,7 +1473,6 @@ static void vrend_destroy_program(struct vrend_linked_shader_program *ent)
free(ent->samp_locs[i]); free(ent->samp_locs[i]);
free(ent->ssbo_locs[i]); free(ent->ssbo_locs[i]);
free(ent->img_locs[i]); free(ent->img_locs[i]);
free(ent->const_locs[i]);
free(ent->ubo_locs[i]); free(ent->ubo_locs[i]);
} }
free(ent->attrib_locs); free(ent->attrib_locs);
@ -3674,12 +3667,11 @@ static void vrend_draw_bind_const_shader(struct vrend_context *ctx,
int shader_type, bool new_program) int shader_type, bool new_program)
{ {
if (ctx->sub->consts[shader_type].consts && if (ctx->sub->consts[shader_type].consts &&
ctx->sub->prog->const_locs[shader_type] && (ctx->sub->prog->const_location[shader_type] != -1) &&
(ctx->sub->const_dirty[shader_type] || new_program)) { (ctx->sub->const_dirty[shader_type] || new_program)) {
for (int i = 0; i < ctx->sub->shaders[shader_type]->sinfo.num_consts; i++) { glUniform4uiv(ctx->sub->prog->const_location[shader_type],
if (ctx->sub->prog->const_locs[shader_type][i] != -1) ctx->sub->shaders[shader_type]->sinfo.num_consts,
glUniform4uiv(ctx->sub->prog->const_locs[shader_type][i], 1, &ctx->sub->consts[shader_type].consts[i * 4]); ctx->sub->consts[shader_type].consts);
}
ctx->sub->const_dirty[shader_type] = false; ctx->sub->const_dirty[shader_type] = false;
} }
} }

Loading…
Cancel
Save