Typesafe handles, e.g Instance, Device, Queue etc
This commit is contained in:
parent
e8d679c84f
commit
ac14f440a7
|
@ -60,7 +60,7 @@ impl Entry {
|
||||||
Err(ref err) => Err(LoadingError::LibraryLoadFailure(err.clone())),
|
Err(ref err) => Err(LoadingError::LibraryLoadFailure(err.clone())),
|
||||||
}?;
|
}?;
|
||||||
let entry_fn = vk::EntryFn::load(|name| unsafe {
|
let entry_fn = vk::EntryFn::load(|name| unsafe {
|
||||||
mem::transmute(static_fn.get_instance_proc_addr(ptr::null_mut(), name.as_ptr()))
|
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
|
||||||
}).map_err(|err| LoadingError::EntryLoadError(err))?;
|
}).map_err(|err| LoadingError::EntryLoadError(err))?;
|
||||||
Ok(Entry {
|
Ok(Entry {
|
||||||
static_fn: static_fn,
|
static_fn: static_fn,
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl Instance {
|
||||||
create_info: &vk::DeviceCreateInfo)
|
create_info: &vk::DeviceCreateInfo)
|
||||||
-> Result<Device, DeviceError> {
|
-> Result<Device, DeviceError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut device = mem::uninitialized();
|
let mut device: vk::Device = mem::uninitialized();
|
||||||
let err_code = self.instance_fn
|
let err_code = self.instance_fn
|
||||||
.create_device(physical_device, create_info, ptr::null(), &mut device);
|
.create_device(physical_device, create_info, ptr::null(), &mut device);
|
||||||
if err_code != vk::Result::Success {
|
if err_code != vk::Result::Success {
|
||||||
|
|
52
src/vk.rs
52
src/vk.rs
|
@ -3209,36 +3209,36 @@ pub mod types {
|
||||||
CallbackRef = 1,
|
CallbackRef = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! vk_define_handle{
|
||||||
|
($name: ident) => {
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[doc(hidden)]
|
pub struct $name{
|
||||||
pub struct Instance_T(u8);
|
ptr: *mut u8
|
||||||
pub type Instance = *mut Instance_T;
|
}
|
||||||
|
|
||||||
|
impl $name{
|
||||||
|
pub unsafe fn null() -> Self{
|
||||||
|
$name{
|
||||||
|
ptr: ::std::ptr::null_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
impl ::std::ops::Deref for $name{
|
||||||
#[doc(hidden)]
|
type Target = *mut u8;
|
||||||
pub struct PhysicalDevice_T(u8);
|
fn deref(&self) -> &Self::Target{
|
||||||
pub type PhysicalDevice = *mut PhysicalDevice_T;
|
&self.ptr
|
||||||
|
}
|
||||||
|
}
|
||||||
#[repr(C)]
|
}
|
||||||
#[doc(hidden)]
|
}
|
||||||
pub struct Device_T(u8);
|
|
||||||
pub type Device = *mut Device_T;
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct Queue_T(u8);
|
|
||||||
pub type Queue = *mut Queue_T;
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct CommandBuffer_T(u8);
|
|
||||||
pub type CommandBuffer = *mut CommandBuffer_T;
|
|
||||||
|
|
||||||
|
vk_define_handle!(Instance);
|
||||||
|
vk_define_handle!(Device);
|
||||||
|
vk_define_handle!(PhysicalDevice);
|
||||||
|
vk_define_handle!(Queue);
|
||||||
|
vk_define_handle!(CommandBuffer);
|
||||||
|
|
||||||
handle_nondispatchable!(Semaphore);
|
handle_nondispatchable!(Semaphore);
|
||||||
handle_nondispatchable!(Fence);
|
handle_nondispatchable!(Fence);
|
||||||
|
|
Loading…
Reference in a new issue