diff options
Diffstat (limited to 'src/shader_recompiler/ir_opt')
| -rw-r--r-- | src/shader_recompiler/ir_opt/dual_vertex_pass.cpp | 74 | ||||
| -rw-r--r-- | src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp | 26 | ||||
| -rw-r--r-- | src/shader_recompiler/ir_opt/passes.h | 7 | ||||
| -rw-r--r-- | src/shader_recompiler/ir_opt/texture_pass.cpp | 21 |
4 files changed, 128 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 | ||
diff --git a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp index 87eca2a0d..1d11a00d8 100644 --- a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp +++ b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp | |||
| @@ -499,4 +499,30 @@ void GlobalMemoryToStorageBufferPass(IR::Program& program) { | |||
| 499 | } | 499 | } |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | template <typename Descriptors, typename Descriptor, typename Func> | ||
| 503 | static u32 Add(Descriptors& descriptors, const Descriptor& desc, Func&& pred) { | ||
| 504 | // TODO: Handle arrays | ||
| 505 | const auto it{std::ranges::find_if(descriptors, pred)}; | ||
| 506 | if (it != descriptors.end()) { | ||
| 507 | return static_cast<u32>(std::distance(descriptors.begin(), it)); | ||
| 508 | } | ||
| 509 | descriptors.push_back(desc); | ||
| 510 | return static_cast<u32>(descriptors.size()) - 1; | ||
| 511 | } | ||
| 512 | |||
| 513 | void JoinStorageInfo(Info& base, Info& source) { | ||
| 514 | auto& descriptors = base.storage_buffers_descriptors; | ||
| 515 | for (auto& desc : source.storage_buffers_descriptors) { | ||
| 516 | auto it{std::ranges::find_if(descriptors, [&desc](const auto& existing) { | ||
| 517 | return desc.cbuf_index == existing.cbuf_index && | ||
| 518 | desc.cbuf_offset == existing.cbuf_offset && desc.count == existing.count; | ||
| 519 | })}; | ||
| 520 | if (it != descriptors.end()) { | ||
| 521 | it->is_written |= desc.is_written; | ||
| 522 | continue; | ||
| 523 | } | ||
| 524 | descriptors.push_back(desc); | ||
| 525 | } | ||
| 526 | } | ||
| 527 | |||
| 502 | } // namespace Shader::Optimization | 528 | } // namespace Shader::Optimization |
diff --git a/src/shader_recompiler/ir_opt/passes.h b/src/shader_recompiler/ir_opt/passes.h index 186104713..e9cb8546a 100644 --- a/src/shader_recompiler/ir_opt/passes.h +++ b/src/shader_recompiler/ir_opt/passes.h | |||
| @@ -22,4 +22,11 @@ void SsaRewritePass(IR::Program& program); | |||
| 22 | void TexturePass(Environment& env, IR::Program& program); | 22 | void TexturePass(Environment& env, IR::Program& program); |
| 23 | void VerificationPass(const IR::Program& program); | 23 | void VerificationPass(const IR::Program& program); |
| 24 | 24 | ||
| 25 | // Dual Vertex | ||
| 26 | void VertexATransformPass(IR::Program& program); | ||
| 27 | void VertexBTransformPass(IR::Program& program); | ||
| 28 | void DualVertexJoinPass(IR::Program& program); | ||
| 29 | void JoinTextureInfo(Info& base, Info& source); | ||
| 30 | void JoinStorageInfo(Info& base, Info& source); | ||
| 31 | |||
| 25 | } // namespace Shader::Optimization | 32 | } // namespace Shader::Optimization |
diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp index cfa6b34b9..2b38bcf42 100644 --- a/src/shader_recompiler/ir_opt/texture_pass.cpp +++ b/src/shader_recompiler/ir_opt/texture_pass.cpp | |||
| @@ -426,4 +426,25 @@ void TexturePass(Environment& env, IR::Program& program) { | |||
| 426 | } | 426 | } |
| 427 | } | 427 | } |
| 428 | 428 | ||
| 429 | void JoinTextureInfo(Info& base, Info& source) { | ||
| 430 | Descriptors descriptors{ | ||
| 431 | base.texture_buffer_descriptors, | ||
| 432 | base.image_buffer_descriptors, | ||
| 433 | base.texture_descriptors, | ||
| 434 | base.image_descriptors, | ||
| 435 | }; | ||
| 436 | for (auto& desc : source.texture_buffer_descriptors) { | ||
| 437 | descriptors.Add(desc); | ||
| 438 | } | ||
| 439 | for (auto& desc : source.image_buffer_descriptors) { | ||
| 440 | descriptors.Add(desc); | ||
| 441 | } | ||
| 442 | for (auto& desc : source.texture_descriptors) { | ||
| 443 | descriptors.Add(desc); | ||
| 444 | } | ||
| 445 | for (auto& desc : source.image_descriptors) { | ||
| 446 | descriptors.Add(desc); | ||
| 447 | } | ||
| 448 | } | ||
| 449 | |||
| 429 | } // namespace Shader::Optimization | 450 | } // namespace Shader::Optimization |