nir/lower_to_scalar: fix opt_varying with output reads

no_varying cannot be used to eliminate stores on locations which may
be subsequently read

Fixes: 0058989357 ("nir/lower_io_to_scalar: don't create output stores that have no effect")

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35325>
(cherry picked from commit 208450fc57)
This commit is contained in:
Mike Blumenkrantz 2025-06-03 15:08:20 -04:00 committed by Eric Engestrom
parent aa060b69cb
commit 8fa2cd2fee
2 changed files with 11 additions and 4 deletions

View file

@ -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

View file

@ -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;