Reputation: 9540
One way to get functions defined in Vulkan extensions is to use: vkGetInstanceProcAddr
to query fore the string name of the function we are looking for. If things go well we will get a function pointer to the correct method.
I want to know if it is possible to link against a file directly to expose the extension.
e.g to enable the commented out call in this function:
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance,
const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkDebugUtilsMessengerEXT* pDebugMessenger)
{
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance,
"vkCreateDebugUtilsMessengerEXT");
if (func != nullptr)
{
return func(instance, pCreateInfo, pAllocator, pDebugMessenger); //comment
//return vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pDebugMessenger); //uncomment
}
else
{
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
}
Upvotes: 2
Views: 631
Reputation: 12069
I want to know if it is possible to link against a file directly to expose the extension.
The problem is that the runtime library you are linking against is the platform Vulkan driver. The driver may not implement the extension, as it's optional, so attempting to resolve the link directly would simply result in your application failing to start with a dynamic linker symbol resolution error on platforms without the extension.
Typically you would cache the extension loaded via the extension loading mechanism into a local function pointer at load time, and that local function pointer could have whatever nice name you wanted to give it.
Upvotes: 4