diff options
| author | 2019-05-19 15:51:06 +0100 | |
|---|---|---|
| committer | 2019-05-19 15:51:06 +0100 | |
| commit | 2aebbe9bf9d9214fc746cd556e2e051a0f5d8121 (patch) | |
| tree | 2734dcb4043438a502dbf5d6dfb6d4c3d8f15af7 /src | |
| parent | Merge pull request #2495 from lioncash/cache (diff) | |
| parent | shader/shader_ir: Remove unnecessary inline specifiers (diff) | |
| download | yuzu-2aebbe9bf9d9214fc746cd556e2e051a0f5d8121.tar.gz yuzu-2aebbe9bf9d9214fc746cd556e2e051a0f5d8121.tar.xz yuzu-2aebbe9bf9d9214fc746cd556e2e051a0f5d8121.zip | |
Merge pull request #2497 from lioncash/shader-ir
shader/shader_ir: Minor changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/shader/shader_ir.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/shader/shader_ir.h | 41 | ||||
| -rw-r--r-- | src/video_core/shader/track.cpp | 12 |
3 files changed, 28 insertions, 32 deletions
diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp index e4eb0dfd9..196235e5d 100644 --- a/src/video_core/shader/shader_ir.cpp +++ b/src/video_core/shader/shader_ir.cpp | |||
| @@ -21,6 +21,13 @@ using Tegra::Shader::PredCondition; | |||
| 21 | using Tegra::Shader::PredOperation; | 21 | using Tegra::Shader::PredOperation; |
| 22 | using Tegra::Shader::Register; | 22 | using Tegra::Shader::Register; |
| 23 | 23 | ||
| 24 | ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset) | ||
| 25 | : program_code{program_code}, main_offset{main_offset} { | ||
| 26 | Decode(); | ||
| 27 | } | ||
| 28 | |||
| 29 | ShaderIR::~ShaderIR() = default; | ||
| 30 | |||
| 24 | Node ShaderIR::StoreNode(NodeData&& node_data) { | 31 | Node ShaderIR::StoreNode(NodeData&& node_data) { |
| 25 | auto store = std::make_unique<NodeData>(node_data); | 32 | auto store = std::make_unique<NodeData>(node_data); |
| 26 | const Node node = store.get(); | 33 | const Node node = store.get(); |
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 65f1e1de9..e4253fdb3 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h | |||
| @@ -328,40 +328,31 @@ struct MetaTexture { | |||
| 328 | u32 element{}; | 328 | u32 element{}; |
| 329 | }; | 329 | }; |
| 330 | 330 | ||
| 331 | inline constexpr MetaArithmetic PRECISE = {true}; | 331 | constexpr MetaArithmetic PRECISE = {true}; |
| 332 | inline constexpr MetaArithmetic NO_PRECISE = {false}; | 332 | constexpr MetaArithmetic NO_PRECISE = {false}; |
| 333 | 333 | ||
| 334 | using Meta = std::variant<MetaArithmetic, MetaTexture, Tegra::Shader::HalfType>; | 334 | using Meta = std::variant<MetaArithmetic, MetaTexture, Tegra::Shader::HalfType>; |
| 335 | 335 | ||
| 336 | /// Holds any kind of operation that can be done in the IR | 336 | /// Holds any kind of operation that can be done in the IR |
| 337 | class OperationNode final { | 337 | class OperationNode final { |
| 338 | public: | 338 | public: |
| 339 | template <typename... T> | 339 | explicit OperationNode(OperationCode code) : code{code} {} |
| 340 | explicit constexpr OperationNode(OperationCode code) : code{code}, meta{} {} | ||
| 341 | 340 | ||
| 342 | template <typename... T> | 341 | explicit OperationNode(OperationCode code, Meta&& meta) : code{code}, meta{std::move(meta)} {} |
| 343 | explicit constexpr OperationNode(OperationCode code, Meta&& meta) | ||
| 344 | : code{code}, meta{std::move(meta)} {} | ||
| 345 | 342 | ||
| 346 | template <typename... T> | 343 | template <typename... T> |
| 347 | explicit constexpr OperationNode(OperationCode code, const T*... operands) | 344 | explicit OperationNode(OperationCode code, const T*... operands) |
| 348 | : OperationNode(code, {}, operands...) {} | 345 | : OperationNode(code, {}, operands...) {} |
| 349 | 346 | ||
| 350 | template <typename... T> | 347 | template <typename... T> |
| 351 | explicit constexpr OperationNode(OperationCode code, Meta&& meta, const T*... operands_) | 348 | explicit OperationNode(OperationCode code, Meta&& meta, const T*... operands_) |
| 352 | : code{code}, meta{std::move(meta)} { | 349 | : code{code}, meta{std::move(meta)}, operands{operands_...} {} |
| 353 | |||
| 354 | auto operands_list = {operands_...}; | ||
| 355 | for (auto& operand : operands_list) { | ||
| 356 | operands.push_back(operand); | ||
| 357 | } | ||
| 358 | } | ||
| 359 | 350 | ||
| 360 | explicit OperationNode(OperationCode code, Meta&& meta, std::vector<Node>&& operands) | 351 | explicit OperationNode(OperationCode code, Meta&& meta, std::vector<Node>&& operands) |
| 361 | : code{code}, meta{meta}, operands{std::move(operands)} {} | 352 | : code{code}, meta{meta}, operands{std::move(operands)} {} |
| 362 | 353 | ||
| 363 | explicit OperationNode(OperationCode code, std::vector<Node>&& operands) | 354 | explicit OperationNode(OperationCode code, std::vector<Node>&& operands) |
| 364 | : code{code}, meta{}, operands{std::move(operands)} {} | 355 | : code{code}, operands{std::move(operands)} {} |
| 365 | 356 | ||
| 366 | OperationCode GetCode() const { | 357 | OperationCode GetCode() const { |
| 367 | return code; | 358 | return code; |
| @@ -567,11 +558,8 @@ private: | |||
| 567 | 558 | ||
| 568 | class ShaderIR final { | 559 | class ShaderIR final { |
| 569 | public: | 560 | public: |
| 570 | explicit ShaderIR(const ProgramCode& program_code, u32 main_offset) | 561 | explicit ShaderIR(const ProgramCode& program_code, u32 main_offset); |
| 571 | : program_code{program_code}, main_offset{main_offset} { | 562 | ~ShaderIR(); |
| 572 | |||
| 573 | Decode(); | ||
| 574 | } | ||
| 575 | 563 | ||
| 576 | const std::map<u32, NodeBlock>& GetBasicBlocks() const { | 564 | const std::map<u32, NodeBlock>& GetBasicBlocks() const { |
| 577 | return basic_blocks; | 565 | return basic_blocks; |
| @@ -814,11 +802,12 @@ private: | |||
| 814 | void WriteLop3Instruction(NodeBlock& bb, Tegra::Shader::Register dest, Node op_a, Node op_b, | 802 | void WriteLop3Instruction(NodeBlock& bb, Tegra::Shader::Register dest, Node op_a, Node op_b, |
| 815 | Node op_c, Node imm_lut, bool sets_cc); | 803 | Node op_c, Node imm_lut, bool sets_cc); |
| 816 | 804 | ||
| 817 | Node TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor); | 805 | Node TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) const; |
| 818 | 806 | ||
| 819 | std::optional<u32> TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor); | 807 | std::optional<u32> TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) const; |
| 820 | 808 | ||
| 821 | std::pair<Node, s64> TrackRegister(const GprNode* tracked, const NodeBlock& code, s64 cursor); | 809 | std::pair<Node, s64> TrackRegister(const GprNode* tracked, const NodeBlock& code, |
| 810 | s64 cursor) const; | ||
| 822 | 811 | ||
| 823 | std::tuple<Node, Node, GlobalMemoryBase> TrackAndGetGlobalMemory(NodeBlock& bb, | 812 | std::tuple<Node, Node, GlobalMemoryBase> TrackAndGetGlobalMemory(NodeBlock& bb, |
| 824 | Node addr_register, | 813 | Node addr_register, |
| @@ -835,12 +824,10 @@ private: | |||
| 835 | return StoreNode(OperationNode(code, std::move(meta), operands...)); | 824 | return StoreNode(OperationNode(code, std::move(meta), operands...)); |
| 836 | } | 825 | } |
| 837 | 826 | ||
| 838 | template <typename... T> | ||
| 839 | Node Operation(OperationCode code, std::vector<Node>&& operands) { | 827 | Node Operation(OperationCode code, std::vector<Node>&& operands) { |
| 840 | return StoreNode(OperationNode(code, std::move(operands))); | 828 | return StoreNode(OperationNode(code, std::move(operands))); |
| 841 | } | 829 | } |
| 842 | 830 | ||
| 843 | template <typename... T> | ||
| 844 | Node Operation(OperationCode code, Meta&& meta, std::vector<Node>&& operands) { | 831 | Node Operation(OperationCode code, Meta&& meta, std::vector<Node>&& operands) { |
| 845 | return StoreNode(OperationNode(code, std::move(meta), std::move(operands))); | 832 | return StoreNode(OperationNode(code, std::move(meta), std::move(operands))); |
| 846 | } | 833 | } |
diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp index 4505667ff..19ede1eb9 100644 --- a/src/video_core/shader/track.cpp +++ b/src/video_core/shader/track.cpp | |||
| @@ -17,22 +17,24 @@ std::pair<Node, s64> FindOperation(const NodeBlock& code, s64 cursor, | |||
| 17 | for (; cursor >= 0; --cursor) { | 17 | for (; cursor >= 0; --cursor) { |
| 18 | const Node node = code.at(cursor); | 18 | const Node node = code.at(cursor); |
| 19 | if (const auto operation = std::get_if<OperationNode>(node)) { | 19 | if (const auto operation = std::get_if<OperationNode>(node)) { |
| 20 | if (operation->GetCode() == operation_code) | 20 | if (operation->GetCode() == operation_code) { |
| 21 | return {node, cursor}; | 21 | return {node, cursor}; |
| 22 | } | ||
| 22 | } | 23 | } |
| 23 | if (const auto conditional = std::get_if<ConditionalNode>(node)) { | 24 | if (const auto conditional = std::get_if<ConditionalNode>(node)) { |
| 24 | const auto& conditional_code = conditional->GetCode(); | 25 | const auto& conditional_code = conditional->GetCode(); |
| 25 | const auto [found, internal_cursor] = FindOperation( | 26 | const auto [found, internal_cursor] = FindOperation( |
| 26 | conditional_code, static_cast<s64>(conditional_code.size() - 1), operation_code); | 27 | conditional_code, static_cast<s64>(conditional_code.size() - 1), operation_code); |
| 27 | if (found) | 28 | if (found) { |
| 28 | return {found, cursor}; | 29 | return {found, cursor}; |
| 30 | } | ||
| 29 | } | 31 | } |
| 30 | } | 32 | } |
| 31 | return {}; | 33 | return {}; |
| 32 | } | 34 | } |
| 33 | } // namespace | 35 | } // namespace |
| 34 | 36 | ||
| 35 | Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) { | 37 | Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) const { |
| 36 | if (const auto cbuf = std::get_if<CbufNode>(tracked)) { | 38 | if (const auto cbuf = std::get_if<CbufNode>(tracked)) { |
| 37 | // Cbuf found, but it has to be immediate | 39 | // Cbuf found, but it has to be immediate |
| 38 | return std::holds_alternative<ImmediateNode>(*cbuf->GetOffset()) ? tracked : nullptr; | 40 | return std::holds_alternative<ImmediateNode>(*cbuf->GetOffset()) ? tracked : nullptr; |
| @@ -65,7 +67,7 @@ Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) { | |||
| 65 | return nullptr; | 67 | return nullptr; |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 68 | std::optional<u32> ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) { | 70 | std::optional<u32> ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) const { |
| 69 | // Reduce the cursor in one to avoid infinite loops when the instruction sets the same register | 71 | // Reduce the cursor in one to avoid infinite loops when the instruction sets the same register |
| 70 | // that it uses as operand | 72 | // that it uses as operand |
| 71 | const auto [found, found_cursor] = | 73 | const auto [found, found_cursor] = |
| @@ -80,7 +82,7 @@ std::optional<u32> ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, | |||
| 80 | } | 82 | } |
| 81 | 83 | ||
| 82 | std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, | 84 | std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, |
| 83 | s64 cursor) { | 85 | s64 cursor) const { |
| 84 | for (; cursor >= 0; --cursor) { | 86 | for (; cursor >= 0; --cursor) { |
| 85 | const auto [found_node, new_cursor] = FindOperation(code, cursor, OperationCode::Assign); | 87 | const auto [found_node, new_cursor] = FindOperation(code, cursor, OperationCode::Assign); |
| 86 | if (!found_node) { | 88 | if (!found_node) { |