From 177af4557738b03faa6ea62b1f2925256800adad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 4 May 2023 15:45:49 -0400 Subject: [PATCH] nir/lower_io: don't renumber VS inputs when not called from a linker This fixes a Nine regression. The comment explains it. The new varying linking code will set true here. Fixes: d29dd333 - nir: assign IO bases in nir_lower_io_passes Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8935 Reviewed-by: Timothy Arceri Part-of: --- src/compiler/nir/nir.h | 2 +- src/compiler/nir/nir_lower_io.c | 13 +++++++++++-- src/gallium/drivers/radeonsi/si_shader_nir.c | 2 +- src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 8e0c73b3459..208759d80de 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4904,7 +4904,7 @@ bool nir_lower_io(nir_shader *shader, bool nir_io_add_const_offset_to_base(nir_shader *nir, nir_variable_mode modes); bool nir_lower_color_inputs(nir_shader *nir); -void nir_lower_io_passes(nir_shader *nir); +void nir_lower_io_passes(nir_shader *nir, bool renumber_vs_inputs); bool nir_io_add_intrinsic_xfb_info(nir_shader *nir); bool diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index a3a94a4a733..8a324e02305 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -3045,9 +3045,16 @@ type_size_vec4(const struct glsl_type *type, bool bindless) /** * This runs all compiler passes needed to lower IO, lower indirect IO access, * set transform feedback info in IO intrinsics, and clean up the IR. + * + * \param renumber_vs_inputs + * Set to true if holes between VS inputs should be removed, which is safe + * to do in any shader linker that can handle that. Set to false if you want + * to keep holes between VS inputs, which is recommended to do in gallium + * drivers so as not to break the mapping of vertex elements to VS inputs + * expected by gallium frontends. */ void -nir_lower_io_passes(nir_shader *nir) +nir_lower_io_passes(nir_shader *nir, bool renumber_vs_inputs) { if (!nir->options->lower_io_variables || nir->info.stage == MESA_SHADER_COMPUTE) @@ -3089,7 +3096,9 @@ nir_lower_io_passes(nir_shader *nir) * This kind of canonicalizes all bases. */ NIR_PASS_V(nir, nir_recompute_io_bases, - nir_var_shader_in | nir_var_shader_out); + (nir->info.stage != MESA_SHADER_VERTEX || + renumber_vs_inputs ? nir_var_shader_in : 0) | + nir_var_shader_out); /* nir_io_add_const_offset_to_base needs actual constants. */ NIR_PASS_V(nir, nir_opt_constant_folding); diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c index 7ffd9ef57e3..3d78642848f 100644 --- a/src/gallium/drivers/radeonsi/si_shader_nir.c +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c @@ -437,7 +437,7 @@ char *si_finalize_nir(struct pipe_screen *screen, void *nirptr) struct si_screen *sscreen = (struct si_screen *)screen; struct nir_shader *nir = (struct nir_shader *)nirptr; - nir_lower_io_passes(nir); + nir_lower_io_passes(nir, false); NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_in | nir_var_shader_out, NULL); if (nir->info.stage == MESA_SHADER_FRAGMENT) diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index a07ac24b4d1..bec2d850142 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -1081,7 +1081,7 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, * This depends on st_nir_assign_varying_locations. */ if (nir->options->lower_io_variables) { - nir_lower_io_passes(nir); + nir_lower_io_passes(nir, false); NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_in | nir_var_shader_out, NULL); }