aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-11-14 20:22:02 -0200
committerAc_K <Acoustik666@gmail.com>2018-11-14 23:22:02 +0100
commit85ffd760161c6995f0004e042178d2e9259b2af5 (patch)
tree5b9b1a1149b0a296b7232708ae6b9f0b267d3d53 /Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
parent453543fb882c2465b771b32baa204a1c085e0ea1 (diff)
Force cache to remove entries when memory usage exceeds a given threshold (#492)
Diffstat (limited to 'Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs')
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs22
1 files changed, 19 insertions, 3 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
index efacb4d4..6e17872b 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
@@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
public delegate void DeleteValue(T Value);
- private const int MaxTimeDelta = 5 * 60000;
+ private const int MinTimeDelta = 5 * 60000;
private const int MaxRemovalsPerRun = 10;
private struct CacheBucket
@@ -41,8 +41,13 @@ namespace Ryujinx.Graphics.Gal.OpenGL
private bool Locked;
- public OGLCachedResource(DeleteValue DeleteValueCallback)
+ private long MaxSize;
+ private long TotalSize;
+
+ public OGLCachedResource(DeleteValue DeleteValueCallback, long MaxSize)
{
+ this.MaxSize = MaxSize;
+
if (DeleteValueCallback == null)
{
throw new ArgumentNullException(nameof(DeleteValueCallback));
@@ -98,12 +103,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
SortedCache.Remove(Bucket.Node);
+ TotalSize -= Bucket.DataSize;
+
Cache[Key] = NewBucket;
}
else
{
Cache.Add(Key, NewBucket);
}
+
+ TotalSize += Size;
}
public bool TryGetValue(long Key, out T Value)
@@ -159,7 +168,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
long TimeDelta = Timestamp - Bucket.Timestamp;
- if ((uint)TimeDelta <= (uint)MaxTimeDelta)
+ if (TimeDelta <= MinTimeDelta && !UnderMemoryPressure())
{
break;
}
@@ -169,7 +178,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Cache.Remove(Node.Value);
DeleteValueCallback(Bucket.Value);
+
+ TotalSize -= Bucket.DataSize;
}
}
+
+ private bool UnderMemoryPressure()
+ {
+ return TotalSize >= MaxSize;
+ }
}
} \ No newline at end of file