24 VkBufferUsageFlags buffer_usage,
25 VkMemoryPropertyFlags required_flags,
26 VkMemoryPropertyFlags preferred_flags,
27 VmaAllocationCreateFlags allocation_flags,
34 if (allocation_failed_) {
47 VkBufferCreateInfo create_info = {};
48 create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
49 create_info.flags = 0;
50 create_info.size = alloc_size_in_bytes_;
51 create_info.usage = buffer_usage;
54 create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
55 create_info.queueFamilyIndexCount = 1;
57 create_info.pQueueFamilyIndices = queue_family_indices;
59 VkExternalMemoryBufferCreateInfo external_memory_create_info = {
60 VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
nullptr, 0};
62 VmaAllocationCreateInfo vma_create_info = {};
63 vma_create_info.flags = allocation_flags;
64 vma_create_info.priority = priority;
65 vma_create_info.requiredFlags = required_flags;
66 vma_create_info.preferredFlags = preferred_flags;
67 vma_create_info.usage = VMA_MEMORY_USAGE_AUTO;
70 create_info.pNext = &external_memory_create_info;
72 external_memory_create_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT;
74 external_memory_create_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
77 vma_create_info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
82 if (use_descriptor_buffer) {
83 create_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
86 VkResult
result = vmaCreateBuffer(
87 allocator, &create_info, &vma_create_info, &vk_buffer_, &allocation_,
nullptr);
88 if (
result != VK_SUCCESS) {
89 allocation_failed_ =
true;
91 alloc_size_in_bytes_ = 0;
97 if (use_descriptor_buffer) {
98 VkBufferDeviceAddressInfo vk_buffer_device_address_info = {
99 VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
nullptr, vk_buffer_};
100 vk_device_address = vkGetBufferDeviceAddress(device.
vk_handle(),
101 &vk_buffer_device_address_info);
104 vmaGetAllocationMemoryProperties(allocator, allocation_, &vk_memory_property_flags_);
105 if (vk_memory_property_flags_ & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
bool create(size_t size, VkBufferUsageFlags buffer_usage, VkMemoryPropertyFlags required_flags, VkMemoryPropertyFlags preferred_flags, VmaAllocationCreateFlags vma_allocation_flags, float priority, bool export_memory=false)