nir: use nir_shader_instructions_pass in nir_lower_fb_read
Changes: - nir_metadata_preserve(..., nir_metadata_block_index | nir_metadata_dominance) is called only when pass makes progress - 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:

committed by
Marge Bot

parent
2e410c4c05
commit
a87070937d
@@ -46,9 +46,26 @@
|
|||||||
* hidden texture to read from the fb.
|
* hidden texture to read from the fb.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
lower_fb_read(nir_builder *b, nir_intrinsic_instr *intr)
|
nir_lower_fb_read_instr(nir_builder *b, nir_instr *instr, UNUSED void *cb_data)
|
||||||
{
|
{
|
||||||
|
if (instr->type != nir_instr_type_intrinsic)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||||
|
if (intr->intrinsic != nir_intrinsic_load_output)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* TODO KHR_blend_equation_advanced is limited to non-MRT
|
||||||
|
* scenarios.. but possible there are other extensions
|
||||||
|
* where this pass would be useful that do support MRT?
|
||||||
|
*
|
||||||
|
* I guess for now I'll leave that as an exercise for the
|
||||||
|
* reader.
|
||||||
|
*/
|
||||||
|
if (nir_intrinsic_base(intr) != 0 || nir_src_as_uint(intr->src[0]) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
b->cursor = nir_before_instr(&intr->instr);
|
b->cursor = nir_before_instr(&intr->instr);
|
||||||
|
|
||||||
nir_ssa_def *fragcoord = nir_load_frag_coord(b);
|
nir_ssa_def *fragcoord = nir_load_frag_coord(b);
|
||||||
@@ -70,52 +87,17 @@ lower_fb_read(nir_builder *b, nir_intrinsic_instr *intr)
|
|||||||
nir_builder_instr_insert(b, &tex->instr);
|
nir_builder_instr_insert(b, &tex->instr);
|
||||||
|
|
||||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, &tex->dest.ssa);
|
nir_ssa_def_rewrite_uses(&intr->dest.ssa, &tex->dest.ssa);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nir_lower_fb_read(nir_shader *shader)
|
nir_lower_fb_read(nir_shader *shader)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
|
||||||
|
|
||||||
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
||||||
|
|
||||||
nir_foreach_function(function, shader) {
|
return nir_shader_instructions_pass(shader, nir_lower_fb_read_instr,
|
||||||
nir_function_impl *impl = function->impl;
|
nir_metadata_block_index |
|
||||||
|
nir_metadata_dominance,
|
||||||
if (!impl)
|
NULL);
|
||||||
continue;
|
|
||||||
|
|
||||||
nir_foreach_block(block, impl) {
|
|
||||||
nir_foreach_instr_safe(instr, block) {
|
|
||||||
if (instr->type != nir_instr_type_intrinsic)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
|
||||||
if (intr->intrinsic != nir_intrinsic_load_output)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* TODO KHR_blend_equation_advanced is limited to non-MRT
|
|
||||||
* scenarios.. but possible there are other extensions
|
|
||||||
* where this pass would be useful that do support MRT?
|
|
||||||
*
|
|
||||||
* I guess for now I'll leave that as an exercise for the
|
|
||||||
* reader.
|
|
||||||
*/
|
|
||||||
if (nir_intrinsic_base(intr) != 0 ||
|
|
||||||
nir_src_as_uint(intr->src[0]) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
nir_builder b;
|
|
||||||
nir_builder_init(&b, impl);
|
|
||||||
lower_fb_read(&b, intr);
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nir_metadata_preserve(impl, nir_metadata_block_index |
|
|
||||||
nir_metadata_dominance);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return progress;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user