Vulkan bindings for the rust programming language.
This crate is no longer under development: I recommend using ash
instead.
[dependencies]
vulkan_rs = "0.4"
extern crate vulkan_rs;
use vulkan_rs::prelude::*;
fn main() {
let app_name = CString::new("Application name").unwrap();
let app_info = VkApplicationInfo::new()
.set_application_name(Some(&app_name))
.set_application_version(vk_make_version(1, 0, 0))
.set_engine_name(Some(&app_name))
.set_engine_version(vk_make_version(1, 0, 0))
.set_api_version(VK_API_VERSION_1_0);
let create_info = VkInstanceCreateInfo::new()
.set_application_info(Some(&app_info));
let instance = vkCreateInstance(&create_info, None).unwrap();
let phys_devices = vkEnumeratePhysicalDevices(instance).unwrap();
println!("There are {} physical devices", phys_devices.len());
// [...]
vkDestroyInstance(instance, None);
}
I'm a little bit experimenting with the API generator. I might introduce non-backward compatible changes, for making the API more safe and sound.
Some topics, that might come in the future ([x] = already done):
- safe commands:
- pass length- and array-pointer pairs as
slice
- use references (and no pointers) where possible
- usage of
Option<T>
for optional parameters (especialy for references and handles) - returning of "output-parameters" (
Result<T,VkResult>
when command returnsVkResult
) - enumerating: returning
Vec<T>
orResult<Vec<T>,VkResult>
(e.g. vkEnumeratePhysicalDevices) - simplify passing of
&str
(&[&str]
not required?)
- pass length- and array-pointer pairs as
- safe enums:
- usage of
enum
for enums and notu32
- usage of
crate bitflags
for bitmasks - own
VkError
enum (VkResult items, but withoutVK_SUCCESS
),VkResult = Result<(),VkError>
- usage of
- safe structs:
- hide length- and array-pointer pairs
- provide safe setter with
slice
parameter
- provide safe setter with
- hide
VkStructureType
and provide default - use references (and no pointers) where possible (hide pointers)
- usage of
Option<T>
for optional fields - simplify passing of
&str
and&[&str]
- setting string-arrays (
const char* const*
) not possible at the moment
- setting string-arrays (
- setting of
const void* pNext
chain ⚠️ Keep the structs binary compatible (same length, same padding)
- hide length- and array-pointer pairs
- safe handles:
- non-zero handles (use
Optional<T>
for zeroable handles) - Owned and Borrowed handles
vkCreate*
commands return Owned handlesvkDestroy*
commands consume Owned handles- everything else uses Borrowed handles
- implement
Drop
(either panic or callvkDestroy*
) - lifetimes: child-handle shouldn't outlive it's parent-handle
- non-zero handles (use