From d61edf079b4d5008454d7da5b040418899824924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 21 Jul 2025 21:30:00 -0400 Subject: [PATCH] nir: add nir_move_only_convergent/divergent This will be needed by nir_opt_move_reorder_loads, which will use the move flags. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir.h | 4 ++++ src/compiler/nir/nir_opt_move.c | 3 +++ src/compiler/nir/nir_opt_sink.c | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 815a9bcecf0..08abbf8464e 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6219,6 +6219,10 @@ typedef enum { nir_move_load_uniform = BITFIELD_BIT(20), nir_move_load_buffer_amd = BITFIELD_BIT(21), nir_move_load_frag_coord = BITFIELD_BIT(22), + + /* The following options only impact load_global/ubo/ssbo/smem_amd. */ + nir_move_only_convergent = BITFIELD_BIT(30), + nir_move_only_divergent = BITFIELD_BIT(31), } nir_move_options; bool nir_can_move_instr(nir_instr *instr, nir_move_options options); diff --git a/src/compiler/nir/nir_opt_move.c b/src/compiler/nir/nir_opt_move.c index db984518668..35eab8d2fb9 100644 --- a/src/compiler/nir/nir_opt_move.c +++ b/src/compiler/nir/nir_opt_move.c @@ -138,6 +138,9 @@ nir_opt_move(nir_shader *shader, nir_move_options options) bool progress = false; nir_foreach_function_impl(impl, shader) { + if (options & (nir_move_only_convergent | nir_move_only_divergent)) + nir_metadata_require(impl, nir_metadata_divergence); + bool impl_progress = false; nir_foreach_block(block, impl) { if (nir_opt_move_block(block, options)) diff --git a/src/compiler/nir/nir_opt_sink.c b/src/compiler/nir/nir_opt_sink.c index e202a58f87e..d81b1967a31 100644 --- a/src/compiler/nir/nir_opt_sink.c +++ b/src/compiler/nir/nir_opt_sink.c @@ -147,6 +147,19 @@ can_sink_instr(nir_instr *instr, nir_move_options options, bool *can_mov_out_of_ if (!nir_intrinsic_can_reorder(intrin)) return false; + if (intrin->intrinsic == nir_intrinsic_load_global || + intrin->intrinsic == nir_intrinsic_load_ubo || + intrin->intrinsic == nir_intrinsic_load_ssbo || + intrin->intrinsic == nir_intrinsic_load_smem_amd) { + if (intrin->def.divergent) { + if (options & nir_move_only_convergent) + return false; + } else { + if (options & nir_move_only_divergent) + return false; + } + } + *can_mov_out_of_loop = false; switch (intrin->intrinsic) { @@ -345,7 +358,10 @@ nir_opt_sink(nir_shader *shader, nir_move_options options) nir_foreach_function_impl(impl, shader) { nir_metadata_require(impl, - nir_metadata_control_flow); + nir_metadata_control_flow | + (options & (nir_move_only_convergent | + nir_move_only_divergent) ? + nir_metadata_divergence : 0)); nir_foreach_block_reverse(block, impl) { nir_foreach_instr_reverse_safe(instr, block) {