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 | |
| 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')
4 files changed, 103 insertions, 1 deletions
diff --git a/src/shader_recompiler/frontend/ir/attribute.h b/src/shader_recompiler/frontend/ir/attribute.h index ca1199494..5c5e7bb4b 100644 --- a/src/shader_recompiler/frontend/ir/attribute.h +++ b/src/shader_recompiler/frontend/ir/attribute.h | |||
| @@ -224,6 +224,8 @@ enum class Attribute : u64 { | |||
| 224 | 224 | ||
| 225 | constexpr size_t NUM_GENERICS = 32; | 225 | constexpr size_t NUM_GENERICS = 32; |
| 226 | 226 | ||
| 227 | constexpr size_t NUM_FIXED_FNC_TEXTURES = 10; | ||
| 228 | |||
| 227 | [[nodiscard]] bool IsGeneric(Attribute attribute) noexcept; | 229 | [[nodiscard]] bool IsGeneric(Attribute attribute) noexcept; |
| 228 | 230 | ||
| 229 | [[nodiscard]] u32 GenericAttributeIndex(Attribute attribute); | 231 | [[nodiscard]] u32 GenericAttributeIndex(Attribute attribute); |
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 |
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 |
diff --git a/src/shader_recompiler/varying_state.h b/src/shader_recompiler/varying_state.h index 9d7b24a76..bc4f273c8 100644 --- a/src/shader_recompiler/varying_state.h +++ b/src/shader_recompiler/varying_state.h | |||
| @@ -53,7 +53,8 @@ struct VaryingState { | |||
| 53 | return AnyComponent(IR::Attribute::ColorFrontDiffuseR) || | 53 | return AnyComponent(IR::Attribute::ColorFrontDiffuseR) || |
| 54 | AnyComponent(IR::Attribute::ColorFrontSpecularR) || | 54 | AnyComponent(IR::Attribute::ColorFrontSpecularR) || |
| 55 | AnyComponent(IR::Attribute::ColorBackDiffuseR) || | 55 | AnyComponent(IR::Attribute::ColorBackDiffuseR) || |
| 56 | AnyComponent(IR::Attribute::ColorBackSpecularR) || FixedFunctionTexture(); | 56 | AnyComponent(IR::Attribute::ColorBackSpecularR) || FixedFunctionTexture() || |
| 57 | mask[static_cast<size_t>(IR::Attribute::FogCoordinate)]; | ||
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | [[nodiscard]] bool FixedFunctionTexture() const noexcept { | 60 | [[nodiscard]] bool FixedFunctionTexture() const noexcept { |