Foundations

The Vulkan loader

A program never calls the GPU driver by name. Each Vulkan call goes through a small library, the loader, which finds the driver, puts optional layers such as validation in between, and passes the call on. This page explains that path, the two ways a program can get the functions, and why the version of the loader and the version of the GPU are two different numbers. The last part shows how RASM does it.

In short

  • The loader (vulkan-1.dll, libvulkan) sits between the program and the driver. Layers can sit in between too.
  • A function the program gets from the loader is a trampoline: it reads which driver the handle belongs to, then jumps there. One extra jump per call.
  • Linked against the loader, the program cannot start when the loader lacks one of its functions. Loaded at run time, the program starts, checks, and says what is wrong.
  • Functions come in three levels: global, instance and device. Device functions from vkGetDeviceProcAddr skip the trampoline, but they belong to one device: keep a table per device.
  • The loader's version limits instance-level features. Device commands need the GPU's version, and come from the driver. A 1.3 loader can run a 1.4 GPU.

1From a call to the driver

Follow one draw call. It leaves the program, passes the loader and maybe some layers, and ends in the driver of the GPU that owns the command buffer.

your program vkCmdDraw(...) loader vulkan-1.dll libvulkan on macOS, Linux layers validation, capture optional driver (ICD) talks to the GPU VkCommandBuffer first word: its dispatch table the device's dispatch table vkCmdDraw → layer or driver vkCmdDispatch → layer or driver vkQueueSubmit2 → layer or driver trampoline reads it
Every dispatchable handle (instance, physical device, device, queue, command buffer) starts with a pointer to its dispatch table. The loader's function for vkCmdDraw is a trampoline: it reads that pointer and jumps to the table's entry. Handles of other kinds (buffers, images) are plain numbers.

The table belongs to one device, because each device can have another driver behind it: two GPUs from two vendors, or a GPU and a software rasterizer. The trampoline is what lets one function name serve them all.

2Linked or loaded

A program can get the loader's functions in two ways. The difference shows on a machine whose loader is older than the program expects.

program.exe vkCreateInstance vkCmdDraw vkCopyMemory… loader 1.3 vkCreateInstance vkCmdDraw no 1.4 names

Linked: the OS checks first

The import table names each function. One missing name, and the OS stops the program before main, with a system error. The program never gets to explain.

program.exe main(): 1 open the loader 2 check its version 3 ask for functions loader vkGetInstance- ProcAddr

Loaded: the program checks

It opens the loader in main, asks for each function by name, and gets null for one that does not exist. It can say "update your driver", or work without that feature.

Loading also means the program starts on a machine with no Vulkan at all: tools and tests that never touch the GPU run anywhere. Libraries such as volk do the loading: one call opens the loader, and the functions are then plain function pointers with the usual names.

3Three levels of functions

Which function you can get, and from where, depends on what its first parameter is.

loader GetInstanceProcAddr(NULL)

Global

No handle yet: vkCreateInstance, vkEnumerateInstanceVersion, the instance layers and extensions.

instance physical device GetInstanceProcAddr(inst)

Instance

The first parameter is an instance or a physical device: vkEnumeratePhysicalDevices, the properties and features of a GPU, surface queries. Trampolines.

device, queue, command buffer GetDeviceProcAddr(dev)

Device

Almost every call of a frame: vkCmdDraw, vkQueueSubmit2, vkCreateBuffer. From vkGetDeviceProcAddr they skip the trampoline.

You askFor a device function you getValid for
the import library (linked)the loader's trampolineevery device
vkGetInstanceProcAddr(instance, ...)the loader's trampolineevery device of that instance
vkGetDeviceProcAddr(device, ...)the first layer's function, or the driver'sthat one device only

4A table per device

A function from vkGetDeviceProcAddr saves a jump on every call, but it is tied to the device it came from. Where to keep it?

device A device B trampolines

Global trampolines

Right for every device, one extra jump per call. What linking gives you.

correct, a little slower

device A device B globals,from A

Globals from one device

Fast for device A. A second device calls A's functions, which may belong to another driver.

wrong with two devices

device A device B A's table B's table

A table per device

Each device object holds a struct of pointers and calls through it: table.vkCmdDraw(cmd, ...).

correct and direct

How much does the jump cost? A few nanoseconds: a load, an indirect jump, and a cache line that is usually warm. A frame that records ten thousand commands pays tens of microseconds. A GPU-driven renderer records few commands per frame (one indirect draw draws thousands of objects), so there the saving is small. The table is worth having mostly for correctness with several devices.

Make the wrong call impossible

With a table per device, also remove the global device functions from the build, so a call that skips the table does not compile. volk does this with VOLK_NO_DEVICE_PROTOTYPES; Vulkan's own header does it with VK_NO_PROTOTYPES.

5Whose version?

"Vulkan 1.4" can mean two things. The loader's version (vkEnumerateInstanceVersion) says which instance-level features the instance has. The GPU's version (VkPhysicalDeviceProperties::apiVersion) says which device features and commands its driver has.

instance features ≤ min(loader version, apiVersion)

device features ≤ min(GPU version, apiVersion)

apiVersion
the highest version the program asks for when it creates the instance
loader version
comes with the GPU driver installer, or with another program that put its own loader next to it
GPU version
what the driver of that one GPU supports; two GPUs in one machine can differ

Vulkan 1.4 added only device commands (host image copy, push descriptors, vkCmdBindIndexBuffer2, ...), and no new instance or physical-device commands. A device command from vkGetDeviceProcAddr comes from the driver, which knows it, even when the loader is older. So a program that loads its functions needs only the loader version of its instance features, and a 1.4 GPU. A linked program needs every name in the loader. Try both:

The program uses one 1.4 command, needs a 1.3 loader for its instance features, and needs a 1.4 GPU. Link it, and pick a 1.3 loader: it stops before main. Load it instead: it runs. Then pick a 1.3 GPU or a 1.2 loader and read what it says.
A loader can arrive with another program

Windows looks for a DLL in the program's own folder before the system folder. A browser, a game launcher or a tool may ship its own vulkan-1.dll next to its executable, and an old one there wins for that program. The system's loader comes with the GPU driver and is usually new.

6Pitfalls

The program does not start, with a system error about an entry point
It is linked against the loader and uses a function this loader does not have. Load the functions at run time instead, and check the version yourself.
A link error for every vk... function
The header declared prototypes (no VK_NO_PROTOTYPES) and the code called them, but nothing links the loader. Call through the loaded pointers or the device table.
A function pointer is null
Its extension or version was not enabled when the instance or device was made, or the loader or driver does not have it. Enable it first, and check for null.
The window's surface belongs to another loader
A windowing library (SDL, GLFW) may open the loader itself. If the program opens another copy, by another name or path, the surface and the instance come from two libraries. Take the windowing library's vkGetInstanceProcAddr, or give it yours.
The loader is not found on macOS
libvulkan.dylib lives in /usr/local/lib after the SDK's system install, and the dynamic linker may not search there for a plain name. Try that path too, or set DYLD_LIBRARY_PATH.
Calls are slow only with validation
With layers on, a device pointer leads to the first layer, which checks the call. That is expected; the table still skips the loader's trampoline.

7In RASM

Nothing in RASM links the loader. volk opens it when the device starts, with a window or without one, and each VulkanDevice keeps its own table of device functions. SDL never opens a loader: a window reaches the device as native handles, and RASM makes the surface itself with its own instance.

a window: native handles createVulkanSurface window or headless volkInitialize() after the instance loadVulkan no loader, or older than 1.3: a clear error, then stop volk's globals global + instance functions (volkLoadInstanceOnly) used by vk-bootstrap and VMA VulkanDevice volkLoadDeviceTable(&vk, ...) no 1.4 GPU: each GPU named with its version (logOldDevices) VMA: vmaImportVulkanFunctionsFromVolk instance level getVkTable(), a reference in VulkanCommandBuffer VulkanQueue VulkanSwapchain driver (or layer)
volk finds the loader in every mode, and the surface is made from the window's native handles with that loader's instance, so the surface and the instance always come from one library. Global and instance functions are volk's process-wide globals. Device functions live in each device's VolkDeviceTable.
This pageRASM
Link or loadLoad, with volk (vcpkg port volk). No executable imports vulkan-1.dll or libvulkan; CI checks every executable and DLL of the build with llvm-objdump and otool.
Which loadervolkInitialize, with a window or headless; on macOS it tries /usr/local/lib/libvulkan.dylib too. The surface comes from the window's NativeWindow through that loader (createVulkanSurface), so no windowing library opens a second copy.
VersionsThe loader must be 1.3 or newer and the GPU 1.4. Each check logs the version it found. A 1.3 loader runs RASM, as the image tests show on CI's runner.
Global and instance functionsvolk's globals, one set per process, loaded with volkLoadInstanceOnly. They are trampolines, so a second instance does not break them.
A table per deviceVulkanDevice::vk, a VolkDeviceTable. VOLK_NO_DEVICE_PROTOTYPES leaves no global device function, so a call outside the table does not compile. vkSetDebugUtilsObjectNameEXT belongs to an instance extension and stays global.
Other librariesvk-bootstrap gets volk's vkGetInstanceProcAddr; VMA gets its pointers from vmaImportVulkanFunctionsFromVolk. The Vulkan headers come from vcpkg at volk's version, so all of them see one header.
Programs with no GPUrasm_tests never creates a device, so it starts with no Vulkan on the machine (the macOS CI job installs none).

In examples/05_city (headless, Release, RTX 3060), the CPU time to record a frame's commands (the self time of RenderGraph::execute) went down a little when the device calls left the trampoline, within the run-to-run noise of 5 to 8%:

0.204 msrecording, through the trampolinemean of two 9.5 s captures: 0.208 and 0.199
0.194 msrecording, through the device tablemean of two captures: 0.195 and 0.193
1.32 msframe time, both waysthe frame is bound by the GPU wait, not by the calls

Where it lives in code

WhatWhere
Open the loader, check versionsloadVulkan, logOldDevices in src/rhi/vulkan/vulkanDevice.cpp
The device table, VMAVulkanDevice::initialize in the same file
Calls through the tablesrc/rhi/vulkan/vulkanCommandBuffer.cpp, src/rhi/vulkan/vulkanQueue.cpp, src/rhi/vulkan/vulkanSwapchain.cpp
The surfacecreateVulkanSurface in src/rhi/vulkan/vulkanSurface.cpp
Buildsrc/CMakeLists.txt, vcpkg.json, cmake/rasmConfig.cmake.in
CI check.github/workflows/ci.yml
Rules to keep

Call device functions through the device's table (vk.vkCmdDraw, getVkTable()), never through a global. Do not add Vulkan::Vulkan or any other loader link; CI fails on it. A library that calls Vulkan itself gets volk's pointers, not its own loader.

Further reading