OGLConstBuffer.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. namespace Ryujinx.Graphics.Gal.OpenGL
  4. {
  5. class OGLConstBuffer : IGalConstBuffer
  6. {
  7. private const long MaxConstBufferCacheSize = 64 * 1024 * 1024;
  8. private OGLCachedResource<OGLStreamBuffer> Cache;
  9. public OGLConstBuffer()
  10. {
  11. Cache = new OGLCachedResource<OGLStreamBuffer>(DeleteBuffer, MaxConstBufferCacheSize);
  12. }
  13. public void LockCache()
  14. {
  15. Cache.Lock();
  16. }
  17. public void UnlockCache()
  18. {
  19. Cache.Unlock();
  20. }
  21. public void Create(long Key, long Size)
  22. {
  23. OGLStreamBuffer Buffer = new OGLStreamBuffer(BufferTarget.UniformBuffer, Size);
  24. Cache.AddOrUpdate(Key, Buffer, Size);
  25. }
  26. public bool IsCached(long Key, long Size)
  27. {
  28. return Cache.TryGetSize(Key, out long CachedSize) && CachedSize == Size;
  29. }
  30. public void SetData(long Key, long Size, IntPtr HostAddress)
  31. {
  32. if (Cache.TryGetValue(Key, out OGLStreamBuffer Buffer))
  33. {
  34. Buffer.SetData(Size, HostAddress);
  35. }
  36. }
  37. public bool TryGetUbo(long Key, out int UboHandle)
  38. {
  39. if (Cache.TryGetValue(Key, out OGLStreamBuffer Buffer))
  40. {
  41. UboHandle = Buffer.Handle;
  42. return true;
  43. }
  44. UboHandle = 0;
  45. return false;
  46. }
  47. private static void DeleteBuffer(OGLStreamBuffer Buffer)
  48. {
  49. Buffer.Dispose();
  50. }
  51. }
  52. }