aboutsummaryrefslogtreecommitdiff
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
parent453543fb882c2465b771b32baa204a1c085e0ea1 (diff)
Force cache to remove entries when memory usage exceeds a given threshold (#492)
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs22
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLConstBuffer.cs4
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs7
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs4
4 files changed, 30 insertions, 7 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
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLConstBuffer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLConstBuffer.cs
index 4958b53b..e04190e0 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLConstBuffer.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLConstBuffer.cs
@@ -5,11 +5,13 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
class OGLConstBuffer : IGalConstBuffer
{
+ private const long MaxConstBufferCacheSize = 64 * 1024 * 1024;
+
private OGLCachedResource<OGLStreamBuffer> Cache;
public OGLConstBuffer()
{
- Cache = new OGLCachedResource<OGLStreamBuffer>(DeleteBuffer);
+ Cache = new OGLCachedResource<OGLStreamBuffer>(DeleteBuffer, MaxConstBufferCacheSize);
}
public void LockCache()
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
index cefbb2d2..cd6292f7 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
@@ -5,6 +5,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
class OGLRasterizer : IGalRasterizer
{
+ private const long MaxVertexBufferCacheSize = 128 * 1024 * 1024;
+ private const long MaxIndexBufferCacheSize = 64 * 1024 * 1024;
+
private int[] VertexBuffers;
private OGLCachedResource<int> VboCache;
@@ -24,8 +27,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
VertexBuffers = new int[32];
- VboCache = new OGLCachedResource<int>(GL.DeleteBuffer);
- IboCache = new OGLCachedResource<int>(GL.DeleteBuffer);
+ VboCache = new OGLCachedResource<int>(GL.DeleteBuffer, MaxVertexBufferCacheSize);
+ IboCache = new OGLCachedResource<int>(GL.DeleteBuffer, MaxIndexBufferCacheSize);
IndexBuffer = new IbInfo();
}
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
index 274b94ea..6f843b9c 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs
@@ -6,13 +6,15 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
class OGLTexture : IGalTexture
{
+ private const long MaxTextureCacheSize = 768 * 1024 * 1024;
+
private OGLCachedResource<ImageHandler> TextureCache;
public EventHandler<int> TextureDeleted { get; set; }
public OGLTexture()
{
- TextureCache = new OGLCachedResource<ImageHandler>(DeleteTexture);
+ TextureCache = new OGLCachedResource<ImageHandler>(DeleteTexture, MaxTextureCacheSize);
}
public void LockCache()