diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2018-07-09 23:01:59 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-09 23:01:59 -0300 |
| commit | 1968386808bb48f823b1877b0e5ff8c6e2f8bd49 (patch) | |
| tree | 40b4dd9e9dc1f756af99fcd571a7ef5272f4cc8f /Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs | |
| parent | 791fe70810f0f0f417c74aaff5446551bed78fee (diff) | |
Add locking methods to the ogl resource cache (#238)
* Add locking methods to the ogl resource cache
* Remove some unused arguments
* Add the ZF32 texture format
Diffstat (limited to 'Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs')
| -rw-r--r-- | Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs index 06d76b8b..01ebf982 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs @@ -36,6 +36,10 @@ namespace Ryujinx.Graphics.Gal.OpenGL private DeleteValue DeleteValueCallback; + private Queue<T> DeletePending; + + private bool Locked; + public OGLCachedResource(DeleteValue DeleteValueCallback) { if (DeleteValueCallback == null) @@ -48,11 +52,33 @@ namespace Ryujinx.Graphics.Gal.OpenGL Cache = new Dictionary<long, CacheBucket>(); SortedCache = new LinkedList<long>(); + + DeletePending = new Queue<T>(); } - public void AddOrUpdate(long Key, T Value, long Size) + public void Lock() + { + Locked = true; + } + + public void Unlock() { + Locked = false; + + while (DeletePending.TryDequeue(out T Value)) + { + DeleteValueCallback(Value); + } + ClearCacheIfNeeded(); + } + + public void AddOrUpdate(long Key, T Value, long Size) + { + if (!Locked) + { + ClearCacheIfNeeded(); + } LinkedListNode<long> Node = SortedCache.AddLast(Key); @@ -60,7 +86,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL if (Cache.TryGetValue(Key, out CacheBucket Bucket)) { - DeleteValueCallback(Bucket.Value); + if (Locked) + { + DeletePending.Enqueue(Bucket.Value); + } + else + { + DeleteValueCallback(Bucket.Value); + } SortedCache.Remove(Bucket.Node); @@ -78,6 +111,12 @@ namespace Ryujinx.Graphics.Gal.OpenGL { Value = Bucket.Value; + SortedCache.Remove(Bucket.Node); + + LinkedListNode<long> Node = SortedCache.AddLast(Key); + + Cache[Key] = new CacheBucket(Value, Bucket.DataSize, Node); + return true; } |
