From aea949dd299f193001eac00aa5e58ef57f46a78f Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 29 Sep 2025 14:30:37 +0200 Subject: [PATCH] tu: Make sure we clear dead writes to vars before nir_link_opt_varyings(). It assumes you don't have dead writes to variables in the last block, and will copy-propagate consts from the first write it finds. Without this, the upcoming nir_opt_copy_prop_vars() change to have more restricted write masks caused less nir_opt_dead_write_vars() (since it doesn't trim write masks for dead writes, only removes fully-dead writes), and then zero-initialization of variables at the top of a shader got propagated, rather than the final store of the used channels of the variable. Part-of: --- src/freedreno/vulkan/tu_shader.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/freedreno/vulkan/tu_shader.cc b/src/freedreno/vulkan/tu_shader.cc index 4ca6f11a231..7a4200a4ae9 100644 --- a/src/freedreno/vulkan/tu_shader.cc +++ b/src/freedreno/vulkan/tu_shader.cc @@ -2923,6 +2923,12 @@ lower_io_to_scalar_early(nir_shader *nir, nir_variable_mode mask) */ NIR_PASS(_, nir, nir_opt_copy_prop_vars); + /* This must be called before nir_link_opt_varyings() and after + * nir_opt_copy_prop_vars(), otherwise repeated (scalarized) stores in the + * last block will propagate the wrong values into the consumer. + */ + NIR_PASS(_, nir, nir_opt_dead_write_vars); + NIR_PASS(_, nir, nir_opt_dce); const nir_remove_dead_variables_options var_opts = {