nir/lower_tex: Add a lower_txs_cube_array option

Several bits of hardware require the division by 6 to happen in the
shader.  May as well have common lowering for it.

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12005>
This commit is contained in:
Jason Ekstrand 2021-07-21 16:39:15 -05:00
parent c6102dda0a
commit 60b5faf572
2 changed files with 32 additions and 0 deletions

View file

@ -4913,6 +4913,12 @@ typedef struct nir_lower_tex_options {
*/
bool lower_txs_lod;
/**
* If true, lower nir_texop_txs for cube arrays to a nir_texop_txs with a
* 2D array type followed by a nir_idiv by 6.
*/
bool lower_txs_cube_array;
/**
* If true, apply a .bagr swizzle on tg4 results to handle Broadcom's
* mixed-up tg4 locations.

View file

@ -1155,6 +1155,25 @@ nir_lower_txs_lod(nir_builder *b, nir_tex_instr *tex)
return true;
}
static void
nir_lower_txs_cube_array(nir_builder *b, nir_tex_instr *tex)
{
assert(tex->sampler_dim == GLSL_SAMPLER_DIM_CUBE && tex->is_array);
tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
b->cursor = nir_after_instr(&tex->instr);
assert(tex->dest.is_ssa);
assert(tex->dest.ssa.num_components == 3);
nir_ssa_def *size = &tex->dest.ssa;
size = nir_vec3(b, nir_channel(b, size, 0),
nir_channel(b, size, 1),
nir_idiv(b, nir_channel(b, size, 2),
nir_imm_int(b, 6)));
nir_ssa_def_rewrite_uses_after(&tex->dest.ssa, size, size->parent_instr);
}
static bool
nir_lower_tex_block(nir_block *block, nir_builder *b,
const nir_lower_tex_options *options,
@ -1346,6 +1365,13 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
continue;
}
if (options->lower_txs_cube_array && tex->op == nir_texop_txs &&
tex->sampler_dim == GLSL_SAMPLER_DIM_CUBE && tex->is_array) {
nir_lower_txs_cube_array(b, tex);
progress = true;
continue;
}
/* has to happen after all the other lowerings as the original tg4 gets
* replaced by 4 tg4 instructions.
*/