public MemoryBlock(DeviceMemory memory) { Memory = memory; first = last = new Node { Offset = 0, Size = memory.Size }; TreeInsert(first); }
public MemoryAlloc(MemoryAllocator allocator, MemoryBlock memoryBlock, MemoryBlock.Node memoryBlockNode) { Allocator = allocator; MemoryBlock = memoryBlock; MemoryBlockNode = memoryBlockNode; Memory = memoryBlock.Memory; Offset = memoryBlockNode.Offset; Size = memoryBlockNode.Size; }
private void FreeDeviceMemory(DeviceMemory memory) { if (ShouldMapPersistenly(memory.Type)) { UnmapDeviceMemory(memory); } if (memory.MapCounter > 0) { throw new InvalidOperationException(); } Context.Device.FreeMemory(memory.Memory); }
private void UnmapDeviceMemory(DeviceMemory memory) { lock (memory) { if (memory.MapCounter == 0) { throw new InvalidOperationException(); } memory.MapCounter--; if (memory.MapCounter == 0) { Context.Device.UnmapMemory(memory.Memory); } } }
private IntPtr MapDeviceMemory(DeviceMemory memory) { if ((memory.Type.PropertyFlags & SharpVulkan.MemoryPropertyFlags.HostVisible) == 0) { throw new InvalidOperationException(); } lock (memory) { memory.MapCounter++; if (memory.MapCounter == 1) { memory.MappedMemory = Context.Device.MapMemory(memory.Memory, 0, memory.Size, SharpVulkan.MemoryMapFlags.None); } return(memory.MappedMemory); } }
private DeviceMemory TryAllocateDeviceMemory(MemoryType type, ulong size, SharpVulkan.Ext.MemoryDedicatedAllocateInfo *dedicatedAllocateInfo) { var allocateInfo = new SharpVulkan.MemoryAllocateInfo { StructureType = SharpVulkan.StructureType.MemoryAllocateInfo, MemoryTypeIndex = type.Index, AllocationSize = size, Next = new IntPtr(dedicatedAllocateInfo) }; DeviceMemory memory; try { memory = new DeviceMemory(Context.Device.AllocateMemory(ref allocateInfo), type, size); } catch (SharpVulkan.SharpVulkanException e) when(e.Result == SharpVulkan.Result.ErrorOutOfDeviceMemory) { return(null); } if (ShouldMapPersistenly(type)) { MapDeviceMemory(memory); } return(memory); }
public MemoryAlloc(MemoryAllocator allocator, DeviceMemory memory) { Allocator = allocator; Memory = memory; Size = memory.Size; }