From 937d84018e568d73b1dc019454ccb8e585e0e855 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 23 May 2024 13:15:23 -0400 Subject: [PATCH] Start Proper Dispose --- Directory.Packages.props | 2 +- src/Ryujinx.Graphics.Metal/MetalRenderer.cs | 20 +++++++++++--------- src/Ryujinx.Graphics.Metal/Program.cs | 4 +++- src/Ryujinx.Graphics.Metal/Sampler.cs | 1 + src/Ryujinx.Graphics.Metal/Texture.cs | 1 + 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index cfb884d01..70404ef8e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -38,7 +38,7 @@ - + diff --git a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs index b5496028c..6e844e7c0 100644 --- a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs +++ b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs @@ -215,17 +215,19 @@ namespace Ryujinx.Graphics.Metal { var blitEncoder = _pipeline.GetOrCreateBlitEncoder(); - MTLBuffer src = _device.NewBuffer((ulong)data.Length, MTLResourceOptions.ResourceStorageModeManaged); - var span = new Span(src.Contents.ToPointer(), data.Length); - data.CopyTo(span); - src.DidModifyRange(new NSRange + using MTLBuffer src = _device.NewBuffer((ulong)data.Length, MTLResourceOptions.ResourceStorageModeManaged); { - location = 0, - length = (ulong)data.Length - }); + var span = new Span(src.Contents.ToPointer(), data.Length); + data.CopyTo(span); + src.DidModifyRange(new NSRange + { + location = 0, + length = (ulong)data.Length + }); - MTLBuffer dst = new(Unsafe.As(ref buffer)); - blitEncoder.CopyFromBuffer(src, 0, dst, (ulong)offset, (ulong)data.Length); + MTLBuffer dst = new(Unsafe.As(ref buffer)); + blitEncoder.CopyFromBuffer(src, 0, dst, (ulong)offset, (ulong)data.Length); + } } public void UpdateCounters() diff --git a/src/Ryujinx.Graphics.Metal/Program.cs b/src/Ryujinx.Graphics.Metal/Program.cs index 764bcf126..ee0ce4f78 100644 --- a/src/Ryujinx.Graphics.Metal/Program.cs +++ b/src/Ryujinx.Graphics.Metal/Program.cs @@ -63,7 +63,9 @@ namespace Ryujinx.Graphics.Metal public void Dispose() { - return; + VertexFunction.Dispose(); + FragmentFunction.Dispose(); + ComputeFunction.Dispose(); } } } diff --git a/src/Ryujinx.Graphics.Metal/Sampler.cs b/src/Ryujinx.Graphics.Metal/Sampler.cs index 5cb898a9f..f416b5da5 100644 --- a/src/Ryujinx.Graphics.Metal/Sampler.cs +++ b/src/Ryujinx.Graphics.Metal/Sampler.cs @@ -45,6 +45,7 @@ namespace Ryujinx.Graphics.Metal public void Dispose() { + _mtlSamplerState.Dispose(); } } } diff --git a/src/Ryujinx.Graphics.Metal/Texture.cs b/src/Ryujinx.Graphics.Metal/Texture.cs index a50d416aa..524cd6cf9 100644 --- a/src/Ryujinx.Graphics.Metal/Texture.cs +++ b/src/Ryujinx.Graphics.Metal/Texture.cs @@ -329,6 +329,7 @@ namespace Ryujinx.Graphics.Metal public void Dispose() { MTLTexture.SetPurgeableState(MTLPurgeableState.Volatile); + MTLTexture.Dispose(); } } }