From f95b7c58779f01d9077996da67953d8d9acd058c Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 29 Jul 2023 18:47:03 -0300 Subject: Fix incorrect fragment origin when YNegate is enabled (#4673) * Fix incorrect fragment origin when YNegate is enabled * Shader cache version bump * Do not update support buffer if shader does not read gl_FragCoord * Pass unscaled viewport size to the support buffer --- .../Shader/DiskCache/DiskCacheGpuAccessor.cs | 6 ++++++ .../Shader/DiskCache/DiskCacheHostStorage.cs | 9 ++++++++- src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs | 16 +++++++++++----- .../Shader/GpuChannelGraphicsState.cs | 12 ++++++++++-- .../Shader/ShaderSpecializationState.cs | 5 +++++ 5 files changed, 40 insertions(+), 8 deletions(-) (limited to 'src/Ryujinx.Graphics.Gpu/Shader') diff --git a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs index 7f01aca6..b5f9395e 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGpuAccessor.cs @@ -247,6 +247,12 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache return _oldSpecState.GraphicsState.ViewportTransformDisable; } + /// + public bool QueryYNegateEnabled() + { + return _oldSpecState.GraphicsState.YNegateEnabled; + } + /// public void RegisterTexture(int handle, int cbufSlot) { diff --git a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs index 672b3b8d..4bab165d 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs @@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMinor = 2; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; - private const uint CodeGenVersion = 5266; + private const uint CodeGenVersion = 4675; private const string SharedTocFileName = "shared.toc"; private const string SharedDataFileName = "shared.data"; @@ -140,6 +140,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// public ShaderStage Stage; + /// + /// Indicates if the fragment shader accesses the fragment coordinate built-in variable. + /// + public bool UsesFragCoord; + /// /// Indicates if the shader accesses the Instance ID built-in variable. /// @@ -781,6 +786,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache ShaderIdentification.None, 0, dataInfo.Stage, + dataInfo.UsesFragCoord, dataInfo.UsesInstanceId, dataInfo.UsesDrawParameters, dataInfo.UsesRtLayer, @@ -807,6 +813,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache TexturesCount = (ushort)info.Textures.Count, ImagesCount = (ushort)info.Images.Count, Stage = info.Stage, + UsesFragCoord = info.UsesFragCoord, UsesInstanceId = info.UsesInstanceId, UsesDrawParameters = info.UsesDrawParameters, UsesRtLayer = info.UsesRtLayer, diff --git a/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs b/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs index ca9c883e..1fcc93c5 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs @@ -113,6 +113,13 @@ namespace Ryujinx.Graphics.Gpu.Shader return _state.GraphicsState.AttributeTypes[location]; } + /// + public bool QueryEarlyZForce() + { + _state.SpecializationState?.RecordEarlyZForce(); + return _state.GraphicsState.EarlyZForce; + } + /// public AttributeType QueryFragmentOutputType(int location) { @@ -276,16 +283,15 @@ namespace Ryujinx.Graphics.Gpu.Shader } /// - public bool QueryEarlyZForce() + public bool QueryViewportTransformDisable() { - _state.SpecializationState?.RecordEarlyZForce(); - return _state.GraphicsState.EarlyZForce; + return _state.GraphicsState.ViewportTransformDisable; } /// - public bool QueryViewportTransformDisable() + public bool QueryYNegateEnabled() { - return _state.GraphicsState.ViewportTransformDisable; + return _state.GraphicsState.YNegateEnabled; } /// diff --git a/src/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs b/src/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs index 544e689a..f392491c 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/GpuChannelGraphicsState.cs @@ -97,6 +97,11 @@ namespace Ryujinx.Graphics.Gpu.Shader /// public bool DualSourceBlendEnable; + /// + /// Indicates whether Y negate of the fragment coordinates is enabled. + /// + public bool YNegateEnabled; + /// /// Creates a new GPU graphics state. /// @@ -116,7 +121,8 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Indicates that the draw is writing the base vertex, base instance and draw index to Constant Buffer 0 /// Indicates that any storage buffer use is unaligned /// Type of the fragment shader outputs - /// Type of the vertex attributes consumed by the shader + /// Indicates whether dual source blend is enabled + /// Indicates whether Y negate of the fragment coordinates is enabled public GpuChannelGraphicsState( bool earlyZForce, PrimitiveTopology topology, @@ -134,7 +140,8 @@ namespace Ryujinx.Graphics.Gpu.Shader bool hasConstantBufferDrawParameters, bool hasUnalignedStorageBuffer, ref Array8 fragmentOutputTypes, - bool dualSourceBlendEnable) + bool dualSourceBlendEnable, + bool yNegateEnabled) { EarlyZForce = earlyZForce; Topology = topology; @@ -153,6 +160,7 @@ namespace Ryujinx.Graphics.Gpu.Shader HasUnalignedStorageBuffer = hasUnalignedStorageBuffer; FragmentOutputTypes = fragmentOutputTypes; DualSourceBlendEnable = dualSourceBlendEnable; + YNegateEnabled = yNegateEnabled; } } } diff --git a/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs b/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs index 775bfb2a..b33f96c5 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs @@ -540,6 +540,11 @@ namespace Ryujinx.Graphics.Gpu.Shader return false; } + if (graphicsState.YNegateEnabled != GraphicsState.YNegateEnabled) + { + return false; + } + return Matches(channel, ref poolState, checkTextures, isCompute: false); } -- cgit v1.2.3