Add locking methods to the ogl resource cache

This commit is contained in:
gdkchan 2018-07-09 01:09:45 -03:00
parent 095db47e13
commit 3ce4e58cd7
6 changed files with 85 additions and 2 deletions

View file

@ -2,6 +2,9 @@ namespace Ryujinx.Graphics.Gal
{
public interface IGalRasterizer
{
void LockCaches();
void UnlockCaches();
void ClearBuffers(GalClearBufferFlags Flags);
bool IsVboCached(long Key, long DataSize);

View file

@ -2,6 +2,9 @@ namespace Ryujinx.Graphics.Gal
{
public interface IGalTexture
{
void LockCache();
void UnlockCache();
void Create(long Key, byte[] Data, GalTexture Texture);
bool TryGetCachedTexture(long Key, long DataSize, out GalTexture Texture);

View file

@ -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 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)
{
ClearCacheIfNeeded();
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;
}

View file

@ -71,6 +71,18 @@ namespace Ryujinx.Graphics.Gal.OpenGL
IndexBuffer = new IbInfo();
}
public void LockCaches()
{
VboCache.Lock();
IboCache.Lock();
}
public void UnlockCaches()
{
VboCache.Unlock();
IboCache.Unlock();
}
public void ClearBuffers(GalClearBufferFlags Flags)
{
ClearBufferMask Mask = ClearBufferMask.ColorBufferBit;

View file

@ -26,6 +26,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
TextureCache = new OGLCachedResource<TCE>(DeleteTexture);
}
public void LockCache()
{
TextureCache.Lock();
}
public void UnlockCache()
{
TextureCache.Unlock();
}
private static void DeleteTexture(TCE CachedTexture)
{
GL.DeleteTexture(CachedTexture.Handle);

View file

@ -73,6 +73,8 @@ namespace Ryujinx.HLE.Gpu.Engines
private void VertexEndGl(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
{
LockCaches();
SetFrameBuffer(Vmm, 0);
long[] Keys = UploadShaders(Vmm);
@ -90,6 +92,20 @@ namespace Ryujinx.HLE.Gpu.Engines
UploadTextures(Vmm, Keys);
UploadUniforms(Vmm);
UploadVertexArrays(Vmm);
UnlockCaches();
}
private void LockCaches()
{
Gpu.Renderer.Rasterizer.LockCaches();
Gpu.Renderer.Texture.LockCache();
}
private void UnlockCaches()
{
Gpu.Renderer.Rasterizer.UnlockCaches();
Gpu.Renderer.Texture.UnlockCache();
}
private void ClearBuffers(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)