summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend')
-rw-r--r--src/shader_recompiler/frontend/ir/attribute.h2
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.inc1
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp95
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.h4
4 files changed, 102 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/attribute.h b/src/shader_recompiler/frontend/ir/attribute.h
index ca1199494..3bbd38a03 100644
--- a/src/shader_recompiler/frontend/ir/attribute.h
+++ b/src/shader_recompiler/frontend/ir/attribute.h
@@ -224,6 +224,8 @@ enum class Attribute : u64 {
224 224
225constexpr size_t NUM_GENERICS = 32; 225constexpr size_t NUM_GENERICS = 32;
226 226
227constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
228
227[[nodiscard]] bool IsGeneric(Attribute attribute) noexcept; 229[[nodiscard]] bool IsGeneric(Attribute attribute) noexcept;
228 230
229[[nodiscard]] u32 GenericAttributeIndex(Attribute attribute); 231[[nodiscard]] u32 GenericAttributeIndex(Attribute attribute);
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc
index 6929919df..b94ce7406 100644
--- a/src/shader_recompiler/frontend/ir/opcodes.inc
+++ b/src/shader_recompiler/frontend/ir/opcodes.inc
@@ -40,6 +40,7 @@ OPCODE(GetCbufU32, U32, U32,
40OPCODE(GetCbufF32, F32, U32, U32, ) 40OPCODE(GetCbufF32, F32, U32, U32, )
41OPCODE(GetCbufU32x2, U32x2, U32, U32, ) 41OPCODE(GetCbufU32x2, U32x2, U32, U32, )
42OPCODE(GetAttribute, F32, Attribute, U32, ) 42OPCODE(GetAttribute, F32, Attribute, U32, )
43OPCODE(GetAttributeU32, U32, Attribute, U32, )
43OPCODE(SetAttribute, Void, Attribute, F32, U32, ) 44OPCODE(SetAttribute, Void, Attribute, F32, U32, )
44OPCODE(GetAttributeIndexed, F32, U32, U32, ) 45OPCODE(GetAttributeIndexed, F32, U32, U32, )
45OPCODE(SetAttributeIndexed, Void, U32, F32, U32, ) 46OPCODE(SetAttributeIndexed, Void, U32, F32, U32, )
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 267ebe4af..248ad3ced 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"
@@ -127,6 +128,42 @@ void AddNVNStorageBuffers(IR::Program& program) {
127 }); 128 });
128 } 129 }
129} 130}
131
132bool IsLegacyAttribute(IR::Attribute attribute) {
133 return (attribute >= IR::Attribute::ColorFrontDiffuseR &&
134 attribute <= IR::Attribute::ColorBackSpecularA) ||
135 attribute == IR::Attribute::FogCoordinate ||
136 (attribute >= IR::Attribute::FixedFncTexture0S &&
137 attribute <= IR::Attribute::FixedFncTexture9Q);
138}
139
140std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings(
141 const VaryingState& state, std::queue<IR::Attribute> ununsed_generics) {
142 std::map<IR::Attribute, IR::Attribute> mapping;
143 for (size_t index = 0; index < 4; ++index) {
144 auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4;
145 if (state.AnyComponent(attr)) {
146 for (size_t i = 0; i < 4; ++i) {
147 mapping.insert({attr + i, ununsed_generics.front() + i});
148 }
149 ununsed_generics.pop();
150 }
151 }
152 if (state[IR::Attribute::FogCoordinate]) {
153 mapping.insert({IR::Attribute::FogCoordinate, ununsed_generics.front()});
154 ununsed_generics.pop();
155 }
156 for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) {
157 auto attr = IR::Attribute::FixedFncTexture0S + index * 4;
158 if (state.AnyComponent(attr)) {
159 for (size_t i = 0; i < 4; ++i) {
160 mapping.insert({attr + i, ununsed_generics.front() + i});
161 }
162 ununsed_generics.pop();
163 }
164 }
165 return mapping;
166}
130} // Anonymous namespace 167} // Anonymous namespace
131 168
132IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, 169IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
@@ -226,4 +263,62 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b
226 return result; 263 return result;
227} 264}
228 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