freedreno: Convert nir_lower_tg4_to_tex to the NIR lowering helper.

Cuts a bunch of boilerplate.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
This commit is contained in:
Eric Anholt 2019-07-16 11:19:28 -07:00
parent 56f4ede73d
commit 0d8a4c67cf
1 changed files with 50 additions and 87 deletions

View File

@ -29,24 +29,12 @@
* direct texture calls. * direct texture calls.
*/ */
static bool static nir_ssa_def *
lower_tg4(nir_block *block, nir_builder *b, void *mem_ctx) ir3_nir_lower_tg4_to_tex_instr(nir_builder *b, nir_instr *instr, void *data)
{ {
bool progress = false; nir_tex_instr *tg4 = nir_instr_as_tex(instr);
static const int offsets[3][2] = { {0, 1}, {1, 1}, {1, 0} }; static const int offsets[3][2] = { {0, 1}, {1, 1}, {1, 0} };
nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_tex)
continue;
nir_tex_instr *tg4 = (nir_tex_instr *)instr;
if (tg4->op != nir_texop_tg4)
continue;
b->cursor = nir_before_instr(&tg4->instr);
nir_ssa_def *results[4]; nir_ssa_def *results[4];
int offset_index = nir_tex_instr_src_index(tg4, nir_tex_src_offset); int offset_index = nir_tex_instr_src_index(tg4, nir_tex_src_offset);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -94,45 +82,20 @@ lower_tg4(nir_block *block, nir_builder *b, void *mem_ctx)
results[i] = nir_channel(b, &tex->dest.ssa, tg4->component); results[i] = nir_channel(b, &tex->dest.ssa, tg4->component);
} }
nir_ssa_def *result = nir_vec4(b, results[0], results[1], results[2], results[3]); return nir_vec(b, results, 4);
nir_ssa_def_rewrite_uses(&tg4->dest.ssa, nir_src_for_ssa(result));
nir_instr_remove(&tg4->instr);
progress = true;
}
return progress;
} }
static bool static bool
lower_tg4_func(nir_function_impl *impl) ir3_nir_lower_tg4_to_tex_filter(const nir_instr *instr, const void *data)
{ {
void *mem_ctx = ralloc_parent(impl); return (instr->type == nir_instr_type_tex &&
nir_builder b; nir_instr_as_tex(instr)->op == nir_texop_tg4);
nir_builder_init(&b, impl);
bool progress = false;
nir_foreach_block_safe(block, impl) {
progress |= lower_tg4(block, &b, mem_ctx);
}
if (progress)
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);
return progress;
} }
bool bool
ir3_nir_lower_tg4_to_tex(nir_shader *shader) ir3_nir_lower_tg4_to_tex(nir_shader *shader)
{ {
bool progress = false; return nir_shader_lower_instructions(shader,
ir3_nir_lower_tg4_to_tex_filter,
nir_foreach_function(function, shader) { ir3_nir_lower_tg4_to_tex_instr, NULL);
if (function->impl)
progress |= lower_tg4_func(function->impl);
}
return progress;
} }