vkgen
Generates Rust source code from vk.xml
Benefits
- easy to use
- no dependencies except libloading
- only ~1.500 lines of code
- can easily be modified to support other languages (just replace gen() with your own code)
General information
- libloading is required to load vkGetInstanceProcAddr from the Vulkan shared library
- all other functions are loaded dynamically during runtime via vkGetInstanceProcAddr and vkGetDeviceProcAddr
- a very thin wrapper is generated for all dispatchable handles to store function pointers / parent handles, but without any remarkable performance penalties
Usage
Step 1
Download vk.xml from the official Vulkan-Headers repository (https://github.com/KhronosGroup/Vulkan-Headers/blob/master/registry/vk.xml)
Step 2
Generate Rust source code from vk.xml
$ vkgen <input file>
Arguments
input file
is the Vulkan registry file to be parsed
Output
<input file>.rs
contains the generated source code<input file>.toml
contains a list of all versions and extensions
Example
$ vkgen ./vk.xml
Parses a file named vk.xml
containing the Vulkan registry and outputs the generated
code to vk.rs
and a list of all versions and extensions to vk.toml
.
Step 3
Copy the Rust file into your project folder and add the versions and extensions located in the toml file to your project's Cargo.toml:
...
[]
= ["VK_VERSION_1_0", "VK_VERSION_1_1"]
...
= []
= []
...
[]
= "*"
...
Step 3a (optional)
If you do not want to use libloading, remove the dependency and edit vkInit
to load the
function pointers with your preferred method.
Examples
This simple example demonstrates how to load libvulkan on linux, output the instance version (1.1.0) and create an instance. vk.rs is the file containing the generated Rust source code.
Cargo.toml:
[]
= "vkgen_test"
= "0.1.0"
= ["tobias"]
= "2018"
[]
= ["VK_VERSION_1_0", "VK_VERSION_1_1"]
= []
= []
[]
= "0.5.0"
main.rs:
use *;
use null;