MemoryAllocation.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Silk.NET.Vulkan;
  2. using System;
  3. namespace Ryujinx.Graphics.Vulkan
  4. {
  5. readonly struct MemoryAllocation : IDisposable
  6. {
  7. private readonly MemoryAllocatorBlockList _owner;
  8. private readonly MemoryAllocatorBlockList.Block _block;
  9. private readonly HostMemoryAllocator _hostMemory;
  10. public DeviceMemory Memory { get; }
  11. public IntPtr HostPointer { get; }
  12. public ulong Offset { get; }
  13. public ulong Size { get; }
  14. public MemoryAllocation(
  15. MemoryAllocatorBlockList owner,
  16. MemoryAllocatorBlockList.Block block,
  17. DeviceMemory memory,
  18. IntPtr hostPointer,
  19. ulong offset,
  20. ulong size)
  21. {
  22. _owner = owner;
  23. _block = block;
  24. Memory = memory;
  25. HostPointer = hostPointer;
  26. Offset = offset;
  27. Size = size;
  28. }
  29. public MemoryAllocation(
  30. HostMemoryAllocator hostMemory,
  31. DeviceMemory memory,
  32. IntPtr hostPointer,
  33. ulong offset,
  34. ulong size)
  35. {
  36. _hostMemory = hostMemory;
  37. Memory = memory;
  38. HostPointer = hostPointer;
  39. Offset = offset;
  40. Size = size;
  41. }
  42. public void Dispose()
  43. {
  44. if (_hostMemory != null)
  45. {
  46. _hostMemory.Free(Memory, Offset, Size);
  47. }
  48. else
  49. {
  50. _owner.Free(_block, Offset, Size);
  51. }
  52. }
  53. }
  54. }