如何在 Vulkan 中获取支持的扩展

Bre*_*ent 2 vulkan

我正在开发一个使用 Vulkan 的 C++ 应用程序。如何获取支持的扩展集?

像这样的签名std::set<std::string> get_supported_extensions()是理想的。

Bre*_*ent 7

vkEnumerateInstanceExtensionProperties API 执行此操作

std::set<std::string> get_supported_extensions() {
    VkResult result = 0;

    /*
     * From the link above:
     * If `pProperties` is NULL, then the number of extensions properties
     * available is returned in `pPropertyCount`.
     *
     * Basically, gets the number of extensions.
     */
    uint32_t count = 0;
    result = vkEnumerateInstanceExtensionProperties(nullptr, &count, nullptr);
    if (result != VK_SUCCESS) {
        // Throw an exception or log the error
    }

    std::vector<VkExtensionProperties> extensionProperties(count);

    // Get the extensions
    result = vkEnumerateInstanceExtensionProperties(nullptr, &count, extensionProperties.data());
    if (result != VK_SUCCESS) {
        // Throw an exception or log the error
    }

    std::set<std::string> extensions;
    for (auto & extension : extensionProperties) {
        extensions.insert(extension.extensionName);
    }

    return extensions;
}
Run Code Online (Sandbox Code Playgroud)