From 7654f0b16c369f6ae751c7692d6c0c13296bd3dd Mon Sep 17 00:00:00 2001 From: Samuliak Date: Sat, 25 May 2024 08:17:43 +0200 Subject: [PATCH] dispose all objects in encoder state manager --- .../EncoderStateManager.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index ab9b362bab..688f0077b8 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -143,6 +143,9 @@ namespace Ryujinx.Graphics.Metal SetTextureAndSampler(renderCommandEncoder, ShaderStage.Vertex, _currentState.VertexTextures, _currentState.VertexSamplers); SetTextureAndSampler(renderCommandEncoder, ShaderStage.Fragment, _currentState.FragmentTextures, _currentState.FragmentSamplers); + // Cleanup + renderPassDescriptor.Dispose(); + return renderCommandEncoder; } @@ -217,16 +220,13 @@ namespace Ryujinx.Graphics.Metal } } - renderPipelineDescriptor.VertexDescriptor = BuildVertexDescriptor(_currentState.VertexBuffers, _currentState.VertexAttribs); + var vertexDescriptor = BuildVertexDescriptor(_currentState.VertexBuffers, _currentState.VertexAttribs); + renderPipelineDescriptor.VertexDescriptor = vertexDescriptor; if (_currentState.VertexFunction != null) { renderPipelineDescriptor.VertexFunction = _currentState.VertexFunction.Value; } - else - { - return; - } if (_currentState.FragmentFunction != null) { @@ -242,6 +242,10 @@ namespace Ryujinx.Graphics.Metal _currentState.BlendColor.Green, _currentState.BlendColor.Blue, _currentState.BlendColor.Alpha); + + // Cleanup + renderPipelineDescriptor.Dispose(); + vertexDescriptor.Dispose(); } public void UpdateIndexBuffer(BufferRange buffer, IndexType type) @@ -320,7 +324,7 @@ namespace Ryujinx.Graphics.Metal // Inlineable public void UpdateStencilState(StencilTestDescriptor stencilTest) { - _currentState.BackFaceStencil = new MTLStencilDescriptor + var backFace = new MTLStencilDescriptor { StencilFailureOperation = stencilTest.BackSFail.Convert(), DepthFailureOperation = stencilTest.BackDpFail.Convert(), @@ -329,8 +333,9 @@ namespace Ryujinx.Graphics.Metal ReadMask = (uint)stencilTest.BackFuncMask, WriteMask = (uint)stencilTest.BackMask }; + _currentState.BackFaceStencil = backFace; - _currentState.FrontFaceStencil = new MTLStencilDescriptor + var frontFace = new MTLStencilDescriptor { StencilFailureOperation = stencilTest.FrontSFail.Convert(), DepthFailureOperation = stencilTest.FrontDpFail.Convert(), @@ -339,6 +344,7 @@ namespace Ryujinx.Graphics.Metal ReadMask = (uint)stencilTest.FrontFuncMask, WriteMask = (uint)stencilTest.FrontMask }; + _currentState.FrontFaceStencil = frontFace; _currentState.StencilTestEnabled = stencilTest.TestEnable; @@ -358,6 +364,11 @@ namespace Ryujinx.Graphics.Metal // Mark dirty _currentState.Dirty.DepthStencil = true; + + // Cleanup + descriptor.Dispose(); + frontFace.Dispose(); + backFace.Dispose(); } // Inlineable @@ -382,6 +393,9 @@ namespace Ryujinx.Graphics.Metal // Mark dirty _currentState.Dirty.DepthStencil = true; + + // Cleanup + descriptor.Dispose(); } // Inlineable