glsl: use nir_shader_instructions_pass in gl_nir_lower_samplers_as_deref

No functional changes.

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-06 15:36:18 +02:00
committed by Marge Bot
parent d3708d6cf5
commit cb201e92ac

View File

@@ -353,36 +353,23 @@ lower_intrinsic(nir_intrinsic_instr *instr,
}
static bool
lower_impl(nir_function_impl *impl, struct lower_samplers_as_deref_state *state)
lower_instr(nir_builder *b, nir_instr *instr, void *cb_data)
{
nir_builder b;
nir_builder_init(&b, impl);
bool progress = false;
struct lower_samplers_as_deref_state *state = cb_data;
nir_foreach_block(block, impl) {
nir_foreach_instr(instr, block) {
if (instr->type == nir_instr_type_tex)
progress |= lower_sampler(nir_instr_as_tex(instr), state, &b);
else if (instr->type == nir_instr_type_intrinsic)
progress |= lower_intrinsic(nir_instr_as_intrinsic(instr), state, &b);
}
}
if (instr->type == nir_instr_type_tex)
return lower_sampler(nir_instr_as_tex(instr), state, b);
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
if (instr->type == nir_instr_type_intrinsic)
return lower_intrinsic(nir_instr_as_intrinsic(instr), state, b);
return progress;
return false;
}
bool
gl_nir_lower_samplers_as_deref(nir_shader *shader,
const struct gl_shader_program *shader_program)
{
bool progress = false;
struct lower_samplers_as_deref_state state;
state.shader = shader;
@@ -390,10 +377,10 @@ gl_nir_lower_samplers_as_deref(nir_shader *shader,
state.remap_table = _mesa_hash_table_create(NULL, _mesa_hash_string,
_mesa_key_string_equal);
nir_foreach_function(function, shader) {
if (function->impl)
progress |= lower_impl(function->impl, &state);
}
bool progress = nir_shader_instructions_pass(shader, lower_instr,
nir_metadata_block_index |
nir_metadata_dominance,
&state);
/* keys are freed automatically by ralloc */
_mesa_hash_table_destroy(state.remap_table, NULL);