Automatically-generated D bindings for Vulkan.
D-Vulkan, at its core, does not load functions into global variables, like similar bindings do.
Instead, functions are loaded into a VulkanFunctions structure. This is because Vulkan functions
are inherently tied to the instance, or device, that they were loaded from. For example, global
variables would make using the device-specific functions impossible to use with multiple devices.
To use the VulkanFunctions struct:
- Import via
import dvulkan;. - Get a pointer to the
vkGetInstanceProcAddr, through platform-specific means (ex. loading the Vulkan shared library, using the Derelict loader, orglfwGetInstanceProcAddressif using GLFW). - Define a
VulkanFunctionsstructure somewhere (ex. on the stack viaVulkanFunctions funcs;) - Call
VulkanFunctions.loadInitializationFunctions(getProcAddr), wheregetProcAddris the address of the loadedvkGetInstanceProcAddrfunction, to load the following functions:vkGetInstanceProcAddr(sets the function from the passed value)vkCreateInstancevkEnumerateInstanceExtensionPropertiesvkEnumerateInstanceLayerProperties
- Create a
VkInstanceusing the above functions. - Call
VulkanFunctions.loadInstanceFunctions(instance)to load the rest of the functions. - (Optional) Call
VulkanFunctions.loadDeviceFunctions(device)once you have aVkDeviceto load specific functions for a device.
For your convenience, the VulkanFunctions structure includes the fields instance and device,
that are set whenever loadInstanceFunctions and loadDeviceFunctions are called, respectively.
Note that the VulkanFunctions struct is fairly large; be sure, if you are passing it around, to
pass by reference or pointer.
For convenience, when the DVulkanGlobalFunctions version is set (it is set in the default
configuration), D-Vulkan will generate global variables holding Vulkan functions.
To use the global functions, follow the steps for using the VulkanFunctions struct, but instead of
using the VulkanFunctions.load*Functions member functions, use the dvulkan.global.load*Functions
global functions instead.
VK_NULL_HANDLEwill not work. The C Vulkan headers rely on the fact that 0 in C is implicitly convertible to the null pointer, but that is not the case in D. Instead, use theVK_NULL_[NON_]DISPATCHABLE_HANDLEconstants (as approprate for the type) orVkType.init(whereTypeis the type to get a null handle for).- All structures have their
sTypefield set to the appropriate value upon initialization; explicit initialization is not needed. - Without the
DVulkanGlobalEnumsversion (on by default), Vulkan enums must be prefixed by their type, as they are defined as D enums (ex.VkResult.VK_SUCCESS). VkPipelineShaderStageCreateInfo.modulehas been renamed toVkPipelineShaderStageCreateInfo._module, sincemoduleis a D keyword.- The
VK_KHR_*_surfaceextensions are not yet implemented, as they require types from external libraries (X11, XCB, ...). They can be manually loaded withvkGetInstanceProcAddrif needed.
D-Vulkan has two configurations, settable via the subConfigurations dub option
- default: The default. Sets the versions
DVulkanDerelict,DVulkanAllExtensions,DVulkanGlobalEnums, andDVulkanGlobalFunctions(see below), and includesderelict-util. - bare: No versions are set, you must specify what you want manually (usually at least
DVulkan_VK_VERSION_1_0).
D-Vulkan has several versions, settable via the versions dub option.
DVulkanGlobalEnums: Defines global aliases for all enumerations.DVulkanGlobalFunctions: Generates global function pointers for Vulkan functions.DVulkanDerelict: Includes a small loader for the Vulkan shared library usingderelict-util. When using this version with thebareconfig, you must addderelict-utilto your dependencies.DVulkan_(EXT): Where(EXT)is an Vulkan version or extension name (ex.VK_VERSION_1_0orVK_KHR_swapchain), generates bindings
Examples can be found in the examples directory, and ran with dub run d-vulkan:examplename.
D-Vulkan includes a small loader using derelict-util to load the Vulkan shared library when the
DVulkanDerelict version is defined.
To use it, call DVulkanDerelict.load(), then either DVulkanDerelict.getInitializationFunctions(),
which returns a VulkanFunctions struct containing the initialization functions loaded by
VulkanFunctions.getInitializationFunctions, or, if DVulkanGlobalFunctions is also specified,
DVulkanDerelict.loadInitializationFunctions() to load the same functions to the global variables.
Two examples can be found in the examples directory, and can be ran with
dub run d-vulkan:examplename.
devices: Lists devices. Uses the derelict loader.
layers: Lists available layers. Uses the derelict loader, global enums, and whitelisted extension loading.
To generate bindings, download the Vulkan-Docs repo,
copy/move/symlink vkdgen.py into src/spec/, cd there, and execute it, passing in an output
folder to place the D files. Requires Python 3.