From b46b63e06a36845175f68331edb5ddeeb34de27b Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 5 Jul 2022 19:58:36 -0300 Subject: Add support for alpha to coverage dithering (#3069) * Add support for alpha to coverage dithering * Shader cache version bump * Fix wrong alpha register * Ensure support buffer is cleared * New shader specialization based approach --- Ryujinx.Graphics.Gpu/Shader/Cache/Migration.cs | 2 ++ .../Shader/DiskCache/DiskCacheGpuAccessor.cs | 6 ++++++ .../Shader/DiskCache/DiskCacheHostStorage.cs | 2 +- Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs | 6 ++++++ .../Shader/GpuChannelGraphicsState.cs | 22 +++++++++++++++++++++- .../Shader/ShaderSpecializationState.cs | 8 ++++++++ 6 files changed, 44 insertions(+), 2 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Shader') diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/Migration.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/Migration.cs index 4de6eff9..885bcd09 100644 --- a/Ryujinx.Graphics.Gpu/Shader/Cache/Migration.cs +++ b/Ryujinx.Graphics.Gpu/Shader/Cache/Migration.cs @@ -167,6 +167,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache accessorHeader.StateFlags.HasFlag(GuestGpuStateFlags.EarlyZForce), topology, tessMode, + false, + false, false); TransformFeedbackDescriptor[] tfdNew = null; diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs index bc63f714..e5476426 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs @@ -67,6 +67,12 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache return MemoryMarshal.Cast(_data.Span.Slice((int)address)); } + /// + public bool QueryAlphaToCoverageDitherEnable() + { + return _oldSpecState.GraphicsState.AlphaToCoverageEnable && _oldSpecState.GraphicsState.AlphaToCoverageDitherEnable; + } + /// public int QueryBindingConstantBuffer(int index) { diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs index 59801001..37b25793 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMinor = 1; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; - private const uint CodeGenVersion = 3424; + private const uint CodeGenVersion = 3069; private const string SharedTocFileName = "shared.toc"; private const string SharedDataFileName = "shared.data"; diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs index 5cd966af..5317aab9 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs @@ -66,6 +66,12 @@ namespace Ryujinx.Graphics.Gpu.Shader return MemoryMarshal.Cast(_channel.MemoryManager.GetSpan(address, size)); } + /// + public bool QueryAlphaToCoverageDitherEnable() + { + return _state.GraphicsState.AlphaToCoverageEnable && _state.GraphicsState.AlphaToCoverageDitherEnable; + } + /// public int QueryBindingConstantBuffer(int index) { diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs b/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs index 92ec117f..fae670ea 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs @@ -30,6 +30,16 @@ namespace Ryujinx.Graphics.Gpu.Shader /// public readonly bool ViewportTransformDisable; + /// + /// Indicates whenever alpha-to-coverage is enabled. + /// + public readonly bool AlphaToCoverageEnable; + + /// + /// Indicates whenever alpha-to-coverage dithering is enabled. + /// + public readonly bool AlphaToCoverageDitherEnable; + /// /// Creates a new GPU graphics state. /// @@ -37,12 +47,22 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Primitive topology /// Tessellation mode /// Indicates whenever the viewport transform is disabled - public GpuChannelGraphicsState(bool earlyZForce, PrimitiveTopology topology, TessMode tessellationMode, bool viewportTransformDisable) + /// Indicates whenever alpha-to-coverage is enabled + /// Indicates whenever alpha-to-coverage dithering is enabled + public GpuChannelGraphicsState( + bool earlyZForce, + PrimitiveTopology topology, + TessMode tessellationMode, + bool viewportTransformDisable, + bool alphaToCoverageEnable, + bool alphaToCoverageDitherEnable) { EarlyZForce = earlyZForce; Topology = topology; TessellationMode = tessellationMode; ViewportTransformDisable = viewportTransformDisable; + AlphaToCoverageEnable = alphaToCoverageEnable; + AlphaToCoverageDitherEnable = alphaToCoverageDitherEnable; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs index 587d60a7..7e39c8a3 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs @@ -455,6 +455,14 @@ namespace Ryujinx.Graphics.Gpu.Shader return false; } + bool thisA2cDitherEnable = GraphicsState.AlphaToCoverageEnable && GraphicsState.AlphaToCoverageDitherEnable; + bool otherA2cDitherEnable = graphicsState.AlphaToCoverageEnable && graphicsState.AlphaToCoverageDitherEnable; + + if (otherA2cDitherEnable != thisA2cDitherEnable) + { + return false; + } + return Matches(channel, poolState, checkTextures, isCompute: false); } -- cgit v1.2.3