Module: Mesa Branch: main Commit: 16664b74a2cc18c8e5cbed0ce9b0e39d803f2ace URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=16664b74a2cc18c8e5cbed0ce9b0e39d803f2ace
Author: Faith Ekstrand <[email protected]> Date: Mon Oct 23 10:33:14 2023 -0500 nir: Add a lower_read_first_invocation option to lower_subgroups Reviewed-by: Daniel Schürmann <[email protected]> Reviewed-by: Timur Kristóf <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25894> --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_lower_subgroups.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 7d2f80ce491..4839ef0b0ba 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5528,6 +5528,7 @@ typedef struct nir_lower_subgroups_options { bool lower_vote_trivial : 1; bool lower_vote_eq : 1; bool lower_first_invocation_to_ballot : 1; + bool lower_read_first_invocation : 1; bool lower_subgroup_masks : 1; bool lower_relative_shuffle : 1; bool lower_shuffle_to_32bit : 1; diff --git a/src/compiler/nir/nir_lower_subgroups.c b/src/compiler/nir/nir_lower_subgroups.c index a7577bb5d84..8c53d7fb6b8 100644 --- a/src/compiler/nir/nir_lower_subgroups.c +++ b/src/compiler/nir/nir_lower_subgroups.c @@ -556,6 +556,12 @@ lower_first_invocation_to_ballot(nir_builder *b, nir_intrinsic_instr *intrin, return nir_ballot_find_lsb(b, 32, nir_ballot(b, 4, 32, nir_imm_true(b))); } +static nir_def * +lower_read_first_invocation(nir_builder *b, nir_intrinsic_instr *intrin) +{ + return nir_read_invocation(b, intrin->src[0].ssa, nir_first_invocation(b)); +} + static nir_def * lower_read_invocation_to_cond(nir_builder *b, nir_intrinsic_instr *intrin) { @@ -616,6 +622,9 @@ lower_subgroups_instr(nir_builder *b, nir_instr *instr, void *_options) case nir_intrinsic_read_first_invocation: if (options->lower_to_scalar && intrin->num_components > 1) return lower_subgroup_op_to_scalar(b, intrin); + + if (options->lower_read_first_invocation) + return lower_read_first_invocation(b, intrin); break; case nir_intrinsic_load_subgroup_eq_mask:
