From 4741a05df95dd8964543f9770d8bfe15d842beaf Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 1 Jun 2023 08:05:39 +0100 Subject: [PATCH] Vulkan: Include DepthMode in ProgramPipelineState (#5185) --- src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs | 2 ++ .../Engine/Threed/StateUpdater.cs | 6 +++++- .../Shader/ShaderSpecializationState.cs | 15 +++++++++++++++ src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs b/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs index 41afb34b0b..96fd667ad4 100644 --- a/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs +++ b/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs @@ -63,6 +63,8 @@ namespace Ryujinx.Graphics.GAL public bool PrimitiveRestartEnable; public uint PatchControlPoints; + public DepthMode DepthMode; + public void SetVertexAttribs(ReadOnlySpan vertexAttribs) { VertexAttribCount = vertexAttribs.Length; diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index 4feb8bafc6..5fa4702b89 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -771,7 +771,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed /// private void UpdateDepthMode() { - _context.Renderer.Pipeline.SetDepthMode(GetDepthMode()); + DepthMode mode = GetDepthMode(); + + _pipeline.DepthMode = mode; + + _context.Renderer.Pipeline.SetDepthMode(mode); } /// diff --git a/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs b/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs index b2c4fccdb9..9b0c8b9b9d 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs @@ -736,6 +736,19 @@ namespace Ryujinx.Graphics.Gpu.Shader return MatchesTexture(specializationState, descriptor); } + /// + /// Populates pipeline state that doesn't exist in older caches with default values + /// based on specialization state. + /// + /// Pipeline state to prepare + private void PreparePipelineState(ref ProgramPipelineState pipelineState) + { + if (!_compute) + { + pipelineState.DepthMode = GraphicsState.DepthMode ? DepthMode.MinusOneToOne : DepthMode.ZeroToOne; + } + } + /// /// Reads shader specialization state that has been serialized. /// @@ -776,6 +789,8 @@ namespace Ryujinx.Graphics.Gpu.Shader { ProgramPipelineState pipelineState = default; dataReader.ReadWithMagicAndSize(ref pipelineState, PgpsMagic); + + specState.PreparePipelineState(ref pipelineState); specState.PipelineState = pipelineState; } diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs b/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs index 79179ce07b..a52b446224 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs @@ -165,6 +165,7 @@ namespace Ryujinx.Graphics.Vulkan pipeline.DepthTestEnable = state.DepthTest.TestEnable; pipeline.DepthWriteEnable = state.DepthTest.WriteEnable; pipeline.DepthCompareOp = state.DepthTest.Func.Convert(); + pipeline.DepthMode = state.DepthMode == DepthMode.MinusOneToOne; pipeline.FrontFace = state.FrontFace.Convert();