diff options
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/translate_program.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate_program.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp index 77efb4f57..3aee33a96 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp | |||
| @@ -137,28 +137,35 @@ bool IsLegacyAttribute(IR::Attribute attribute) { | |||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings( | 139 | std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings( |
| 140 | const VaryingState& state, std::queue<IR::Attribute> ununsed_generics) { | 140 | const VaryingState& state, std::queue<IR::Attribute> unused_generics, |
| 141 | const std::map<IR::Attribute, IR::Attribute>& previous_stage_mapping) { | ||
| 141 | std::map<IR::Attribute, IR::Attribute> mapping; | 142 | std::map<IR::Attribute, IR::Attribute> mapping; |
| 143 | auto update_mapping = [&mapping, &unused_generics, previous_stage_mapping](IR::Attribute attr, | ||
| 144 | size_t count) { | ||
| 145 | if (previous_stage_mapping.find(attr) != previous_stage_mapping.end()) { | ||
| 146 | for (size_t i = 0; i < count; ++i) { | ||
| 147 | mapping.insert({attr + i, previous_stage_mapping.at(attr + i)}); | ||
| 148 | } | ||
| 149 | } else { | ||
| 150 | for (size_t i = 0; i < count; ++i) { | ||
| 151 | mapping.insert({attr + i, unused_generics.front() + i}); | ||
| 152 | } | ||
| 153 | unused_generics.pop(); | ||
| 154 | } | ||
| 155 | }; | ||
| 142 | for (size_t index = 0; index < 4; ++index) { | 156 | for (size_t index = 0; index < 4; ++index) { |
| 143 | auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4; | 157 | auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4; |
| 144 | if (state.AnyComponent(attr)) { | 158 | if (state.AnyComponent(attr)) { |
| 145 | for (size_t i = 0; i < 4; ++i) { | 159 | update_mapping(attr, 4); |
| 146 | mapping.insert({attr + i, ununsed_generics.front() + i}); | ||
| 147 | } | ||
| 148 | ununsed_generics.pop(); | ||
| 149 | } | 160 | } |
| 150 | } | 161 | } |
| 151 | if (state[IR::Attribute::FogCoordinate]) { | 162 | if (state[IR::Attribute::FogCoordinate]) { |
| 152 | mapping.insert({IR::Attribute::FogCoordinate, ununsed_generics.front()}); | 163 | update_mapping(IR::Attribute::FogCoordinate, 1); |
| 153 | ununsed_generics.pop(); | ||
| 154 | } | 164 | } |
| 155 | for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) { | 165 | for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) { |
| 156 | auto attr = IR::Attribute::FixedFncTexture0S + index * 4; | 166 | auto attr = IR::Attribute::FixedFncTexture0S + index * 4; |
| 157 | if (state.AnyComponent(attr)) { | 167 | if (state.AnyComponent(attr)) { |
| 158 | for (size_t i = 0; i < 4; ++i) { | 168 | update_mapping(attr, 4); |
| 159 | mapping.insert({attr + i, ununsed_generics.front() + i}); | ||
| 160 | } | ||
| 161 | ununsed_generics.pop(); | ||
| 162 | } | 169 | } |
| 163 | } | 170 | } |
| 164 | return mapping; | 171 | return mapping; |
| @@ -271,15 +278,16 @@ void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& run | |||
| 271 | ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4); | 278 | ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4); |
| 272 | } | 279 | } |
| 273 | } | 280 | } |
| 274 | auto mappings = GenerateLegacyToGenericMappings(stores, ununsed_output_generics); | 281 | program.info.legacy_stores_mapping = |
| 282 | GenerateLegacyToGenericMappings(stores, ununsed_output_generics, {}); | ||
| 275 | for (IR::Block* const block : program.post_order_blocks) { | 283 | for (IR::Block* const block : program.post_order_blocks) { |
| 276 | for (IR::Inst& inst : block->Instructions()) { | 284 | for (IR::Inst& inst : block->Instructions()) { |
| 277 | switch (inst.GetOpcode()) { | 285 | switch (inst.GetOpcode()) { |
| 278 | case IR::Opcode::SetAttribute: { | 286 | case IR::Opcode::SetAttribute: { |
| 279 | const auto attr = inst.Arg(0).Attribute(); | 287 | const auto attr = inst.Arg(0).Attribute(); |
| 280 | if (IsLegacyAttribute(attr)) { | 288 | if (IsLegacyAttribute(attr)) { |
| 281 | stores.Set(mappings[attr], true); | 289 | stores.Set(program.info.legacy_stores_mapping[attr], true); |
| 282 | inst.SetArg(0, Shader::IR::Value(mappings[attr])); | 290 | inst.SetArg(0, Shader::IR::Value(program.info.legacy_stores_mapping[attr])); |
| 283 | } | 291 | } |
| 284 | break; | 292 | break; |
| 285 | } | 293 | } |
| @@ -300,7 +308,8 @@ void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& run | |||
| 300 | ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4); | 308 | ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4); |
| 301 | } | 309 | } |
| 302 | } | 310 | } |
| 303 | auto mappings = GenerateLegacyToGenericMappings(loads, ununsed_input_generics); | 311 | auto mappings = GenerateLegacyToGenericMappings( |
| 312 | loads, ununsed_input_generics, runtime_info.previous_stage_legacy_stores_mapping); | ||
| 304 | for (IR::Block* const block : program.post_order_blocks) { | 313 | for (IR::Block* const block : program.post_order_blocks) { |
| 305 | for (IR::Inst& inst : block->Instructions()) { | 314 | for (IR::Inst& inst : block->Instructions()) { |
| 306 | switch (inst.GetOpcode()) { | 315 | switch (inst.GetOpcode()) { |