Example #1
0
 public MemoryType(uint index, SharpVulkan.MemoryPropertyFlags propertyFlags, ulong blockSize, ulong minAlignment)
 {
     Index         = index;
     PropertyFlags = propertyFlags;
     BlockSize     = blockSize;
     MinAlignment  = minAlignment;
 }
Example #2
0
 public BackingBuffer(PlatformRenderContext context, SharpVulkan.BufferUsageFlags usage, SharpVulkan.MemoryPropertyFlags memoryPropertyFlags, ulong size)
 {
     this.context             = context;
     this.usage               = usage;
     this.memoryPropertyFlags = memoryPropertyFlags;
     sliceSize      = size;
     sliceAlignment = GetAlignmentForBufferUsage(context, usage);
     sliceCount     = 1;
     CreateBuffer();
     sliceOffset = sliceQueue.Dequeue().Offset;
 }
Example #3
0
        private ulong GetMemoryTypeMinAlignment(SharpVulkan.MemoryPropertyFlags propertyFlags)
        {
            var hostVisible  = SharpVulkan.MemoryPropertyFlags.HostVisible;
            var hostCoherent = SharpVulkan.MemoryPropertyFlags.HostCoherent;

            if ((propertyFlags & (hostVisible | hostCoherent)) == hostVisible)
            {
                return(Context.PhysicalDeviceLimits.NonCoherentAtomSize);
            }
            return(1);
        }
Example #4
0
 private MemoryType TryFindMemoryType(uint typeBits, SharpVulkan.MemoryPropertyFlags propertyFlags)
 {
     foreach (var type in memoryTypes)
     {
         var mask = 1 << (int)type.Index;
         if ((typeBits & mask) != 0 && (type.PropertyFlags & propertyFlags) == propertyFlags)
         {
             return(type);
         }
     }
     return(null);
 }
Example #5
0
        public MemoryAlloc Allocate(SharpVulkan.Buffer buffer, SharpVulkan.MemoryPropertyFlags propertyFlags)
        {
            GetBufferMemoryRequirements(buffer,
                                        out var requirements,
                                        out var prefersDedicated,
                                        out bool requiresDedicated);
            var dedicatedAllocateInfo = new SharpVulkan.Ext.MemoryDedicatedAllocateInfo {
                StructureType = SharpVulkan.Ext.StructureType.MemoryDedicatedAllocateInfo,
                Buffer        = buffer
            };
            var alloc = Allocate(
                requirements, &dedicatedAllocateInfo, prefersDedicated, requiresDedicated,
                propertyFlags, true);

            Context.Device.BindBufferMemory(buffer, alloc.Memory.Memory, alloc.Offset);
            return(alloc);
        }
Example #6
0
        public MemoryAlloc Allocate(SharpVulkan.Image image, SharpVulkan.MemoryPropertyFlags propertyFlags, SharpVulkan.ImageTiling tiling)
        {
            GetImageMemoryRequirements(image,
                                       out var requirements,
                                       out var prefersDedicated,
                                       out bool requiresDedicated);
            var dedicatedAllocateInfo = new SharpVulkan.Ext.MemoryDedicatedAllocateInfo {
                StructureType = SharpVulkan.Ext.StructureType.MemoryDedicatedAllocateInfo,
                Image         = image
            };
            var alloc = Allocate(
                requirements, &dedicatedAllocateInfo, prefersDedicated, requiresDedicated,
                propertyFlags, tiling == SharpVulkan.ImageTiling.Linear);

            Context.Device.BindImageMemory(image, alloc.Memory.Memory, alloc.Offset);
            return(alloc);
        }
Example #7
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));
        }