summaryrefslogtreecommitdiff
path: root/src/video_core/shader/track.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-01-05 15:23:24 -0400
committerGravatar FernandoS272020-01-24 16:43:30 -0400
commit603c861532ed1a89254556ff84bbe121bd700765 (patch)
tree8bf8f67ff6393ce7b00b04a3b4b2d596cd8eb5bc /src/video_core/shader/track.cpp
parentShader_IR: Address Feedback (diff)
downloadyuzu-603c861532ed1a89254556ff84bbe121bd700765.tar.gz
yuzu-603c861532ed1a89254556ff84bbe121bd700765.tar.xz
yuzu-603c861532ed1a89254556ff84bbe121bd700765.zip
Shader_IR: Implement initial code for tracking indexed samplers.
Diffstat (limited to 'src/video_core/shader/track.cpp')
-rw-r--r--src/video_core/shader/track.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp
index 165c79330..69a677394 100644
--- a/src/video_core/shader/track.cpp
+++ b/src/video_core/shader/track.cpp
@@ -8,6 +8,7 @@
8 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "video_core/shader/node.h" 10#include "video_core/shader/node.h"
11#include "video_core/shader/node_helper.h"
11#include "video_core/shader/shader_ir.h" 12#include "video_core/shader/shader_ir.h"
12 13
13namespace VideoCommon::Shader { 14namespace VideoCommon::Shader {
@@ -37,6 +38,87 @@ std::pair<Node, s64> FindOperation(const NodeBlock& code, s64 cursor,
37} 38}
38} // Anonymous namespace 39} // Anonymous namespace
39 40
41std::optional<std::pair<Node, Node>> DecoupleIndirectRead(const OperationNode& operation) {
42 if (operation.GetCode() != OperationCode::UAdd) {
43 return std::nullopt;
44 }
45 Node gpr{};
46 Node offset{};
47 if (operation.GetOperandsCount() != 2) {
48 return std::nullopt;
49 }
50 for (std::size_t i = 0; i < operation.GetOperandsCount(); i++) {
51 Node operand = operation[i];
52 if (std::holds_alternative<ImmediateNode>(*operand)) {
53 offset = operation[i];
54 } else if (std::holds_alternative<GprNode>(*operand)) {
55 gpr = operation[i];
56 }
57 }
58 if (offset && gpr) {
59 return {std::make_pair(gpr, offset)};
60 }
61 return std::nullopt;
62}
63
64std::tuple<Node, TrackSampler> ShaderIR::TrackSampler(Node tracked, const NodeBlock& code,
65 s64 cursor) const {
66 if (const auto cbuf = std::get_if<CbufNode>(&*tracked)) {
67 // Constant buffer found, test if it's an immediate
68 const auto offset = cbuf->GetOffset();
69 if (const auto immediate = std::get_if<ImmediateNode>(&*offset)) {
70 auto track =
71 MakeTrackSampler<BindlessSamplerNode>(cbuf->GetIndex(), immediate->GetValue());
72 return {tracked, track};
73 } else if (const auto operation = std::get_if<OperationNode>(&*offset)) {
74 auto bound_buffer = locker.ObtainBoundBuffer();
75 if (!bound_buffer) {
76 return {};
77 }
78 if (*bound_buffer != cbuf->GetIndex()) {
79 return {};
80 }
81 auto pair = DecoupleIndirectRead(*operation);
82 if (!pair) {
83 return {};
84 }
85 auto [gpr, base_offset] = *pair;
86 const auto offset_inm = std::get_if<ImmediateNode>(&*base_offset);
87 // TODO Implement Bindless Index custom variable
88 auto track =
89 MakeTrackSampler<ArraySamplerNode>(cbuf->GetIndex(), offset_inm->GetValue(), 0);
90 return {tracked, track};
91 }
92 return {};
93 }
94 if (const auto gpr = std::get_if<GprNode>(&*tracked)) {
95 if (gpr->GetIndex() == Tegra::Shader::Register::ZeroIndex) {
96 return {};
97 }
98 // Reduce the cursor in one to avoid infinite loops when the instruction sets the same
99 // register that it uses as operand
100 const auto [source, new_cursor] = TrackRegister(gpr, code, cursor - 1);
101 if (!source) {
102 return {};
103 }
104 return TrackSampler(source, code, new_cursor);
105 }
106 if (const auto operation = std::get_if<OperationNode>(&*tracked)) {
107 for (std::size_t i = operation->GetOperandsCount(); i > 0; --i) {
108 if (auto found = TrackSampler((*operation)[i - 1], code, cursor); std::get<0>(found)) {
109 // Cbuf found in operand.
110 return found;
111 }
112 }
113 return {};
114 }
115 if (const auto conditional = std::get_if<ConditionalNode>(&*tracked)) {
116 const auto& conditional_code = conditional->GetCode();
117 return TrackSampler(tracked, conditional_code, static_cast<s64>(conditional_code.size()));
118 }
119 return {};
120}
121
40std::tuple<Node, u32, u32> ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, 122std::tuple<Node, u32, u32> ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code,
41 s64 cursor) const { 123 s64 cursor) const {
42 if (const auto cbuf = std::get_if<CbufNode>(&*tracked)) { 124 if (const auto cbuf = std::get_if<CbufNode>(&*tracked)) {