shader: Force two-side color emission only if it is really needed

Don't use the shader key when forcing it.

Changing a shader key within vrend_create_shader will always force
virglrenderer to recreate the shader the next time it is looked up, so
memory usage will grow and performance will go down.

Also it is actually not needed if with each emitted back color also has a
corresponding front color is emitted. So restrict forcing two-sided coloring
to the cases where a back color is emitted without a front color, and don't
change the shader key.

Fixes #130

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Gert Wollny 5 years ago
parent e66a1d97cb
commit def64149af
  1. 19
      src/vrend_shader.c

@ -247,6 +247,7 @@ struct dump_ctx {
bool has_sample_input; bool has_sample_input;
bool early_depth_stencil; bool early_depth_stencil;
bool has_file_memory; bool has_file_memory;
bool force_color_two_side;
int tcs_vertices_out; int tcs_vertices_out;
int tes_prim_mode; int tes_prim_mode;
@ -5912,6 +5913,8 @@ emit_ios_generic_outputs(struct dump_ctx *ctx,
const can_emit_generic_callback can_emit_generic) const can_emit_generic_callback can_emit_generic)
{ {
uint32_t i; uint32_t i;
uint64_t fc_emitted = 0;
uint64_t bc_emitted = 0;
for (i = 0; i < ctx->num_outputs; i++) { for (i = 0; i < ctx->num_outputs; i++) {
@ -5929,14 +5932,14 @@ emit_ios_generic_outputs(struct dump_ctx *ctx,
prefix = INTERP_PREFIX; prefix = INTERP_PREFIX;
} }
if (ctx->outputs[i].name == TGSI_SEMANTIC_COLOR) if (ctx->outputs[i].name == TGSI_SEMANTIC_COLOR) {
ctx->front_back_color_emitted_flags[ctx->outputs[i].sid] |= FRONT_COLOR_EMITTED; ctx->front_back_color_emitted_flags[ctx->outputs[i].sid] |= FRONT_COLOR_EMITTED;
fc_emitted |= 1ull << ctx->outputs[i].sid;
}
if (ctx->outputs[i].name == TGSI_SEMANTIC_BCOLOR) { if (ctx->outputs[i].name == TGSI_SEMANTIC_BCOLOR) {
// We have a back color so we must force the output emission to declare
// two sides
ctx->key->color_two_side = 1;
ctx->front_back_color_emitted_flags[ctx->outputs[i].sid] |= BACK_COLOR_EMITTED; ctx->front_back_color_emitted_flags[ctx->outputs[i].sid] |= BACK_COLOR_EMITTED;
bc_emitted |= 1ull << ctx->outputs[i].sid;
} }
emit_ios_generic(ctx, io_out, prefix, &ctx->outputs[i], emit_ios_generic(ctx, io_out, prefix, &ctx->outputs[i],
@ -5948,6 +5951,12 @@ emit_ios_generic_outputs(struct dump_ctx *ctx,
ctx->outputs[i].glsl_name); ctx->outputs[i].glsl_name);
} }
} }
/* If a back color emitted without a corresponding front color, then
* we have to force two side coloring, because the FS shader might expect
* a front color too. */
if (bc_emitted & ~fc_emitted)
ctx->force_color_two_side = 1;
} }
static void static void
@ -6002,7 +6011,7 @@ static void emit_ios_vs(struct dump_ctx *ctx)
emit_ios_generic_outputs(ctx, can_emit_generic_default); emit_ios_generic_outputs(ctx, can_emit_generic_default);
if (ctx->key->color_two_side) { if (ctx->key->color_two_side || ctx->force_color_two_side) {
bool fcolor_emitted, bcolor_emitted; bool fcolor_emitted, bcolor_emitted;
for (i = 0; i < ctx->num_outputs; i++) { for (i = 0; i < ctx->num_outputs; i++) {

Loading…
Cancel
Save