@@ -43,6 +43,9 @@ VkDevice g_hDevice;
43
43
VmaAllocator g_hAllocator;
44
44
bool g_MemoryAliasingWarningEnabled = true ;
45
45
46
+ static bool VK_KHR_get_memory_requirements2_enabled = false ;
47
+ static bool VK_KHR_dedicated_allocation_enabled = false ;
48
+
46
49
static HINSTANCE g_hAppInstance;
47
50
static HWND g_hWnd;
48
51
static LONG g_SizeX = 1280 , g_SizeY = 720 ;
@@ -1208,14 +1211,39 @@ static void InitializeApplication()
1208
1211
deviceFeatures.fillModeNonSolid = VK_TRUE;
1209
1212
deviceFeatures.samplerAnisotropy = VK_TRUE;
1210
1213
1214
+ // Determine list of device extensions to enable.
1211
1215
std::vector<const char *> enabledDeviceExtensions;
1212
1216
enabledDeviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1217
+ {
1218
+ uint32_t propertyCount = 0 ;
1219
+ ERR_GUARD_VULKAN ( vkEnumerateDeviceExtensionProperties (g_hPhysicalDevice, nullptr , &propertyCount, nullptr ) );
1220
+
1221
+ if (propertyCount)
1222
+ {
1223
+ std::vector<VkExtensionProperties> properties{propertyCount};
1224
+ ERR_GUARD_VULKAN ( vkEnumerateDeviceExtensionProperties (g_hPhysicalDevice, nullptr , &propertyCount, properties.data ()) );
1225
+
1226
+ for (uint32_t i = 0 ; i < propertyCount; ++i)
1227
+ {
1228
+ if (strcmp (properties[i].extensionName , VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME) == 0 )
1229
+ {
1230
+ enabledDeviceExtensions.push_back (VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
1231
+ VK_KHR_get_memory_requirements2_enabled = true ;
1232
+ }
1233
+ else if (strcmp (properties[i].extensionName , VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0 )
1234
+ {
1235
+ enabledDeviceExtensions.push_back (VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
1236
+ VK_KHR_dedicated_allocation_enabled = true ;
1237
+ }
1238
+ }
1239
+ }
1240
+ }
1213
1241
1214
1242
VkDeviceCreateInfo deviceCreateInfo = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
1215
1243
deviceCreateInfo.enabledLayerCount = 0 ;
1216
1244
deviceCreateInfo.ppEnabledLayerNames = nullptr ;
1217
1245
deviceCreateInfo.enabledExtensionCount = (uint32_t )enabledDeviceExtensions.size ();
1218
- deviceCreateInfo.ppEnabledExtensionNames = enabledDeviceExtensions.data ();
1246
+ deviceCreateInfo.ppEnabledExtensionNames = ! enabledDeviceExtensions.empty () ? enabledDeviceExtensions. data () : nullptr ;
1219
1247
deviceCreateInfo.queueCreateInfoCount = g_PresentQueueFamilyIndex != g_GraphicsQueueFamilyIndex ? 2 : 1 ;
1220
1248
deviceCreateInfo.pQueueCreateInfos = deviceQueueCreateInfo;
1221
1249
deviceCreateInfo.pEnabledFeatures = &deviceFeatures;
@@ -1227,6 +1255,10 @@ static void InitializeApplication()
1227
1255
VmaAllocatorCreateInfo allocatorInfo = {};
1228
1256
allocatorInfo.physicalDevice = g_hPhysicalDevice;
1229
1257
allocatorInfo.device = g_hDevice;
1258
+ if (VK_KHR_dedicated_allocation_enabled)
1259
+ {
1260
+ allocatorInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
1261
+ }
1230
1262
ERR_GUARD_VULKAN ( vmaCreateAllocator (&allocatorInfo, &g_hAllocator) );
1231
1263
1232
1264
// Retrieve queue (doesn't need to be destroyed)
0 commit comments