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); }
private MemoryAlloc Allocate( SharpVulkan.MemoryRequirements requirements, SharpVulkan.Ext.MemoryDedicatedAllocateInfo *dedicatedAllocateInfo, bool prefersDedicated, bool requiresDedicated, SharpVulkan.MemoryPropertyFlags propertyFlags, bool linear) { var type = TryFindMemoryType(requirements.MemoryTypeBits, propertyFlags); if (type == null) { throw new InvalidOperationException(); } if (prefersDedicated) { var memory = TryAllocateDeviceMemory(type, requirements.Size, dedicatedAllocateInfo); if (memory != null) { return(new MemoryAlloc(this, memory)); } if (requiresDedicated) { throw new OutOfMemoryException(); } } return(AllocateFromBlock(type, requirements.Size, requirements.Alignment, linear)); }