Mesa (master): spirv: Run repair_ssa if there are discard instructions
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Sep 8 19:58:33 UTC 2020
Module: Mesa
Branch: master
Commit: 7cedc4128a1f9d8ecae00ff41ccf1b63e4f3ebd0
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7cedc4128a1f9d8ecae00ff41ccf1b63e4f3ebd0
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Mon Jun 1 18:01:05 2020 -0500
spirv: Run repair_ssa if there are discard instructions
SPIR-V's OpKill is a control-flow instruction but NIR's discard is not.
Therefore, it can be valid SPIR-V to have
if (...) {
foo = /* something */
} else {
discard;
}
use(foo);
without any phi between the definition of foo and its use. This is not
true in NIR, however, because NIR's discard isn't considered
control-flow. Arguably, this is a NIR bug but making discard control-
flow is a very deep change that can have serious ans subtle
side-effects. The easier thing to do is just fix up the SSA in case we
have an OpKill which might have gotten us into the above case.
Fixes dEQP-VK.graphicsfuzz.vectors-and-discard-in-function with the new
NIR dominance validation pass enabled.
Cc: mesa-stable at lists.freedesktop.org
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5288>
---
src/compiler/spirv/vtn_cfg.c | 3 ++-
src/compiler/spirv/vtn_private.h | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index a1573565b81..fa7ab5eda28 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -686,6 +686,7 @@ vtn_process_block(struct vtn_builder *b,
return NULL;
case SpvOpKill:
+ b->has_kill = true;
block->branch_type = vtn_branch_type_discard;
return NULL;
@@ -1367,7 +1368,7 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
* but instructions in the continue may use SSA defs in the loop body.
* Therefore, we need to repair SSA to insert the needed phi nodes.
*/
- if (b->has_loop_continue)
+ if (b->has_loop_continue || b->has_kill)
nir_repair_ssa_impl(func->impl);
func->emitted = true;
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index b47fed64649..b0d8d11eb70 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -683,6 +683,7 @@ struct vtn_builder {
unsigned func_param_idx;
bool has_loop_continue;
+ bool has_kill;
/* false by default, set to true by the ContractionOff execution mode */
bool exact;
More information about the mesa-commit
mailing list