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/translate_program.cpp95
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.h4
2 files changed, 99 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 267ebe4af..40c9307db 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
@@ -5,6 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6#include <memory> 6#include <memory>
7#include <vector> 7#include <vector>
8#include <queue>
8 9
9#include "common/settings.h" 10#include "common/settings.h"
10#include "shader_recompiler/exception.h" 11#include "shader_recompiler/exception.h"
@@ -226,4 +227,98 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b
226 return result; 227 return result;
227} 228}
228 229
230bool IsLegacyAttribute(IR::Attribute attribute) {
231 return (attribute >= IR::Attribute::ColorFrontDiffuseR &&
232 attribute <= IR::Attribute::ColorBackSpecularA) ||
233 attribute == IR::Attribute::FogCoordinate ||
234 (attribute >= IR::Attribute::FixedFncTexture0S &&
235 attribute <= IR::Attribute::FixedFncTexture9Q);
236}
237
238std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings(
239 const VaryingState& state, std::queue<IR::Attribute> ununsed_generics) {
240 std::map<IR::Attribute, IR::Attribute> mapping;
241 for (size_t index = 0; index < 4; ++index) {
242 auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4;
243 if (state.AnyComponent(attr)) {
244 for (size_t i = 0; i < 4; ++i) {
245 mapping.insert({attr + i, ununsed_generics.front() + i});
246 }
247 ununsed_generics.pop();
248 }
249 }
250 if (state[IR::Attribute::FogCoordinate]) {
251 mapping.insert({IR::Attribute::FogCoordinate, ununsed_generics.front()});
252 ununsed_generics.pop();
253 }
254 for (size_t index = 0; index < IR::NUM_FIXED_FNC_TEXTURES; ++index) {
255 auto attr = IR::Attribute::FixedFncTexture0S + index * 4;
256 if (state.AnyComponent(attr)) {
257 for (size_t i = 0; i < 4; ++i) {
258 mapping.insert({attr + i, ununsed_generics.front() + i});
259 }
260 ununsed_generics.pop();
261 }
262 }
263 return mapping;
264}
265
266void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& runtime_info) {
267 auto& stores = program.info.stores;
268 if (stores.Legacy()) {
269 std::queue<IR::Attribute> ununsed_output_generics{};
270 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
271 if (!stores.Generic(index)) {
272 ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4);
273 }
274 }
275 auto mappings = GenerateLegacyToGenericMappings(stores, ununsed_output_generics);
276 for (IR::Block* const block : program.post_order_blocks) {
277 for (IR::Inst& inst : block->Instructions()) {
278 switch (inst.GetOpcode()) {
279 case IR::Opcode::SetAttribute: {
280 const auto attr = inst.Arg(0).Attribute();
281 if (IsLegacyAttribute(attr)) {
282 stores.Set(mappings[attr], true);
283 inst.SetArg(0, Shader::IR::Value(mappings[attr]));
284 }
285 break;
286 }
287 default:
288 break;
289 }
290 }
291 }
292 }
293
294 auto& loads = program.info.loads;
295 if (loads.Legacy()) {
296 std::queue<IR::Attribute> ununsed_input_generics{};
297 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
298 const AttributeType input_type{runtime_info.generic_input_types[index]};
299 if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) ||
300 input_type == AttributeType::Disabled) {
301 ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4);
302 }
303 }
304 auto mappings = GenerateLegacyToGenericMappings(loads, ununsed_input_generics);
305 for (IR::Block* const block : program.post_order_blocks) {
306 for (IR::Inst& inst : block->Instructions()) {
307 switch (inst.GetOpcode()) {
308 case IR::Opcode::GetAttribute: {
309 const auto attr = inst.Arg(0).Attribute();
310 if (IsLegacyAttribute(attr)) {
311 loads.Set(mappings[attr], true);
312 inst.SetArg(0, Shader::IR::Value(mappings[attr]));
313 }
314 break;
315 }
316 default:
317 break;
318 }
319 }
320 }
321 }
322}
323
229} // namespace Shader::Maxwell 324} // namespace Shader::Maxwell
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.h b/src/shader_recompiler/frontend/maxwell/translate_program.h
index a84814811..cd535f20d 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.h
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.h
@@ -10,6 +10,7 @@
10#include "shader_recompiler/frontend/maxwell/control_flow.h" 10#include "shader_recompiler/frontend/maxwell/control_flow.h"
11#include "shader_recompiler/host_translate_info.h" 11#include "shader_recompiler/host_translate_info.h"
12#include "shader_recompiler/object_pool.h" 12#include "shader_recompiler/object_pool.h"
13#include "shader_recompiler/runtime_info.h"
13 14
14namespace Shader::Maxwell { 15namespace Shader::Maxwell {
15 16
@@ -20,4 +21,7 @@ namespace Shader::Maxwell {
20[[nodiscard]] IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b, 21[[nodiscard]] IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b,
21 Environment& env_vertex_b); 22 Environment& env_vertex_b);
22 23
24[[nodiscard]] void ConvertLegacyToGeneric(IR::Program& program,
25 const Shader::RuntimeInfo& runtime_info);
26
23} // namespace Shader::Maxwell 27} // namespace Shader::Maxwell