Module: Mesa Branch: main Commit: fd1e27a8f885f5569500a76d517b84d0bd3ee78f URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd1e27a8f885f5569500a76d517b84d0bd3ee78f
Author: Timur Kristóf <[email protected]> Date: Sun Mar 26 23:49:23 2023 +0200 radv: Fix swizzled VS input loads when some components are unused. Fix how out-of-bounds loads are decided. It was incorrect because it mismatched the swizzle. The decision is now made using the loaded num_components. Fixes: 27c81319780d4a9693ef609b6a891981d1417b70 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8712 Signed-off-by: Timur Kristóf <[email protected]> Reviewed-by: Konstantin Seurer <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22124> --- src/amd/vulkan/radv_nir_lower_vs_inputs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/amd/vulkan/radv_nir_lower_vs_inputs.c b/src/amd/vulkan/radv_nir_lower_vs_inputs.c index c3efb7e05f4..3d00276c94d 100644 --- a/src/amd/vulkan/radv_nir_lower_vs_inputs.c +++ b/src/amd/vulkan/radv_nir_lower_vs_inputs.c @@ -374,14 +374,20 @@ lower_load_vs_input(nir_builder *b, nir_intrinsic_instr *intrin, lower_vs_inputs nir_ssa_def *channels[NIR_MAX_VEC_COMPONENTS] = {0}; for (unsigned i = 0; i < dest_num_components; ++i) { const unsigned c = i + component; + if (!(dest_use_mask & BITFIELD_BIT(c))) { /* Fill unused channels with zero. */ channels[i] = nir_imm_zero(b, 1, bit_size); - } else if (c < max_loaded_channels) { + continue; + } + + const unsigned sw = f->swizzle[c]; + assert(sw >= first_used_channel); + const unsigned loaded_channel = sw - first_used_channel; + + if (load && loaded_channel < load->num_components) { /* Use channels that were loaded from VRAM. */ - const unsigned sw = f->swizzle[c]; - assert(sw >= first_used_channel); - channels[i] = nir_channel(b, load, sw - first_used_channel); + channels[i] = nir_channel(b, load, loaded_channel); if (alpha_adjust != AC_ALPHA_ADJUST_NONE && c == 3) channels[i] = adjust_vertex_fetch_alpha(b, alpha_adjust, channels[i]);
