Skip to content

Commit

Permalink
Add device extension query to common library
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Dec 30, 2024
1 parent 17190a7 commit 9dc98f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
36 changes: 36 additions & 0 deletions source_common/framework/manual_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,42 @@ std::vector<std::string> getInstanceExtensionList(
return foundExtensions;
}

/* See header for documentation. */
std::vector<std::string> getDeviceExtensionList(
VkInstance instance,
VkPhysicalDevice physicalDevice,
const VkDeviceCreateInfo* pCreateInfo
) {
std::vector<std::string> 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<PFN_vkEnumerateDeviceExtensionProperties>(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<VkExtensionProperties> 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,
Expand Down
14 changes: 14 additions & 0 deletions source_common/framework/manual_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ PFN_vkVoidFunction getDeviceLayerFunction(
std::vector<std::string> 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<std::string> getDeviceExtensionList(
VkInstance instance,
VkPhysicalDevice physicalDevice,
const VkDeviceCreateInfo* pCreateInfo);

/**
* @brief Is an extension in the passed extension list.
*
Expand Down

0 comments on commit 9dc98f0

Please sign in to comment.