28 VkBufferUsageFlags buffer_usage,
29 VmaMemoryUsage vma_memory_usage,
30 VmaAllocationCreateFlags allocation_flags,
37 if (allocation_failed_) {
55 "Couldn't allocate buffer, requested allocation exceeds the maxBufferSize of the device.");
56 allocation_failed_ =
true;
58 alloc_size_in_bytes_ = 0;
63 VkBufferCreateInfo create_info = {};
64 create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
65 create_info.flags = 0;
66 create_info.size = alloc_size_in_bytes_;
67 create_info.usage = buffer_usage;
70 create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
71 create_info.queueFamilyIndexCount = 1;
73 create_info.pQueueFamilyIndices = queue_family_indices;
75 VkExternalMemoryBufferCreateInfo external_memory_create_info = {
76 VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
nullptr, 0};
78 VmaAllocationCreateInfo vma_create_info = {};
79 vma_create_info.flags = allocation_flags;
80 vma_create_info.priority = priority;
81 vma_create_info.usage = vma_memory_usage;
84 create_info.pNext = &external_memory_create_info;
88 vma_create_info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
93 if (use_descriptor_buffer) {
94 create_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
97 VkResult
result = vmaCreateBuffer(
98 allocator, &create_info, &vma_create_info, &vk_buffer_, &allocation_,
nullptr);
99 if (
result != VK_SUCCESS) {
100 allocation_failed_ =
true;
102 alloc_size_in_bytes_ = 0;
108 if (use_descriptor_buffer) {
109 VkBufferDeviceAddressInfo vk_buffer_device_address_info = {
110 VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
nullptr, vk_buffer_};
111 vk_device_address = vkGetBufferDeviceAddress(device.
vk_handle(),
112 &vk_buffer_device_address_info);
115 vmaGetAllocationMemoryProperties(allocator, allocation_, &vk_memory_property_flags_);
116 if (vk_memory_property_flags_ & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
bool create(size_t size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage vma_memory_usage, VmaAllocationCreateFlags vma_allocation_flags, float priority, bool export_memory=false)