From: Karol Herbst Date: Tue, 19 Mar 2019 17:47:20 +0000 (+0100) Subject: nir/lower_tex: Add support for tg4 offsets lowering X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d8a0658d8ba80d56c5c7f487b24f0ecaa85c1e34;p=mesa.git nir/lower_tex: Add support for tg4 offsets lowering Signed-off-by: Karol Herbst --- diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 2c1caf2687a..1da9874060b 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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; diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 903b975d6c3..05d5a40f72c 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -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;