summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/CMakeLists.txt1
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp3
-rw-r--r--src/shader_recompiler/host_translate_info.h2
-rw-r--r--src/shader_recompiler/ir_opt/conditional_barrier_pass.cpp44
-rw-r--r--src/shader_recompiler/ir_opt/passes.h1
5 files changed, 51 insertions, 0 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt
index 525b2363c..2baa64322 100644
--- a/src/shader_recompiler/CMakeLists.txt
+++ b/src/shader_recompiler/CMakeLists.txt
@@ -216,6 +216,7 @@ add_library(shader_recompiler STATIC
216 frontend/maxwell/translate_program.h 216 frontend/maxwell/translate_program.h
217 host_translate_info.h 217 host_translate_info.h
218 ir_opt/collect_shader_info_pass.cpp 218 ir_opt/collect_shader_info_pass.cpp
219 ir_opt/conditional_barrier_pass.cpp
219 ir_opt/constant_propagation_pass.cpp 220 ir_opt/constant_propagation_pass.cpp
220 ir_opt/dead_code_elimination_pass.cpp 221 ir_opt/dead_code_elimination_pass.cpp
221 ir_opt/dual_vertex_pass.cpp 222 ir_opt/dual_vertex_pass.cpp
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 17a6d4888..529382355 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
@@ -286,6 +286,9 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo
286 if (!host_info.support_int64) { 286 if (!host_info.support_int64) {
287 Optimization::LowerInt64ToInt32(program); 287 Optimization::LowerInt64ToInt32(program);
288 } 288 }
289 if (!host_info.support_conditional_barrier) {
290 Optimization::ConditionalBarrierPass(program);
291 }
289 Optimization::SsaRewritePass(program); 292 Optimization::SsaRewritePass(program);
290 293
291 Optimization::ConstantPropagationPass(env, program); 294 Optimization::ConstantPropagationPass(env, program);
diff --git a/src/shader_recompiler/host_translate_info.h b/src/shader_recompiler/host_translate_info.h
index 2aaa6c5ea..d4e4f4d28 100644
--- a/src/shader_recompiler/host_translate_info.h
+++ b/src/shader_recompiler/host_translate_info.h
@@ -17,6 +17,8 @@ struct HostTranslateInfo {
17 bool support_viewport_index_layer{}; ///< True when the device supports gl_Layer in VS 17 bool support_viewport_index_layer{}; ///< True when the device supports gl_Layer in VS
18 bool support_geometry_shader_passthrough{}; ///< True when the device supports geometry 18 bool support_geometry_shader_passthrough{}; ///< True when the device supports geometry
19 ///< passthrough shaders 19 ///< passthrough shaders
20 bool support_conditional_barrier{}; ///< True when the device supports barriers in conditional
21 ///< control flow
20}; 22};
21 23
22} // namespace Shader 24} // namespace Shader
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 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "shader_recompiler/frontend/ir/program.h"
5#include "shader_recompiler/ir_opt/passes.h"
6
7namespace Shader::Optimization {
8
9void ConditionalBarrierPass(IR::Program& program) {
10 s32 conditional_control_flow_count{0};
11 s32 conditional_return_count{0};
12 for (IR::AbstractSyntaxNode& node : program.syntax_list) {
13 switch (node.type) {
14 case IR::AbstractSyntaxNode::Type::If:
15 case IR::AbstractSyntaxNode::Type::Loop:
16 conditional_control_flow_count++;
17 break;
18 case IR::AbstractSyntaxNode::Type::EndIf:
19 case IR::AbstractSyntaxNode::Type::Repeat:
20 conditional_control_flow_count--;
21 break;
22 case IR::AbstractSyntaxNode::Type::Unreachable:
23 case IR::AbstractSyntaxNode::Type::Return:
24 if (conditional_control_flow_count > 0) {
25 conditional_return_count++;
26 }
27 break;
28 case IR::AbstractSyntaxNode::Type::Block:
29 for (IR::Inst& inst : node.data.block->Instructions()) {
30 if ((conditional_control_flow_count > 0 || conditional_return_count > 0) &&
31 inst.GetOpcode() == IR::Opcode::Barrier) {
32 LOG_WARNING(Shader, "Barrier within conditional control flow");
33 inst.ReplaceOpcode(IR::Opcode::Identity);
34 }
35 }
36 break;
37 default:
38 break;
39 }
40 }
41 ASSERT(conditional_control_flow_count == 0);
42}
43
44} // namespace Shader::Optimization
diff --git a/src/shader_recompiler/ir_opt/passes.h b/src/shader_recompiler/ir_opt/passes.h
index 1f8f2ba95..a677bfc65 100644
--- a/src/shader_recompiler/ir_opt/passes.h
+++ b/src/shader_recompiler/ir_opt/passes.h
@@ -13,6 +13,7 @@ struct HostTranslateInfo;
13namespace Shader::Optimization { 13namespace Shader::Optimization {
14 14
15void CollectShaderInfoPass(Environment& env, IR::Program& program); 15void CollectShaderInfoPass(Environment& env, IR::Program& program);
16void ConditionalBarrierPass(IR::Program& program);
16void ConstantPropagationPass(Environment& env, IR::Program& program); 17void ConstantPropagationPass(Environment& env, IR::Program& program);
17void DeadCodeEliminationPass(IR::Program& program); 18void DeadCodeEliminationPass(IR::Program& program);
18void GlobalMemoryToStorageBufferPass(IR::Program& program); 19void GlobalMemoryToStorageBufferPass(IR::Program& program);