From 8fa2cd2fee35b619dca0af1b2d5c2fc6407c6d53 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 3 Jun 2025 15:08:20 -0400 Subject: [PATCH] nir/lower_to_scalar: fix opt_varying with output reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no_varying cannot be used to eliminate stores on locations which may be subsequently read Fixes: 00589893579 ("nir/lower_io_to_scalar: don't create output stores that have no effect") Reviewed-by: Marek Olšák Part-of: (cherry picked from commit 208450fc57f6ddf0e3a2bd20e9fce8b6d8f77a19) --- .pick_status.json | 2 +- src/compiler/nir/nir_lower_io_to_scalar.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 6007895ad30..a8af3b6e459 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -6864,7 +6864,7 @@ "description": "nir/lower_to_scalar: fix opt_varying with output reads", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "00589893579a66e2cc00a86edae47dff9bf9a7f1", "notes": null diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c b/src/compiler/nir/nir_lower_io_to_scalar.c index 49b102028a7..f00d2b83900 100644 --- a/src/compiler/nir/nir_lower_io_to_scalar.c +++ b/src/compiler/nir/nir_lower_io_to_scalar.c @@ -159,9 +159,16 @@ lower_store_output_to_scalar(nir_builder *b, nir_intrinsic_instr *intr) * they are not a sysval output, they don't feed the next shader, and * they don't write xfb. Don't create such stores. */ - if ((sem.no_sysval_output || - !nir_slot_is_sysval_output(sem.location, MESA_SHADER_NONE)) && - (sem.no_varying || + bool tcs_read = b->shader->info.stage == MESA_SHADER_TESS_CTRL && + (sem.location >= VARYING_SLOT_VAR0_16BIT ? + b->shader->info.outputs_read_16bit & + BITFIELD_BIT(sem.location - VARYING_SLOT_VAR0_16BIT) : + sem.location >= VARYING_SLOT_PATCH0 ? + b->shader->info.patch_outputs_read & + BITFIELD_BIT(sem.location - VARYING_SLOT_PATCH0) : + b->shader->info.outputs_read & BITFIELD64_BIT(sem.location)); + if ((sem.no_sysval_output || !nir_slot_is_sysval_output(sem.location, MESA_SHADER_NONE)) && + ((sem.no_varying && !tcs_read) || !nir_slot_is_varying(sem.location, MESA_SHADER_NONE)) && !has_xfb) continue;