diff options
author | Erik Faye-Lund <[email protected]> | 2019-10-03 16:35:23 -0400 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2019-10-17 10:41:36 +0200 |
commit | b1c4c4c7f53cde52a8f3b3ec17cd66b89bf04199 (patch) | |
tree | 45eebd1e657b0ccdb45c1e34ba52c65762d9b99f /src/mesa/state_tracker | |
parent | 6d7e02e37da5335d2be11ca1d4bfa002e73c5770 (diff) |
mesa/gallium: automatically lower alpha-testing
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_atom_shader.c | 5 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_context.c | 10 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_context.h | 1 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.c | 8 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.h | 1 |
5 files changed, 24 insertions, 1 deletions
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index da269537866..f79c401e3e7 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -122,6 +122,11 @@ st_update_fp( struct st_context *st ) key.lower_flatshade = st->lower_flatshade && st->ctx->Light.ShadeModel == GL_FLAT; + /* _NEW_COLOR */ + key.lower_alpha_func = COMPARE_FUNC_NEVER; + if (st->lower_alpha_test && _mesa_is_alpha_test_enabled(st->ctx)) + key.lower_alpha_func = st->ctx->Color.AlphaFunc; + /* _NEW_FRAG_CLAMP */ key.clamp_color = st->clamp_frag_color_in_shader && st->ctx->Color._ClampFragmentColor; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 0441ebb27c8..8d4705bcc68 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -500,7 +500,12 @@ st_init_driver_flags(struct st_context *st) f->NewFramebufferSRGB = ST_NEW_FB_STATE; f->NewScissorRect = ST_NEW_SCISSOR; f->NewScissorTest = ST_NEW_SCISSOR | ST_NEW_RASTERIZER; - f->NewAlphaTest = ST_NEW_DSA; + + if (st->lower_alpha_test) + f->NewAlphaTest = ST_NEW_FS_STATE; + else + f->NewAlphaTest = ST_NEW_DSA; + f->NewBlend = ST_NEW_BLEND; f->NewBlendColor = ST_NEW_BLEND_COLOR; f->NewColorMask = ST_NEW_BLEND; @@ -670,6 +675,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, screen->get_param(screen, PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET); st->lower_flatshade = !screen->get_param(screen, PIPE_CAP_FLATSHADE); + st->lower_alpha_test = + !screen->get_param(screen, PIPE_CAP_ALPHA_TEST); st->has_hw_atomics = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, @@ -738,6 +745,7 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->shader_has_one_variant[MESA_SHADER_FRAGMENT] = st->has_shareable_shaders && !st->lower_flatshade && + !st->lower_alpha_test && !st->clamp_frag_color_in_shader && !st->clamp_frag_depth_in_shader && !st->force_persample_in_shader; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 851202f61f0..99f43828f44 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -148,6 +148,7 @@ struct st_context boolean can_bind_const_buffer_as_vertex; boolean has_signed_vertex_buffer_offset; boolean lower_flatshade; + boolean lower_alpha_test; /** * If a shader can be created when we get its source. diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 80487032063..f1d3f7b3ce7 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -1150,6 +1150,8 @@ st_create_fp_variant(struct st_context *st, { STATE_INTERNAL, STATE_PT_SCALE }; static const gl_state_index16 bias_state[STATE_LENGTH] = { STATE_INTERNAL, STATE_PT_BIAS }; + static const gl_state_index16 alpha_ref_state[STATE_LENGTH] = + { STATE_INTERNAL, STATE_ALPHA_REF }; if (!variant) return NULL; @@ -1164,6 +1166,12 @@ st_create_fp_variant(struct st_context *st, if (key->lower_flatshade) NIR_PASS_V(tgsi.ir.nir, nir_lower_flatshade); + if (key->lower_alpha_func != COMPARE_FUNC_NEVER) { + _mesa_add_state_reference(params, alpha_ref_state); + NIR_PASS_V(tgsi.ir.nir, nir_lower_alpha_test, key->lower_alpha_func, + false, alpha_ref_state); + } + if (key->persample_shading) { nir_shader *shader = tgsi.ir.nir; nir_foreach_variable(var, &shader->inputs) diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index bd20c0259c0..b84d219e3c8 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -132,6 +132,7 @@ struct st_fp_variant_key struct st_external_sampler_key external; GLuint lower_flatshade:1; + enum compare_func lower_alpha_func:3; }; |