From: Eric Anholt Date: Thu, 20 Aug 2020 19:32:20 +0000 (-0700) Subject: nir/lower_discard_to_demote: Use nir_shader_instructions_pass(). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=31f75aaeefe0e1bce48a00efef2c153c0f5b8be7;p=mesa.git nir/lower_discard_to_demote: Use nir_shader_instructions_pass(). Cleans up indentation, and clears the metadata tracking flag that would break if this pass was used in in NIR_PASS(). Reviewed-By: Mike Blumenkrantz Part-of: --- diff --git a/src/compiler/nir/nir_lower_discard_to_demote.c b/src/compiler/nir/nir_lower_discard_to_demote.c index eb13796d952..88bc9c940a2 100644 --- a/src/compiler/nir/nir_lower_discard_to_demote.c +++ b/src/compiler/nir/nir_lower_discard_to_demote.c @@ -23,6 +23,31 @@ */ #include "nir.h" +#include "nir_builder.h" + +static bool +nir_lower_discard_to_demote_instr(nir_builder *b, nir_instr *instr, void *data) +{ + if (instr->type != nir_instr_type_intrinsic) + return false; + + nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); + switch (intrin->intrinsic) { + case nir_intrinsic_discard: + intrin->intrinsic = nir_intrinsic_demote; + b->shader->info.fs.uses_demote = true; + return true; + case nir_intrinsic_discard_if: + intrin->intrinsic = nir_intrinsic_demote_if; + b->shader->info.fs.uses_demote = true; + return true; + case nir_intrinsic_load_helper_invocation: + intrin->intrinsic = nir_intrinsic_is_helper_invocation; + return true; + default: + return false; + } +} /** * This pass is intended as workaround for game bugs to force correct @@ -38,34 +63,8 @@ nir_lower_discard_to_demote(nir_shader *shader) if (shader->info.stage != MESA_SHADER_FRAGMENT) return false; - bool progress = false; - - nir_foreach_function(function, shader) { - nir_foreach_block(block, function->impl) { - nir_foreach_instr(instr, block) { - if (instr->type != nir_instr_type_intrinsic) - continue; - - nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); - switch (intrin->intrinsic) { - case nir_intrinsic_discard: - intrin->intrinsic = nir_intrinsic_demote; - shader->info.fs.uses_demote = true; - break; - case nir_intrinsic_discard_if: - intrin->intrinsic = nir_intrinsic_demote_if; - shader->info.fs.uses_demote = true; - break; - case nir_intrinsic_load_helper_invocation: - intrin->intrinsic = nir_intrinsic_is_helper_invocation; - break; - default: - continue; - } - progress = true; - } - } - } - - return progress; + return nir_shader_instructions_pass(shader, + nir_lower_discard_to_demote_instr, + nir_metadata_all, + NULL); }