From 348b8859dc178e5b7599073282c7789d72bfa6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Wed, 12 Jun 2024 14:00:01 +0200 Subject: [PATCH] ac/nir/tess: Only write tess factors that the TES reads. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we would write to a memory location reserved for another per-patch output. Fixes: 2cf7f282df720b9bf80e8bfa6ffae0d7b51a09f5 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11324 Signed-off-by: Timur Kristóf Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/common/ac_nir_lower_tess_io_to_mem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/amd/common/ac_nir_lower_tess_io_to_mem.c b/src/amd/common/ac_nir_lower_tess_io_to_mem.c index a016a0fce02..009f7140653 100644 --- a/src/amd/common/ac_nir_lower_tess_io_to_mem.c +++ b/src/amd/common/ac_nir_lower_tess_io_to_mem.c @@ -803,7 +803,13 @@ hs_store_tess_factors_for_tes(nir_builder *b, tess_levels tessfactors, lower_tes nir_def *offchip_offset = nir_load_ring_tess_offchip_offset_amd(b); nir_def *zero = nir_imm_int(b, 0); - if (st->tcs_tess_level_outer_mask) { + /* For linked shaders, we must only write the tess factors that the TES actually reads, + * otherwise we would write to a memory location reserved for another per-patch output. + */ + const bool tes_reads_outer = st->tes_inputs_read & VARYING_BIT_TESS_LEVEL_OUTER; + const bool tes_reads_inner = st->tes_inputs_read & VARYING_BIT_TESS_LEVEL_INNER; + + if (st->tcs_tess_level_outer_mask && tes_reads_outer) { const unsigned tf_outer_loc = hs_output_vram_map_io_location(b->shader, false, VARYING_SLOT_TESS_LEVEL_OUTER, st); nir_def *vmem_off_outer = hs_per_patch_output_vmem_offset(b, st, NULL, tf_outer_loc * 16); @@ -813,7 +819,7 @@ hs_store_tess_factors_for_tes(nir_builder *b, tess_levels tessfactors, lower_tes .access = ACCESS_COHERENT); } - if (tessfactors.inner && st->tcs_tess_level_inner_mask) { + if (tessfactors.inner && st->tcs_tess_level_inner_mask && tes_reads_inner) { const unsigned tf_inner_loc = hs_output_vram_map_io_location(b->shader, false, VARYING_SLOT_TESS_LEVEL_INNER, st); nir_def *vmem_off_inner = hs_per_patch_output_vmem_offset(b, st, NULL, tf_inner_loc * 16);