summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/maxwell
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell')
-rw-r--r--src/shader_recompiler/frontend/maxwell/maxwell.inc4
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp8
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp209
3 files changed, 211 insertions, 10 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/maxwell.inc b/src/shader_recompiler/frontend/maxwell/maxwell.inc
index c6cd2a79b..d668dc1aa 100644
--- a/src/shader_recompiler/frontend/maxwell/maxwell.inc
+++ b/src/shader_recompiler/frontend/maxwell/maxwell.inc
@@ -254,8 +254,8 @@ INST(TEX_b, "TEX (b)", "1101 1110 10-- ----")
254INST(TEXS, "TEXS", "1101 -00- ---- ----") 254INST(TEXS, "TEXS", "1101 -00- ---- ----")
255INST(TLD, "TLD", "1101 1100 --11 1---") 255INST(TLD, "TLD", "1101 1100 --11 1---")
256INST(TLD_b, "TLD (b)", "1101 1101 --11 1---") 256INST(TLD_b, "TLD (b)", "1101 1101 --11 1---")
257INST(TLD4, "TLD4", "1100 10-- --11 1---") 257INST(TLD4, "TLD4", "1100 10-- ---- ----")
258INST(TLD4_b, "TLD4 (b)", "1101 1110 1111 1---") 258INST(TLD4_b, "TLD4 (b)", "1101 1110 11-- ----")
259INST(TLD4S, "TLD4S", "1101 1111 -0-- ----") 259INST(TLD4S, "TLD4S", "1101 1111 -0-- ----")
260INST(TLDS, "TLDS", "1101 -01- ---- ----") 260INST(TLDS, "TLDS", "1101 -01- ---- ----")
261INST(TMML, "TMML", "1101 1111 0101 1---") 261INST(TMML, "TMML", "1101 1111 0101 1---")
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
index 3ccd7b925..e59c3326e 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
@@ -349,14 +349,6 @@ void TranslatorVisitor::TLD_b(u64) {
349 ThrowNotImplemented(Opcode::TLD_b); 349 ThrowNotImplemented(Opcode::TLD_b);
350} 350}
351 351
352void TranslatorVisitor::TLD4(u64) {
353 ThrowNotImplemented(Opcode::TLD4);
354}
355
356void TranslatorVisitor::TLD4_b(u64) {
357 ThrowNotImplemented(Opcode::TLD4_b);
358}
359
360void TranslatorVisitor::TLD4S(u64) { 352void TranslatorVisitor::TLD4S(u64) {
361 ThrowNotImplemented(Opcode::TLD4S); 353 ThrowNotImplemented(Opcode::TLD4S);
362} 354}
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp
new file mode 100644
index 000000000..d64865876
--- /dev/null
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp
@@ -0,0 +1,209 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <optional>
6
7#include "common/bit_field.h"
8#include "common/common_types.h"
9#include "shader_recompiler/frontend/ir/modifiers.h"
10#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
11
12namespace Shader::Maxwell {
13namespace {
14
15enum class TextureType : u64 {
16 _1D,
17 ARRAY_1D,
18 _2D,
19 ARRAY_2D,
20 _3D,
21 ARRAY_3D,
22 CUBE,
23 ARRAY_CUBE,
24};
25
26enum class OffsetType : u64 {
27 None = 0,
28 AOFFI,
29 PTP,
30 Invalid,
31};
32
33enum class ComponentType : u64 {
34 R = 0,
35 G = 1,
36 B = 2,
37 A = 3,
38};
39
40Shader::TextureType GetType(TextureType type, bool dc) {
41 switch (type) {
42 case TextureType::_1D:
43 return dc ? Shader::TextureType::Shadow1D : Shader::TextureType::Color1D;
44 case TextureType::ARRAY_1D:
45 return dc ? Shader::TextureType::ShadowArray1D : Shader::TextureType::ColorArray1D;
46 case TextureType::_2D:
47 return dc ? Shader::TextureType::Shadow2D : Shader::TextureType::Color2D;
48 case TextureType::ARRAY_2D:
49 return dc ? Shader::TextureType::ShadowArray2D : Shader::TextureType::ColorArray2D;
50 case TextureType::_3D:
51 return dc ? Shader::TextureType::Shadow3D : Shader::TextureType::Color3D;
52 case TextureType::ARRAY_3D:
53 throw NotImplementedException("3D array texture type");
54 case TextureType::CUBE:
55 return dc ? Shader::TextureType::ShadowCube : Shader::TextureType::ColorCube;
56 case TextureType::ARRAY_CUBE:
57 return dc ? Shader::TextureType::ShadowArrayCube : Shader::TextureType::ColorArrayCube;
58 }
59 throw NotImplementedException("Invalid texture type {}", type);
60}
61
62IR::Value MakeCoords(TranslatorVisitor& v, IR::Reg reg, TextureType type) {
63 const auto read_array{[&]() -> IR::F32 { return v.ir.ConvertUToF(32, 16, v.X(reg)); }};
64 switch (type) {
65 case TextureType::_1D:
66 return v.F(reg);
67 case TextureType::ARRAY_1D:
68 return v.ir.CompositeConstruct(read_array(), v.F(reg + 1));
69 case TextureType::_2D:
70 return v.ir.CompositeConstruct(v.F(reg), v.F(reg + 1));
71 case TextureType::ARRAY_2D:
72 return v.ir.CompositeConstruct(read_array(), v.F(reg + 1), v.F(reg + 2));
73 case TextureType::_3D:
74 return v.ir.CompositeConstruct(v.F(reg), v.F(reg + 1), v.F(reg + 2));
75 case TextureType::ARRAY_3D:
76 throw NotImplementedException("3D array texture type");
77 case TextureType::CUBE:
78 return v.ir.CompositeConstruct(v.F(reg), v.F(reg + 1), v.F(reg + 2));
79 case TextureType::ARRAY_CUBE:
80 return v.ir.CompositeConstruct(read_array(), v.F(reg + 1), v.F(reg + 2), v.F(reg + 3));
81 }
82 throw NotImplementedException("Invalid texture type {}", type);
83}
84
85IR::Value MakeOffset(TranslatorVisitor& v, IR::Reg& reg, TextureType type) {
86 const IR::U32 value{v.X(reg++)};
87 switch (type) {
88 case TextureType::_1D:
89 case TextureType::ARRAY_1D:
90 return v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(6), true);
91 case TextureType::_2D:
92 case TextureType::ARRAY_2D:
93 return v.ir.CompositeConstruct(
94 v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(6), true),
95 v.ir.BitFieldExtract(value, v.ir.Imm32(8), v.ir.Imm32(6), true));
96 case TextureType::_3D:
97 case TextureType::ARRAY_3D:
98 return v.ir.CompositeConstruct(
99 v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(6), true),
100 v.ir.BitFieldExtract(value, v.ir.Imm32(8), v.ir.Imm32(6), true),
101 v.ir.BitFieldExtract(value, v.ir.Imm32(16), v.ir.Imm32(6), true));
102 case TextureType::CUBE:
103 case TextureType::ARRAY_CUBE:
104 throw NotImplementedException("Illegal offset on CUBE sample");
105 }
106 throw NotImplementedException("Invalid texture type {}", type);
107}
108
109std::pair<IR::Value, IR::Value> MakeOffsetPTP(TranslatorVisitor& v, IR::Reg& reg) {
110 const IR::U32 value1{v.X(reg++)};
111 const IR::U32 value2{v.X(reg++)};
112 const auto getVector = ([&v](const IR::U32& value) {
113 return v.ir.CompositeConstruct(
114 v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(6), true),
115 v.ir.BitFieldExtract(value, v.ir.Imm32(8), v.ir.Imm32(6), true),
116 v.ir.BitFieldExtract(value, v.ir.Imm32(16), v.ir.Imm32(6), true),
117 v.ir.BitFieldExtract(value, v.ir.Imm32(24), v.ir.Imm32(6), true));
118 });
119 return {getVector(value1), getVector(value2)};
120}
121
122void Impl(TranslatorVisitor& v, u64 insn, ComponentType component_type, OffsetType offset_type,
123 bool is_bindless) {
124 union {
125 u64 raw;
126 BitField<35, 1, u64> ndv;
127 BitField<49, 1, u64> nodep;
128 BitField<50, 1, u64> dc;
129 BitField<51, 3, IR::Pred> sparse_pred;
130 BitField<0, 8, IR::Reg> dest_reg;
131 BitField<8, 8, IR::Reg> coord_reg;
132 BitField<20, 8, IR::Reg> meta_reg;
133 BitField<28, 3, TextureType> type;
134 BitField<31, 4, u64> mask;
135 BitField<36, 13, u64> cbuf_offset;
136 } const tld4{insn};
137
138 const IR::Value coords{MakeCoords(v, tld4.coord_reg, tld4.type)};
139
140 IR::Reg meta_reg{tld4.meta_reg};
141 IR::Value handle;
142 IR::Value offset;
143 IR::Value offset2;
144 IR::F32 dref;
145 if (!is_bindless) {
146 handle = v.ir.Imm32(static_cast<u32>(tld4.cbuf_offset.Value() * 4));
147 } else {
148 handle = v.X(meta_reg++);
149 }
150 switch (offset_type) {
151 case OffsetType::None:
152 break;
153 case OffsetType::AOFFI: {
154 offset = MakeOffset(v, meta_reg, tld4.type);
155 break;
156 }
157 case OffsetType::PTP: {
158 std::tie(offset, offset2) = MakeOffsetPTP(v, meta_reg);
159 break;
160 }
161 default:
162 throw NotImplementedException("Invalid offset type {}", offset_type);
163 }
164 if (tld4.dc != 0) {
165 dref = v.F(meta_reg++);
166 }
167 IR::TextureInstInfo info{};
168 info.type.Assign(GetType(tld4.type, tld4.dc != 0));
169 info.gather_component.Assign(static_cast<u32>(component_type));
170 const IR::Value sample{[&]() -> IR::Value {
171 if (tld4.dc == 0) {
172 return v.ir.ImageGather(handle, coords, offset, offset2, info);
173 }
174 return v.ir.ImageGatherDref(handle, coords, offset, offset2, dref, info);
175 }()};
176
177 IR::Reg dest_reg{tld4.dest_reg};
178 for (size_t element = 0; element < 4; ++element) {
179 if (((tld4.mask >> element) & 1) == 0) {
180 continue;
181 }
182 v.F(dest_reg, IR::F32{v.ir.CompositeExtract(sample, element)});
183 ++dest_reg;
184 }
185 if (tld4.sparse_pred != IR::Pred::PT) {
186 v.ir.SetPred(tld4.sparse_pred, v.ir.LogicalNot(v.ir.GetSparseFromOp(sample)));
187 }
188}
189} // Anonymous namespace
190
191void TranslatorVisitor::TLD4(u64 insn) {
192 union {
193 u64 raw;
194 BitField<56, 2, ComponentType> component;
195 BitField<54, 2, OffsetType> offset;
196 } const tld4{insn};
197 Impl(*this, insn, tld4.component, tld4.offset, false);
198}
199
200void TranslatorVisitor::TLD4_b(u64 insn) {
201 union {
202 u64 raw;
203 BitField<38, 2, ComponentType> component;
204 BitField<36, 2, OffsetType> offset;
205 } const tld4{insn};
206 Impl(*this, insn, tld4.component, tld4.offset, true);
207}
208
209} // namespace Shader::Maxwell