diff options
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate_program.cpp | 95 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate_program.h | 4 |
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..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 | |||
| 132 | bool 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 | |||
| 140 | std::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 | ||
| 132 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, | 169 | IR::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 | ||
| 266 | void 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 | ||
| 14 | namespace Shader::Maxwell { | 15 | namespace 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 |