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 | |
parent | 6d7e02e37da5335d2be11ca1d4bfa002e73c5770 (diff) |
mesa/gallium: automatically lower alpha-testing
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/auxiliary/util/u_screen.c | 1 | ||||
-rw-r--r-- | src/gallium/docs/source/screen.rst | 1 | ||||
-rw-r--r-- | src/gallium/include/pipe/p_defines.h | 1 | ||||
-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 |
8 files changed, 27 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c index 3593e055590..ec43f9b7971 100644 --- a/src/gallium/auxiliary/util/u_screen.c +++ b/src/gallium/auxiliary/util/u_screen.c @@ -395,6 +395,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen, return 1; case PIPE_CAP_FLATSHADE: + case PIPE_CAP_ALPHA_TEST: return 1; default: diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst index 8bb83aff77c..a18f481f212 100644 --- a/src/gallium/docs/source/screen.rst +++ b/src/gallium/docs/source/screen.rst @@ -559,6 +559,7 @@ The integer capabilities: * ``PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION``: True if driver supports demote keyword in GLSL programs. * ``PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE``: True if driver wants the TG4 component encoded in sampler swizzle rather than as a separate source. * ``PIPE_CAP_FLATSHADE``: Driver supports pipe_rasterizer_state::flatshade. +* ``PIPE_CAP_ALPHA_TEST``: Driver supports alpha-testing. .. _pipe_capf: diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index a9c5a466194..8a0a86a8c42 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -905,6 +905,7 @@ enum pipe_cap PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION, PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE, PIPE_CAP_FLATSHADE, + PIPE_CAP_ALPHA_TEST, }; /** 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; }; |