@@ -461,6 +461,14 @@ typedef enum VmaAllocatorCreateFlagBits
461
461
*/
462
462
VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT = 0x00000100,
463
463
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
+
464
472
VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
465
473
} VmaAllocatorCreateFlagBits;
466
474
/// See #VmaAllocatorCreateFlagBits.
@@ -1035,6 +1043,11 @@ typedef struct VmaVulkanFunctions
1035
1043
/// Fetch from "vkGetDeviceImageMemoryRequirements" on Vulkan >= 1.3, but you can also fetch it from "vkGetDeviceImageMemoryRequirementsKHR" if you enabled extension VK_KHR_maintenance4.
1036
1044
PFN_vkGetDeviceImageMemoryRequirementsKHR VMA_NULLABLE vkGetDeviceImageMemoryRequirements;
1037
1045
#endif
1046
+ #ifdef VK_USE_PLATFORM_WIN32_KHR
1047
+ PFN_vkGetMemoryWin32HandleKHR VMA_NULLABLE vkGetMemoryWin32HandleKHR;
1048
+ #else
1049
+ void* VMA_NULLABLE vkGetMemoryWin32HandleKHR;
1050
+ #endif
1038
1051
} VmaVulkanFunctions;
1039
1052
1040
1053
/// Description of a Allocator to be created.
@@ -10176,6 +10189,7 @@ struct VmaAllocator_T
10176
10189
bool m_UseExtMemoryPriority;
10177
10190
bool m_UseKhrMaintenance4;
10178
10191
bool m_UseKhrMaintenance5;
10192
+ bool m_UseKhrExternalMemoryWin32;
10179
10193
const VkDevice m_hDevice;
10180
10194
const VkInstance m_hInstance;
10181
10195
const bool m_AllocationCallbacksSpecified;
@@ -11095,7 +11109,7 @@ void VmaAllocation_T::PrintParameters(class VmaJsonWriter& json) const
11095
11109
VkResult VmaAllocation_T::GetWin32Handle(VmaAllocator hAllocator, HANDLE hTargetProcess, HANDLE* pHandle) const noexcept
11096
11110
{
11097
11111
// Where do we get this function from?
11098
- auto pvkGetMemoryWin32HandleKHR = & vkGetMemoryWin32HandleKHR;
11112
+ auto pvkGetMemoryWin32HandleKHR = hAllocator->GetVulkanFunctions(). vkGetMemoryWin32HandleKHR;
11099
11113
switch (m_Type)
11100
11114
{
11101
11115
case ALLOCATION_TYPE_BLOCK:
@@ -12838,6 +12852,7 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
12838
12852
m_UseExtMemoryPriority((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT) != 0),
12839
12853
m_UseKhrMaintenance4((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT) != 0),
12840
12854
m_UseKhrMaintenance5((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT) != 0),
12855
+ m_UseKhrExternalMemoryWin32((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_EXTERNAL_MEMORY_WIN32) != 0),
12841
12856
m_hDevice(pCreateInfo->device),
12842
12857
m_hInstance(pCreateInfo->instance),
12843
12858
m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
@@ -12929,6 +12944,19 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
12929
12944
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.");
12930
12945
}
12931
12946
#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
12932
12960
12933
12961
memset(&m_DeviceMemoryCallbacks, 0 ,sizeof(m_DeviceMemoryCallbacks));
12934
12962
memset(&m_PhysicalDeviceProperties, 0, sizeof(m_PhysicalDeviceProperties));
@@ -13104,6 +13132,11 @@ void VmaAllocator_T::ImportVulkanFunctions_Static()
13104
13132
m_VulkanFunctions.vkGetDeviceImageMemoryRequirements = (PFN_vkGetDeviceImageMemoryRequirements)vkGetDeviceImageMemoryRequirements;
13105
13133
}
13106
13134
#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
13107
13140
}
13108
13141
13109
13142
#endif // VMA_STATIC_VULKAN_FUNCTIONS == 1
@@ -13153,7 +13186,9 @@ void VmaAllocator_T::ImportVulkanFunctions_Custom(const VmaVulkanFunctions* pVul
13153
13186
VMA_COPY_IF_NOT_NULL(vkGetDeviceBufferMemoryRequirements);
13154
13187
VMA_COPY_IF_NOT_NULL(vkGetDeviceImageMemoryRequirements);
13155
13188
#endif
13156
-
13189
+ #ifdef VK_USE_PLATFORM_WIN32_KHR
13190
+ VMA_COPY_IF_NOT_NULL(vkGetMemoryWin32HandleKHR);
13191
+ #endif
13157
13192
#undef VMA_COPY_IF_NOT_NULL
13158
13193
}
13159
13194
@@ -13255,7 +13290,12 @@ void VmaAllocator_T::ImportVulkanFunctions_Dynamic()
13255
13290
VMA_FETCH_DEVICE_FUNC(vkGetDeviceImageMemoryRequirements, PFN_vkGetDeviceImageMemoryRequirementsKHR, "vkGetDeviceImageMemoryRequirementsKHR");
13256
13291
}
13257
13292
#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
13259
13299
#undef VMA_FETCH_DEVICE_FUNC
13260
13300
#undef VMA_FETCH_INSTANCE_FUNC
13261
13301
}
@@ -13304,6 +13344,12 @@ void VmaAllocator_T::ValidateVulkanFunctions()
13304
13344
VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR != VMA_NULL);
13305
13345
}
13306
13346
#endif
13347
+ #ifdef VK_USE_PLATFORM_WIN32_KHR
13348
+ if (m_UseKhrExternalMemoryWin32)
13349
+ {
13350
+ VMA_ASSERT(m_VulkanFunctions.vkGetMemoryWin32HandleKHR != VMA_NULL);
13351
+ }
13352
+ #endif
13307
13353
13308
13354
// Not validating these due to suspected driver bugs with these function
13309
13355
// pointers being null despite correct extension or Vulkan version is enabled.
0 commit comments