From e6492f8e786c3712f80f1ccb53a68282215e436f Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Wed, 29 May 2024 09:45:56 -0700 Subject: [PATCH] Reduce unneeded state changes --- src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 11 +++-- .../PipelineDynamicState.cs | 5 ++- src/Ryujinx.Graphics.Vulkan/PipelineState.cs | 41 ++++++++++++++----- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 076d4351c1..eec57b83d8 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -880,12 +880,10 @@ namespace Ryujinx.Graphics.Vulkan public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) { - DynamicState.SetDepthBias(factor, units, clamp, (enables != 0)); + bool enable = enables != 0; + DynamicState.SetDepthBias(factor, units, clamp, enable); - if (!_supportExtDynamic2) - { - _newState.DepthBiasEnable = enables != 0; - } + _newState.DepthBiasEnable = enable; SignalStateChange(); } @@ -919,11 +917,12 @@ namespace Ryujinx.Graphics.Vulkan } else { - _newState.DepthTestEnable = depthTest.TestEnable; _newState.DepthWriteEnable = depthTest.WriteEnable; _newState.DepthCompareOp = depthTest.Func.Convert(); } + _newState.DepthTestEnable = depthTest.TestEnable; + SignalStateChange(); } diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs index e873e1d5e6..d44c3f7084 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs @@ -434,7 +434,10 @@ namespace Ryujinx.Graphics.Vulkan { api.CmdSetDepthTestEnable(commandBuffer, DepthTestEnable); - api.CmdSetDepthWriteEnable(commandBuffer, DepthWriteEnable); + if (DepthTestEnable) + { + api.CmdSetDepthWriteEnable(commandBuffer, DepthWriteEnable); + } } private readonly void RecordDepthTestCompareOp(ExtExtendedDynamicState api, CommandBuffer commandBuffer) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineState.cs index e210bebd76..bf2be65ca1 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineState.cs @@ -526,7 +526,10 @@ namespace Ryujinx.Graphics.Vulkan depthStencilState.Back = stencilBack; depthStencilState.StencilTestEnable = StencilTestEnable; depthStencilState.DepthTestEnable = DepthTestEnable; - depthStencilState.DepthWriteEnable = DepthWriteEnable; + if (DepthTestEnable) + { + depthStencilState.DepthWriteEnable = DepthWriteEnable; + } depthStencilState.DepthCompareOp = DepthCompareOp; } @@ -579,7 +582,7 @@ namespace Ryujinx.Graphics.Vulkan colorBlendState.PNext = &colorBlendAdvancedState; } - int baseDynamicStatesCount = 7; + int baseDynamicStatesCount = 6; int additionalDynamicStatesCount = 0; if (!isMoltenVk) @@ -587,9 +590,19 @@ namespace Ryujinx.Graphics.Vulkan baseDynamicStatesCount++; } + if (DepthBiasEnable) + { + baseDynamicStatesCount++; + } + if (supportsExtDynamicState) { - additionalDynamicStatesCount += isMoltenVk ? 8 : 9; + additionalDynamicStatesCount += isMoltenVk ? 7 : 8; + + if (DepthTestEnable) + { + additionalDynamicStatesCount++; + } } if (supportsExtDynamicState2) @@ -610,13 +623,16 @@ namespace Ryujinx.Graphics.Vulkan dynamicStates[0] = DynamicState.Viewport; dynamicStates[1] = DynamicState.Scissor; - dynamicStates[2] = DynamicState.DepthBias; - dynamicStates[3] = DynamicState.StencilCompareMask; - dynamicStates[4] = DynamicState.StencilWriteMask; - dynamicStates[5] = DynamicState.StencilReference; - dynamicStates[6] = DynamicState.BlendConstants; + dynamicStates[2] = DynamicState.StencilCompareMask; + dynamicStates[3] = DynamicState.StencilWriteMask; + dynamicStates[4] = DynamicState.StencilReference; + dynamicStates[5] = DynamicState.BlendConstants; - int currentIndex = 7; + if (DepthBiasEnable) + { + dynamicStates[6] = DynamicState.DepthBias; + } + int currentIndex = DepthBiasEnable ? 7 : 6; if (!isMoltenVk) { @@ -636,7 +652,12 @@ namespace Ryujinx.Graphics.Vulkan dynamicStates[currentIndex++] = DynamicState.CullModeExt; dynamicStates[currentIndex++] = DynamicState.FrontFaceExt; dynamicStates[currentIndex++] = DynamicState.DepthTestEnableExt; - dynamicStates[currentIndex++] = DynamicState.DepthWriteEnableExt; + + if (DepthTestEnable) + { + dynamicStates[currentIndex++] = DynamicState.DepthWriteEnableExt; + } + dynamicStates[currentIndex++] = DynamicState.DepthCompareOpExt; dynamicStates[currentIndex++] = DynamicState.StencilTestEnableExt; dynamicStates[currentIndex++] = DynamicState.StencilOpExt;