Revert "Revert the Metal Experiment (#701)"
This reverts commit fe1617ffea.
This commit is contained in:
42
src/Ryujinx.Graphics.Metal/StateCache.cs
Normal file
42
src/Ryujinx.Graphics.Metal/StateCache.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
abstract class StateCache<T, TDescriptor, THash> : IDisposable where T : IDisposable
|
||||
{
|
||||
private readonly Dictionary<THash, T> _cache = new();
|
||||
|
||||
protected abstract THash GetHash(TDescriptor descriptor);
|
||||
|
||||
protected abstract T CreateValue(TDescriptor descriptor);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (T value in _cache.Values)
|
||||
{
|
||||
value.Dispose();
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public T GetOrCreate(TDescriptor descriptor)
|
||||
{
|
||||
THash hash = GetHash(descriptor);
|
||||
if (_cache.TryGetValue(hash, out T value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
T newValue = CreateValue(descriptor);
|
||||
_cache.Add(hash, newValue);
|
||||
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user