Beispiel #1
0
 private void GetBufferMemoryRequirements(
     SharpVulkan.Buffer buffer,
     out SharpVulkan.MemoryRequirements requirements,
     out bool prefersDedicatedAllocation,
     out bool requiresDedicatedAllocation)
 {
     if (Context.SupportsDedicatedAllocation)
     {
         var requirementsInfo = new SharpVulkan.Ext.BufferMemoryRequirementsInfo2 {
             StructureType = SharpVulkan.Ext.StructureType.BufferMemoryRequirementsInfo2,
             Buffer        = buffer
         };
         var dedicatedRequirements = new SharpVulkan.Ext.MemoryDedicatedRequirements {
             StructureType = SharpVulkan.Ext.StructureType.MemoryDedicatedRequirements
         };
         var requirements2 = new SharpVulkan.Ext.MemoryRequirements2 {
             StructureType = SharpVulkan.Ext.StructureType.MemoryRequirements2,
             Next          = new IntPtr(&dedicatedRequirements)
         };
         Context.VKExt.GetBufferMemoryRequirements2(Context.Device, ref requirementsInfo, ref requirements2);
         requirements = requirements2.MemoryRequirements;
         prefersDedicatedAllocation  = dedicatedRequirements.PrefersDedicatedAllocation;
         requiresDedicatedAllocation = dedicatedRequirements.RequiresDedicatedAllocation;
     }
     else
     {
         Context.Device.GetBufferMemoryRequirements(buffer, out requirements);
         prefersDedicatedAllocation  = false;
         requiresDedicatedAllocation = false;
     }
 }
Beispiel #2
0
        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));
        }