| 50 | */ |
| 51 | template <typename DeviceType = vkb::core::DeviceC> |
| 52 | void init(const DeviceType &device) |
| 53 | { |
| 54 | VmaVulkanFunctions vma_vulkan_func{}; |
| 55 | vma_vulkan_func.vkGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 56 | vma_vulkan_func.vkGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 57 | |
| 58 | VmaAllocatorCreateInfo allocator_info{}; |
| 59 | allocator_info.pVulkanFunctions = &vma_vulkan_func; |
| 60 | allocator_info.physicalDevice = static_cast<VkPhysicalDevice>(device.get_gpu().get_handle()); |
| 61 | allocator_info.device = static_cast<VkDevice>(device.get_handle()); |
| 62 | allocator_info.instance = static_cast<VkInstance>(device.get_gpu().get_instance().get_handle()); |
| 63 | |
| 64 | bool can_get_memory_requirements = device.get_gpu().is_extension_supported(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME); |
| 65 | bool has_dedicated_allocation = device.get_gpu().is_extension_supported(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME); |
| 66 | if (can_get_memory_requirements && has_dedicated_allocation && device.is_extension_enabled(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME)) |
| 67 | { |
| 68 | allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; |
| 69 | } |
| 70 | |
| 71 | if (device.get_gpu().is_extension_supported(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME) && |
| 72 | device.is_extension_enabled(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)) |
| 73 | { |
| 74 | allocator_info.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; |
| 75 | } |
| 76 | |
| 77 | if (device.get_gpu().is_extension_supported(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME) && device.is_extension_enabled(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) |
| 78 | { |
| 79 | allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; |
| 80 | } |
| 81 | |
| 82 | if (device.get_gpu().is_extension_supported(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME) && |
| 83 | device.is_extension_enabled(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) |
| 84 | { |
| 85 | allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT; |
| 86 | } |
| 87 | |
| 88 | if (device.get_gpu().is_extension_supported(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME) && device.is_extension_enabled(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME)) |
| 89 | { |
| 90 | allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT; |
| 91 | } |
| 92 | |
| 93 | if (device.get_gpu().is_extension_supported(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME) && |
| 94 | device.is_extension_enabled(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME)) |
| 95 | { |
| 96 | allocator_info.flags |= VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT; |
| 97 | } |
| 98 | |
| 99 | init(allocator_info); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @brief Shuts down the VMA allocator and releases all resources. Should be preceeded with a call to `init`. |
no test coverage detected