Generates Rust source code from vk.xml
Download vk.xml from the official Vulkan-Headers repository (https://github.com/KhronosGroup/Vulkan-Headers/blob/master/registry/vk.xml)
Generate Rust source code from vk.xml
$ vkgen <input file> <fags>
input file
is the Vulkan registry file to be parsedflags
see Flags--verbose
, -v
print all warnings<input file>.rs
contains the generated source code<input file>.toml
contains a list of all versions and extensions$ 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
.
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:
toml
...
[features]
default = ["VK_VERSION_1_0", "VK_VERSION_1_1"]
...
VK_VERSION_1_0 = []
VK_VERSION_1_1 = []
...
[dependencies]
libloading = "*"
...
If you do not want to use libloading, remove the dependency and edit vkInit
to load the
function pointers with your preferred method.
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: ```toml [package] name = "vkgen_test" version = "0.1.0" authors = ["tobias"] edition = "2018"
[features] default = ["VKVERSION10", "VKVERSION11"] VKVERSION10 = [] VKVERSION11 = []
[dependencies]
libloading = "0.5.0"
main.rs:
rust
mod vk;
use self::vk::*; use std::ptr::null;
fn main() { let mut v: u32 = 0; VkInstanceImpl::enumerateVersion(&mut v); println!("vulkan instance version is {}.{}.{}", VKVERSIONMAJOR(v), VKVERSIONMINOR(v), VKVERSIONPATCH(v));
let instance_info = VkInstanceCreateInfo {
sType: VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
pNext: null(),
flags: 0,
pApplicationInfo: &VkApplicationInfo {
sType: VK_STRUCTURE_TYPE_APPLICATION_INFO,
pNext: null(),
pApplicationName: "test app\0".as_ptr(),
applicationVersion: VK_MAKE_VERSION(0, 0, 1),
pEngineName: "test engine\0".as_ptr(),
engineVersion: VK_MAKE_VERSION(0, 0, 1),
apiVersion: VK_MAKE_VERSION(1, 1, 0),
},
enabledLayerCount: 0,
ppEnabledLayerNames: null(),
enabledExtensionCount: 0,
ppEnabledExtensionNames: null()
};
let mut instance = VK_NULL_HANDLE;
if VkInstanceImpl::create(&instance_info, null(), &mut instance) != VK_SUCCESS {
panic!("something went wrong :-/");
};
let instance = unsafe { VkInstanceImpl::new(instance) };
}
```