diff --git a/source_common/framework/manual_functions.cpp b/source_common/framework/manual_functions.cpp index 46d68c4..e44e72d 100644 --- a/source_common/framework/manual_functions.cpp +++ b/source_common/framework/manual_functions.cpp @@ -215,6 +215,42 @@ std::vector getInstanceExtensionList( return foundExtensions; } +/* See header for documentation. */ +std::vector getDeviceExtensionList( + VkInstance instance, + VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo +) { + std::vector foundExtensions; + + // Fetch the functions needed to query extensions availability + auto* chainInfo = getChainInfo(pCreateInfo); + auto fpGetProcAddr = chainInfo->u.pLayerInfo->pfnNextGetInstanceProcAddr; + auto fpGetExtensionsRaw = fpGetProcAddr(instance, "vkEnumerateDeviceExtensionProperties"); + auto fpGetExtensions = reinterpret_cast(fpGetExtensionsRaw); + if (!fpGetExtensions) + { + return foundExtensions; + } + + // Query number of extensions + uint32_t count; + fpGetExtensions(physicalDevice, nullptr, &count, nullptr); + + // Reserve memory for, and then query, the extensions + std::vector extensions; + extensions.resize(count); + fpGetExtensions(physicalDevice, nullptr, &count, extensions.data()); + + // Build the function return list + for (uint32_t i = 0; i < count; i++) + { + foundExtensions.emplace_back(extensions[i].extensionName); + } + + return foundExtensions; +} + /* See header for documentation. */ bool isInExtensionList( const std::string& target, diff --git a/source_common/framework/manual_functions.hpp b/source_common/framework/manual_functions.hpp index de50267..dcb8760 100644 --- a/source_common/framework/manual_functions.hpp +++ b/source_common/framework/manual_functions.hpp @@ -119,6 +119,20 @@ PFN_vkVoidFunction getDeviceLayerFunction( std::vector getInstanceExtensionList( const VkInstanceCreateInfo* pCreateInfo); +/** + * @brief Fetch the list of supported extensions from a physical device. + * + * @param instance The instance we are connected to. + * @param physicalDevice The physical device to query. + * @param pCreateInfo The device creation data from the loader. + * + * @return The list of supported extensions; empty list on failure. + */ +std::vector getDeviceExtensionList( + VkInstance instance, + VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo); + /** * @brief Is an extension in the passed extension list. *