From 3affe3cb178b68eaf77ee780431e424395e70998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 15 Nov 2024 15:26:42 -0500 Subject: [PATCH] vc4/lower_blend: don't read non-existent channels nir_lower_texcoord_replace_late had swapped parameters in nir_undef. Reviewed-by: Alyssa Rosenzweig Reviewed-by: Emma Anholt Part-of: --- src/compiler/nir/nir_builder.h | 9 +++++++++ src/compiler/nir/nir_lower_texcoord_replace_late.c | 9 --------- src/gallium/drivers/asahi/agx_state.c | 9 --------- src/gallium/drivers/vc4/vc4_nir_lower_blend.c | 2 +- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 9d7071e2cf5..dc79d5e780d 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -767,6 +767,15 @@ nir_channel(nir_builder *b, nir_def *def, unsigned c) return nir_swizzle(b, def, &c, 1); } +static inline nir_def * +nir_channel_or_undef(nir_builder *b, nir_def *def, signed int channel) +{ + if (channel >= 0 && channel < def->num_components) + return nir_channel(b, def, channel); + else + return nir_undef(b, 1, def->bit_size); +} + static inline nir_def * nir_channels(nir_builder *b, nir_def *def, nir_component_mask_t mask) { diff --git a/src/compiler/nir/nir_lower_texcoord_replace_late.c b/src/compiler/nir/nir_lower_texcoord_replace_late.c index 22c13c6c0ba..d47ac10cfad 100644 --- a/src/compiler/nir/nir_lower_texcoord_replace_late.c +++ b/src/compiler/nir/nir_lower_texcoord_replace_late.c @@ -13,15 +13,6 @@ struct opts { bool point_coord_is_sysval; }; -static nir_def * -nir_channel_or_undef(nir_builder *b, nir_def *def, signed int channel) -{ - if (channel >= 0 && channel < def->num_components) - return nir_channel(b, def, channel); - else - return nir_undef(b, def->bit_size, 1); -} - static bool pass(nir_builder *b, nir_instr *instr, void *data) { diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 2e0c9cff2a2..56fd2377493 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1473,15 +1473,6 @@ agx_nir_lower_clip_m1_1(nir_builder *b, nir_intrinsic_instr *intr, return true; } -static nir_def * -nir_channel_or_undef(nir_builder *b, nir_def *def, signed int channel) -{ - if (channel >= 0 && channel < def->num_components) - return nir_channel(b, def, channel); - else - return nir_undef(b, 1, def->bit_size); -} - /* * To implement point sprites, we'll replace TEX0...7 with point coordinate * reads as required. However, the .zw needs to read back 0.0/1.0. This pass diff --git a/src/gallium/drivers/vc4/vc4_nir_lower_blend.c b/src/gallium/drivers/vc4/vc4_nir_lower_blend.c index 7f6454d424d..7df2247d531 100644 --- a/src/gallium/drivers/vc4/vc4_nir_lower_blend.c +++ b/src/gallium/drivers/vc4/vc4_nir_lower_blend.c @@ -443,7 +443,7 @@ vc4_nir_blend_pipeline(struct vc4_compile *c, nir_builder *b, nir_def *src, nir_def *dst_vec4 = nir_unpack_unorm_4x8(b, packed_dst_color); nir_def *src_color[4], *unpacked_dst_color[4]; for (unsigned i = 0; i < 4; i++) { - src_color[i] = nir_channel(b, src, i); + src_color[i] = nir_channel_or_undef(b, src, i); unpacked_dst_color[i] = nir_channel(b, dst_vec4, i); }