vrend: use uniform for alpha func value

Some applications change glAlphaFunc nearly every frame.

Sam 3 apitrace replay went from ~4 fps to ~19 fps on a chromebook.

Signed-off-by: John Bates <jbates@chromium.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
John Bates 5 years ago
parent 466f32dd97
commit e4df9556cf
  1. 11
      src/vrend_renderer.c
  2. 22
      src/vrend_shader.c
  3. 4
      src/vrend_shader.h

@ -347,6 +347,8 @@ struct vrend_linked_shader_program {
GLint fs_stipple_loc; GLint fs_stipple_loc;
GLint fs_alpha_ref_val_loc;
GLuint clip_locs[8]; GLuint clip_locs[8];
uint32_t images_used_mask[PIPE_SHADER_TYPES]; uint32_t images_used_mask[PIPE_SHADER_TYPES];
@ -1602,6 +1604,10 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_conte
sprog->fs_stipple_loc = glGetUniformLocation(prog_id, "pstipple_sampler"); sprog->fs_stipple_loc = glGetUniformLocation(prog_id, "pstipple_sampler");
else else
sprog->fs_stipple_loc = -1; sprog->fs_stipple_loc = -1;
if (vrend_shader_needs_alpha_func(&fs->key))
sprog->fs_alpha_ref_val_loc = glGetUniformLocation(prog_id, "alpha_ref_val");
else
sprog->fs_alpha_ref_val_loc = -1;
sprog->vs_ws_adjust_loc = glGetUniformLocation(prog_id, "winsys_adjust_y"); sprog->vs_ws_adjust_loc = glGetUniformLocation(prog_id, "winsys_adjust_y");
vrend_use_program(ctx, prog_id); vrend_use_program(ctx, prog_id);
@ -3138,7 +3144,6 @@ static inline void vrend_fill_shader_key(struct vrend_context *ctx,
if (add_alpha_test) { if (add_alpha_test) {
key->add_alpha_test = ctx->sub->dsa_state.alpha.enabled; key->add_alpha_test = ctx->sub->dsa_state.alpha.enabled;
key->alpha_test = ctx->sub->dsa_state.alpha.func; key->alpha_test = ctx->sub->dsa_state.alpha.func;
key->alpha_ref_val = ctx->sub->dsa_state.alpha.ref_value;
} }
key->pstipple_tex = ctx->sub->rs_state.poly_stipple_enable; key->pstipple_tex = ctx->sub->rs_state.poly_stipple_enable;
@ -4228,6 +4233,10 @@ static void vrend_draw_bind_objects(struct vrend_context *ctx, bool new_program)
glBindTexture(GL_TEXTURE_2D, ctx->pstipple_tex_id); glBindTexture(GL_TEXTURE_2D, ctx->pstipple_tex_id);
glUniform1i(ctx->sub->prog->fs_stipple_loc, next_sampler_id); glUniform1i(ctx->sub->prog->fs_stipple_loc, next_sampler_id);
} }
if (vrend_state.use_core_profile && ctx->sub->prog->fs_alpha_ref_val_loc != -1) {
glUniform1i(ctx->sub->prog->fs_alpha_ref_val_loc, ctx->sub->dsa_state.alpha.ref_value);
}
} }
static static

@ -1724,7 +1724,7 @@ static void emit_alpha_test(struct dump_ctx *ctx)
case PIPE_FUNC_GREATER: case PIPE_FUNC_GREATER:
case PIPE_FUNC_NOTEQUAL: case PIPE_FUNC_NOTEQUAL:
case PIPE_FUNC_GEQUAL: case PIPE_FUNC_GEQUAL:
snprintf(comp_buf, 128, "%s %s %f", "fsout_c0.w", atests[ctx->key->alpha_test], ctx->key->alpha_ref_val); snprintf(comp_buf, 128, "%s %s alpha_ref_val", "fsout_c0.w", atests[ctx->key->alpha_test]);
break; break;
default: default:
vrend_printf( "invalid alpha-test: %x\n", ctx->key->alpha_test); vrend_printf( "invalid alpha-test: %x\n", ctx->key->alpha_test);
@ -6137,6 +6137,10 @@ static void emit_ios_fs(struct dump_ctx *ctx)
} }
} }
if (vrend_shader_needs_alpha_func(ctx->key)) {
emit_hdr(ctx, "uniform float alpha_ref_val;\n");
}
if (ctx->key->color_two_side) { if (ctx->key->color_two_side) {
if (ctx->color_in_mask & 1) if (ctx->color_in_mask & 1)
emit_hdr(ctx, "vec4 realcolor0;\n"); emit_hdr(ctx, "vec4 realcolor0;\n");
@ -7060,3 +7064,19 @@ fail:
free(ctx.temp_ranges); free(ctx.temp_ranges);
return false; return false;
} }
bool vrend_shader_needs_alpha_func(const struct vrend_shader_key *key) {
if (!key->add_alpha_test)
return false;
switch (key->alpha_test) {
default:
return false;
case PIPE_FUNC_LESS:
case PIPE_FUNC_EQUAL:
case PIPE_FUNC_LEQUAL:
case PIPE_FUNC_GREATER:
case PIPE_FUNC_NOTEQUAL:
case PIPE_FUNC_GEQUAL:
return true;
}
}

@ -117,7 +117,6 @@ struct vrend_shader_key {
uint8_t prev_stage_num_clip_out; uint8_t prev_stage_num_clip_out;
uint8_t prev_stage_num_cull_out; uint8_t prev_stage_num_cull_out;
float alpha_ref_val;
uint32_t cbufs_are_a8_bitmask; uint32_t cbufs_are_a8_bitmask;
uint8_t num_indirect_generic_outputs; uint8_t num_indirect_generic_outputs;
uint8_t num_indirect_patch_outputs; uint8_t num_indirect_patch_outputs;
@ -176,4 +175,7 @@ bool vrend_shader_create_passthrough_tcs(struct vrend_context *ctx,
struct vrend_shader_info *sinfo, struct vrend_shader_info *sinfo,
struct vrend_strarray *shader, struct vrend_strarray *shader,
int vertices_per_patch); int vertices_per_patch);
bool vrend_shader_needs_alpha_func(const struct vrend_shader_key *key);
#endif #endif

Loading…
Cancel
Save