From c26df1f7a3f5c2e36396e4f24ed6e29c809785db Mon Sep 17 00:00:00 2001 From: Samuliak Date: Fri, 24 May 2024 20:03:55 +0200 Subject: [PATCH] dispose caches --- src/Ryujinx.Graphics.Metal/EncoderStateManager.cs | 8 +++++++- src/Ryujinx.Graphics.Metal/StateCache.cs | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 313d380f45..ab9b362bab 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -10,7 +10,7 @@ using System.Runtime.Versioning; namespace Ryujinx.Graphics.Metal { [SupportedOSPlatform("macos")] - struct EncoderStateManager + struct EncoderStateManager : IDisposable { private readonly Pipeline _pipeline; @@ -34,6 +34,12 @@ namespace Ryujinx.Graphics.Metal _depthStencilCache = new(device); } + public void Dispose() + { + _renderPipelineCache.Dispose(); + _depthStencilCache.Dispose(); + } + public void SaveState() { _backStates.Add(_currentState); diff --git a/src/Ryujinx.Graphics.Metal/StateCache.cs b/src/Ryujinx.Graphics.Metal/StateCache.cs index 2abf5f528e..4b2c6c5a48 100644 --- a/src/Ryujinx.Graphics.Metal/StateCache.cs +++ b/src/Ryujinx.Graphics.Metal/StateCache.cs @@ -1,10 +1,11 @@ +using System; using System.Collections.Generic; using System.Runtime.Versioning; namespace Ryujinx.Graphics.Metal { [SupportedOSPlatform("macos")] - public abstract class StateCache + public abstract class StateCache : IDisposable where T : IDisposable { private readonly Dictionary _cache = new(); @@ -12,6 +13,14 @@ namespace Ryujinx.Graphics.Metal protected abstract T CreateValue(TDescriptor descriptor); + public void Dispose() + { + foreach (T value in _cache.Values) + { + value.Dispose(); + } + } + public T GetOrCreate(TDescriptor descriptor) { var hash = GetHash(descriptor);