diff options
| author | 2019-04-30 00:18:28 -0300 | |
|---|---|---|
| committer | 2019-05-02 21:46:25 -0300 | |
| commit | b7d412c99bb42291dca616910a269dabca7a3938 (patch) | |
| tree | a2f3f07a0885f159d0f9cd54ff38c616798c981c /src | |
| parent | gl_shader_decompiler: Declare all possible varyings on physical attribute usage (diff) | |
| download | yuzu-b7d412c99bb42291dca616910a269dabca7a3938.tar.gz yuzu-b7d412c99bb42291dca616910a269dabca7a3938.tar.xz yuzu-b7d412c99bb42291dca616910a269dabca7a3938.zip | |
gl_shader_decompiler: Abstract generic attribute operations
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 8df91a4c6..1ad33107d 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -134,6 +134,19 @@ bool IsPrecise(Node node) { | |||
| 134 | return false; | 134 | return false; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | constexpr bool IsGenericAttribute(Attribute::Index index) { | ||
| 138 | return index >= Attribute::Index::Attribute_0 && index <= Attribute::Index::Attribute_31; | ||
| 139 | } | ||
| 140 | |||
| 141 | constexpr Attribute::Index ToGenericAttribute(u32 value) { | ||
| 142 | return static_cast<Attribute::Index>(value + static_cast<u32>(Attribute::Index::Attribute_0)); | ||
| 143 | } | ||
| 144 | |||
| 145 | u32 GetGenericAttributeIndex(Attribute::Index index) { | ||
| 146 | ASSERT(IsGenericAttribute(index)); | ||
| 147 | return static_cast<u32>(index) - static_cast<u32>(Attribute::Index::Attribute_0); | ||
| 148 | } | ||
| 149 | |||
| 137 | class GLSLDecompiler final { | 150 | class GLSLDecompiler final { |
| 138 | public: | 151 | public: |
| 139 | explicit GLSLDecompiler(const Device& device, const ShaderIR& ir, ShaderStage stage, | 152 | explicit GLSLDecompiler(const Device& device, const ShaderIR& ir, ShaderStage stage, |
| @@ -320,9 +333,7 @@ private: | |||
| 320 | const u32 num_inputs{stage == ShaderStage::Vertex ? GetNumPhysicalAttributes() | 333 | const u32 num_inputs{stage == ShaderStage::Vertex ? GetNumPhysicalAttributes() |
| 321 | : GetNumPhysicalVaryings()}; | 334 | : GetNumPhysicalVaryings()}; |
| 322 | for (u32 i = 0; i < num_inputs; ++i) { | 335 | for (u32 i = 0; i < num_inputs; ++i) { |
| 323 | constexpr auto generic_base{static_cast<u32>(Attribute::Index::Attribute_0)}; | 336 | DeclareInputAttribute(ToGenericAttribute(i)); |
| 324 | const auto index{static_cast<Attribute::Index>(generic_base + i)}; | ||
| 325 | DeclareInputAttribute(index); | ||
| 326 | } | 337 | } |
| 327 | code.AddNewLine(); | 338 | code.AddNewLine(); |
| 328 | return; | 339 | return; |
| @@ -330,24 +341,22 @@ private: | |||
| 330 | 341 | ||
| 331 | const auto& attributes = ir.GetInputAttributes(); | 342 | const auto& attributes = ir.GetInputAttributes(); |
| 332 | for (const auto index : attributes) { | 343 | for (const auto index : attributes) { |
| 333 | if (index < Attribute::Index::Attribute_0 || index > Attribute::Index::Attribute_31) { | 344 | if (IsGenericAttribute(index)) { |
| 334 | // Skip when it's not a generic attribute | 345 | DeclareInputAttribute(index); |
| 335 | continue; | ||
| 336 | } | 346 | } |
| 337 | DeclareInputAttribute(index); | ||
| 338 | } | 347 | } |
| 339 | if (!attributes.empty()) | 348 | if (!attributes.empty()) |
| 340 | code.AddNewLine(); | 349 | code.AddNewLine(); |
| 341 | } | 350 | } |
| 342 | 351 | ||
| 343 | void DeclareInputAttribute(Attribute::Index index) { | 352 | void DeclareInputAttribute(Attribute::Index index) { |
| 344 | const u32 generic_index{static_cast<u32>(index) - | 353 | const u32 generic_index{GetGenericAttributeIndex(index)}; |
| 345 | static_cast<u32>(Attribute::Index::Attribute_0)}; | ||
| 346 | 354 | ||
| 347 | std::string name{GetInputAttribute(index)}; | 355 | std::string name{GetInputAttribute(index)}; |
| 348 | if (stage == ShaderStage::Geometry) { | 356 | if (stage == ShaderStage::Geometry) { |
| 349 | name = "gs_" + name + "[]"; | 357 | name = "gs_" + name + "[]"; |
| 350 | } | 358 | } |
| 359 | |||
| 351 | std::string suffix; | 360 | std::string suffix; |
| 352 | if (stage == ShaderStage::Fragment) { | 361 | if (stage == ShaderStage::Fragment) { |
| 353 | const auto input_mode{header.ps.GetAttributeUse(generic_index)}; | 362 | const auto input_mode{header.ps.GetAttributeUse(generic_index)}; |
| @@ -367,9 +376,7 @@ private: | |||
| 367 | void DeclareOutputAttributes() { | 376 | void DeclareOutputAttributes() { |
| 368 | if (ir.HasPhysicalAttributes()) { | 377 | if (ir.HasPhysicalAttributes()) { |
| 369 | for (u32 i = 0; i < GetNumPhysicalVaryings(); ++i) { | 378 | for (u32 i = 0; i < GetNumPhysicalVaryings(); ++i) { |
| 370 | constexpr auto generic_base{static_cast<u32>(Attribute::Index::Attribute_0)}; | 379 | DeclareOutputAttribute(ToGenericAttribute(i)); |
| 371 | const auto index{static_cast<Attribute::Index>(generic_base + i)}; | ||
| 372 | DeclareOutputAttribute(index); | ||
| 373 | } | 380 | } |
| 374 | code.AddNewLine(); | 381 | code.AddNewLine(); |
| 375 | return; | 382 | return; |
| @@ -377,20 +384,16 @@ private: | |||
| 377 | 384 | ||
| 378 | const auto& attributes = ir.GetOutputAttributes(); | 385 | const auto& attributes = ir.GetOutputAttributes(); |
| 379 | for (const auto index : attributes) { | 386 | for (const auto index : attributes) { |
| 380 | if (index < Attribute::Index::Attribute_0 || index > Attribute::Index::Attribute_31) { | 387 | if (IsGenericAttribute(index)) { |
| 381 | // Skip when it's not a generic attribute | 388 | DeclareOutputAttribute(index); |
| 382 | continue; | ||
| 383 | } | 389 | } |
| 384 | DeclareOutputAttribute(index); | ||
| 385 | } | 390 | } |
| 386 | if (!attributes.empty()) | 391 | if (!attributes.empty()) |
| 387 | code.AddNewLine(); | 392 | code.AddNewLine(); |
| 388 | } | 393 | } |
| 389 | 394 | ||
| 390 | void DeclareOutputAttribute(Attribute::Index index) { | 395 | void DeclareOutputAttribute(Attribute::Index index) { |
| 391 | const auto location{static_cast<u32>(index) - | 396 | const u32 location{GetGenericAttributeIndex(index) + GENERIC_VARYING_START_LOCATION}; |
| 392 | static_cast<u32>(Attribute::Index::Attribute_0) + | ||
| 393 | GENERIC_VARYING_START_LOCATION}; | ||
| 394 | code.AddLine("layout (location = " + std::to_string(location) + ") out vec4 " + | 397 | code.AddLine("layout (location = " + std::to_string(location) + ") out vec4 " + |
| 395 | GetOutputAttribute(index) + ';'); | 398 | GetOutputAttribute(index) + ';'); |
| 396 | } | 399 | } |
| @@ -569,8 +572,7 @@ private: | |||
| 569 | UNIMPLEMENTED_MSG("Unmanaged FrontFacing element={}", element); | 572 | UNIMPLEMENTED_MSG("Unmanaged FrontFacing element={}", element); |
| 570 | return "0"; | 573 | return "0"; |
| 571 | default: | 574 | default: |
| 572 | if (attribute >= Attribute::Index::Attribute_0 && | 575 | if (IsGenericAttribute(attribute)) { |
| 573 | attribute <= Attribute::Index::Attribute_31) { | ||
| 574 | return GeometryPass(GetInputAttribute(attribute)) + GetSwizzle(element); | 576 | return GeometryPass(GetInputAttribute(attribute)) + GetSwizzle(element); |
| 575 | } | 577 | } |
| 576 | break; | 578 | break; |
| @@ -873,8 +875,7 @@ private: | |||
| 873 | case Attribute::Index::ClipDistances4567: | 875 | case Attribute::Index::ClipDistances4567: |
| 874 | return "gl_ClipDistance[" + std::to_string(abuf->GetElement() + 4) + ']'; | 876 | return "gl_ClipDistance[" + std::to_string(abuf->GetElement() + 4) + ']'; |
| 875 | default: | 877 | default: |
| 876 | if (attribute >= Attribute::Index::Attribute_0 && | 878 | if (IsGenericAttribute(attribute)) { |
| 877 | attribute <= Attribute::Index::Attribute_31) { | ||
| 878 | return GetOutputAttribute(attribute) + GetSwizzle(abuf->GetElement()); | 879 | return GetOutputAttribute(attribute) + GetSwizzle(abuf->GetElement()); |
| 879 | } | 880 | } |
| 880 | UNIMPLEMENTED_MSG("Unhandled output attribute: {}", | 881 | UNIMPLEMENTED_MSG("Unhandled output attribute: {}", |
| @@ -1631,15 +1632,11 @@ private: | |||
| 1631 | } | 1632 | } |
| 1632 | 1633 | ||
| 1633 | std::string GetInputAttribute(Attribute::Index attribute) const { | 1634 | std::string GetInputAttribute(Attribute::Index attribute) const { |
| 1634 | const auto index{static_cast<u32>(attribute) - | 1635 | return GetDeclarationWithSuffix(GetGenericAttributeIndex(attribute), "input_attr"); |
| 1635 | static_cast<u32>(Attribute::Index::Attribute_0)}; | ||
| 1636 | return GetDeclarationWithSuffix(index, "input_attr"); | ||
| 1637 | } | 1636 | } |
| 1638 | 1637 | ||
| 1639 | std::string GetOutputAttribute(Attribute::Index attribute) const { | 1638 | std::string GetOutputAttribute(Attribute::Index attribute) const { |
| 1640 | const auto index{static_cast<u32>(attribute) - | 1639 | return GetDeclarationWithSuffix(GetGenericAttributeIndex(attribute), "output_attr"); |
| 1641 | static_cast<u32>(Attribute::Index::Attribute_0)}; | ||
| 1642 | return GetDeclarationWithSuffix(index, "output_attr"); | ||
| 1643 | } | 1640 | } |
| 1644 | 1641 | ||
| 1645 | std::string GetConstBuffer(u32 index) const { | 1642 | std::string GetConstBuffer(u32 index) const { |