vrend: refactor select program

Use helper variables for some pointer derefs and query the shader ID's
only once.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
Gert Wollny 4 years ago
parent d9b4e34933
commit 03dd77537a
  1. 111
      src/vrend_renderer.c

@ -580,7 +580,7 @@ struct vrend_sub_context {
struct vrend_shader_selector *shaders[PIPE_SHADER_TYPES]; struct vrend_shader_selector *shaders[PIPE_SHADER_TYPES];
struct vrend_linked_shader_program *prog; struct vrend_linked_shader_program *prog;
int prog_ids[PIPE_SHADER_TYPES]; GLuint prog_ids[PIPE_SHADER_TYPES];
struct vrend_shader_view views[PIPE_SHADER_TYPES]; struct vrend_shader_view views[PIPE_SHADER_TYPES];
struct vrend_constants consts[PIPE_SHADER_TYPES]; struct vrend_constants consts[PIPE_SHADER_TYPES];
@ -4397,9 +4397,12 @@ vrend_select_program(struct vrend_context *ctx, const struct pipe_draw_info *inf
bool new_program = false; bool new_program = false;
ctx->sub->shader_dirty = false; struct vrend_sub_context *sub = ctx->sub;
struct vrend_shader_selector **shaders = sub->shaders;
if (!ctx->sub->shaders[PIPE_SHADER_VERTEX] || !ctx->sub->shaders[PIPE_SHADER_FRAGMENT]) { sub->shader_dirty = false;
if (!shaders[PIPE_SHADER_VERTEX] || !shaders[PIPE_SHADER_FRAGMENT]) {
vrend_printf("dropping rendering due to missing shaders: %s\n", ctx->debug_name); vrend_printf("dropping rendering due to missing shaders: %s\n", ctx->debug_name);
return false; return false;
} }
@ -4409,89 +4412,87 @@ vrend_select_program(struct vrend_context *ctx, const struct pipe_draw_info *inf
// buffer formats when the shader is created, we only know it here. // buffer formats when the shader is created, we only know it here.
// Set it to true so the underlying code knows to use the buffer formats // Set it to true so the underlying code knows to use the buffer formats
// now. // now.
ctx->sub->drawing = true; sub->drawing = true;
vrend_shader_select(ctx, ctx->sub->shaders[PIPE_SHADER_VERTEX], &vs_dirty); vrend_shader_select(ctx, shaders[PIPE_SHADER_VERTEX], &vs_dirty);
ctx->sub->drawing = false; sub->drawing = false;
if (ctx->sub->shaders[PIPE_SHADER_TESS_CTRL] && ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]->tokens) if (shaders[PIPE_SHADER_TESS_CTRL] && shaders[PIPE_SHADER_TESS_CTRL]->tokens)
vrend_shader_select(ctx, ctx->sub->shaders[PIPE_SHADER_TESS_CTRL], &tcs_dirty); vrend_shader_select(ctx, shaders[PIPE_SHADER_TESS_CTRL], &tcs_dirty);
else if (vrend_state.use_gles && ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]) { else if (vrend_state.use_gles && shaders[PIPE_SHADER_TESS_EVAL]) {
VREND_DEBUG(dbg_shader, ctx, "Need to inject a TCS\n"); VREND_DEBUG(dbg_shader, ctx, "Need to inject a TCS\n");
vrend_inject_tcs(ctx, info->vertices_per_patch); vrend_inject_tcs(ctx, info->vertices_per_patch);
vrend_shader_select(ctx, ctx->sub->shaders[PIPE_SHADER_VERTEX], &vs_dirty); vrend_shader_select(ctx, shaders[PIPE_SHADER_VERTEX], &vs_dirty);
} }
if (ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]) if (shaders[PIPE_SHADER_TESS_EVAL])
vrend_shader_select(ctx, ctx->sub->shaders[PIPE_SHADER_TESS_EVAL], &tes_dirty); vrend_shader_select(ctx, shaders[PIPE_SHADER_TESS_EVAL], &tes_dirty);
if (ctx->sub->shaders[PIPE_SHADER_GEOMETRY]) if (shaders[PIPE_SHADER_GEOMETRY])
vrend_shader_select(ctx, ctx->sub->shaders[PIPE_SHADER_GEOMETRY], &gs_dirty); vrend_shader_select(ctx, shaders[PIPE_SHADER_GEOMETRY], &gs_dirty);
vrend_shader_select(ctx, ctx->sub->shaders[PIPE_SHADER_FRAGMENT], &fs_dirty); vrend_shader_select(ctx, shaders[PIPE_SHADER_FRAGMENT], &fs_dirty);
if (!ctx->sub->shaders[PIPE_SHADER_VERTEX]->current || if (!shaders[PIPE_SHADER_VERTEX]->current ||
!ctx->sub->shaders[PIPE_SHADER_FRAGMENT]->current || !shaders[PIPE_SHADER_FRAGMENT]->current ||
(ctx->sub->shaders[PIPE_SHADER_GEOMETRY] && !ctx->sub->shaders[PIPE_SHADER_GEOMETRY]->current) || (shaders[PIPE_SHADER_GEOMETRY] && !shaders[PIPE_SHADER_GEOMETRY]->current) ||
(ctx->sub->shaders[PIPE_SHADER_TESS_CTRL] && !ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]->current) || (shaders[PIPE_SHADER_TESS_CTRL] && !shaders[PIPE_SHADER_TESS_CTRL]->current) ||
(ctx->sub->shaders[PIPE_SHADER_TESS_EVAL] && !ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]->current)) { (shaders[PIPE_SHADER_TESS_EVAL] && !shaders[PIPE_SHADER_TESS_EVAL]->current)) {
vrend_printf( "failure to compile shader variants: %s\n", ctx->debug_name); vrend_printf( "failure to compile shader variants: %s\n", ctx->debug_name);
return false; return false;
} }
GLuint vs_id = shaders[PIPE_SHADER_VERTEX]->current->id;
GLuint fs_id = shaders[PIPE_SHADER_FRAGMENT]->current->id;
GLuint gs_id = shaders[PIPE_SHADER_GEOMETRY] ? shaders[PIPE_SHADER_GEOMETRY]->current->id : 0;
GLuint tcs_id = shaders[PIPE_SHADER_TESS_CTRL] ? shaders[PIPE_SHADER_TESS_CTRL]->current->id : 0;
GLuint tes_id = shaders[PIPE_SHADER_TESS_EVAL] ? shaders[PIPE_SHADER_TESS_EVAL]->current->id : 0;
same_prog = true; same_prog = true;
if (ctx->sub->shaders[PIPE_SHADER_VERTEX]->current->id != (GLuint)ctx->sub->prog_ids[PIPE_SHADER_VERTEX]) if (vs_id != sub->prog_ids[PIPE_SHADER_VERTEX])
same_prog = false; same_prog = false;
if (ctx->sub->shaders[PIPE_SHADER_FRAGMENT]->current->id != (GLuint)ctx->sub->prog_ids[PIPE_SHADER_FRAGMENT]) if (fs_id != sub->prog_ids[PIPE_SHADER_FRAGMENT])
same_prog = false; same_prog = false;
if (ctx->sub->shaders[PIPE_SHADER_GEOMETRY] && ctx->sub->shaders[PIPE_SHADER_GEOMETRY]->current->id != (GLuint)ctx->sub->prog_ids[PIPE_SHADER_GEOMETRY]) if (gs_id != sub->prog_ids[PIPE_SHADER_GEOMETRY])
same_prog = false; same_prog = false;
if (ctx->sub->prog && ctx->sub->prog->dual_src_linked != dual_src) if (sub->prog && sub->prog->dual_src_linked != dual_src)
same_prog = false; same_prog = false;
if (ctx->sub->shaders[PIPE_SHADER_TESS_CTRL] && ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]->current->id != (GLuint)ctx->sub->prog_ids[PIPE_SHADER_TESS_CTRL]) if (tcs_id != sub->prog_ids[PIPE_SHADER_TESS_CTRL])
same_prog = false; same_prog = false;
if (ctx->sub->shaders[PIPE_SHADER_TESS_EVAL] && ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]->current->id != (GLuint)ctx->sub->prog_ids[PIPE_SHADER_TESS_EVAL]) if (tes_id != sub->prog_ids[PIPE_SHADER_TESS_EVAL])
same_prog = false; same_prog = false;
if (!same_prog) { if (!same_prog) {
prog = lookup_shader_program(ctx, prog = lookup_shader_program(ctx, vs_id, fs_id, gs_id, tcs_id, tes_id, dual_src);
ctx->sub->shaders[PIPE_SHADER_VERTEX]->current->id,
ctx->sub->shaders[PIPE_SHADER_FRAGMENT]->current->id,
ctx->sub->shaders[PIPE_SHADER_GEOMETRY] ? ctx->sub->shaders[PIPE_SHADER_GEOMETRY]->current->id : 0,
ctx->sub->shaders[PIPE_SHADER_TESS_CTRL] ? ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]->current->id : 0,
ctx->sub->shaders[PIPE_SHADER_TESS_EVAL] ? ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]->current->id : 0,
dual_src);
if (!prog) { if (!prog) {
prog = add_shader_program(ctx, prog = add_shader_program(ctx,
ctx->sub->shaders[PIPE_SHADER_VERTEX]->current, sub->shaders[PIPE_SHADER_VERTEX]->current,
ctx->sub->shaders[PIPE_SHADER_FRAGMENT]->current, sub->shaders[PIPE_SHADER_FRAGMENT]->current,
ctx->sub->shaders[PIPE_SHADER_GEOMETRY] ? ctx->sub->shaders[PIPE_SHADER_GEOMETRY]->current : NULL, gs_id ? sub->shaders[PIPE_SHADER_GEOMETRY]->current : NULL,
ctx->sub->shaders[PIPE_SHADER_TESS_CTRL] ? ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]->current : NULL, tcs_id ? sub->shaders[PIPE_SHADER_TESS_CTRL]->current : NULL,
ctx->sub->shaders[PIPE_SHADER_TESS_EVAL] ? ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]->current : NULL); tes_id ? sub->shaders[PIPE_SHADER_TESS_EVAL]->current : NULL);
if (!prog) if (!prog)
return false; return false;
} }
ctx->sub->last_shader_idx = ctx->sub->shaders[PIPE_SHADER_TESS_EVAL] ? PIPE_SHADER_TESS_EVAL : (ctx->sub->shaders[PIPE_SHADER_GEOMETRY] ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT); sub->last_shader_idx = sub->shaders[PIPE_SHADER_TESS_EVAL] ? PIPE_SHADER_TESS_EVAL : (sub->shaders[PIPE_SHADER_GEOMETRY] ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT);
} else } else
prog = ctx->sub->prog; prog = sub->prog;
if (ctx->sub->prog != prog) { if (sub->prog != prog) {
new_program = true; new_program = true;
ctx->sub->prog_ids[PIPE_SHADER_VERTEX] = ctx->sub->shaders[PIPE_SHADER_VERTEX]->current->id; sub->prog_ids[PIPE_SHADER_VERTEX] = vs_id;
ctx->sub->prog_ids[PIPE_SHADER_FRAGMENT] = ctx->sub->shaders[PIPE_SHADER_FRAGMENT]->current->id; sub->prog_ids[PIPE_SHADER_FRAGMENT] = fs_id;
if (ctx->sub->shaders[PIPE_SHADER_GEOMETRY]) sub->prog_ids[PIPE_SHADER_GEOMETRY] = gs_id;
ctx->sub->prog_ids[PIPE_SHADER_GEOMETRY] = ctx->sub->shaders[PIPE_SHADER_GEOMETRY]->current->id; sub->prog_ids[PIPE_SHADER_TESS_CTRL] = tcs_id;
if (ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]) sub->prog_ids[PIPE_SHADER_TESS_EVAL] = tes_id;
ctx->sub->prog_ids[PIPE_SHADER_TESS_CTRL] = ctx->sub->shaders[PIPE_SHADER_TESS_CTRL]->current->id; sub->prog_ids[PIPE_SHADER_COMPUTE] = 0;
if (ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]) sub->prog = prog;
ctx->sub->prog_ids[PIPE_SHADER_TESS_EVAL] = ctx->sub->shaders[PIPE_SHADER_TESS_EVAL]->current->id;
ctx->sub->prog_ids[PIPE_SHADER_COMPUTE] = -1;
ctx->sub->prog = prog;
/* mark all constbufs and sampler views as dirty */ /* mark all constbufs and sampler views as dirty */
for (int stage = PIPE_SHADER_VERTEX; stage <= PIPE_SHADER_FRAGMENT; stage++) { for (int stage = PIPE_SHADER_VERTEX; stage <= PIPE_SHADER_FRAGMENT; stage++) {
ctx->sub->const_bufs_dirty[stage] = ~0; sub->const_bufs_dirty[stage] = ~0;
ctx->sub->sampler_views_dirty[stage] = ~0; sub->sampler_views_dirty[stage] = ~0;
} }
prog->ref_context = ctx->sub; prog->ref_context = sub;
} }
return new_program; return new_program;
} }
@ -4802,7 +4803,7 @@ void vrend_launch_grid(struct vrend_context *ctx,
if (ctx->sub->prog != prog) { if (ctx->sub->prog != prog) {
new_program = true; new_program = true;
ctx->sub->prog_ids[PIPE_SHADER_VERTEX] = -1; ctx->sub->prog_ids[PIPE_SHADER_VERTEX] = 0;
ctx->sub->prog_ids[PIPE_SHADER_COMPUTE] = ctx->sub->shaders[PIPE_SHADER_COMPUTE]->current->id; ctx->sub->prog_ids[PIPE_SHADER_COMPUTE] = ctx->sub->shaders[PIPE_SHADER_COMPUTE]->current->id;
ctx->sub->prog = prog; ctx->sub->prog = prog;
prog->ref_context = ctx->sub; prog->ref_context = ctx->sub;

Loading…
Cancel
Save