30 VkBufferUsageFlags buffer_usage,
31 VmaMemoryUsage vma_memory_usage,
32 VmaAllocationCreateFlags allocation_flags,
35 const char *debug_name,
39 BLI_assert(resource_.vk_handle == VK_NULL_HANDLE);
41 if (allocation_failed_) {
59 "Couldn't allocate buffer, requested allocation exceeds the maxBufferSize of the device.");
60 allocation_failed_ =
true;
62 alloc_size_in_bytes_ = 0;
67 VkBufferCreateInfo create_info = {};
68 create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
69 create_info.flags = 0;
70 create_info.size = alloc_size_in_bytes_;
71 create_info.usage = buffer_usage;
74 create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
75 create_info.queueFamilyIndexCount = 1;
77 create_info.pQueueFamilyIndices = queue_family_indices;
79 VkExternalMemoryBufferCreateInfo external_memory_create_info = {
80 VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
nullptr, 0};
82 VmaAllocationCreateInfo vma_create_info = {};
83 vma_create_info.flags = allocation_flags;
84 vma_create_info.priority = priority;
85 vma_create_info.usage = vma_memory_usage;
88 create_info.pNext = &external_memory_create_info;
92 vma_create_info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
97 vma_create_info.flags |= VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT;
98 vma_create_info.pUserData = (
void *)debug_name;
101 VkResult
result = vmaCreateBufferWithAlignment(allocator,
105 &resource_.vk_handle,
108 if (
result != VK_SUCCESS) {
109 allocation_failed_ =
true;
111 alloc_size_in_bytes_ = 0;
117 if (
bool(create_info.usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT)) {
118 VkBufferDeviceAddressInfo vk_buffer_device_address_info = {
119 VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
nullptr, resource_};
120 vk_device_address = device.
functions.vkGetBufferDeviceAddressKHR(
121 device.
vk_handle(), &vk_buffer_device_address_info);
134 const bool is_mappable = bool(allocation_flags &
135 (VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT |
136 VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT));
bool create(size_t size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage vma_memory_usage, VmaAllocationCreateFlags vma_allocation_flags, float priority, bool export_memory=false, const char *debug_name="VKBuffer", size_t alignment=0)