nir/lower_io: don't renumber VS inputs when not called from a linker
authorMarek Olšák <marek.olsak@amd.com>
Thu, 4 May 2023 19:45:49 +0000 (15:45 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 18 May 2023 07:03:47 +0000 (07:03 +0000)
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 <tarceri@yahoo.com.au>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22859>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_io.c
src/gallium/drivers/radeonsi/si_shader_nir.c
src/mesa/state_tracker/st_glsl_to_nir.cpp

index 8e0c73b..208759d 100644 (file)
@@ -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
index a3a94a4..8a324e0 100644 (file)
@@ -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);
index 7ffd9ef..3d78642 100644 (file)
@@ -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)
index a07ac24..bec2d85 100644 (file)
@@ -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);
    }