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())),
|
||||
}?;
|
||||
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))?;
|
||||
Ok(Entry {
|
||||
static_fn: static_fn,
|
||||
|
|
|
@ -34,7 +34,7 @@ impl Instance {
|
|||
create_info: &vk::DeviceCreateInfo)
|
||||
-> Result<Device, DeviceError> {
|
||||
unsafe {
|
||||
let mut device = mem::uninitialized();
|
||||
let mut device: vk::Device = mem::uninitialized();
|
||||
let err_code = self.instance_fn
|
||||
.create_device(physical_device, create_info, ptr::null(), &mut device);
|
||||
if err_code != vk::Result::Success {
|
||||
|
|
54
src/vk.rs
54
src/vk.rs
|
@ -3209,36 +3209,36 @@ pub mod types {
|
|||
CallbackRef = 1,
|
||||
}
|
||||
|
||||
macro_rules! vk_define_handle{
|
||||
($name: ident) => {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct $name{
|
||||
ptr: *mut u8
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[doc(hidden)]
|
||||
pub struct Instance_T(u8);
|
||||
pub type Instance = *mut Instance_T;
|
||||
impl $name{
|
||||
pub unsafe fn null() -> Self{
|
||||
$name{
|
||||
ptr: ::std::ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Deref for $name{
|
||||
type Target = *mut u8;
|
||||
fn deref(&self) -> &Self::Target{
|
||||
&self.ptr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[doc(hidden)]
|
||||
pub struct PhysicalDevice_T(u8);
|
||||
pub type PhysicalDevice = *mut PhysicalDevice_T;
|
||||
|
||||
|
||||
#[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!(Fence);
|
||||
|
|
Loading…
Reference in a new issue