Skip to content

Vulkan bindings for the rust programming language.

License

Notifications You must be signed in to change notification settings

HellButcher/vulkan-rs

Repository files navigation

vulkan_rs

Vulkan bindings for the rust programming language.

Version Docs Build Status License

Discontinued ⚠

This crate is no longer under development: I recommend using ash instead.

Basic usage

[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);
}

Stability Notice

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 returns VkResult)
    • enumerating: returning Vec<T> or Result<Vec<T>,VkResult> (e.g. vkEnumeratePhysicalDevices)
    • simplify passing of &str (&[&str] not required?)
  • safe enums:
    • usage of enum for enums and not u32
    • usage of crate bitflags for bitmasks
    • own VkError enum (VkResult items, but without VK_SUCCESS), VkResult = Result<(),VkError>
  • safe structs:
    • hide length- and array-pointer pairs
      • provide safe setter with slice parameter
    • 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 of const void* pNext chain
    • ⚠️ Keep the structs binary compatible (same length, same padding)
  • safe handles:
    • non-zero handles (use Optional<T> for zeroable handles)
    • Owned and Borrowed handles
      • vkCreate* commands return Owned handles
      • vkDestroy* commands consume Owned handles
      • everything else uses Borrowed handles
    • implement Drop (either panic or call vkDestroy*)
    • lifetimes: child-handle shouldn't outlive it's parent-handle

About

Vulkan bindings for the rust programming language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published