mesa/st, nir: commonize unlower_io_to_vars pass

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37540>
This commit is contained in:
Simon Perretta 2025-09-23 14:51:35 +01:00
parent 4531b8ace4
commit 83aecc8f3f
7 changed files with 23 additions and 14 deletions

View file

@ -332,6 +332,7 @@ else
'nir_to_lcssa.c', 'nir_to_lcssa.c',
'nir_tcs_info.h', 'nir_tcs_info.h',
'nir_trivialize_registers.c', 'nir_trivialize_registers.c',
'nir_unlower_io_to_vars.c',
'nir_use_dominance.c', 'nir_use_dominance.c',
'nir_validate.c', 'nir_validate.c',
'nir_vla.h', 'nir_vla.h',

View file

@ -6771,6 +6771,8 @@ void nir_gather_output_clipper_var_groups(nir_shader *nir,
bool nir_lower_cooperative_matrix_flexible_dimensions(nir_shader *shader, unsigned m_gran, unsigned n_gran, unsigned k_gran); bool nir_lower_cooperative_matrix_flexible_dimensions(nir_shader *shader, unsigned m_gran, unsigned n_gran, unsigned k_gran);
bool nir_unlower_io_to_vars(nir_shader *nir, bool keep_intrinsics);
#include "nir_inline_helpers.h" #include "nir_inline_helpers.h"
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -3,7 +3,6 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "st_nir.h"
#include "nir_builder.h" #include "nir_builder.h"
struct io_desc { struct io_desc {
@ -676,8 +675,11 @@ unlower_io_to_vars(nir_builder *b, nir_intrinsic_instr *intr, void *opaque)
return true; return true;
} }
/* If keep_intrinsics is set, the pass will skip unlowering lowered I/O
* intrinsics to derefs, and only (re)create I/O variables from them.
*/
bool bool
st_nir_unlower_io_to_vars(nir_shader *nir) nir_unlower_io_to_vars(nir_shader *nir, bool keep_intrinsics)
{ {
if (nir->info.stage == MESA_SHADER_COMPUTE) if (nir->info.stage == MESA_SHADER_COMPUTE)
return false; return false;
@ -691,7 +693,12 @@ st_nir_unlower_io_to_vars(nir_shader *nir)
assert(!(nir->options->io_options & assert(!(nir->options->io_options &
nir_io_mix_convergent_flat_with_interpolated)); nir_io_mix_convergent_flat_with_interpolated));
nir_foreach_variable_with_modes(var, nir, nir_var_shader_in | nir_var_shader_out) { nir_foreach_variable_with_modes_safe(var, nir, nir_var_shader_in | nir_var_shader_out) {
if (keep_intrinsics) {
exec_node_remove(&var->node);
continue;
}
UNREACHABLE("the shader should have no IO variables"); UNREACHABLE("the shader should have no IO variables");
} }
@ -719,11 +726,13 @@ st_nir_unlower_io_to_vars(nir_shader *nir)
} }
/* Unlower IO using the created variables. */ /* Unlower IO using the created variables. */
ASSERTED bool lower_progress = if (!keep_intrinsics) {
nir_shader_intrinsics_pass(nir, unlower_io_to_vars, ASSERTED bool lower_progress =
nir_metadata_control_flow, NULL); nir_shader_intrinsics_pass(nir, unlower_io_to_vars,
assert(lower_progress); nir_metadata_control_flow, NULL);
nir->info.io_lowered = false; assert(lower_progress);
nir->info.io_lowered = false;
}
/* Count IO variables. */ /* Count IO variables. */
nir->num_inputs = 0; nir->num_inputs = 0;

View file

@ -350,7 +350,6 @@ files_libmesa = files(
'state_tracker/st_nir_lower_point_size_mov.c', 'state_tracker/st_nir_lower_point_size_mov.c',
'state_tracker/st_nir_lower_position_invariant.c', 'state_tracker/st_nir_lower_position_invariant.c',
'state_tracker/st_nir_lower_tex_src_plane.c', 'state_tracker/st_nir_lower_tex_src_plane.c',
'state_tracker/st_nir_unlower_io_to_vars.c',
'state_tracker/st_pbo.c', 'state_tracker/st_pbo.c',
'state_tracker/st_pbo_compute.c', 'state_tracker/st_pbo_compute.c',
'state_tracker/st_pbo.h', 'state_tracker/st_pbo.h',

View file

@ -111,8 +111,6 @@ bool st_nir_lower_position_invariant(struct nir_shader *s,
struct gl_program_parameter_list *paramList, struct gl_program_parameter_list *paramList,
bool packed_driver_uniform_storage); bool packed_driver_uniform_storage);
bool st_nir_unlower_io_to_vars(struct nir_shader *nir);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -64,7 +64,7 @@ st_nir_finish_builtin_nir(struct st_context *st, nir_shader *nir)
if (nir->info.io_lowered && if (nir->info.io_lowered &&
!(nir->options->io_options & nir_io_has_intrinsics)) { !(nir->options->io_options & nir_io_has_intrinsics)) {
NIR_PASS(_, nir, st_nir_unlower_io_to_vars); NIR_PASS(_, nir, nir_unlower_io_to_vars, false);
gl_nir_opts(nir); gl_nir_opts(nir);
} }

View file

@ -873,7 +873,7 @@ st_create_common_variant(struct st_context *st,
* are still counted as enabled IO, which breaks things. * are still counted as enabled IO, which breaks things.
*/ */
NIR_PASS(_, state.ir.nir, nir_opt_dce); NIR_PASS(_, state.ir.nir, nir_opt_dce);
NIR_PASS(_, state.ir.nir, st_nir_unlower_io_to_vars); NIR_PASS(_, state.ir.nir, nir_unlower_io_to_vars, false);
if (state.ir.nir->info.stage == MESA_SHADER_TESS_CTRL && if (state.ir.nir->info.stage == MESA_SHADER_TESS_CTRL &&
state.ir.nir->options->compact_arrays && state.ir.nir->options->compact_arrays &&
@ -1256,7 +1256,7 @@ st_create_fp_variant(struct st_context *st,
* are still counted as enabled IO, which breaks things. * are still counted as enabled IO, which breaks things.
*/ */
NIR_PASS(_, state.ir.nir, nir_opt_dce); NIR_PASS(_, state.ir.nir, nir_opt_dce);
NIR_PASS(_, state.ir.nir, st_nir_unlower_io_to_vars); NIR_PASS(_, state.ir.nir, nir_unlower_io_to_vars, false);
gl_nir_opts(state.ir.nir); gl_nir_opts(state.ir.nir);
finalize = true; finalize = true;
} }