From 5c710e86a0ce0664bbc2374c39b956b9928b2f29 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Fri, 4 Feb 2022 15:17:02 +0100 Subject: [PATCH] Added support for Vulkan 1.3 Fixes #228 --- README.md | 2 +- include/vk_mem_alloc.h | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1c70814..d960926 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Additional features: - Support for sparse binding and sparse residency: Convenience functions that allocate or free multiple memory pages at once. - Custom memory pools: Create a pool with desired parameters (e.g. fixed or limited maximum size) and allocate memory out of it. - Linear allocator: Create a pool with linear algorithm and use it for much faster allocations and deallocations in free-at-once, stack, double stack, or ring buffer fashion. -- Support for Vulkan 1.0, 1.1, 1.2. +- Support for Vulkan 1.0, 1.1, 1.2, 1.3. - Support for extensions (and equivalent functionality included in new Vulkan versions): - VK_EXT_memory_budget: Used internally if available to query for current usage and budget. If not available, it falls back to an estimation based on memory heap sizes. - VK_KHR_dedicated_allocation: Just enable it and it will be used automatically by the library. diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 84e6414..6a0feb0 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -126,6 +126,21 @@ for user-defined purpose without allocating any real GPU memory. extern "C" { #endif +// Define this macro to declare maximum supported Vulkan version in format AAABBBCCC, +// where AAA = major, BBB = minor, CCC = patch. +// If you want to use version > 1.0, it still needs to be enabled via VmaAllocatorCreateInfo::vulkanApiVersion. +#if !defined(VMA_VULKAN_VERSION) + #if defined(VK_VERSION_1_3) + #define VMA_VULKAN_VERSION 1003000 + #elif defined(VK_VERSION_1_2) + #define VMA_VULKAN_VERSION 1002000 + #elif defined(VK_VERSION_1_1) + #define VMA_VULKAN_VERSION 1001000 + #else + #define VMA_VULKAN_VERSION 1000000 + #endif +#endif + #if defined(__ANDROID__) && defined(VK_NO_PROTOTYPES) && VMA_STATIC_VULKAN_FUNCTIONS extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; extern PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr; @@ -166,19 +181,6 @@ extern "C" { #define VK_ERROR_UNKNOWN ((VkResult)-13) #endif -// Define this macro to declare maximum supported Vulkan version in format AAABBBCCC, -// where AAA = major, BBB = minor, CCC = patch. -// If you want to use version > 1.0, it still needs to be enabled via VmaAllocatorCreateInfo::vulkanApiVersion. -#if !defined(VMA_VULKAN_VERSION) - #if defined(VK_VERSION_1_2) - #define VMA_VULKAN_VERSION 1002000 - #elif defined(VK_VERSION_1_1) - #define VMA_VULKAN_VERSION 1001000 - #else - #define VMA_VULKAN_VERSION 1000000 - #endif -#endif - #if !defined(VMA_DEDICATED_ALLOCATION) #if VK_KHR_get_memory_requirements2 && VK_KHR_dedicated_allocation #define VMA_DEDICATED_ALLOCATION 1 @@ -1000,7 +1002,7 @@ typedef struct VmaAllocatorCreateInfo It must be a value in the format as created by macro `VK_MAKE_VERSION` or a constant like: `VK_API_VERSION_1_1`, `VK_API_VERSION_1_0`. The patch version number specified is ignored. Only the major and minor versions are considered. It must be less or equal (preferably equal) to value as passed to `vkCreateInstance` as `VkApplicationInfo::apiVersion`. - Only versions 1.0, 1.1, 1.2 are supported by the current implementation. + Only versions 1.0, 1.1, 1.2, 1.3 are supported by the current implementation. Leaving it initialized to zero is equivalent to `VK_API_VERSION_1_0`. */ uint32_t vulkanApiVersion; @@ -16446,7 +16448,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator( { VMA_ASSERT(pCreateInfo && pAllocator); VMA_ASSERT(pCreateInfo->vulkanApiVersion == 0 || - (VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) == 1 && VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) <= 2)); + (VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) == 1 && VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) <= 3)); VMA_DEBUG_LOG("vmaCreateAllocator"); *pAllocator = vma_new(pCreateInfo->pAllocationCallbacks, VmaAllocator_T)(pCreateInfo); VkResult result = (*pAllocator)->Init(pCreateInfo);