diff options
Diffstat (limited to 'src/shader_recompiler/ir_opt/dual_vertex_pass.cpp')
| -rw-r--r-- | src/shader_recompiler/ir_opt/dual_vertex_pass.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp b/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp new file mode 100644 index 000000000..f35c6478a --- /dev/null +++ b/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <ranges> | ||
| 7 | #include <tuple> | ||
| 8 | #include <type_traits> | ||
| 9 | |||
| 10 | #include "common/bit_cast.h" | ||
| 11 | #include "common/bit_util.h" | ||
| 12 | #include "shader_recompiler/exception.h" | ||
| 13 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | ||
| 14 | #include "shader_recompiler/ir_opt/passes.h" | ||
| 15 | |||
| 16 | namespace Shader::Optimization { | ||
| 17 | |||
| 18 | void VertexATransformPass(IR::Program& program) { | ||
| 19 | bool replaced_join{}; | ||
| 20 | bool eliminated_epilogue{}; | ||
| 21 | for (IR::Block* const block : program.post_order_blocks) { | ||
| 22 | for (IR::Inst& inst : block->Instructions()) { | ||
| 23 | switch (inst.GetOpcode()) { | ||
| 24 | case IR::Opcode::Return: | ||
| 25 | inst.ReplaceOpcode(IR::Opcode::Join); | ||
| 26 | replaced_join = true; | ||
| 27 | break; | ||
| 28 | case IR::Opcode::Epilogue: | ||
| 29 | inst.Invalidate(); | ||
| 30 | eliminated_epilogue = true; | ||
| 31 | break; | ||
| 32 | default: | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | if (replaced_join && eliminated_epilogue) { | ||
| 36 | return; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | void VertexBTransformPass(IR::Program& program) { | ||
| 43 | for (IR::Block* const block : program.post_order_blocks | std::views::reverse) { | ||
| 44 | for (IR::Inst& inst : block->Instructions()) { | ||
| 45 | if (inst.GetOpcode() == IR::Opcode::Prologue) { | ||
| 46 | return inst.Invalidate(); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void DualVertexJoinPass(IR::Program& program) { | ||
| 53 | const auto& blocks = program.blocks; | ||
| 54 | s64 s = static_cast<s64>(blocks.size()) - 1; | ||
| 55 | if (s < 1) { | ||
| 56 | throw NotImplementedException("Dual Vertex Join pass failed, expected atleast 2 blocks!"); | ||
| 57 | } | ||
| 58 | for (s64 index = 0; index < s; index++) { | ||
| 59 | IR::Block* const current_block = blocks[index]; | ||
| 60 | IR::Block* const next_block = blocks[index + 1]; | ||
| 61 | for (IR::Inst& inst : current_block->Instructions()) { | ||
| 62 | if (inst.GetOpcode() == IR::Opcode::Join) { | ||
| 63 | IR::IREmitter ir{*current_block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 64 | ir.Branch(next_block); | ||
| 65 | inst.Invalidate(); | ||
| 66 | // only 1 join should exist | ||
| 67 | return; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | throw NotImplementedException("Dual Vertex Join pass failed, no join present!"); | ||
| 72 | } | ||
| 73 | |||
| 74 | } // namespace Shader::Optimization | ||