@@ -43,6 +43,9 @@ VkDevice g_hDevice;
4343VmaAllocator g_hAllocator;
4444bool g_MemoryAliasingWarningEnabled = true ;
4545
46+ static bool VK_KHR_get_memory_requirements2_enabled = false ;
47+ static bool VK_KHR_dedicated_allocation_enabled = false ;
48+
4649static HINSTANCE g_hAppInstance;
4750static HWND g_hWnd;
4851static LONG g_SizeX = 1280 , g_SizeY = 720 ;
@@ -1208,14 +1211,39 @@ static void InitializeApplication()
12081211 deviceFeatures.fillModeNonSolid = VK_TRUE;
12091212 deviceFeatures.samplerAnisotropy = VK_TRUE;
12101213
1214+ // Determine list of device extensions to enable.
12111215 std::vector<const char *> enabledDeviceExtensions;
12121216 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+ }
12131241
12141242 VkDeviceCreateInfo deviceCreateInfo = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
12151243 deviceCreateInfo.enabledLayerCount = 0 ;
12161244 deviceCreateInfo.ppEnabledLayerNames = nullptr ;
12171245 deviceCreateInfo.enabledExtensionCount = (uint32_t )enabledDeviceExtensions.size ();
1218- deviceCreateInfo.ppEnabledExtensionNames = enabledDeviceExtensions.data ();
1246+ deviceCreateInfo.ppEnabledExtensionNames = ! enabledDeviceExtensions.empty () ? enabledDeviceExtensions. data () : nullptr ;
12191247 deviceCreateInfo.queueCreateInfoCount = g_PresentQueueFamilyIndex != g_GraphicsQueueFamilyIndex ? 2 : 1 ;
12201248 deviceCreateInfo.pQueueCreateInfos = deviceQueueCreateInfo;
12211249 deviceCreateInfo.pEnabledFeatures = &deviceFeatures;
@@ -1227,6 +1255,10 @@ static void InitializeApplication()
12271255 VmaAllocatorCreateInfo allocatorInfo = {};
12281256 allocatorInfo.physicalDevice = g_hPhysicalDevice;
12291257 allocatorInfo.device = g_hDevice;
1258+ if (VK_KHR_dedicated_allocation_enabled)
1259+ {
1260+ allocatorInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
1261+ }
12301262 ERR_GUARD_VULKAN ( vmaCreateAllocator (&allocatorInfo, &g_hAllocator) );
12311263
12321264 // Retrieve queue (doesn't need to be destroyed)
0 commit comments