Reduce unneeded state changes

This commit is contained in:
sunshineinabox 2024-05-29 09:45:56 -07:00
parent 5c65880ec0
commit e6492f8e78
3 changed files with 40 additions and 17 deletions

View file

@ -880,12 +880,10 @@ namespace Ryujinx.Graphics.Vulkan
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) 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 = enable;
{
_newState.DepthBiasEnable = enables != 0;
}
SignalStateChange(); SignalStateChange();
} }
@ -919,11 +917,12 @@ namespace Ryujinx.Graphics.Vulkan
} }
else else
{ {
_newState.DepthTestEnable = depthTest.TestEnable;
_newState.DepthWriteEnable = depthTest.WriteEnable; _newState.DepthWriteEnable = depthTest.WriteEnable;
_newState.DepthCompareOp = depthTest.Func.Convert(); _newState.DepthCompareOp = depthTest.Func.Convert();
} }
_newState.DepthTestEnable = depthTest.TestEnable;
SignalStateChange(); SignalStateChange();
} }

View file

@ -434,8 +434,11 @@ namespace Ryujinx.Graphics.Vulkan
{ {
api.CmdSetDepthTestEnable(commandBuffer, DepthTestEnable); api.CmdSetDepthTestEnable(commandBuffer, DepthTestEnable);
if (DepthTestEnable)
{
api.CmdSetDepthWriteEnable(commandBuffer, DepthWriteEnable); api.CmdSetDepthWriteEnable(commandBuffer, DepthWriteEnable);
} }
}
private readonly void RecordDepthTestCompareOp(ExtExtendedDynamicState api, CommandBuffer commandBuffer) private readonly void RecordDepthTestCompareOp(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
{ {

View file

@ -526,7 +526,10 @@ namespace Ryujinx.Graphics.Vulkan
depthStencilState.Back = stencilBack; depthStencilState.Back = stencilBack;
depthStencilState.StencilTestEnable = StencilTestEnable; depthStencilState.StencilTestEnable = StencilTestEnable;
depthStencilState.DepthTestEnable = DepthTestEnable; depthStencilState.DepthTestEnable = DepthTestEnable;
if (DepthTestEnable)
{
depthStencilState.DepthWriteEnable = DepthWriteEnable; depthStencilState.DepthWriteEnable = DepthWriteEnable;
}
depthStencilState.DepthCompareOp = DepthCompareOp; depthStencilState.DepthCompareOp = DepthCompareOp;
} }
@ -579,7 +582,7 @@ namespace Ryujinx.Graphics.Vulkan
colorBlendState.PNext = &colorBlendAdvancedState; colorBlendState.PNext = &colorBlendAdvancedState;
} }
int baseDynamicStatesCount = 7; int baseDynamicStatesCount = 6;
int additionalDynamicStatesCount = 0; int additionalDynamicStatesCount = 0;
if (!isMoltenVk) if (!isMoltenVk)
@ -587,9 +590,19 @@ namespace Ryujinx.Graphics.Vulkan
baseDynamicStatesCount++; baseDynamicStatesCount++;
} }
if (DepthBiasEnable)
{
baseDynamicStatesCount++;
}
if (supportsExtDynamicState) if (supportsExtDynamicState)
{ {
additionalDynamicStatesCount += isMoltenVk ? 8 : 9; additionalDynamicStatesCount += isMoltenVk ? 7 : 8;
if (DepthTestEnable)
{
additionalDynamicStatesCount++;
}
} }
if (supportsExtDynamicState2) if (supportsExtDynamicState2)
@ -610,13 +623,16 @@ namespace Ryujinx.Graphics.Vulkan
dynamicStates[0] = DynamicState.Viewport; dynamicStates[0] = DynamicState.Viewport;
dynamicStates[1] = DynamicState.Scissor; dynamicStates[1] = DynamicState.Scissor;
dynamicStates[2] = DynamicState.DepthBias; dynamicStates[2] = DynamicState.StencilCompareMask;
dynamicStates[3] = DynamicState.StencilCompareMask; dynamicStates[3] = DynamicState.StencilWriteMask;
dynamicStates[4] = DynamicState.StencilWriteMask; dynamicStates[4] = DynamicState.StencilReference;
dynamicStates[5] = DynamicState.StencilReference; dynamicStates[5] = DynamicState.BlendConstants;
dynamicStates[6] = DynamicState.BlendConstants;
int currentIndex = 7; if (DepthBiasEnable)
{
dynamicStates[6] = DynamicState.DepthBias;
}
int currentIndex = DepthBiasEnable ? 7 : 6;
if (!isMoltenVk) if (!isMoltenVk)
{ {
@ -636,7 +652,12 @@ namespace Ryujinx.Graphics.Vulkan
dynamicStates[currentIndex++] = DynamicState.CullModeExt; dynamicStates[currentIndex++] = DynamicState.CullModeExt;
dynamicStates[currentIndex++] = DynamicState.FrontFaceExt; dynamicStates[currentIndex++] = DynamicState.FrontFaceExt;
dynamicStates[currentIndex++] = DynamicState.DepthTestEnableExt; dynamicStates[currentIndex++] = DynamicState.DepthTestEnableExt;
if (DepthTestEnable)
{
dynamicStates[currentIndex++] = DynamicState.DepthWriteEnableExt; dynamicStates[currentIndex++] = DynamicState.DepthWriteEnableExt;
}
dynamicStates[currentIndex++] = DynamicState.DepthCompareOpExt; dynamicStates[currentIndex++] = DynamicState.DepthCompareOpExt;
dynamicStates[currentIndex++] = DynamicState.StencilTestEnableExt; dynamicStates[currentIndex++] = DynamicState.StencilTestEnableExt;
dynamicStates[currentIndex++] = DynamicState.StencilOpExt; dynamicStates[currentIndex++] = DynamicState.StencilOpExt;