@@ -1669,6 +1669,62 @@ typedef struct VmaVirtualAllocationInfo
1669
1669
@{
1670
1670
*/
1671
1671
1672
+ #ifdef VOLK_HEADER_VERSION
1673
+ /** \brief Fully initializes `pDstVulkanFunctions` structure with Vulkan functions needed by VMA
1674
+ using [volk library](https://github.com/zeux/volk).
1675
+
1676
+ This function is defined in VMA header only if "volk.h" was included before it.
1677
+
1678
+ To use this function properly:
1679
+
1680
+ -# Initialize volk and Vulkan:
1681
+ -# Call `volkInitialize()`
1682
+ -# Create `VkInstance` object
1683
+ -# Call `volkLoadInstance()`
1684
+ -# Create `VkDevice` object
1685
+ -# Call `volkLoadDevice()`
1686
+ -# Fill in structure #VmaAllocatorCreateInfo, especially members:
1687
+ - VmaAllocatorCreateInfo::device
1688
+ - VmaAllocatorCreateInfo::vulkanApiVersion
1689
+ - VmaAllocatorCreateInfo::flags - set appropriate flags for the Vulkan extensions you enabled
1690
+ -# Create an instance of the #VmaVulkanFunctions structure.
1691
+ -# Call vmaImportVulkanFunctionsFromVolk().
1692
+ Parameter `pAllocatorCreateInfo` is read to find out which functions should be fetched for
1693
+ appropriate Vulkan version and extensions.
1694
+ Parameter `pDstVulkanFunctions` is filled with those function pointers, or null if not applicable.
1695
+ -# Attach the #VmaVulkanFunctions structure to VmaAllocatorCreateInfo::pVulkanFunctions.
1696
+ -# Call vmaCreateAllocator() to create the #VmaAllocator object.
1697
+
1698
+ Example:
1699
+
1700
+ \code
1701
+ VmaAllocatorCreateInfo allocatorCreateInfo = {};
1702
+ allocatorCreateInfo.physicalDevice = myPhysicalDevice;
1703
+ allocatorCreateInfo.device = myDevice;
1704
+ allocatorCreateInfo.instance = myInstance;
1705
+ allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_3;
1706
+ allocatorCreateInfo.flags = VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT |
1707
+ VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT |
1708
+ VMA_ALLOCATOR_CREATE_KHR_EXTERNAL_MEMORY_WIN32_BIT;
1709
+
1710
+ VmaVulkanFunctions vulkanFunctions;
1711
+ VkResult res = vmaImportVulkanFunctionsFromVolk(&allocatorCreateInfo, &vulkanFunctions);
1712
+ // Check res...
1713
+ allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions;
1714
+
1715
+ VmaAllocator allocator;
1716
+ res = vmaCreateAllocator(&allocatorCreateInfo, &allocator);
1717
+ // Check res...
1718
+ \endcode
1719
+
1720
+ Internally in this function, pointers to functions related to the entire Vulkan instance are fetched using global function definitions,
1721
+ while pointers to functions related to the Vulkan device are fetched using `volkLoadDeviceTable()` for given `pAllocatorCreateInfo->device`.
1722
+ */
1723
+ VMA_CALL_PRE VkResult VMA_CALL_POST vmaImportVulkanFunctionsFromVolk(
1724
+ const VmaAllocatorCreateInfo* VMA_NOT_NULL pAllocatorCreateInfo,
1725
+ VmaVulkanFunctions* VMA_NOT_NULL pDstVulkanFunctions);
1726
+ #endif
1727
+
1672
1728
/// Creates #VmaAllocator object.
1673
1729
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator(
1674
1730
const VmaAllocatorCreateInfo* VMA_NOT_NULL pCreateInfo,
@@ -15067,6 +15123,103 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
15067
15123
15068
15124
15069
15125
#ifndef _VMA_PUBLIC_INTERFACE
15126
+
15127
+ #ifdef VOLK_HEADER_VERSION
15128
+
15129
+ VMA_CALL_PRE VkResult VMA_CALL_POST vmaImportVulkanFunctionsFromVolk(
15130
+ const VmaAllocatorCreateInfo* VMA_NOT_NULL pAllocatorCreateInfo,
15131
+ VmaVulkanFunctions* VMA_NOT_NULL pDstVulkanFunctions)
15132
+ {
15133
+ VMA_ASSERT(pAllocatorCreateInfo != VMA_NULL);
15134
+ VMA_ASSERT(pAllocatorCreateInfo->instance != VK_NULL_HANDLE);
15135
+ VMA_ASSERT(pAllocatorCreateInfo->device != VK_NULL_HANDLE);
15136
+
15137
+ memset(pDstVulkanFunctions, 0, sizeof(*pDstVulkanFunctions));
15138
+
15139
+ VolkDeviceTable src = {};
15140
+ volkLoadDeviceTable(&src, pAllocatorCreateInfo->device);
15141
+
15142
+ #define COPY_GLOBAL_TO_VMA_FUNC(volkName, vmaName) if(!pDstVulkanFunctions->vmaName) pDstVulkanFunctions->vmaName = volkName;
15143
+ #define COPY_DEVICE_TO_VMA_FUNC(volkName, vmaName) if(!pDstVulkanFunctions->vmaName) pDstVulkanFunctions->vmaName = src.volkName;
15144
+
15145
+ COPY_GLOBAL_TO_VMA_FUNC(vkGetInstanceProcAddr, vkGetInstanceProcAddr)
15146
+ COPY_GLOBAL_TO_VMA_FUNC(vkGetDeviceProcAddr, vkGetDeviceProcAddr)
15147
+ COPY_GLOBAL_TO_VMA_FUNC(vkGetPhysicalDeviceProperties, vkGetPhysicalDeviceProperties)
15148
+ COPY_GLOBAL_TO_VMA_FUNC(vkGetPhysicalDeviceMemoryProperties, vkGetPhysicalDeviceMemoryProperties)
15149
+ COPY_DEVICE_TO_VMA_FUNC(vkAllocateMemory, vkAllocateMemory)
15150
+ COPY_DEVICE_TO_VMA_FUNC(vkFreeMemory, vkFreeMemory)
15151
+ COPY_DEVICE_TO_VMA_FUNC(vkMapMemory, vkMapMemory)
15152
+ COPY_DEVICE_TO_VMA_FUNC(vkUnmapMemory, vkUnmapMemory)
15153
+ COPY_DEVICE_TO_VMA_FUNC(vkFlushMappedMemoryRanges, vkFlushMappedMemoryRanges)
15154
+ COPY_DEVICE_TO_VMA_FUNC(vkInvalidateMappedMemoryRanges, vkInvalidateMappedMemoryRanges)
15155
+ COPY_DEVICE_TO_VMA_FUNC(vkBindBufferMemory, vkBindBufferMemory)
15156
+ COPY_DEVICE_TO_VMA_FUNC(vkBindImageMemory, vkBindImageMemory)
15157
+ COPY_DEVICE_TO_VMA_FUNC(vkGetBufferMemoryRequirements, vkGetBufferMemoryRequirements)
15158
+ COPY_DEVICE_TO_VMA_FUNC(vkGetImageMemoryRequirements, vkGetImageMemoryRequirements)
15159
+ COPY_DEVICE_TO_VMA_FUNC(vkCreateBuffer, vkCreateBuffer)
15160
+ COPY_DEVICE_TO_VMA_FUNC(vkDestroyBuffer, vkDestroyBuffer)
15161
+ COPY_DEVICE_TO_VMA_FUNC(vkCreateImage, vkCreateImage)
15162
+ COPY_DEVICE_TO_VMA_FUNC(vkDestroyImage, vkDestroyImage)
15163
+ COPY_DEVICE_TO_VMA_FUNC(vkCmdCopyBuffer, vkCmdCopyBuffer)
15164
+ #if VMA_VULKAN_VERSION >= 1001000
15165
+ if (pAllocatorCreateInfo->vulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
15166
+ {
15167
+ COPY_GLOBAL_TO_VMA_FUNC(vkGetPhysicalDeviceMemoryProperties2, vkGetPhysicalDeviceMemoryProperties2KHR)
15168
+ COPY_DEVICE_TO_VMA_FUNC(vkGetBufferMemoryRequirements2, vkGetBufferMemoryRequirements2KHR)
15169
+ COPY_DEVICE_TO_VMA_FUNC(vkGetImageMemoryRequirements2, vkGetImageMemoryRequirements2KHR)
15170
+ COPY_DEVICE_TO_VMA_FUNC(vkBindBufferMemory2, vkBindBufferMemory2KHR)
15171
+ COPY_DEVICE_TO_VMA_FUNC(vkBindImageMemory2, vkBindImageMemory2KHR)
15172
+ }
15173
+ #endif
15174
+ #if VMA_VULKAN_VERSION >= 1003000
15175
+ if (pAllocatorCreateInfo->vulkanApiVersion >= VK_MAKE_VERSION(1, 3, 0))
15176
+ {
15177
+ COPY_DEVICE_TO_VMA_FUNC(vkGetDeviceBufferMemoryRequirements, vkGetDeviceBufferMemoryRequirements)
15178
+ COPY_DEVICE_TO_VMA_FUNC(vkGetDeviceImageMemoryRequirements, vkGetDeviceImageMemoryRequirements)
15179
+ }
15180
+ #endif
15181
+ #if VMA_KHR_MAINTENANCE4
15182
+ if((pAllocatorCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT) != 0)
15183
+ {
15184
+ COPY_DEVICE_TO_VMA_FUNC(vkGetDeviceBufferMemoryRequirementsKHR, vkGetDeviceBufferMemoryRequirements)
15185
+ COPY_DEVICE_TO_VMA_FUNC(vkGetDeviceImageMemoryRequirementsKHR, vkGetDeviceImageMemoryRequirements)
15186
+ }
15187
+ #endif
15188
+ #if VMA_DEDICATED_ALLOCATION
15189
+ if ((pAllocatorCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0)
15190
+ {
15191
+ COPY_DEVICE_TO_VMA_FUNC(vkGetBufferMemoryRequirements2KHR, vkGetBufferMemoryRequirements2KHR)
15192
+ COPY_DEVICE_TO_VMA_FUNC(vkGetImageMemoryRequirements2KHR, vkGetImageMemoryRequirements2KHR)
15193
+ }
15194
+ #endif
15195
+ #if VMA_BIND_MEMORY2
15196
+ if ((pAllocatorCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT) != 0)
15197
+ {
15198
+ COPY_DEVICE_TO_VMA_FUNC(vkBindBufferMemory2KHR, vkBindBufferMemory2KHR)
15199
+ COPY_DEVICE_TO_VMA_FUNC(vkBindImageMemory2KHR, vkBindImageMemory2KHR)
15200
+ }
15201
+ #endif
15202
+ #if VMA_MEMORY_BUDGET
15203
+ if ((pAllocatorCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT) != 0)
15204
+ {
15205
+ COPY_GLOBAL_TO_VMA_FUNC(vkGetPhysicalDeviceMemoryProperties2KHR, vkGetPhysicalDeviceMemoryProperties2KHR)
15206
+ }
15207
+ #endif
15208
+ #if VMA_EXTERNAL_MEMORY_WIN32
15209
+ if ((pAllocatorCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_EXTERNAL_MEMORY_WIN32_BIT) != 0)
15210
+ {
15211
+ COPY_DEVICE_TO_VMA_FUNC(vkGetMemoryWin32HandleKHR, vkGetMemoryWin32HandleKHR)
15212
+ }
15213
+ #endif
15214
+
15215
+ #undef COPY_DEVICE_TO_VMA_FUNC
15216
+ #undef COPY_GLOBAL_TO_VMA_FUNC
15217
+
15218
+ return VK_SUCCESS;
15219
+ }
15220
+
15221
+ #endif // #ifdef VOLK_HEADER_VERSION
15222
+
15070
15223
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator(
15071
15224
const VmaAllocatorCreateInfo* pCreateInfo,
15072
15225
VmaAllocator* pAllocator)
@@ -16781,7 +16934,7 @@ See code sample below.
16781
16934
16782
16935
\subsection quick_start_initialization_importing_vulkan_functions Importing Vulkan functions
16783
16936
16784
- You may need to configure importing Vulkan functions. There are 3 ways to do this:
16937
+ You may need to configure importing Vulkan functions. There are 4 ways to do this:
16785
16938
16786
16939
-# **If you link with Vulkan static library** (e.g. "vulkan-1.lib" on Windows):
16787
16940
- You don't need to do anything.
@@ -16792,10 +16945,13 @@ You may need to configure importing Vulkan functions. There are 3 ways to do thi
16792
16945
- Provide pointers to these two functions via VmaVulkanFunctions::vkGetInstanceProcAddr,
16793
16946
VmaVulkanFunctions::vkGetDeviceProcAddr.
16794
16947
- The library will fetch pointers to all other functions it needs internally.
16795
- -# **If you fetch pointers to all Vulkan functions in a custom way**, e.g. using some loader like
16796
- [Volk](https://github.com/zeux/volk):
16948
+ -# **If you fetch pointers to all Vulkan functions in a custom way**:
16797
16949
- Define `VMA_STATIC_VULKAN_FUNCTIONS` and `VMA_DYNAMIC_VULKAN_FUNCTIONS` to 0.
16798
16950
- Pass these pointers via structure #VmaVulkanFunctions.
16951
+ -# **If you use [volk library](https://github.com/zeux/volk)**:
16952
+ - Define `VMA_STATIC_VULKAN_FUNCTIONS` and `VMA_DYNAMIC_VULKAN_FUNCTIONS` to 0.
16953
+ - Use function vmaImportVulkanFunctionsFromVolk() to fill in the structure #VmaVulkanFunctions.
16954
+ For more information, see the description of this function.
16799
16955
16800
16956
\subsection quick_start_initialization_enabling_extensions Enabling extensions
16801
16957
0 commit comments