vulkan-tutorial-hpp icon indicating copy to clipboard operation
vulkan-tutorial-hpp copied to clipboard

How to enable dynamic dispatch loader

Open eidloi opened this issue 9 months ago • 0 comments

Hello,

This isn't really an "issue", but rather how to enable the dynamic dispatch loader in vulkan.hpp.

I noticed this comment and decided to investigate: https://github.com/bwasty/vulkan-tutorial-hpp/blob/4662ff18b1b55246523f0d9245bf5763a8f2fb12/steps/02_validation_layers.cpp#L132

Basically, this is a functionality that needs to be enabled to work. There is a documentation that explains this process here: https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers

Basically, you need to:

// Enable loader with the define:
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1

// User this macro - or implement manually - to add the type (once, somewhere "globally" available)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE

Then, as part of the vkInstance creation:

// Initialize the loader with the bare minimum function pointers (required for instance creation)
VULKAN_HPP_DEFAULT_DISPATCHER.init();

// ... Initialize Vulkan instance normally ...

// Reinit the dispatcher, binding the instance to it
VULKAN_HPP_DEFAULT_DISPATCHER.init(m_VkInstance.get());

With the above, instance->createDebugUtilsMessengerEXTUnique(createInfo); will work and not have linking errors anymore.

This is using the "default" dispatcher defined by vulkan.hpp. It is also possible to pass user-defined dispatchers to function calls to implement your own lookup. See docs for details on that.

Cheers!

eidloi avatar May 06 '25 17:05 eidloi