nir/lower_tex: Add support for tg4 offsets lowering

Signed-off-by: Karol Herbst <kherbst@redhat.com>
This commit is contained in:
Karol Herbst
2019-03-19 18:47:20 +01:00
committed by Karol Herbst
parent 99f202432b
commit d8a0658d8b
2 changed files with 62 additions and 0 deletions

View File

@@ -3236,6 +3236,11 @@ typedef struct nir_lower_tex_options {
*/
bool lower_tg4_broadcom_swizzle;
/**
* If true, lowers tg4 with 4 constant offsets to 4 tg4 calls
*/
bool lower_tg4_offsets;
enum nir_lower_tex_packing lower_tex_packing[32];
} nir_lower_tex_options;

View File

@@ -924,6 +924,53 @@ sampler_index_lt(nir_tex_instr *tex, unsigned max)
return sampler_index < max;
}
static bool
lower_tg4_offsets(nir_builder *b, nir_tex_instr *tex)
{
assert(tex->op == nir_texop_tg4);
assert(nir_tex_instr_has_explicit_tg4_offsets(tex));
assert(nir_tex_instr_src_index(tex, nir_tex_src_offset) == -1);
b->cursor = nir_after_instr(&tex->instr);
nir_ssa_def *dest[4];
for (unsigned i = 0; i < 4; ++i) {
nir_tex_instr *tex_copy = nir_tex_instr_create(b->shader, tex->num_srcs + 1);
tex_copy->op = tex->op;
tex_copy->coord_components = tex->coord_components;
tex_copy->sampler_dim = tex->sampler_dim;
tex_copy->is_array = tex->is_array;
tex_copy->is_shadow = tex->is_shadow;
tex_copy->is_new_style_shadow = tex->is_new_style_shadow;
tex_copy->component = tex->component;
tex_copy->dest_type = tex->dest_type;
for (unsigned j = 0; j < tex->num_srcs; ++j) {
nir_src_copy(&tex_copy->src[j].src, &tex->src[j].src, tex_copy);
tex_copy->src[j].src_type = tex->src[j].src_type;
}
nir_tex_src src;
src.src = nir_src_for_ssa(nir_imm_ivec2(b, tex->tg4_offsets[i][0],
tex->tg4_offsets[i][1]));
src.src_type = nir_tex_src_offset;
tex_copy->src[tex_copy->num_srcs - 1] = src;
nir_ssa_dest_init(&tex_copy->instr, &tex_copy->dest,
nir_tex_instr_dest_size(tex), 32, NULL);
nir_builder_instr_insert(b, &tex_copy->instr);
dest[i] = nir_channel(b, &tex_copy->dest.ssa, 3);
}
nir_ssa_def *res = nir_vec4(b, dest[0], dest[1], dest[2], dest[3]);
nir_ssa_def_rewrite_uses(&tex->dest.ssa, nir_src_for_ssa(res));
nir_instr_remove(&tex->instr);
return true;
}
static bool
nir_lower_tex_block(nir_block *block, nir_builder *b,
const nir_lower_tex_options *options)
@@ -1069,6 +1116,16 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
progress = true;
continue;
}
/* has to happen after all the other lowerings as the original tg4 gets
* replaced by 4 tg4 instructions.
*/
if (tex->op == nir_texop_tg4 &&
nir_tex_instr_has_explicit_tg4_offsets(tex) &&
options->lower_tg4_offsets) {
progress |= lower_tg4_offsets(b, tex);
continue;
}
}
return progress;