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:
parent
56f4ede73d
commit
0d8a4c67cf
|
@ -29,24 +29,12 @@
|
|||
* direct texture calls.
|
||||
*/
|
||||
|
||||
static bool
|
||||
lower_tg4(nir_block *block, nir_builder *b, void *mem_ctx)
|
||||
static nir_ssa_def *
|
||||
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} };
|
||||
|
||||
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];
|
||||
int offset_index = nir_tex_instr_src_index(tg4, nir_tex_src_offset);
|
||||
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);
|
||||
}
|
||||
|
||||
nir_ssa_def *result = nir_vec4(b, results[0], results[1], results[2], results[3]);
|
||||
nir_ssa_def_rewrite_uses(&tg4->dest.ssa, nir_src_for_ssa(result));
|
||||
|
||||
nir_instr_remove(&tg4->instr);
|
||||
|
||||
progress = true;
|
||||
}
|
||||
|
||||
return progress;
|
||||
return nir_vec(b, results, 4);
|
||||
}
|
||||
|
||||
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);
|
||||
nir_builder b;
|
||||
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;
|
||||
return (instr->type == nir_instr_type_tex &&
|
||||
nir_instr_as_tex(instr)->op == nir_texop_tg4);
|
||||
}
|
||||
|
||||
bool
|
||||
ir3_nir_lower_tg4_to_tex(nir_shader *shader)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_function(function, shader) {
|
||||
if (function->impl)
|
||||
progress |= lower_tg4_func(function->impl);
|
||||
}
|
||||
|
||||
return progress;
|
||||
return nir_shader_lower_instructions(shader,
|
||||
ir3_nir_lower_tg4_to_tex_filter,
|
||||
ir3_nir_lower_tg4_to_tex_instr, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue