diff options
Diffstat (limited to 'src/video_core/shader/track.cpp')
| -rw-r--r-- | src/video_core/shader/track.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp index 33b071747..4505667ff 100644 --- a/src/video_core/shader/track.cpp +++ b/src/video_core/shader/track.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <utility> | 6 | #include <utility> |
| 7 | #include <variant> | 7 | #include <variant> |
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | ||
| 9 | #include "video_core/shader/shader_ir.h" | 10 | #include "video_core/shader/shader_ir.h" |
| 10 | 11 | ||
| 11 | namespace VideoCommon::Shader { | 12 | namespace VideoCommon::Shader { |
| @@ -14,7 +15,7 @@ namespace { | |||
| 14 | std::pair<Node, s64> FindOperation(const NodeBlock& code, s64 cursor, | 15 | std::pair<Node, s64> FindOperation(const NodeBlock& code, s64 cursor, |
| 15 | OperationCode operation_code) { | 16 | OperationCode operation_code) { |
| 16 | for (; cursor >= 0; --cursor) { | 17 | for (; cursor >= 0; --cursor) { |
| 17 | const Node node = code[cursor]; | 18 | const Node node = code.at(cursor); |
| 18 | if (const auto operation = std::get_if<OperationNode>(node)) { | 19 | if (const auto operation = std::get_if<OperationNode>(node)) { |
| 19 | if (operation->GetCode() == operation_code) | 20 | if (operation->GetCode() == operation_code) |
| 20 | return {node, cursor}; | 21 | return {node, cursor}; |
| @@ -64,6 +65,20 @@ Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) { | |||
| 64 | return nullptr; | 65 | return nullptr; |
| 65 | } | 66 | } |
| 66 | 67 | ||
| 68 | std::optional<u32> ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) { | ||
| 69 | // Reduce the cursor in one to avoid infinite loops when the instruction sets the same register | ||
| 70 | // that it uses as operand | ||
| 71 | const auto [found, found_cursor] = | ||
| 72 | TrackRegister(&std::get<GprNode>(*tracked), code, cursor - 1); | ||
| 73 | if (!found) { | ||
| 74 | return {}; | ||
| 75 | } | ||
| 76 | if (const auto immediate = std::get_if<ImmediateNode>(found)) { | ||
| 77 | return immediate->GetValue(); | ||
| 78 | } | ||
| 79 | return {}; | ||
| 80 | } | ||
| 81 | |||
| 67 | std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, | 82 | std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, |
| 68 | s64 cursor) { | 83 | s64 cursor) { |
| 69 | for (; cursor >= 0; --cursor) { | 84 | for (; cursor >= 0; --cursor) { |