vkgen
Generates Rust source code from vk.xml
Benefits
- easy to use
- no dependencies except libloading
- only ~1.000 lines of code which ensures easy maintainability
- 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> <output file>
Arguments
input file
the Vulkan registry file to be parsedoutput file
the file to which the generated code will be written, it will be created if it does not exist
Options
TBA
Example
$ vkgen ./vk.xml ./vk.rs
Parses a file called vk.xml
which contains the Vulkan registry and writes the generated code to vk.rs
.
Step 3
Add libloading to your project's cargo.toml
[dependencies]
libloading = "0.5.0"
libloading
is required to load vkGetInstanceProcAddr from the Vulkan shared library.
Step 4
Load libvulkan in order to use the generated functions
unsafe
Note: vkLoad() only loads vkGetInstanceProcAddr from the shared library, all other functions are loaded dynamically via vkGetInstanceProcAddr andvkGetDeviceProcAddr to avoid additional dispatch overhead.
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. The location of libvulkan.so/vulkan.dll may vary depending on the OS.
use *;
use null;