New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for Vulkan functions to use the results of clients call to vkGetDeviceProcAddr #120
Comments
We're working on a solution which will allow using multiple dispatch tables retrived through vkGetDeviceProcAddr or vkGetInstanceProcAddr. In addition to this we plan to provide the required utility functions to build the dispatch tables to mimimize work on the developer side. |
Just wondering if there is an update to this? I'm currently having to write chunks of code falling back to the C interface when I'm fetching functions. It seems like it would make sense to be able to supply a v-table of functions as required, e.g. perhaps something like the following: struct MyFunctions {
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR;
PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
PFN_vkQueuePresentKHR vkQueuePresentKHR;
}
class PhysicalDevice {
template <typename FunctionsT>
auto getPhysicalDeviceSurfaceFormatsKHR(..., const FunctionsT & functions) {
// ...
functions.vkGetPhysicalDeviceSurfaceFormatsKHR(...)
// ...
}
}; |
I've started to implement something like an extension loader and proxy handles in a new namespace tbd. The idea was to generate a proxy vk handle out of a vk handle and a functions table like this
|
My first attempt is to use a prototype class like so:
I added another version of
Perhaps throw would be better - fail early. If you need more complex logic perhaps you should implement it using the basic |
It would also probably make sense to use |
We discussed the solution passing an object to forward all Vulkan functions and came to the conclusion that it's a good solution besides some template ugliness. With this change each (member) function will become a template function with the forwarder class as new template argument void vkXyz(arguments) ; will become template <typename Dispatcher = DefaultDispatcher>
void vkXyz(arguments, Dispatcher const & dispatcher = Dispatcher());
If people want to use their own dispatch mechanism they have to pass a dispatch object to each function call. Another feature we can integrate is a constexpr (or enum because of vs2013) for each function which specifies whether the function is supported by the dispatcher. This way developers will get a failure at compile time and they know that they've to go the route through the function pointers. |
I've submitted a first version of Vulkan-Hpp with support for a dispatch class to https://github.com/mtavenrath/Vulkan-Hpp/tree/extension_loader. All calls into Vulkan now go through a dispatcher class. The default dispatcher class is Existing code will continue to work. Calling This feature enables interesting possibilities, i.e. one does not have to specify all Vulkan functions in a class, but just a subset. E.g. this piece of code just works fine (and of course doesn't make much sense):
Besides some cleanup the missing part is implementing a class which gets all functions through vk*GetProcAddress. |
That's great |
What is the situation on this officially? |
We have merged a PR a day ago which provides the basic infrastructure: e97e346 as described in my comment from Dec 11th including a dispatch class for the Vulkan loader. What's missing is a dispatch class with function pointers for each Vulkan function and two functions to initialize those, one for instance functions and one for device functions. |
@ioquatix, @UPS7kYkHEPbZIucaqjje Can you give https://github.com/mtavenrath/Vulkan-Hpp/tree/extension_loader a try to see if it fits your needs? Usage:
It's also possible to initialize the dispatch loader deferred by calling dld.init(instance, ); |
That's awesome, I'll try it out. |
The feature has been merged. Closing. |
I'm referencing this stack-overflow question (look at the accepted answers where it talks about Vulkan.hpp)
https://stackoverflow.com/questions/45868990/should-i-use-the-vulkan-loader/45871076?noredirect=1#comment78702774_45871076
which talks about using vkGetDeviceProcAddr in order to avoid using the loader trampoline/terminator for efficiency reasons as described in this link
https://vulkan.lunarg.com/doc/view/1.0.57.0/windows/LoaderAndLayerInterface.html#user-content-best-application-performance-setup
Currently, I don't see a way to accomplish this using Vulkan.hpp
The text was updated successfully, but these errors were encountered: