nir: don't remove dead IO variables in nir_lower_io_passes for st_link_nir
authorMarek Olšák <marek.olsak@amd.com>
Wed, 1 Mar 2023 04:12:58 +0000 (23:12 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 19 Apr 2023 21:42:11 +0000 (21:42 +0000)
We need to keep variables in the IR because a few places use them,
like nir_build_program_resource_list. This will allow us to lower IO
in the linker.

Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21861>

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 ab29036..eff8d15 100644 (file)
@@ -3183,8 +3183,7 @@ nir_lower_io_passes(nir_shader *nir)
    /* Lower and remove dead derefs and variables to clean up the IR. */
    NIR_PASS_V(nir, nir_lower_vars_to_ssa);
    NIR_PASS_V(nir, nir_opt_dce);
-   NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp |
-              nir_var_shader_in | nir_var_shader_out, NULL);
+   NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp, NULL);
 
    if (nir->xfb_info)
       NIR_PASS_V(nir, nir_io_add_intrinsic_xfb_info);
index e5424c4..62f3a2d 100644 (file)
@@ -413,6 +413,7 @@ char *si_finalize_nir(struct pipe_screen *screen, void *nirptr)
    struct nir_shader *nir = (struct nir_shader *)nirptr;
 
    nir_lower_io_passes(nir);
+   NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_in | nir_var_shader_out, NULL);
 
    NIR_PASS_V(nir, ac_nir_lower_subdword_loads,
               (ac_nir_lower_subdword_options) {
index 02d588b..ed2ef5c 100644 (file)
@@ -1076,8 +1076,11 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
    /* Lower load_deref/store_deref of inputs and outputs.
     * This depends on st_nir_assign_varying_locations.
     */
-   if (nir->options->lower_io_variables)
+   if (nir->options->lower_io_variables) {
       nir_lower_io_passes(nir);
+      NIR_PASS_V(nir, nir_remove_dead_variables,
+                 nir_var_shader_in | nir_var_shader_out, NULL);
+   }
 
    /* Set num_uniforms in number of attribute slots (vec4s) */
    nir->num_uniforms = DIV_ROUND_UP(prog->Parameters->NumParameterValues, 4);