From 493f7b80847ff78bdcbeddd0ab6b5fd70e7bda3d Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Fri, 29 Nov 2024 17:09:16 +0100 Subject: [PATCH] nir/lower_subgroups: add extra filter data to options It might be convenient for filter implementations to have access to extra information. This will be used, for example, by ir3 to access compiler features. Signed-off-by: Job Noorman Reviewed-by: Connor Abbott Part-of: --- src/compiler/nir/nir.h | 5 ++++- src/compiler/nir/nir_lower_subgroups.c | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 2d2ff03ed72..c238de29945 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6144,10 +6144,13 @@ bool nir_lower_atomics(nir_shader *shader, nir_instr_filter_cb filter); typedef struct nir_lower_subgroups_options { /* In addition to the boolean lowering options below, this optional callback * will filter instructions for lowering if non-NULL. The data passed will be - * this options struct itself. + * filter_data. */ nir_instr_filter_cb filter; + /* Extra data passed to the filter. */ + const void *filter_data; + /* In case the exact subgroup size is not known, subgroup_size should be * set to 0. In that case, the maximum subgroup size will be calculated by * ballot_components * ballot_bit_size. diff --git a/src/compiler/nir/nir_lower_subgroups.c b/src/compiler/nir/nir_lower_subgroups.c index 896cf11da36..718d018c704 100644 --- a/src/compiler/nir/nir_lower_subgroups.c +++ b/src/compiler/nir/nir_lower_subgroups.c @@ -893,6 +893,12 @@ lower_scan_reduce(nir_builder *b, nir_intrinsic_instr *intrin, static bool lower_subgroups_filter(const nir_instr *instr, const void *_options) { + const nir_lower_subgroups_options *options = _options; + + if (options->filter) { + return options->filter(instr, options->filter_data); + } + return instr->type == nir_instr_type_intrinsic; } @@ -1343,8 +1349,7 @@ bool nir_lower_subgroups(nir_shader *shader, const nir_lower_subgroups_options *options) { - void *filter = options->filter ? options->filter : lower_subgroups_filter; - return nir_shader_lower_instructions(shader, filter, + return nir_shader_lower_instructions(shader, lower_subgroups_filter, lower_subgroups_instr, (void *)options); }