diff options
| author | 2021-11-19 15:32:53 +0800 | |
|---|---|---|
| committer | 2021-11-19 22:53:58 +0800 | |
| commit | 4dd85f86a89338ff84d05a3981c14f6de1be4606 (patch) | |
| tree | b2a48b24bf216a325e62f5e363bc98b41de84444 /src/shader_recompiler/frontend/maxwell/translate_program.cpp | |
| parent | Merge pull request #7349 from ameerj/ogl-convert-image (diff) | |
| download | yuzu-4dd85f86a89338ff84d05a3981c14f6de1be4606.tar.gz yuzu-4dd85f86a89338ff84d05a3981c14f6de1be4606.tar.xz yuzu-4dd85f86a89338ff84d05a3981c14f6de1be4606.zip | |
Implement convert legacy to generic
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/translate_program.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate_program.cpp | 95 |
1 files changed, 95 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..40c9307db 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" |
| @@ -226,4 +227,98 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b | |||
| 226 | return result; | 227 | return result; |
| 227 | } | 228 | } |
| 228 | 229 | ||
| 230 | bool IsLegacyAttribute(IR::Attribute attribute) { | ||
| 231 | return (attribute >= IR::Attribute::ColorFrontDiffuseR && | ||
| 232 | attribute <= IR::Attribute::ColorBackSpecularA) || | ||
| 233 | attribute == IR::Attribute::FogCoordinate || | ||
| 234 | (attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 235 | attribute <= IR::Attribute::FixedFncTexture9Q); | ||
| 236 | } | ||
| 237 | |||
| 238 | std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings( | ||
| 239 | const VaryingState& state, std::queue<IR::Attribute> ununsed_generics) { | ||
| 240 | std::map<IR::Attribute, IR::Attribute> mapping; | ||
| 241 | for (size_t index = 0; index < 4; ++index) { | ||
| 242 | auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4; | ||
| 243 | if (state.AnyComponent(attr)) { | ||
| 244 | for (size_t i = 0; i < 4; ++i) { | ||
| 245 | mapping.insert({attr + i, ununsed_generics.front() + i}); | ||
| 246 | } | ||
| 247 | ununsed_generics.pop(); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | if (state[IR::Attribute::FogCoordinate]) { | ||
| 251 | mapping.insert({IR::Attribute::FogCoordinate, ununsed_generics.front()}); | ||
| 252 | ununsed_generics.pop(); | ||
| 253 | } | ||
| 254 | for (size_t index = 0; index < IR::NUM_FIXED_FNC_TEXTURES; ++index) { | ||
| 255 | auto attr = IR::Attribute::FixedFncTexture0S + index * 4; | ||
| 256 | if (state.AnyComponent(attr)) { | ||
| 257 | for (size_t i = 0; i < 4; ++i) { | ||
| 258 | mapping.insert({attr + i, ununsed_generics.front() + i}); | ||
| 259 | } | ||
| 260 | ununsed_generics.pop(); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | return mapping; | ||
| 264 | } | ||
| 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 |