Module: Mesa Branch: main Commit: fca457790e1423e28ba5596411332267e7cb706a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fca457790e1423e28ba5596411332267e7cb706a
Author: Alyssa Rosenzweig <[email protected]> Date: Sat Nov 12 13:50:07 2022 -0500 nir/lower_blend: Fix alpha=1 for RGBX format In this case we have 4 components but the value of the fourth component is undefined. Apply the fixup we already have. Fixes dEQP-GLES3.functional.draw_buffers_indexed.random.max_implementation_draw_buffers.0 on Asahi. That test blend with DST_ALPHA with its RGB565 attachment, which is fine if RGB565 is preserved, but Asahi is demoting that format to RGBX8 which means -- after lowering the tilebuffer access -- we blend with an ssa_undef. Signed-off-by: Alyssa Rosenzweig <[email protected]> Reviewed-by: Gert Wollny <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20016> --- src/compiler/nir/nir_lower_blend.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/compiler/nir/nir_lower_blend.c b/src/compiler/nir/nir_lower_blend.c index 727d5d26347..02ab040e51a 100644 --- a/src/compiler/nir/nir_lower_blend.c +++ b/src/compiler/nir/nir_lower_blend.c @@ -262,6 +262,13 @@ nir_blend_logicop( return out; } +static bool +channel_exists(const struct util_format_description *desc, unsigned i) +{ + return (i < desc->nr_channels) && + desc->channel[i].type != UTIL_FORMAT_TYPE_VOID; +} + static nir_ssa_def * nir_fsat_signed(nir_builder *b, nir_ssa_def *x) { @@ -315,15 +322,14 @@ nir_blend( const struct util_format_description *desc = util_format_description(format); - if (desc->nr_channels < 4) { - nir_ssa_def *zero = nir_imm_floatN_t(b, 0.0, dst->bit_size); - nir_ssa_def *one = nir_imm_floatN_t(b, 1.0, dst->bit_size); + nir_ssa_def *zero = nir_imm_floatN_t(b, 0.0, dst->bit_size); + nir_ssa_def *one = nir_imm_floatN_t(b, 1.0, dst->bit_size); - dst = nir_vec4(b, nir_channel(b, dst, 0), - desc->nr_channels > 1 ? nir_channel(b, dst, 1) : zero, - desc->nr_channels > 2 ? nir_channel(b, dst, 2) : zero, - desc->nr_channels > 3 ? nir_channel(b, dst, 3) : one); - } + dst = nir_vec4(b, + channel_exists(desc, 0) ? nir_channel(b, dst, 0) : zero, + channel_exists(desc, 1) ? nir_channel(b, dst, 1) : zero, + channel_exists(desc, 2) ? nir_channel(b, dst, 2) : zero, + channel_exists(desc, 3) ? nir_channel(b, dst, 3) : one); /* We blend per channel and recombine later */ nir_ssa_def *channels[4];
