DEV Community

Mark Nefedov
Mark Nefedov

Posted on

Using Vulkan without linking to it. (volk alternative for vulkan.hpp)

Instead of using the full fledged Vulkan SDK, we only can use the Vulkan-headers package and load actual Vulkan implementation from the driver.

To do this, we need to enable vulkan.hpp dynamic dispatcher by default by setting VULKAN_HPP_DISPATCH_LOADER_DYNAMIC to 1, adding VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE to the source file and updating VULKAN_HPP_DEFAULT_DISPATCHER as we load in more Vulkan features.

#include "vulkan/vulkan.hpp"

// Vulkan defined macro storage for dispatch loader

int main()
    vk::DynamicLoader dl;
    PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
    vk::Instance instance = vk::createInstance({}, nullptr);
    // initialize function pointers for instance
    // create a dispatcher, based on additional vkDevice/vkGetDeviceProcAddr
    std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();  
    vk::Device device = physicalDevices[0].createDevice({}, nullptr);
    // function pointer specialization for device
Enter fullscreen mode Exit fullscreen mode

Top comments (0)