From 266649929f23c2f6d062651075baf37b69978943 Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Sun, 2 Jun 2024 21:00:18 -0700 Subject: [PATCH] Clean up for some clarity and attempt to resolve some validation errors. --- src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 12 ++--- .../PipelineDynamicState.cs | 46 +++++++++---------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 7cc0131d80..b71dc3f70c 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -697,7 +697,7 @@ namespace Ryujinx.Graphics.Vulkan var oldStencilTestEnable = _supportExtDynamic ? DynamicState.StencilTestEnable : _newState.StencilTestEnable; var oldDepthTestEnable = _supportExtDynamic ? DynamicState.DepthTestEnable : _newState.DepthTestEnable; var oldDepthWriteEnable = _supportExtDynamic ? DynamicState.DepthWriteEnable : _newState.DepthWriteEnable; - var oldTopology = _supportExtDynamic ? DynamicState.Topology : _newState.Topology; + var oldTopology = _newState.Topology; var oldViewports = DynamicState.Viewports; var oldViewportsCount = _supportExtDynamic ? DynamicState.ViewportsCount : _newState.ViewportsCount; @@ -728,14 +728,13 @@ namespace Ryujinx.Graphics.Vulkan if (_supportExtDynamic) { var oldTopologyClass = GetTopologyClass(oldTopology); - var newTopologyClass = GetTopologyClass(DynamicState.Topology); DynamicState.SetCullMode(oldCullMode); DynamicState.SetStencilTest(oldStencilTestEnable); DynamicState.SetDepthTestBool(oldDepthTestEnable, oldDepthWriteEnable); DynamicState.SetPrimitiveTopology(oldTopology); - if (oldTopologyClass != newTopologyClass) + if (oldTopologyClass != TopologyClass.Triangle) { _newState.TopologyClass = oldTopology; } @@ -1296,7 +1295,7 @@ namespace Ryujinx.Graphics.Vulkan { if (_supportExtDynamic) { - DynamicState.SetStencilOp( + DynamicState.SetStencilTestandOp( stencilTest.BackSFail.Convert(), stencilTest.BackDpPass.Convert(), stencilTest.BackDpFail.Convert(), @@ -1304,9 +1303,8 @@ namespace Ryujinx.Graphics.Vulkan stencilTest.FrontSFail.Convert(), stencilTest.FrontDpPass.Convert(), stencilTest.FrontDpFail.Convert(), - stencilTest.FrontFunc.Convert()); - - DynamicState.SetStencilTest(stencilTest.TestEnable); + stencilTest.FrontFunc.Convert(), + stencilTest.TestEnable); } else { diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs index d44c3f7084..ebc048cfd7 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs @@ -22,7 +22,6 @@ namespace Ryujinx.Graphics.Vulkan private uint _frontWriteMask; private uint _frontReference; - private bool _opToo; private StencilOp _backFailOp; private StencilOp _backPassOp; private StencilOp _backDepthFailOp; @@ -71,7 +70,7 @@ namespace Ryujinx.Graphics.Vulkan FrontFace = 1 << 6, DepthTestBool = 1 << 7, DepthTestCompareOp = 1 << 8, - StencilTestEnable = 1 << 9, + StencilTestEnableandStencilOp = 1 << 9, LineWidth = 1 << 10, RasterDiscard = 1 << 11, LogicOp = 1 << 12, @@ -79,7 +78,7 @@ namespace Ryujinx.Graphics.Vulkan PrimitiveRestart = 1 << 14, PrimitiveTopology = 1 << 15, Standard = Blend | DepthBias | Scissor | Stencil | Viewport | LineWidth, - Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnable | PrimitiveTopology, + Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnableandStencilOp | PrimitiveTopology, Extended2 = RasterDiscard | LogicOp | PatchControlPoints | PrimitiveRestart, } @@ -123,9 +122,9 @@ namespace Ryujinx.Graphics.Vulkan _dirty |= DirtyFlags.DepthTestCompareOp; } - public void SetStencilOp(StencilOp backFailOp, StencilOp backPassOp, StencilOp backDepthFailOp, + public void SetStencilTestandOp(StencilOp backFailOp, StencilOp backPassOp, StencilOp backDepthFailOp, CompareOp backCompareOp, StencilOp frontFailOp, StencilOp frontPassOp, StencilOp frontDepthFailOp, - CompareOp frontCompareOp) + CompareOp frontCompareOp, bool stencilTestEnable) { _backFailOp = backFailOp; _backPassOp = backPassOp; @@ -135,7 +134,17 @@ namespace Ryujinx.Graphics.Vulkan _frontPassOp = frontPassOp; _frontDepthFailOp = frontDepthFailOp; _frontCompareOp = frontCompareOp; - _opToo = true; + + StencilTestEnable = stencilTestEnable; + + _dirty |= DirtyFlags.StencilTestEnableandStencilOp; + } + + public void SetStencilTest(bool stencilTestEnable) + { + StencilTestEnable = stencilTestEnable; + + _dirty |= DirtyFlags.StencilTestEnableandStencilOp; } public void SetStencilMask(uint backCompareMask, uint backWriteMask, uint backReference, @@ -150,12 +159,6 @@ namespace Ryujinx.Graphics.Vulkan _dirty |= DirtyFlags.Stencil; } - public void SetStencilTest(bool stencilTestEnable) - { - StencilTestEnable = stencilTestEnable; - _dirty |= DirtyFlags.StencilTestEnable; - } - public void SetViewport(int index, Viewport viewport) { Viewports[index] = viewport; @@ -301,9 +304,9 @@ namespace Ryujinx.Graphics.Vulkan RecordDepthTestCompareOp(gd.ExtendedDynamicStateApi, commandBuffer); } - if (_dirty.HasFlag(DirtyFlags.StencilTestEnable)) + if (_dirty.HasFlag(DirtyFlags.StencilTestEnableandStencilOp)) { - RecordStencilTestEnable(gd.ExtendedDynamicStateApi, commandBuffer); + RecordStencilTestandOp(gd.ExtendedDynamicStateApi, commandBuffer); } if (_dirty.HasFlag(DirtyFlags.LineWidth)) @@ -379,14 +382,6 @@ namespace Ryujinx.Graphics.Vulkan private readonly void RecordStencil(VulkanRenderer gd, CommandBuffer commandBuffer) { - if (_opToo) - { - gd.ExtendedDynamicStateApi.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceBackBit, _backFailOp, _backPassOp, - _backDepthFailOp, _backCompareOp); - gd.ExtendedDynamicStateApi.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontFailOp, _frontPassOp, - _frontDepthFailOp, _frontCompareOp); - } - gd.Api.CmdSetStencilCompareMask(commandBuffer, StencilFaceFlags.FaceBackBit, _backCompareMask); gd.Api.CmdSetStencilWriteMask(commandBuffer, StencilFaceFlags.FaceBackBit, _backWriteMask); gd.Api.CmdSetStencilReference(commandBuffer, StencilFaceFlags.FaceBackBit, _backReference); @@ -395,9 +390,14 @@ namespace Ryujinx.Graphics.Vulkan gd.Api.CmdSetStencilReference(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontReference); } - private readonly void RecordStencilTestEnable(ExtExtendedDynamicState api, CommandBuffer commandBuffer) + private readonly void RecordStencilTestandOp(ExtExtendedDynamicState api, CommandBuffer commandBuffer) { api.CmdSetStencilTestEnable(commandBuffer, StencilTestEnable); + + api.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceBackBit, _backFailOp, _backPassOp, + _backDepthFailOp, _backCompareOp); + api.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontFailOp, _frontPassOp, + _frontDepthFailOp, _frontCompareOp); } private void RecordViewport(VulkanRenderer gd, CommandBuffer commandBuffer)