summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/maxwell/translate_program.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/translate_program.cpp')
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 77efb4f57..b58741d4d 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
139std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings( 139std::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;
@@ -265,21 +272,22 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b
265void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& runtime_info) { 272void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& runtime_info) {
266 auto& stores = program.info.stores; 273 auto& stores = program.info.stores;
267 if (stores.Legacy()) { 274 if (stores.Legacy()) {
268 std::queue<IR::Attribute> ununsed_output_generics{}; 275 std::queue<IR::Attribute> unused_output_generics{};
269 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 276 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
270 if (!stores.Generic(index)) { 277 if (!stores.Generic(index)) {
271 ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4); 278 unused_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, unused_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 }
@@ -292,15 +300,16 @@ void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& run
292 300
293 auto& loads = program.info.loads; 301 auto& loads = program.info.loads;
294 if (loads.Legacy()) { 302 if (loads.Legacy()) {
295 std::queue<IR::Attribute> ununsed_input_generics{}; 303 std::queue<IR::Attribute> unused_input_generics{};
296 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 304 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
297 const AttributeType input_type{runtime_info.generic_input_types[index]}; 305 const AttributeType input_type{runtime_info.generic_input_types[index]};
298 if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) || 306 if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) ||
299 input_type == AttributeType::Disabled) { 307 input_type == AttributeType::Disabled) {
300 ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4); 308 unused_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, unused_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()) {