nir: use nir_shader_instructions_pass in nir_lower_bool_to_float

Changes:
- nir_metadata_preserve(..., nir_metadata_all) is called when pass doesn't
  make progress

Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12282>
This commit is contained in:
Marcin Ślusarz
2021-08-09 13:50:53 +02:00
committed by Marge Bot
parent 4a9e2dc1e9
commit d28833d60f

View File

@@ -140,19 +140,13 @@ lower_tex_instr(nir_tex_instr *tex)
} }
static bool static bool
nir_lower_bool_to_float_impl(nir_function_impl *impl) nir_lower_bool_to_float_instr(nir_builder *b,
nir_instr *instr,
UNUSED void *cb_data)
{ {
bool progress = false;
nir_builder b;
nir_builder_init(&b, impl);
nir_foreach_block(block, impl) {
nir_foreach_instr_safe(instr, block) {
switch (instr->type) { switch (instr->type) {
case nir_instr_type_alu: case nir_instr_type_alu:
progress |= lower_alu_instr(&b, nir_instr_as_alu(instr)); return lower_alu_instr(b, nir_instr_as_alu(instr));
break;
case nir_instr_type_load_const: { case nir_instr_type_load_const: {
nir_load_const_instr *load = nir_instr_as_load_const(instr); nir_load_const_instr *load = nir_instr_as_load_const(instr);
@@ -161,45 +155,33 @@ nir_lower_bool_to_float_impl(nir_function_impl *impl)
for (unsigned i = 0; i < load->def.num_components; i++) for (unsigned i = 0; i < load->def.num_components; i++)
load->value[i].f32 = value[i].b ? 1.0 : 0.0; load->value[i].f32 = value[i].b ? 1.0 : 0.0;
load->def.bit_size = 32; load->def.bit_size = 32;
progress = true; return true;
} }
break; return false;
} }
case nir_instr_type_intrinsic: case nir_instr_type_intrinsic:
case nir_instr_type_ssa_undef: case nir_instr_type_ssa_undef:
case nir_instr_type_phi: case nir_instr_type_phi: {
nir_foreach_ssa_def(instr, rewrite_1bit_ssa_def_to_32bit, bool progress = false;
&progress); nir_foreach_ssa_def(instr, rewrite_1bit_ssa_def_to_32bit, &progress);
break; return progress;
}
case nir_instr_type_tex: case nir_instr_type_tex:
progress |= lower_tex_instr(nir_instr_as_tex(instr)); return lower_tex_instr(nir_instr_as_tex(instr));
break;
default: default:
nir_foreach_ssa_def(instr, assert_ssa_def_is_not_1bit, NULL); nir_foreach_ssa_def(instr, assert_ssa_def_is_not_1bit, NULL);
return false;
} }
}
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);
}
return progress;
} }
bool bool
nir_lower_bool_to_float(nir_shader *shader) nir_lower_bool_to_float(nir_shader *shader)
{ {
bool progress = false; return nir_shader_instructions_pass(shader, nir_lower_bool_to_float_instr,
nir_metadata_block_index |
nir_foreach_function(function, shader) { nir_metadata_dominance,
if (function->impl && nir_lower_bool_to_float_impl(function->impl)) NULL);
progress = true;
}
return progress;
} }