mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 16:08:04 +02:00
microsoft/clc: use nir_shader_instructions_pass in clc_nir_dedupe_const_samplers
Changes: - nir_metadata_preserve(..., nir_metadata_all) is called when pass doesn't make progress v2: fix build Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12324>
This commit is contained in:
parent
70723f278f
commit
17a61ec541
1 changed files with 42 additions and 46 deletions
|
|
@ -302,53 +302,49 @@ find_identical_const_sampler(nir_shader *nir, nir_variable *sampler)
|
|||
unreachable("Should have at least found the input sampler");
|
||||
}
|
||||
|
||||
static bool
|
||||
clc_nir_dedupe_const_samplers_instr(nir_builder *b,
|
||||
nir_instr *instr,
|
||||
void *cb_data)
|
||||
{
|
||||
nir_shader *nir = cb_data;
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
int sampler_idx = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
|
||||
if (sampler_idx == -1)
|
||||
return false;
|
||||
|
||||
nir_deref_instr *deref = nir_src_as_deref(tex->src[sampler_idx].src);
|
||||
nir_variable *sampler = nir_deref_instr_get_variable(deref);
|
||||
if (!sampler)
|
||||
return false;
|
||||
|
||||
assert(sampler->data.mode == nir_var_uniform);
|
||||
|
||||
if (!sampler->data.sampler.is_inline_sampler)
|
||||
return false;
|
||||
|
||||
nir_variable *replacement = find_identical_const_sampler(nir, sampler);
|
||||
if (replacement == sampler)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
nir_deref_instr *replacement_deref = nir_build_deref_var(b, replacement);
|
||||
nir_instr_rewrite_src(&tex->instr, &tex->src[sampler_idx].src,
|
||||
nir_src_for_ssa(&replacement_deref->dest.ssa));
|
||||
nir_deref_instr_remove_if_unused(deref);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
clc_nir_dedupe_const_samplers(nir_shader *nir)
|
||||
{
|
||||
bool progress = false;
|
||||
nir_foreach_function(func, nir) {
|
||||
if (!func->impl)
|
||||
continue;
|
||||
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, func->impl);
|
||||
|
||||
nir_foreach_block(block, func->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
continue;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
int sampler_idx = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
|
||||
if (sampler_idx == -1)
|
||||
continue;
|
||||
|
||||
nir_deref_instr *deref = nir_src_as_deref(tex->src[sampler_idx].src);
|
||||
nir_variable *sampler = nir_deref_instr_get_variable(deref);
|
||||
if (!sampler)
|
||||
continue;
|
||||
|
||||
assert(sampler->data.mode == nir_var_uniform);
|
||||
|
||||
if (!sampler->data.sampler.is_inline_sampler)
|
||||
continue;
|
||||
|
||||
nir_variable *replacement = find_identical_const_sampler(nir, sampler);
|
||||
if (replacement == sampler)
|
||||
continue;
|
||||
|
||||
b.cursor = nir_before_instr(&tex->instr);
|
||||
nir_deref_instr *replacement_deref = nir_build_deref_var(&b, replacement);
|
||||
nir_instr_rewrite_src(&tex->instr, &tex->src[sampler_idx].src,
|
||||
nir_src_for_ssa(&replacement_deref->dest.ssa));
|
||||
nir_deref_instr_remove_if_unused(deref);
|
||||
progress = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
nir_metadata_preserve(func->impl, nir_metadata_block_index | nir_metadata_dominance);
|
||||
}
|
||||
}
|
||||
return progress;
|
||||
return nir_shader_instructions_pass(nir,
|
||||
clc_nir_dedupe_const_samplers_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
nir);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue