vkgen 0.1.2

Generates Rust source code from vk.xml
vkgen-0.1.2 is not a library.
Visit the last successful build: vkgen-2.2.1

vkgen

Generates Rust source code from vk.xml

###This crate offers

  • an easy to use cli tool
  • no external dependencies except libloading
  • only ~1.000 lines of code which ensures simple maintainability
  • a generator that can easily be modified to support other languages (just replace vkgen::gen() with your own code)
  • support for all future versions of the Vulkan API (as long as the structure of the registry does not change)

###General information

  • libloading is required to load vkGetInstanceProcAddr from the Vulkan shared library
  • all functions are loaded dynamically during runtime via vkGetInstanceProcAddr and vkGetDeviceProcAddr
  • a very thin wrapper is generated for all dispatchable handles that ensures maximal performance

Usage

First download vk.xml from the official Vulkan repository (https://github.com/KhronosGroup/Vulkan-Headers/blob/master/registry/vk.xml).

$ vkgen <input file> <output file>

  • input file should be the Vulkan registry (vk.xml)
  • output file will be created if it does not exist

To use the generated file one has to add libloading to cargo.toml:

[dependencies]
libloading = "0.5.0"

This is required to load vkGetInstanceProcAddr from the Vulkan shared library. All other functions are loaded dynamically per instance/device via vkGetInstanceProcAddr and vkGetDeviceProcAddr to avoid additional dispatch overhead.

Examples

This simple example demonstrates how to load libvulkan on linux and output the instance version (1.1.0). vk.rs is a file containing the generated Rust source code. The location of libvulkan.so/vulkan.dll may vary depending on the OS.

mod vk;

use self::vk::*;

fn main() {
	unsafe { vkLoad("/usr/lib/x86_64-linux-gnu/libvulkan.so.1.1.92"); }

	let mut v: u32 = 0;
	vkEnumerateInstanceVersion(&mut v as *mut u32);
	println!("vulkan instance version is {}.{}.{}", VK_VERSION_MAJOR(v), VK_VERSION_MINOR(v), VK_VERSION_PATCH(v));
}

Known Issues

  • type aliases are generated for C++ types (uint32_t, uint64_t, ...) which should be avoided because the generator converts theses types into their Rust equivalents
  • enum aliases are not generated (this is because Rust does not allow two enum constants with the same value)