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