From e4df9556cfe914b35f12bc93fe3c186786aa3628 Mon Sep 17 00:00:00 2001 From: John Bates Date: Mon, 13 Apr 2020 16:56:41 -0700 Subject: [PATCH] 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 Reviewed-by: Gert Wollny Reviewed-by: Chia-I Wu --- src/vrend_renderer.c | 11 ++++++++++- src/vrend_shader.c | 22 +++++++++++++++++++++- src/vrend_shader.h | 4 +++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index c5ea3ac..e7e5e7d 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -347,6 +347,8 @@ struct vrend_linked_shader_program { GLint fs_stipple_loc; + GLint fs_alpha_ref_val_loc; + GLuint clip_locs[8]; 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"); else 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"); 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) { key->add_alpha_test = ctx->sub->dsa_state.alpha.enabled; 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; @@ -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); 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 diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 26f5fc5..eac9997 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -1724,7 +1724,7 @@ static void emit_alpha_test(struct dump_ctx *ctx) case PIPE_FUNC_GREATER: case PIPE_FUNC_NOTEQUAL: 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; default: 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->color_in_mask & 1) emit_hdr(ctx, "vec4 realcolor0;\n"); @@ -7060,3 +7064,19 @@ fail: free(ctx.temp_ranges); 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; + } +} diff --git a/src/vrend_shader.h b/src/vrend_shader.h index 4d5ccf0..d8939a6 100644 --- a/src/vrend_shader.h +++ b/src/vrend_shader.h @@ -117,7 +117,6 @@ struct vrend_shader_key { uint8_t prev_stage_num_clip_out; uint8_t prev_stage_num_cull_out; - float alpha_ref_val; uint32_t cbufs_are_a8_bitmask; uint8_t num_indirect_generic_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_strarray *shader, int vertices_per_patch); + +bool vrend_shader_needs_alpha_func(const struct vrend_shader_key *key); + #endif