From 704a78c11f54cf0601b5fe9e9470c9e340a4c139 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Sat, 25 May 2024 13:15:30 +0200 Subject: [PATCH] fix: don't dispose stencil state before using --- .../EncoderStateManager.cs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 525ab0b2d8..4a3993cad5 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -36,6 +36,10 @@ namespace Ryujinx.Graphics.Metal public void Dispose() { + // State + _currentState.FrontFaceStencil.Dispose(); + _currentState.BackFaceStencil.Dispose(); + _renderPipelineCache.Dispose(); _depthStencilCache.Dispose(); } @@ -327,18 +331,11 @@ namespace Ryujinx.Graphics.Metal // Inlineable public void UpdateStencilState(StencilTestDescriptor stencilTest) { - var backFace = new MTLStencilDescriptor - { - StencilFailureOperation = stencilTest.BackSFail.Convert(), - DepthFailureOperation = stencilTest.BackDpFail.Convert(), - DepthStencilPassOperation = stencilTest.BackDpPass.Convert(), - StencilCompareFunction = stencilTest.BackFunc.Convert(), - ReadMask = (uint)stencilTest.BackFuncMask, - WriteMask = (uint)stencilTest.BackMask - }; - _currentState.BackFaceStencil = backFace; + // Cleanup old state + _currentState.FrontFaceStencil.Dispose(); + _currentState.BackFaceStencil.Dispose(); - var frontFace = new MTLStencilDescriptor + _currentState.FrontFaceStencil = new MTLStencilDescriptor { StencilFailureOperation = stencilTest.FrontSFail.Convert(), DepthFailureOperation = stencilTest.FrontDpFail.Convert(), @@ -347,7 +344,16 @@ namespace Ryujinx.Graphics.Metal ReadMask = (uint)stencilTest.FrontFuncMask, WriteMask = (uint)stencilTest.FrontMask }; - _currentState.FrontFaceStencil = frontFace; + + _currentState.BackFaceStencil = new MTLStencilDescriptor + { + StencilFailureOperation = stencilTest.BackSFail.Convert(), + DepthFailureOperation = stencilTest.BackDpFail.Convert(), + DepthStencilPassOperation = stencilTest.BackDpPass.Convert(), + StencilCompareFunction = stencilTest.BackFunc.Convert(), + ReadMask = (uint)stencilTest.BackFuncMask, + WriteMask = (uint)stencilTest.BackMask + }; _currentState.StencilTestEnabled = stencilTest.TestEnable; @@ -370,8 +376,6 @@ namespace Ryujinx.Graphics.Metal // Cleanup descriptor.Dispose(); - frontFace.Dispose(); - backFace.Dispose(); } // Inlineable