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/microinstruction.cpp5
-rw-r--r--src/shader_recompiler/frontend/ir/value.h4
-rw-r--r--src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp6
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp47
4 files changed, 31 insertions, 31 deletions
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp
index 468782eb1..84417980b 100644
--- a/src/shader_recompiler/frontend/ir/microinstruction.cpp
+++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp
@@ -325,11 +325,6 @@ void Inst::AddPhiOperand(Block* predecessor, const Value& value) {
325 phi_args.emplace_back(predecessor, value); 325 phi_args.emplace_back(predecessor, value);
326} 326}
327 327
328void Inst::ErasePhiOperand(size_t index) {
329 const auto operand_it{phi_args.begin() + static_cast<ptrdiff_t>(index)};
330 phi_args.erase(operand_it);
331}
332
333void Inst::OrderPhiArgs() { 328void Inst::OrderPhiArgs() {
334 if (op != Opcode::Phi) { 329 if (op != Opcode::Phi) {
335 throw LogicError("{} is not a Phi instruction", op); 330 throw LogicError("{} is not a Phi instruction", op);
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h
index 1a2e4ccb6..6a673ca05 100644
--- a/src/shader_recompiler/frontend/ir/value.h
+++ b/src/shader_recompiler/frontend/ir/value.h
@@ -178,13 +178,9 @@ public:
178 178
179 /// Get a pointer to the block of a phi argument. 179 /// Get a pointer to the block of a phi argument.
180 [[nodiscard]] Block* PhiBlock(size_t index) const; 180 [[nodiscard]] Block* PhiBlock(size_t index) const;
181
182 /// Add phi operand to a phi instruction. 181 /// Add phi operand to a phi instruction.
183 void AddPhiOperand(Block* predecessor, const Value& value); 182 void AddPhiOperand(Block* predecessor, const Value& value);
184 183
185 // Erase the phi operand at the given index.
186 void ErasePhiOperand(size_t index);
187
188 /// Orders the Phi arguments from farthest away to nearest. 184 /// Orders the Phi arguments from farthest away to nearest.
189 void OrderPhiArgs(); 185 void OrderPhiArgs();
190 186
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
index 578bc8c1b..ce42475d4 100644
--- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
@@ -964,9 +964,9 @@ private:
964 demote_endif_node.type = Type::EndIf; 964 demote_endif_node.type = Type::EndIf;
965 demote_endif_node.data.end_if.merge = return_block_it->data.block; 965 demote_endif_node.data.end_if.merge = return_block_it->data.block;
966 966
967 asl.insert(return_block_it, demote_endif_node); 967 const auto next_it_1 = asl.insert(return_block_it, demote_endif_node);
968 asl.insert(return_block_it, demote_node); 968 const auto next_it_2 = asl.insert(next_it_1, demote_node);
969 asl.insert(return_block_it, demote_if_node); 969 asl.insert(next_it_2, demote_if_node);
970 } 970 }
971 971
972 ObjectPool<Statement>& stmt_pool; 972 ObjectPool<Statement>& stmt_pool;
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index dafb9deee..b7162f719 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;
@@ -267,21 +274,22 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b
267void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& runtime_info) { 274void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& runtime_info) {
268 auto& stores = program.info.stores; 275 auto& stores = program.info.stores;
269 if (stores.Legacy()) { 276 if (stores.Legacy()) {
270 std::queue<IR::Attribute> ununsed_output_generics{}; 277 std::queue<IR::Attribute> unused_output_generics{};
271 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 278 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
272 if (!stores.Generic(index)) { 279 if (!stores.Generic(index)) {
273 ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4); 280 unused_output_generics.push(IR::Attribute::Generic0X + index * 4);
274 } 281 }
275 } 282 }
276 auto mappings = GenerateLegacyToGenericMappings(stores, ununsed_output_generics); 283 program.info.legacy_stores_mapping =
284 GenerateLegacyToGenericMappings(stores, unused_output_generics, {});
277 for (IR::Block* const block : program.post_order_blocks) { 285 for (IR::Block* const block : program.post_order_blocks) {
278 for (IR::Inst& inst : block->Instructions()) { 286 for (IR::Inst& inst : block->Instructions()) {
279 switch (inst.GetOpcode()) { 287 switch (inst.GetOpcode()) {
280 case IR::Opcode::SetAttribute: { 288 case IR::Opcode::SetAttribute: {
281 const auto attr = inst.Arg(0).Attribute(); 289 const auto attr = inst.Arg(0).Attribute();
282 if (IsLegacyAttribute(attr)) { 290 if (IsLegacyAttribute(attr)) {
283 stores.Set(mappings[attr], true); 291 stores.Set(program.info.legacy_stores_mapping[attr], true);
284 inst.SetArg(0, Shader::IR::Value(mappings[attr])); 292 inst.SetArg(0, Shader::IR::Value(program.info.legacy_stores_mapping[attr]));
285 } 293 }
286 break; 294 break;
287 } 295 }
@@ -294,15 +302,16 @@ void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& run
294 302
295 auto& loads = program.info.loads; 303 auto& loads = program.info.loads;
296 if (loads.Legacy()) { 304 if (loads.Legacy()) {
297 std::queue<IR::Attribute> ununsed_input_generics{}; 305 std::queue<IR::Attribute> unused_input_generics{};
298 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 306 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
299 const AttributeType input_type{runtime_info.generic_input_types[index]}; 307 const AttributeType input_type{runtime_info.generic_input_types[index]};
300 if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) || 308 if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) ||
301 input_type == AttributeType::Disabled) { 309 input_type == AttributeType::Disabled) {
302 ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4); 310 unused_input_generics.push(IR::Attribute::Generic0X + index * 4);
303 } 311 }
304 } 312 }
305 auto mappings = GenerateLegacyToGenericMappings(loads, ununsed_input_generics); 313 auto mappings = GenerateLegacyToGenericMappings(
314 loads, unused_input_generics, runtime_info.previous_stage_legacy_stores_mapping);
306 for (IR::Block* const block : program.post_order_blocks) { 315 for (IR::Block* const block : program.post_order_blocks) {
307 for (IR::Inst& inst : block->Instructions()) { 316 for (IR::Inst& inst : block->Instructions()) {
308 switch (inst.GetOpcode()) { 317 switch (inst.GetOpcode()) {