pan/mdg: Use nir_shader_instructions_pass for fdot2 lowering

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6718>
This commit is contained in:
Icecream95 2020-09-05 17:00:37 +12:00 committed by Marge Bot
parent 7a348b43f2
commit 27516baa2a

View file

@ -174,11 +174,15 @@ glsl_type_size(const struct glsl_type *type, bool bindless)
}
/* Lower fdot2 to a vector multiplication followed by channel addition */
static void
midgard_nir_lower_fdot2_body(nir_builder *b, nir_alu_instr *alu)
static bool
midgard_nir_lower_fdot2_instr(nir_builder *b, nir_instr *instr, void *data)
{
if (instr->type != nir_instr_type_alu)
return false;
nir_alu_instr *alu = nir_instr_as_alu(instr);
if (alu->op != nir_op_fdot2)
return;
return false;
b->cursor = nir_before_instr(&alu->instr);
@ -193,36 +197,17 @@ midgard_nir_lower_fdot2_body(nir_builder *b, nir_alu_instr *alu)
/* Replace the fdot2 with this sum */
nir_ssa_def_rewrite_uses(&alu->dest.dest.ssa, nir_src_for_ssa(sum));
return true;
}
static bool
midgard_nir_lower_fdot2(nir_shader *shader)
{
bool progress = false;
nir_foreach_function(function, shader) {
if (!function->impl) continue;
nir_builder _b;
nir_builder *b = &_b;
nir_builder_init(b, function->impl);
nir_foreach_block(block, function->impl) {
nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_alu) continue;
nir_alu_instr *alu = nir_instr_as_alu(instr);
midgard_nir_lower_fdot2_body(b, alu);
progress |= true;
}
}
nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance);
}
return progress;
return nir_shader_instructions_pass(shader,
midgard_nir_lower_fdot2_instr,
nir_metadata_block_index | nir_metadata_dominance,
NULL);
}
static const nir_variable *