d-vulkan ~master
Auto-generated D bindings for Vulkan
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
This package provides sub packages which can be used individually:
d-vulkan:devices - Simple Vulkan example
d-vulkan:layers - Simple Vulkan example
D-Vulkan
Automatically-generated D bindings for Vulkan.
Usage with Function Pointers Struct
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, orglfwGetInstanceProcAddress
if using GLFW). - Define a
VulkanFunctions
structure somewhere (ex. on the stack viaVulkanFunctions funcs;
) - Call
VulkanFunctions.loadInitializationFunctions(getProcAddr)
, wheregetProcAddr
is the address of the loadedvkGetInstanceProcAddr
function, to load the following functions:vkGetInstanceProcAddr
(sets the function from the passed value)vkCreateInstance
vkEnumerateInstanceExtensionProperties
vkEnumerateInstanceLayerProperties
- Create a
VkInstance
using the above functions. - Call
VulkanFunctions.loadInstanceFunctions(instance)
to load the rest of the functions. - (Optional) Call
VulkanFunctions.loadDeviceFunctions(device)
once you have aVkDevice
to 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.
Usage with Global Functions
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.
Differences from C Vulkan
VK_NULL_HANDLE
will 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_HANDLE
constants (as approprate for the type) orVkType.init
(whereType
is the type to get a null handle for).- All structures have their
sType
field set to the appropriate value upon initialization; explicit initialization is not needed. - Without the
DVulkanGlobalEnums
version (on by default), Vulkan enums must be prefixed by their type, as they are defined as D enums (ex.VkResult.VK_SUCCESS
). VkPipelineShaderStageCreateInfo.module
has been renamed toVkPipelineShaderStageCreateInfo._module
, sincemodule
is a D keyword.- The
VK_KHR_*_surface
extensions are not yet implemented, as they require types from external libraries (X11, XCB, ...). They can be manually loaded withvkGetInstanceProcAddr
if needed.
Configurations
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
).
Versions
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 thebare
config, you must addderelict-util
to your dependencies.DVulkan_(EXT)
: Where(EXT)
is an Vulkan version or extension name (ex.VK_VERSION_1_0
orVK_KHR_swapchain
), generates bindings
Examples
Examples can be found in the examples
directory, and ran with dub run d-vulkan:examplename
.
Derelict Loader
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.
Examples
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.
Generating Bindings
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.
- ~master released 8 years ago
- ColonelThirtyTwo/dvulkan
- BSD 2-clause
- Copyright 2015-2016 The Khronos Group Inc.; Copyright 2016, Alex Parrill
- Authors:
- Sub packages:
- d-vulkan:devices, d-vulkan:layers
- Dependencies:
- none
- Versions:
-
0.3.1 2016-May-19 0.3.0 2016-May-19 0.2.0 2016-Mar-26 0.1.0 2016-Mar-19 ~master 2016-May-27 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
2 downloads this month
-
215 downloads total
-
- Score:
- 1.7
- Short URL:
- d-vulkan.dub.pm