diff options
| author | 2019-06-04 22:44:06 -0300 | |
|---|---|---|
| committer | 2019-06-05 20:41:52 -0300 | |
| commit | bf4dfb3ad4c6419216e8154c970f5577bc1bc475 (patch) | |
| tree | fc03ece18cae31f3a855d6702878027bd1f6134a /src/video_core/renderer_vulkan | |
| parent | Merge pull request #2520 from ReinUsesLisp/vulkan-refresh (diff) | |
| download | yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.gz yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.xz yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.zip | |
shader: Use shared_ptr to store nodes and move initialization to file
Instead of having a vector of unique_ptr stored in a vector and
returning star pointers to this, use shared_ptr. While changing
initialization code, move it to a separate file when possible.
This is a first step to allow code analysis and node generation beyond
the ShaderIR class.
Diffstat (limited to 'src/video_core/renderer_vulkan')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp index a85fcae5a..547883425 100644 --- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | |||
| @@ -481,13 +481,13 @@ private: | |||
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | void VisitBasicBlock(const NodeBlock& bb) { | 483 | void VisitBasicBlock(const NodeBlock& bb) { |
| 484 | for (const Node node : bb) { | 484 | for (const auto& node : bb) { |
| 485 | static_cast<void>(Visit(node)); | 485 | static_cast<void>(Visit(node)); |
| 486 | } | 486 | } |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | Id Visit(Node node) { | 489 | Id Visit(const Node& node) { |
| 490 | if (const auto operation = std::get_if<OperationNode>(node)) { | 490 | if (const auto operation = std::get_if<OperationNode>(&*node)) { |
| 491 | const auto operation_index = static_cast<std::size_t>(operation->GetCode()); | 491 | const auto operation_index = static_cast<std::size_t>(operation->GetCode()); |
| 492 | const auto decompiler = operation_decompilers[operation_index]; | 492 | const auto decompiler = operation_decompilers[operation_index]; |
| 493 | if (decompiler == nullptr) { | 493 | if (decompiler == nullptr) { |
| @@ -495,17 +495,17 @@ private: | |||
| 495 | } | 495 | } |
| 496 | return (this->*decompiler)(*operation); | 496 | return (this->*decompiler)(*operation); |
| 497 | 497 | ||
| 498 | } else if (const auto gpr = std::get_if<GprNode>(node)) { | 498 | } else if (const auto gpr = std::get_if<GprNode>(&*node)) { |
| 499 | const u32 index = gpr->GetIndex(); | 499 | const u32 index = gpr->GetIndex(); |
| 500 | if (index == Register::ZeroIndex) { | 500 | if (index == Register::ZeroIndex) { |
| 501 | return Constant(t_float, 0.0f); | 501 | return Constant(t_float, 0.0f); |
| 502 | } | 502 | } |
| 503 | return Emit(OpLoad(t_float, registers.at(index))); | 503 | return Emit(OpLoad(t_float, registers.at(index))); |
| 504 | 504 | ||
| 505 | } else if (const auto immediate = std::get_if<ImmediateNode>(node)) { | 505 | } else if (const auto immediate = std::get_if<ImmediateNode>(&*node)) { |
| 506 | return BitcastTo<Type::Float>(Constant(t_uint, immediate->GetValue())); | 506 | return BitcastTo<Type::Float>(Constant(t_uint, immediate->GetValue())); |
| 507 | 507 | ||
| 508 | } else if (const auto predicate = std::get_if<PredicateNode>(node)) { | 508 | } else if (const auto predicate = std::get_if<PredicateNode>(&*node)) { |
| 509 | const auto value = [&]() -> Id { | 509 | const auto value = [&]() -> Id { |
| 510 | switch (const auto index = predicate->GetIndex(); index) { | 510 | switch (const auto index = predicate->GetIndex(); index) { |
| 511 | case Tegra::Shader::Pred::UnusedIndex: | 511 | case Tegra::Shader::Pred::UnusedIndex: |
| @@ -521,7 +521,7 @@ private: | |||
| 521 | } | 521 | } |
| 522 | return value; | 522 | return value; |
| 523 | 523 | ||
| 524 | } else if (const auto abuf = std::get_if<AbufNode>(node)) { | 524 | } else if (const auto abuf = std::get_if<AbufNode>(&*node)) { |
| 525 | const auto attribute = abuf->GetIndex(); | 525 | const auto attribute = abuf->GetIndex(); |
| 526 | const auto element = abuf->GetElement(); | 526 | const auto element = abuf->GetElement(); |
| 527 | 527 | ||
| @@ -571,8 +571,8 @@ private: | |||
| 571 | } | 571 | } |
| 572 | UNIMPLEMENTED_MSG("Unhandled input attribute: {}", static_cast<u32>(attribute)); | 572 | UNIMPLEMENTED_MSG("Unhandled input attribute: {}", static_cast<u32>(attribute)); |
| 573 | 573 | ||
| 574 | } else if (const auto cbuf = std::get_if<CbufNode>(node)) { | 574 | } else if (const auto cbuf = std::get_if<CbufNode>(&*node)) { |
| 575 | const Node offset = cbuf->GetOffset(); | 575 | const Node& offset = cbuf->GetOffset(); |
| 576 | const Id buffer_id = constant_buffers.at(cbuf->GetIndex()); | 576 | const Id buffer_id = constant_buffers.at(cbuf->GetIndex()); |
| 577 | 577 | ||
| 578 | Id pointer{}; | 578 | Id pointer{}; |
| @@ -584,7 +584,7 @@ private: | |||
| 584 | } else { | 584 | } else { |
| 585 | Id buffer_index{}; | 585 | Id buffer_index{}; |
| 586 | Id buffer_element{}; | 586 | Id buffer_element{}; |
| 587 | if (const auto immediate = std::get_if<ImmediateNode>(offset)) { | 587 | if (const auto immediate = std::get_if<ImmediateNode>(&*offset)) { |
| 588 | // Direct access | 588 | // Direct access |
| 589 | const u32 offset_imm = immediate->GetValue(); | 589 | const u32 offset_imm = immediate->GetValue(); |
| 590 | ASSERT(offset_imm % 4 == 0); | 590 | ASSERT(offset_imm % 4 == 0); |
| @@ -606,7 +606,7 @@ private: | |||
| 606 | } | 606 | } |
| 607 | return Emit(OpLoad(t_float, pointer)); | 607 | return Emit(OpLoad(t_float, pointer)); |
| 608 | 608 | ||
| 609 | } else if (const auto gmem = std::get_if<GmemNode>(node)) { | 609 | } else if (const auto gmem = std::get_if<GmemNode>(&*node)) { |
| 610 | const Id gmem_buffer = global_buffers.at(gmem->GetDescriptor()); | 610 | const Id gmem_buffer = global_buffers.at(gmem->GetDescriptor()); |
| 611 | const Id real = BitcastTo<Type::Uint>(Visit(gmem->GetRealAddress())); | 611 | const Id real = BitcastTo<Type::Uint>(Visit(gmem->GetRealAddress())); |
| 612 | const Id base = BitcastTo<Type::Uint>(Visit(gmem->GetBaseAddress())); | 612 | const Id base = BitcastTo<Type::Uint>(Visit(gmem->GetBaseAddress())); |
| @@ -616,7 +616,7 @@ private: | |||
| 616 | return Emit(OpLoad(t_float, Emit(OpAccessChain(t_gmem_float, gmem_buffer, | 616 | return Emit(OpLoad(t_float, Emit(OpAccessChain(t_gmem_float, gmem_buffer, |
| 617 | Constant(t_uint, 0u), offset)))); | 617 | Constant(t_uint, 0u), offset)))); |
| 618 | 618 | ||
| 619 | } else if (const auto conditional = std::get_if<ConditionalNode>(node)) { | 619 | } else if (const auto conditional = std::get_if<ConditionalNode>(&*node)) { |
| 620 | // It's invalid to call conditional on nested nodes, use an operation instead | 620 | // It's invalid to call conditional on nested nodes, use an operation instead |
| 621 | const Id true_label = OpLabel(); | 621 | const Id true_label = OpLabel(); |
| 622 | const Id skip_label = OpLabel(); | 622 | const Id skip_label = OpLabel(); |
| @@ -631,7 +631,7 @@ private: | |||
| 631 | Emit(skip_label); | 631 | Emit(skip_label); |
| 632 | return {}; | 632 | return {}; |
| 633 | 633 | ||
| 634 | } else if (const auto comment = std::get_if<CommentNode>(node)) { | 634 | } else if (const auto comment = std::get_if<CommentNode>(&*node)) { |
| 635 | Name(Emit(OpUndef(t_void)), comment->GetText()); | 635 | Name(Emit(OpUndef(t_void)), comment->GetText()); |
| 636 | return {}; | 636 | return {}; |
| 637 | } | 637 | } |
| @@ -699,18 +699,18 @@ private: | |||
| 699 | } | 699 | } |
| 700 | 700 | ||
| 701 | Id Assign(Operation operation) { | 701 | Id Assign(Operation operation) { |
| 702 | const Node dest = operation[0]; | 702 | const Node& dest = operation[0]; |
| 703 | const Node src = operation[1]; | 703 | const Node& src = operation[1]; |
| 704 | 704 | ||
| 705 | Id target{}; | 705 | Id target{}; |
| 706 | if (const auto gpr = std::get_if<GprNode>(dest)) { | 706 | if (const auto gpr = std::get_if<GprNode>(&*dest)) { |
| 707 | if (gpr->GetIndex() == Register::ZeroIndex) { | 707 | if (gpr->GetIndex() == Register::ZeroIndex) { |
| 708 | // Writing to Register::ZeroIndex is a no op | 708 | // Writing to Register::ZeroIndex is a no op |
| 709 | return {}; | 709 | return {}; |
| 710 | } | 710 | } |
| 711 | target = registers.at(gpr->GetIndex()); | 711 | target = registers.at(gpr->GetIndex()); |
| 712 | 712 | ||
| 713 | } else if (const auto abuf = std::get_if<AbufNode>(dest)) { | 713 | } else if (const auto abuf = std::get_if<AbufNode>(&*dest)) { |
| 714 | target = [&]() -> Id { | 714 | target = [&]() -> Id { |
| 715 | switch (const auto attribute = abuf->GetIndex(); attribute) { | 715 | switch (const auto attribute = abuf->GetIndex(); attribute) { |
| 716 | case Attribute::Index::Position: | 716 | case Attribute::Index::Position: |
| @@ -735,7 +735,7 @@ private: | |||
| 735 | } | 735 | } |
| 736 | }(); | 736 | }(); |
| 737 | 737 | ||
| 738 | } else if (const auto lmem = std::get_if<LmemNode>(dest)) { | 738 | } else if (const auto lmem = std::get_if<LmemNode>(&*dest)) { |
| 739 | Id address = BitcastTo<Type::Uint>(Visit(lmem->GetAddress())); | 739 | Id address = BitcastTo<Type::Uint>(Visit(lmem->GetAddress())); |
| 740 | address = Emit(OpUDiv(t_uint, address, Constant(t_uint, 4))); | 740 | address = Emit(OpUDiv(t_uint, address, Constant(t_uint, 4))); |
| 741 | target = Emit(OpAccessChain(t_prv_float, local_memory, {address})); | 741 | target = Emit(OpAccessChain(t_prv_float, local_memory, {address})); |
| @@ -781,11 +781,11 @@ private: | |||
| 781 | } | 781 | } |
| 782 | 782 | ||
| 783 | Id LogicalAssign(Operation operation) { | 783 | Id LogicalAssign(Operation operation) { |
| 784 | const Node dest = operation[0]; | 784 | const Node& dest = operation[0]; |
| 785 | const Node src = operation[1]; | 785 | const Node& src = operation[1]; |
| 786 | 786 | ||
| 787 | Id target{}; | 787 | Id target{}; |
| 788 | if (const auto pred = std::get_if<PredicateNode>(dest)) { | 788 | if (const auto pred = std::get_if<PredicateNode>(&*dest)) { |
| 789 | ASSERT_MSG(!pred->IsNegated(), "Negating logical assignment"); | 789 | ASSERT_MSG(!pred->IsNegated(), "Negating logical assignment"); |
| 790 | 790 | ||
| 791 | const auto index = pred->GetIndex(); | 791 | const auto index = pred->GetIndex(); |
| @@ -797,7 +797,7 @@ private: | |||
| 797 | } | 797 | } |
| 798 | target = predicates.at(index); | 798 | target = predicates.at(index); |
| 799 | 799 | ||
| 800 | } else if (const auto flag = std::get_if<InternalFlagNode>(dest)) { | 800 | } else if (const auto flag = std::get_if<InternalFlagNode>(&*dest)) { |
| 801 | target = internal_flags.at(static_cast<u32>(flag->GetFlag())); | 801 | target = internal_flags.at(static_cast<u32>(flag->GetFlag())); |
| 802 | } | 802 | } |
| 803 | 803 | ||
| @@ -883,7 +883,7 @@ private: | |||
| 883 | } else { | 883 | } else { |
| 884 | u32 component_value = 0; | 884 | u32 component_value = 0; |
| 885 | if (meta->component) { | 885 | if (meta->component) { |
| 886 | const auto component = std::get_if<ImmediateNode>(meta->component); | 886 | const auto component = std::get_if<ImmediateNode>(&*meta->component); |
| 887 | ASSERT_MSG(component, "Component is not an immediate value"); | 887 | ASSERT_MSG(component, "Component is not an immediate value"); |
| 888 | component_value = component->GetValue(); | 888 | component_value = component->GetValue(); |
| 889 | } | 889 | } |
| @@ -940,7 +940,7 @@ private: | |||
| 940 | } | 940 | } |
| 941 | 941 | ||
| 942 | Id Branch(Operation operation) { | 942 | Id Branch(Operation operation) { |
| 943 | const auto target = std::get_if<ImmediateNode>(operation[0]); | 943 | const auto target = std::get_if<ImmediateNode>(&*operation[0]); |
| 944 | UNIMPLEMENTED_IF(!target); | 944 | UNIMPLEMENTED_IF(!target); |
| 945 | 945 | ||
| 946 | Emit(OpStore(jmp_to, Constant(t_uint, target->GetValue()))); | 946 | Emit(OpStore(jmp_to, Constant(t_uint, target->GetValue()))); |
| @@ -949,7 +949,7 @@ private: | |||
| 949 | } | 949 | } |
| 950 | 950 | ||
| 951 | Id PushFlowStack(Operation operation) { | 951 | Id PushFlowStack(Operation operation) { |
| 952 | const auto target = std::get_if<ImmediateNode>(operation[0]); | 952 | const auto target = std::get_if<ImmediateNode>(&*operation[0]); |
| 953 | ASSERT(target); | 953 | ASSERT(target); |
| 954 | 954 | ||
| 955 | const Id current = Emit(OpLoad(t_uint, flow_stack_top)); | 955 | const Id current = Emit(OpLoad(t_uint, flow_stack_top)); |