diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2023-04-05 00:25:19 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-05 05:25:19 +0200 |
| commit | c532118d94dea0bbafff7b92000c1a25cd4e021d (patch) | |
| tree | e381eb2b7ca638d6c550eae8557da11325d5ba44 /Ryujinx.Graphics.Shader | |
| parent | 52d6f2e656c21c3e6693df93a3f09cd2e6a4e40e (diff) | |
Use index fragment shader output when dual source blend is enabled (#4404)
* Use index fragment shader output when dual source blend is enabled
* Shader cache version bump
* Actually set DualSourceBlendEnabled to true
* Fix XML doc
---------
Co-authored-by: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'Ryujinx.Graphics.Shader')
| -rw-r--r-- | Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs | 22 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs | 23 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Shader/IGpuAccessor.cs | 9 |
3 files changed, 53 insertions, 1 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index 996d312b..9032ca59 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -612,6 +612,19 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl else { int usedAttributes = context.Config.UsedOutputAttributes; + + if (context.Config.Stage == ShaderStage.Fragment && context.Config.GpuAccessor.QueryDualSourceBlendEnable()) + { + int firstOutput = BitOperations.TrailingZeroCount(usedAttributes); + int mask = 3 << firstOutput; + + if ((usedAttributes & mask) == mask) + { + usedAttributes &= ~mask; + DeclareOutputDualSourceBlendAttribute(context, firstOutput); + } + } + while (usedAttributes != 0) { int index = BitOperations.TrailingZeroCount(usedAttributes); @@ -690,6 +703,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } } + private static void DeclareOutputDualSourceBlendAttribute(CodeGenContext context, int attr) + { + string name = $"{DefaultNames.OAttributePrefix}{attr}"; + string name2 = $"{DefaultNames.OAttributePrefix}{(attr + 1)}"; + + context.AppendLine($"layout (location = {attr}, index = 0) out vec4 {name};"); + context.AppendLine($"layout (location = {attr}, index = 1) out vec4 {name2};"); + } + private static void DeclareUsedOutputAttributesPerPatch(CodeGenContext context, HashSet<int> attrs) { foreach (int attr in attrs.Order()) diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs index 5108d861..df42a13c 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Numerics; using static Spv.Specification; namespace Ryujinx.Graphics.Shader.CodeGen.Spirv @@ -622,7 +623,27 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv else if (attr >= AttributeConsts.FragmentOutputColorBase && attr < AttributeConsts.FragmentOutputColorEnd) { int location = (attr - AttributeConsts.FragmentOutputColorBase) / 16; - context.Decorate(spvVar, Decoration.Location, (LiteralInteger)location); + + if (context.Config.Stage == ShaderStage.Fragment && context.Config.GpuAccessor.QueryDualSourceBlendEnable()) + { + int firstLocation = BitOperations.TrailingZeroCount(context.Config.UsedOutputAttributes); + int index = location - firstLocation; + int mask = 3 << firstLocation; + + if ((uint)index < 2 && (context.Config.UsedOutputAttributes & mask) == mask) + { + context.Decorate(spvVar, Decoration.Location, (LiteralInteger)firstLocation); + context.Decorate(spvVar, Decoration.Index, (LiteralInteger)index); + } + else + { + context.Decorate(spvVar, Decoration.Location, (LiteralInteger)location); + } + } + else + { + context.Decorate(spvVar, Decoration.Location, (LiteralInteger)location); + } } if (!isOutAttr) diff --git a/Ryujinx.Graphics.Shader/IGpuAccessor.cs b/Ryujinx.Graphics.Shader/IGpuAccessor.cs index f364437c..ba5f2a92 100644 --- a/Ryujinx.Graphics.Shader/IGpuAccessor.cs +++ b/Ryujinx.Graphics.Shader/IGpuAccessor.cs @@ -206,6 +206,15 @@ namespace Ryujinx.Graphics.Shader } /// <summary> + /// Queries dual source blend state. + /// </summary> + /// <returns>True if blending is enabled with a dual source blend equation, false otherwise</returns> + bool QueryDualSourceBlendEnable() + { + return false; + } + + /// <summary> /// Queries host about the presence of the FrontFacing built-in variable bug. /// </summary> /// <returns>True if the bug is present on the host device used, false otherwise</returns> |
