From b2de3f71dc516fb0e44d3d1ea4d4930649104e97 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Mon, 7 Aug 2023 10:48:45 +0200 Subject: [PATCH] nir/lower_tex: use a callback to check sampler return size packing The lower_tex_packing pass relies on the sampler index to access packing information, but this is only valid for tex instructions that have sampler state (so not txf, etc). Instead, let backends provide a callback to inform the lowering about the packing used with a given texture instruction which is more flexible. Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir.h | 8 ++++---- src/compiler/nir/nir_lower_tex.c | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 6ff047e25b0..1dd90bb264a 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5520,11 +5520,11 @@ typedef struct nir_lower_tex_options { bool lower_to_fragment_fetch_amd; /** - * To lower packed sampler return formats. - * - * Indexed by sampler-id. + * To lower packed sampler return formats. This will be called for all + * tex instructions. */ - enum nir_lower_tex_packing lower_tex_packing[32]; + enum nir_lower_tex_packing (*lower_tex_packing_cb)(const nir_tex_instr *tex, const void *data); + const void *lower_tex_packing_data; /** * If true, lower nir_texop_lod to return -FLT_MAX if the sum of the diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 7ad80ddf5e0..3ddd847086b 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -1090,7 +1090,7 @@ linearize_srgb_result(nir_builder *b, nir_tex_instr *tex) * to not store the other channels, given that nothing at the NIR level will * read them. */ -static void +static bool lower_tex_packing(nir_builder *b, nir_tex_instr *tex, const nir_lower_tex_options *options) { @@ -1098,9 +1098,13 @@ lower_tex_packing(nir_builder *b, nir_tex_instr *tex, b->cursor = nir_after_instr(&tex->instr); - switch (options->lower_tex_packing[tex->sampler_index]) { + assert(options->lower_tex_packing_cb); + enum nir_lower_tex_packing packing = + options->lower_tex_packing_cb(tex, options->lower_tex_packing_data); + + switch (packing) { case nir_lower_tex_packing_none: - return; + return false; case nir_lower_tex_packing_16: { static const unsigned bits[4] = {16, 16, 16, 16}; @@ -1156,6 +1160,7 @@ lower_tex_packing(nir_builder *b, nir_tex_instr *tex, nir_ssa_def_rewrite_uses_after(&tex->dest.ssa, color, color->parent_instr); + return true; } static bool @@ -1609,13 +1614,11 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, progress = true; } - if (options->lower_tex_packing[tex->sampler_index] != - nir_lower_tex_packing_none && + if (options->lower_tex_packing_cb && tex->op != nir_texop_txs && tex->op != nir_texop_query_levels && tex->op != nir_texop_texture_samples) { - lower_tex_packing(b, tex, options); - progress = true; + progress |= lower_tex_packing(b, tex, options); } if (tex->op == nir_texop_txd &&