summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp
diff options
context:
space:
mode:
authorLiam <byteslice@airmail.cc>2023-06-10 17:40:58 +0200
committerLiam <byteslice@airmail.cc>2023-06-10 18:30:39 +0200
commit2bb7ea436dc74f812a8092201dc597ed58ff3c7a (patch)
tree27b6426a646112e163ae39b733ce60ca6d6aa748 /src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp
parentMerge pull request #10685 from liamwhite/serialization-is-hard (diff)
downloadyuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.tar
yuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.tar.gz
yuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.tar.bz2
yuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.tar.lz
yuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.tar.xz
yuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.tar.zst
yuzu-2bb7ea436dc74f812a8092201dc597ed58ff3c7a.zip
Diffstat (limited to 'src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp')
-rw-r--r--src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp b/src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp
new file mode 100644
index 000000000..c3ed27f4f
--- /dev/null
+++ b/src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp
@@ -0,0 +1,44 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "shader_recompiler/frontend/ir/program.h"
+#include "shader_recompiler/ir_opt/passes.h"
+
+namespace Shader::Optimization {
+
+void ConditionalBarrierPass(IR::Program& program) {
+ s32 conditional_control_flow_count{0};
+ s32 conditional_return_count{0};
+ for (IR::AbstractSyntaxNode& node : program.syntax_list) {
+ switch (node.type) {
+ case IR::AbstractSyntaxNode::Type::If:
+ case IR::AbstractSyntaxNode::Type::Loop:
+ conditional_control_flow_count++;
+ break;
+ case IR::AbstractSyntaxNode::Type::EndIf:
+ case IR::AbstractSyntaxNode::Type::Repeat:
+ conditional_control_flow_count--;
+ break;
+ case IR::AbstractSyntaxNode::Type::Unreachable:
+ case IR::AbstractSyntaxNode::Type::Return:
+ if (conditional_control_flow_count > 0) {
+ conditional_return_count++;
+ }
+ break;
+ case IR::AbstractSyntaxNode::Type::Block:
+ for (IR::Inst& inst : node.data.block->Instructions()) {
+ if ((conditional_control_flow_count > 0 || conditional_return_count > 0) &&
+ inst.GetOpcode() == IR::Opcode::Barrier) {
+ LOG_WARNING(Shader, "Barrier within conditional control flow");
+ inst.ReplaceOpcode(IR::Opcode::Identity);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ ASSERT(conditional_control_flow_count == 0);
+}
+
+} // namespace Shader::Optimization