Example #1
0
        public Buffer(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropFlags, ulong stride, ulong count,
                      VkSharingMode sharingMode = VkSharingMode.Exclusive, uint[] queueFamilyIndices = null, IntPtr data = default)
        {
            Stride = stride;
            Count  = count;
            Size   = stride * count;

            // Create the buffer handle
            var bufferCreateInfo = new VkBufferCreateInfo(usageFlags, Size, queueFamilyIndices)
            {
                sharingMode = sharingMode
            };

            if (data != null && (memoryPropertyFlags & VkMemoryPropertyFlags.HostCoherent) == 0)
            {
                bufferCreateInfo.usage |= VkBufferUsageFlags.TransferDst;
            }

            handle = Device.CreateBuffer(ref bufferCreateInfo);

            UsageFlags          = usageFlags;
            memoryPropertyFlags = memoryPropFlags;

            Device.GetBufferMemoryRequirements(handle, out VkMemoryRequirements memReqs);
            Allocate(memReqs);
            Device.BindBufferMemory(handle, memory, 0);

            if (data != IntPtr.Zero)
            {
                SetData(data, 0, Size);
            }

            SetupDescriptor();
        }
Example #2
0
 public static VkBuffer CreateBuffer(ref VkBufferCreateInfo pCreateInfo)
 {
     VulkanUtil.CheckResult(vkCreateBuffer(device, Utilities.AsPtr(ref pCreateInfo), null, out VkBuffer buffer));
     return(buffer);
 }