@@ -461,6 +461,14 @@ typedef enum VmaAllocatorCreateFlagBits
461461 */
462462 VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT = 0x00000100,
463463
464+ /**
465+ Enables usage of VK_KHR_external_memory_win32 extension in the library.
466+
467+ You should set this flag if you found available and enabled this device extension,
468+ while creating Vulkan device passed as VmaAllocatorCreateInfo::device.
469+ */
470+ VMA_ALLOCATOR_CREATE_KHR_EXTERNAL_MEMORY_WIN32 = 0x00000200,
471+
464472 VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
465473} VmaAllocatorCreateFlagBits;
466474/// See #VmaAllocatorCreateFlagBits.
@@ -1035,6 +1043,11 @@ typedef struct VmaVulkanFunctions
10351043 /// Fetch from "vkGetDeviceImageMemoryRequirements" on Vulkan >= 1.3, but you can also fetch it from "vkGetDeviceImageMemoryRequirementsKHR" if you enabled extension VK_KHR_maintenance4.
10361044 PFN_vkGetDeviceImageMemoryRequirementsKHR VMA_NULLABLE vkGetDeviceImageMemoryRequirements;
10371045#endif
1046+ #ifdef VK_USE_PLATFORM_WIN32_KHR
1047+ PFN_vkGetMemoryWin32HandleKHR VMA_NULLABLE vkGetMemoryWin32HandleKHR;
1048+ #else
1049+ void* VMA_NULLABLE vkGetMemoryWin32HandleKHR;
1050+ #endif
10381051} VmaVulkanFunctions;
10391052
10401053/// Description of a Allocator to be created.
@@ -10176,6 +10189,7 @@ struct VmaAllocator_T
1017610189 bool m_UseExtMemoryPriority;
1017710190 bool m_UseKhrMaintenance4;
1017810191 bool m_UseKhrMaintenance5;
10192+ bool m_UseKhrExternalMemoryWin32;
1017910193 const VkDevice m_hDevice;
1018010194 const VkInstance m_hInstance;
1018110195 const bool m_AllocationCallbacksSpecified;
@@ -11095,7 +11109,7 @@ void VmaAllocation_T::PrintParameters(class VmaJsonWriter& json) const
1109511109VkResult VmaAllocation_T::GetWin32Handle(VmaAllocator hAllocator, HANDLE hTargetProcess, HANDLE* pHandle) const noexcept
1109611110{
1109711111 // Where do we get this function from?
11098- auto pvkGetMemoryWin32HandleKHR = & vkGetMemoryWin32HandleKHR;
11112+ auto pvkGetMemoryWin32HandleKHR = hAllocator->GetVulkanFunctions(). vkGetMemoryWin32HandleKHR;
1109911113 switch (m_Type)
1110011114 {
1110111115 case ALLOCATION_TYPE_BLOCK:
@@ -12838,6 +12852,7 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
1283812852 m_UseExtMemoryPriority((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT) != 0),
1283912853 m_UseKhrMaintenance4((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT) != 0),
1284012854 m_UseKhrMaintenance5((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT) != 0),
12855+ m_UseKhrExternalMemoryWin32((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_EXTERNAL_MEMORY_WIN32) != 0),
1284112856 m_hDevice(pCreateInfo->device),
1284212857 m_hInstance(pCreateInfo->instance),
1284312858 m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
@@ -12929,6 +12944,19 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
1292912944 VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro.");
1293012945 }
1293112946#endif
12947+ #if !(VMA_KHR_MAINTENANCE5)
12948+ if(m_UseKhrMaintenance5)
12949+ {
12950+ VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro.");
12951+ }
12952+ #endif
12953+
12954+ #if !defined(VK_USE_PLATFORM_WIN32_KHR)
12955+ if(m_UseKhrExternalMemoryWin32)
12956+ {
12957+ VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro.");
12958+ }
12959+ #endif
1293212960
1293312961 memset(&m_DeviceMemoryCallbacks, 0 ,sizeof(m_DeviceMemoryCallbacks));
1293412962 memset(&m_PhysicalDeviceProperties, 0, sizeof(m_PhysicalDeviceProperties));
@@ -13104,6 +13132,11 @@ void VmaAllocator_T::ImportVulkanFunctions_Static()
1310413132 m_VulkanFunctions.vkGetDeviceImageMemoryRequirements = (PFN_vkGetDeviceImageMemoryRequirements)vkGetDeviceImageMemoryRequirements;
1310513133 }
1310613134#endif
13135+ #ifdef VK_USE_PLATFORM_WIN32_KHR
13136+ m_VulkanFunctions.vkGetMemoryWin32HandleKHR = (PFN_vkGetMemoryWin32HandleKHR)vkGetMemoryWin32HandleKHR;
13137+ #else
13138+ m_VulkanFunctions.vkGetMemoryWin32HandleKHR = VMA_NULL;
13139+ #endif
1310713140}
1310813141
1310913142#endif // VMA_STATIC_VULKAN_FUNCTIONS == 1
@@ -13153,7 +13186,9 @@ void VmaAllocator_T::ImportVulkanFunctions_Custom(const VmaVulkanFunctions* pVul
1315313186 VMA_COPY_IF_NOT_NULL(vkGetDeviceBufferMemoryRequirements);
1315413187 VMA_COPY_IF_NOT_NULL(vkGetDeviceImageMemoryRequirements);
1315513188#endif
13156-
13189+ #ifdef VK_USE_PLATFORM_WIN32_KHR
13190+ VMA_COPY_IF_NOT_NULL(vkGetMemoryWin32HandleKHR);
13191+ #endif
1315713192#undef VMA_COPY_IF_NOT_NULL
1315813193}
1315913194
@@ -13255,7 +13290,12 @@ void VmaAllocator_T::ImportVulkanFunctions_Dynamic()
1325513290 VMA_FETCH_DEVICE_FUNC(vkGetDeviceImageMemoryRequirements, PFN_vkGetDeviceImageMemoryRequirementsKHR, "vkGetDeviceImageMemoryRequirementsKHR");
1325613291 }
1325713292#endif
13258-
13293+ #ifdef VK_USE_PLATFORM_WIN32_KHR
13294+ if (m_UseKhrExternalMemoryWin32)
13295+ {
13296+ VMA_FETCH_DEVICE_FUNC(vkGetMemoryWin32HandleKHR, PFN_vkGetMemoryWin32HandleKHR, "vkGetMemoryWin32HandleKHR");
13297+ }
13298+ #endif
1325913299#undef VMA_FETCH_DEVICE_FUNC
1326013300#undef VMA_FETCH_INSTANCE_FUNC
1326113301}
@@ -13304,6 +13344,12 @@ void VmaAllocator_T::ValidateVulkanFunctions()
1330413344 VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR != VMA_NULL);
1330513345 }
1330613346#endif
13347+ #ifdef VK_USE_PLATFORM_WIN32_KHR
13348+ if (m_UseKhrExternalMemoryWin32)
13349+ {
13350+ VMA_ASSERT(m_VulkanFunctions.vkGetMemoryWin32HandleKHR != VMA_NULL);
13351+ }
13352+ #endif
1330713353
1330813354 // Not validating these due to suspected driver bugs with these function
1330913355 // pointers being null despite correct extension or Vulkan version is enabled.
0 commit comments