Mesa (master): nir/nir_lower_wrmasks: Use the nir_lower_instructions_pass() helper.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Aug 27 23:24:27 UTC 2020
Module: Mesa
Branch: master
Commit: 265dcb383673822686a3855225b49f376e51ebeb
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=265dcb383673822686a3855225b49f376e51ebeb
Author: Eric Anholt <eric at anholt.net>
Date: Thu Aug 20 12:25:52 2020 -0700
nir/nir_lower_wrmasks: Use the nir_lower_instructions_pass() helper.
This fixes the invalidation of metadata when we didn't modify the shader
and unindents a bunch of code.
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6412>
---
src/compiler/nir/nir_lower_wrmasks.c | 78 ++++++++++++++++++------------------
1 file changed, 40 insertions(+), 38 deletions(-)
diff --git a/src/compiler/nir/nir_lower_wrmasks.c b/src/compiler/nir/nir_lower_wrmasks.c
index b3941ec84af..ea2d4f330f7 100644
--- a/src/compiler/nir/nir_lower_wrmasks.c
+++ b/src/compiler/nir/nir_lower_wrmasks.c
@@ -179,53 +179,55 @@ split_wrmask(nir_builder *b, nir_intrinsic_instr *intr)
nir_instr_remove(&intr->instr);
}
-bool
-nir_lower_wrmasks(nir_shader *shader, nir_instr_filter_cb cb, const void *data)
-{
- bool progress = false;
-
- nir_foreach_function(function, shader) {
- nir_function_impl *impl = function->impl;
+struct nir_lower_wrmasks_state {
+ nir_instr_filter_cb cb;
+ const void *data;
+};
- if (!impl)
- continue;
+static bool
+nir_lower_wrmasks_instr(nir_builder *b, nir_instr *instr, void *data)
+{
+ struct nir_lower_wrmasks_state *state = data;
- nir_foreach_block(block, impl) {
- nir_foreach_instr_safe(instr, block) {
- if (instr->type != nir_instr_type_intrinsic)
- continue;
+ if (instr->type != nir_instr_type_intrinsic)
+ return false;
- nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+ nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
- /* if no wrmask, then skip it: */
- if (!nir_intrinsic_has_write_mask(intr))
- continue;
+ /* if no wrmask, then skip it: */
+ if (!nir_intrinsic_has_write_mask(intr))
+ return false;
- /* if wrmask is already contiguous, then nothing to do: */
- if (nir_intrinsic_write_mask(intr) == BITFIELD_MASK(intr->num_components))
- continue;
+ /* if wrmask is already contiguous, then nothing to do: */
+ if (nir_intrinsic_write_mask(intr) == BITFIELD_MASK(intr->num_components))
+ return false;
- /* do we know how to lower this instruction? */
- if (value_src(intr->intrinsic) < 0)
- continue;
+ /* do we know how to lower this instruction? */
+ if (value_src(intr->intrinsic) < 0)
+ return false;
- assert(offset_src(intr->intrinsic) >= 0);
+ assert(offset_src(intr->intrinsic) >= 0);
- /* does backend need us to lower this intrinsic? */
- if (cb && !cb(instr, data))
- continue;
+ /* does backend need us to lower this intrinsic? */
+ if (state->cb && !state->cb(instr, state->data))
+ return false;
- nir_builder b;
- nir_builder_init(&b, impl);
- split_wrmask(&b, intr);
- progress = true;
- }
- }
+ split_wrmask(b, intr);
- nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
-
- }
+ return true;
+}
- return progress;
+bool
+nir_lower_wrmasks(nir_shader *shader, nir_instr_filter_cb cb, const void *data)
+{
+ struct nir_lower_wrmasks_state state = {
+ .cb = cb,
+ .data = data,
+ };
+
+ return nir_shader_instructions_pass(shader,
+ nir_lower_wrmasks_instr,
+ nir_metadata_block_index |
+ nir_metadata_dominance,
+ &state);
}
More information about the mesa-commit
mailing list