diff options
| author | 2022-11-09 17:58:10 +0100 | |
|---|---|---|
| committer | 2023-01-01 16:43:57 -0500 | |
| commit | aad0cbf024fb8077a9b375a093c60a7e2ab1db3d (patch) | |
| tree | 8c6a86c92ed8cedbafb5f34dd9f72283eaaf4342 /src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |
| parent | MacroHLE: Add Index Buffer size estimation. (diff) | |
| download | yuzu-aad0cbf024fb8077a9b375a093c60a7e2ab1db3d.tar.gz yuzu-aad0cbf024fb8077a9b375a093c60a7e2ab1db3d.tar.xz yuzu-aad0cbf024fb8077a9b375a093c60a7e2ab1db3d.zip | |
MacroHLE: Add HLE replacement for base vertex and base instance.
Diffstat (limited to 'src/shader_recompiler/ir_opt/constant_propagation_pass.cpp')
| -rw-r--r-- | src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp index 826f9a54a..ac10405f3 100644 --- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <type_traits> | 7 | #include <type_traits> |
| 8 | 8 | ||
| 9 | #include "common/bit_cast.h" | 9 | #include "common/bit_cast.h" |
| 10 | #include "shader_recompiler/environment.h" | ||
| 10 | #include "shader_recompiler/exception.h" | 11 | #include "shader_recompiler/exception.h" |
| 11 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | 12 | #include "shader_recompiler/frontend/ir/ir_emitter.h" |
| 12 | #include "shader_recompiler/frontend/ir/value.h" | 13 | #include "shader_recompiler/frontend/ir/value.h" |
| @@ -515,6 +516,8 @@ void FoldBitCast(IR::Inst& inst, IR::Opcode reverse) { | |||
| 515 | case IR::Attribute::PrimitiveId: | 516 | case IR::Attribute::PrimitiveId: |
| 516 | case IR::Attribute::InstanceId: | 517 | case IR::Attribute::InstanceId: |
| 517 | case IR::Attribute::VertexId: | 518 | case IR::Attribute::VertexId: |
| 519 | case IR::Attribute::BaseVertex: | ||
| 520 | case IR::Attribute::BaseInstance: | ||
| 518 | break; | 521 | break; |
| 519 | default: | 522 | default: |
| 520 | return; | 523 | return; |
| @@ -644,7 +647,37 @@ void FoldFSwizzleAdd(IR::Block& block, IR::Inst& inst) { | |||
| 644 | } | 647 | } |
| 645 | } | 648 | } |
| 646 | 649 | ||
| 647 | void ConstantPropagation(IR::Block& block, IR::Inst& inst) { | 650 | void FoldConstBuffer(Environment& env, IR::Block& block, IR::Inst& inst) { |
| 651 | const IR::Value bank{inst.Arg(0)}; | ||
| 652 | const IR::Value offset{inst.Arg(1)}; | ||
| 653 | if (!bank.IsImmediate() || !offset.IsImmediate()) { | ||
| 654 | return; | ||
| 655 | } | ||
| 656 | const auto bank_value = bank.U32(); | ||
| 657 | const auto offset_value = offset.U32(); | ||
| 658 | auto replacement = env.GetReplaceConstBuffer(bank_value, offset_value); | ||
| 659 | if (!replacement) { | ||
| 660 | return; | ||
| 661 | } | ||
| 662 | const auto new_attribute = [replacement]() { | ||
| 663 | switch (*replacement) { | ||
| 664 | case ReplaceConstant::BaseInstance: | ||
| 665 | return IR::Attribute::BaseInstance; | ||
| 666 | case ReplaceConstant::BaseVertex: | ||
| 667 | return IR::Attribute::BaseVertex; | ||
| 668 | default: | ||
| 669 | throw NotImplementedException("Not implemented replacement variable {}", *replacement); | ||
| 670 | } | ||
| 671 | }(); | ||
| 672 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 673 | if (inst.GetOpcode() == IR::Opcode::GetCbufU32) { | ||
| 674 | inst.ReplaceUsesWith(ir.GetAttributeU32(new_attribute)); | ||
| 675 | } else { | ||
| 676 | inst.ReplaceUsesWith(ir.GetAttribute(new_attribute)); | ||
| 677 | } | ||
| 678 | } | ||
| 679 | |||
| 680 | void ConstantPropagation(Environment& env, IR::Block& block, IR::Inst& inst) { | ||
| 648 | switch (inst.GetOpcode()) { | 681 | switch (inst.GetOpcode()) { |
| 649 | case IR::Opcode::GetRegister: | 682 | case IR::Opcode::GetRegister: |
| 650 | return FoldGetRegister(inst); | 683 | return FoldGetRegister(inst); |
| @@ -789,18 +822,24 @@ void ConstantPropagation(IR::Block& block, IR::Inst& inst) { | |||
| 789 | IR::Opcode::CompositeInsertF16x4); | 822 | IR::Opcode::CompositeInsertF16x4); |
| 790 | case IR::Opcode::FSwizzleAdd: | 823 | case IR::Opcode::FSwizzleAdd: |
| 791 | return FoldFSwizzleAdd(block, inst); | 824 | return FoldFSwizzleAdd(block, inst); |
| 825 | case IR::Opcode::GetCbufF32: | ||
| 826 | case IR::Opcode::GetCbufU32: | ||
| 827 | if (env.HasHLEMacroState()) { | ||
| 828 | return FoldConstBuffer(env, block, inst); | ||
| 829 | } | ||
| 830 | break; | ||
| 792 | default: | 831 | default: |
| 793 | break; | 832 | break; |
| 794 | } | 833 | } |
| 795 | } | 834 | } |
| 796 | } // Anonymous namespace | 835 | } // Anonymous namespace |
| 797 | 836 | ||
| 798 | void ConstantPropagationPass(IR::Program& program) { | 837 | void ConstantPropagationPass(Environment& env, IR::Program& program) { |
| 799 | const auto end{program.post_order_blocks.rend()}; | 838 | const auto end{program.post_order_blocks.rend()}; |
| 800 | for (auto it = program.post_order_blocks.rbegin(); it != end; ++it) { | 839 | for (auto it = program.post_order_blocks.rbegin(); it != end; ++it) { |
| 801 | IR::Block* const block{*it}; | 840 | IR::Block* const block{*it}; |
| 802 | for (IR::Inst& inst : block->Instructions()) { | 841 | for (IR::Inst& inst : block->Instructions()) { |
| 803 | ConstantPropagation(*block, inst); | 842 | ConstantPropagation(env, *block, inst); |
| 804 | } | 843 | } |
| 805 | } | 844 | } |
| 806 | } | 845 | } |