Crate vulkanic[−][src]
vulkanic
- Vulkan API adapter
Ultra-thin wrapper sitting on top of vk-sys.
Examples
GLFW:
let ep: EntryPoints = vk::EntryPoints::load(|procname| { glfw_window.get_instance_proc_address(0, procname.to_str().unwrap()) }).into(); // let instance_info = ... let instance = unsafe { ep.create_instance(&instance_info) }?; let ip: InstancePointers = vk::InstancePointers::load(|procname| { glfw_window.get_instance_proc_address(instance, procname.to_str().unwrap()) }).into(); let dp: DevicePointers = vk::DevicePointers::load(|procname| { glfw_window.get_instance_proc_address(instance, procname.to_str().unwrap()) }).into(); for physical_device in ip.enumerate_physical_devices(instance)? { // ... } // ... // use pointers directly, if wrapper implementation is missing // unsafe { dp.InvalidateMappedMemoryRanges(..) }
Crate conventions
- same partitioning like
vk-sys
withEntryPoints
,InstancePointers
andDevicePointers
- Rust naming conventions are met
- function names e.g.
CreateDevice
renamed tocreate_device
- parameter names e.g.
physicalDevice
renamed tophysical_device
- C type prefixes are omitted e.g.
pCreateInfo
tocreate_info
- function names e.g.
- type mapping
vk::Bool32
tobool
- pointers
pCreateInfo: *const DeviceCreateInfo
to borrowscreate_info: &DeviceCreateInfo
- API calls having array parameters e.g.
fenceCount: u32, pFences: *const Fence
will be presented as Rust slices e.g.fences: &[vk::Fence]
.
- return values
std::result::Result<T, vk::Result>
if API call has a resultT
if API call has no result- API calls with a result, will return
Ok(..)
only forvk::SUCCESS
Missing parts
- many Vulkan API calls are still not yet implemented
- API calls like
vkAcquireNextImageKHR
can return non-error results which are currently handled as error. It’s not clear (even from the specs) if out-parameter are valid in this case.
Safety
- many Vulkan API calls are safe Rust regarding they may fail, but will not have undefined behaviour
- all Vulkan API calls with structs containing pointers like
pNext: *const c_void
have to be considered unsafe, because caller has to make sure they are valid. - using
Vec
or slices as ffi pointers is safe, because all vk-sys structs are#[repr(C)]
, which ensures correct alignment without padding.
Structs
DevicePointers | Wrapper for |
EntryPoints | Wrapper for |
InstancePointers | Wrapper for |
Type Definitions
Result | Result type for most Vulkan API calls, if they support them.
Currently non-error return values are handled as |