aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-06-08 21:15:56 -0300
committerGitHub <noreply@github.com>2018-06-08 21:15:56 -0300
commit231fae1a4c97d7588655e9775f37c1dc9bd55fb0 (patch)
tree1c0e7b298ec33d5bf5b6a5693dd69a8c7e0bd23b /Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
parent6fe51f970501fe732276c17ed0dacb564b92a73d (diff)
Texture/Vertex/Index data cache (#132)
* Initial implementation of the texture cache * Cache vertex and index data aswell, some cleanup * Improve handling of the cache by storing cached ranges on a list for each page * Delete old data from the caches automatically, ensure that the cache is cleaned when the mapping/size changes, and some general cleanup
Diffstat (limited to 'Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs')
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs105
1 files changed, 62 insertions, 43 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
index 5b115446..b63c8b35 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs
@@ -44,24 +44,29 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{ GalVertexAttribSize._11_11_10, VertexAttribPointerType.Int } //?
};
+ private int VaoHandle;
+
+ private int[] VertexBuffers;
+
+ private OGLCachedResource<int> VboCache;
+ private OGLCachedResource<int> IboCache;
+
private struct IbInfo
{
- public int IboHandle;
public int Count;
public DrawElementsType Type;
}
- private int VaoHandle;
-
- private int[] VertexBuffers;
-
private IbInfo IndexBuffer;
public OGLRasterizer()
{
VertexBuffers = new int[32];
+ VboCache = new OGLCachedResource<int>(GL.DeleteBuffer);
+ IboCache = new OGLCachedResource<int>(GL.DeleteBuffer);
+
IndexBuffer = new IbInfo();
}
@@ -92,15 +97,53 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.Clear(Mask);
}
- public void SetVertexArray(int VbIndex, int Stride, byte[] Buffer, GalVertexAttrib[] Attribs)
+ public bool IsVboCached(long Tag, long DataSize)
+ {
+ return VboCache.TryGetSize(Tag, out long Size) && Size == DataSize;
+ }
+
+ public bool IsIboCached(long Tag, long DataSize)
+ {
+ return IboCache.TryGetSize(Tag, out long Size) && Size == DataSize;
+ }
+
+ public void CreateVbo(long Tag, byte[] Buffer)
{
- EnsureVbInitialized(VbIndex);
+ int Handle = GL.GenBuffer();
+
+ VboCache.AddOrUpdate(Tag, Handle, (uint)Buffer.Length);
IntPtr Length = new IntPtr(Buffer.Length);
- GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers[VbIndex]);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, Handle);
GL.BufferData(BufferTarget.ArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
+ }
+
+ public void CreateIbo(long Tag, byte[] Buffer)
+ {
+ int Handle = GL.GenBuffer();
+
+ IboCache.AddOrUpdate(Tag, Handle, (uint)Buffer.Length);
+
+ IntPtr Length = new IntPtr(Buffer.Length);
+
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, Handle);
+ GL.BufferData(BufferTarget.ElementArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
+ }
+
+ public void SetVertexArray(int VbIndex, int Stride, long VboTag, GalVertexAttrib[] Attribs)
+ {
+ if (!VboCache.TryGetValue(VboTag, out int VboHandle))
+ {
+ return;
+ }
+
+ if (VaoHandle == 0)
+ {
+ VaoHandle = GL.GenVertexArray();
+ }
GL.BindVertexArray(VaoHandle);
@@ -108,7 +151,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
GL.EnableVertexAttribArray(Attrib.Index);
- GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers[VbIndex]);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);
bool Unsigned =
Attrib.Type == GalVertexAttribType.Unorm ||
@@ -139,22 +182,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.BindVertexArray(0);
}
- public void SetIndexArray(byte[] Buffer, GalIndexFormat Format)
+ public void SetIndexArray(long Tag, int Size, GalIndexFormat Format)
{
- EnsureIbInitialized();
-
IndexBuffer.Type = OGLEnumConverter.GetDrawElementsType(Format);
- IndexBuffer.Count = Buffer.Length >> (int)Format;
-
- IntPtr Length = new IntPtr(Buffer.Length);
-
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer.IboHandle);
- GL.BufferData(BufferTarget.ElementArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
+ IndexBuffer.Count = Size >> (int)Format;
}
- public void DrawArrays(int VbIndex, int First, int PrimCount, GalPrimitiveType PrimType)
+ public void DrawArrays(int First, int PrimCount, GalPrimitiveType PrimType)
{
if (PrimCount == 0)
{
@@ -166,36 +201,20 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.DrawArrays(OGLEnumConverter.GetPrimitiveType(PrimType), First, PrimCount);
}
- public void DrawElements(int VbIndex, int First, GalPrimitiveType PrimType)
+ public void DrawElements(long IboTag, int First, GalPrimitiveType PrimType)
{
+ if (!IboCache.TryGetValue(IboTag, out int IboHandle))
+ {
+ return;
+ }
+
PrimitiveType Mode = OGLEnumConverter.GetPrimitiveType(PrimType);
GL.BindVertexArray(VaoHandle);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer.IboHandle);
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, IboHandle);
GL.DrawElements(Mode, IndexBuffer.Count, IndexBuffer.Type, First);
}
-
- private void EnsureVbInitialized(int VbIndex)
- {
- if (VaoHandle == 0)
- {
- VaoHandle = GL.GenVertexArray();
- }
-
- if (VertexBuffers[VbIndex] == 0)
- {
- VertexBuffers[VbIndex] = GL.GenBuffer();
- }
- }
-
- private void EnsureIbInitialized()
- {
- if (IndexBuffer.IboHandle == 0)
- {
- IndexBuffer.IboHandle = GL.GenBuffer();
- }
- }
}
} \ No newline at end of file