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 <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24537>
This commit is contained in:
Iago Toral Quiroga 2023-08-07 10:48:45 +02:00 committed by Marge Bot
parent 374c660582
commit b2de3f71dc
2 changed files with 14 additions and 11 deletions

View file

@ -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

View file

@ -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 &&