st/mesa: initialize lower alpha func to ALWAYS

The lower_alpha_func is initialized as COMPARE_FUNC_NEVER, and the
nir_lower_alpha_test() only executed if the alpha_func has changed.

This means when user runs an alpha test with GL_NEVER function the
lowering is never executed, and no fragment is discarded.

Rather, we would like to initialize the function as COMPARE_FUNC_ALWAYS,
and run the lowering when the alpha_func is different. If user runs the
alpha test with GL_ALWAYS, indeed the lowering is never executed; but
using GL_ALWAYS makes no fragment is discarded, so it is like not
executing the testing.

Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7251>
This commit is contained in:
Juan A. Suarez Romero
2020-10-21 11:45:08 +02:00
committed by Marge Bot
parent 33ccf0e9bc
commit 3d51c27de5
4 changed files with 6 additions and 2 deletions

View File

@@ -125,7 +125,7 @@ st_update_fp( struct st_context *st )
st->ctx->Light.ShadeModel == GL_FLAT;
/* _NEW_COLOR */
key.lower_alpha_func = COMPARE_FUNC_NEVER;
key.lower_alpha_func = COMPARE_FUNC_ALWAYS;
if (st->lower_alpha_test && _mesa_is_alpha_test_enabled(st->ctx))
key.lower_alpha_func = st->ctx->Color.AlphaFunc;

View File

@@ -179,6 +179,7 @@ setup_render_state(struct gl_context *ctx,
key.bitmap = GL_TRUE;
key.clamp_color = st->clamp_frag_color_in_shader &&
ctx->Color._ClampFragmentColor;
key.lower_alpha_func = COMPARE_FUNC_ALWAYS;
fpv = st_get_fp_variant(st, st->fp, &key);

View File

@@ -1148,6 +1148,7 @@ get_color_fp_variant(struct st_context *st)
key.pixelMaps = ctx->Pixel.MapColorFlag;
key.clamp_color = st->clamp_frag_color_in_shader &&
ctx->Color._ClampFragmentColor;
key.lower_alpha_func = COMPARE_FUNC_ALWAYS;
fpv = st_get_fp_variant(st, st->fp, &key);
@@ -1177,6 +1178,7 @@ get_color_index_fp_variant(struct st_context *st)
key.pixelMaps = 0;
key.clamp_color = st->clamp_frag_color_in_shader &&
ctx->Color._ClampFragmentColor;
key.lower_alpha_func = COMPARE_FUNC_ALWAYS;
fpv = st_get_fp_variant(st, st->fp, &key);

View File

@@ -1247,7 +1247,7 @@ st_create_fp_variant(struct st_context *st,
finalize = true;
}
if (key->lower_alpha_func != COMPARE_FUNC_NEVER) {
if (key->lower_alpha_func != COMPARE_FUNC_ALWAYS) {
_mesa_add_state_reference(params, alpha_ref_state);
NIR_PASS_V(state.ir.nir, nir_lower_alpha_test, key->lower_alpha_func,
false, alpha_ref_state);
@@ -1943,6 +1943,7 @@ st_precompile_shader_variant(struct st_context *st,
memset(&key, 0, sizeof(key));
key.st = st->has_shareable_shaders ? NULL : st;
key.lower_alpha_func = COMPARE_FUNC_ALWAYS;
st_get_fp_variant(st, p, &key);
break;
}