#vulkan #vk #generator

app vkgen

Generates Rust source code from the Vulkan registry

11 releases (1 stable)

✓ Uses Rust 2018 edition

1.0.0 Mar 25, 2019
0.1.9 Feb 9, 2019
0.1.8 Jan 30, 2019

#48 in Graphics APIs

Download history 37/week @ 2019-01-11 32/week @ 2019-01-18 29/week @ 2019-01-25 7/week @ 2019-02-01 12/week @ 2019-02-08 3/week @ 2019-02-15 6/week @ 2019-02-22 26/week @ 2019-03-01 3/week @ 2019-03-08 2/week @ 2019-03-15 136/week @ 2019-03-22

98 downloads per month

MIT license



Generates Rust source code from vk.xml


  • 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


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>

  • input file the Vulkan registry file to be parsed
  • output file the file which the generated code will be written to, it will be created if it does not exist

$ vkgen ./vk.xml ./vk.rs

Parse a file called vk.xml which contains the Vulkan registry and output the generated code to vk.rs.

Step 3

Add libloading to your project's cargo.toml

libloading = "0.5.0"

libloading is used to load vkGetInstanceProcAddr from the Vulkan shared library.

Step 4

Load libvulkan in order to use the generated functions

unsafe { vkLoad(); }

Note: vkLoad() only loads vkGetInstanceProcAddr from the shared library, all other functions are loaded dynamically via vkGetInstanceProcAddr and vkGetDeviceProcAddr to avoid additional dispatch overhead.


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.

mod vk;

use self::vk::*;
use std::ptr::null;

fn main() {
	unsafe { vkLoad(); }

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

	let instance_info = VkInstanceCreateInfo {
		pNext:                   null(),
		flags:                   0,
		pApplicationInfo: &VkApplicationInfo {
			pNext:              null(),
			pApplicationName:   b"test app\0".as_ptr(),
			applicationVersion: VK_MAKE_VERSION(0, 0, 1),
			pEngineName:        b"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 createInstance(&instance_info, null(), &mut instance) != VK_SUCCESS {
		panic!("something went wrong :-/");
	let instance = unsafe { VkInstanceImpl::new(instance) };

No runtime deps