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
This commit is contained in:
gdkchan 2018-07-09 23:01:59 -03:00 committed by GitHub
parent 791fe70810
commit 1968386808
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 122 additions and 26 deletions

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

@ -129,15 +129,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
switch (Format)
{
case GalTextureFormat.R32G32B32A32: return (PixelFormat.Rgba, PixelType.Float);
case GalTextureFormat.R16G16B16A16: return (PixelFormat.Rgba, PixelType.HalfFloat);
case GalTextureFormat.A8B8G8R8: return (PixelFormat.Rgba, PixelType.UnsignedByte);
case GalTextureFormat.R32: return (PixelFormat.Red, PixelType.Float);
case GalTextureFormat.A1B5G5R5: return (PixelFormat.Rgba, PixelType.UnsignedShort5551);
case GalTextureFormat.B5G6R5: return (PixelFormat.Rgb, PixelType.UnsignedShort565);
case GalTextureFormat.G8R8: return (PixelFormat.Rg, PixelType.UnsignedByte);
case GalTextureFormat.R16: return (PixelFormat.Red, PixelType.HalfFloat);
case GalTextureFormat.R8: return (PixelFormat.Red, PixelType.UnsignedByte);
case GalTextureFormat.R32G32B32A32: return (PixelFormat.Rgba, PixelType.Float);
case GalTextureFormat.R16G16B16A16: return (PixelFormat.Rgba, PixelType.HalfFloat);
case GalTextureFormat.A8B8G8R8: return (PixelFormat.Rgba, PixelType.UnsignedByte);
case GalTextureFormat.R32: return (PixelFormat.Red, PixelType.Float);
case GalTextureFormat.A1B5G5R5: return (PixelFormat.Rgba, PixelType.UnsignedShort5551);
case GalTextureFormat.B5G6R5: return (PixelFormat.Rgb, PixelType.UnsignedShort565);
case GalTextureFormat.G8R8: return (PixelFormat.Rg, PixelType.UnsignedByte);
case GalTextureFormat.R16: return (PixelFormat.Red, PixelType.HalfFloat);
case GalTextureFormat.R8: return (PixelFormat.Red, PixelType.UnsignedByte);
case GalTextureFormat.ZF32: return (PixelFormat.DepthComponent, PixelType.Float);
}
throw new NotImplementedException(Format.ToString());

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;
@ -223,7 +235,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.BufferData(BufferTarget.ElementArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
}
public void SetVertexArray(int VbIndex, int Stride, long VboKey, GalVertexAttrib[] Attribs)
public void SetVertexArray(int Stride, long VboKey, GalVertexAttrib[] Attribs)
{
if (!VboCache.TryGetValue(VboKey, out int VboHandle))
{
@ -270,7 +282,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
}
}
public void SetIndexArray(long Key, int Size, GalIndexFormat Format)
public void SetIndexArray(int Size, GalIndexFormat Format)
{
IndexBuffer.Type = OGLEnumConverter.GetDrawElementsType(Format);

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);