예제 #1
0
 public MemoryBlock(DeviceMemory memory)
 {
     Memory = memory;
     first  = last = new Node {
         Offset = 0,
         Size   = memory.Size
     };
     TreeInsert(first);
 }
예제 #2
0
 public MemoryAlloc(MemoryAllocator allocator, MemoryBlock memoryBlock, MemoryBlock.Node memoryBlockNode)
 {
     Allocator       = allocator;
     MemoryBlock     = memoryBlock;
     MemoryBlockNode = memoryBlockNode;
     Memory          = memoryBlock.Memory;
     Offset          = memoryBlockNode.Offset;
     Size            = memoryBlockNode.Size;
 }
예제 #3
0
 private void FreeDeviceMemory(DeviceMemory memory)
 {
     if (ShouldMapPersistenly(memory.Type))
     {
         UnmapDeviceMemory(memory);
     }
     if (memory.MapCounter > 0)
     {
         throw new InvalidOperationException();
     }
     Context.Device.FreeMemory(memory.Memory);
 }
예제 #4
0
 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);
         }
     }
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
        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);
        }
예제 #7
0
 public MemoryAlloc(MemoryAllocator allocator, DeviceMemory memory)
 {
     Allocator = allocator;
     Memory    = memory;
     Size      = memory.Size;
 }