diff --git a/src/device.rs b/src/device.rs index ef87961..bddd982 100644 --- a/src/device.rs +++ b/src/device.rs @@ -7,6 +7,7 @@ use ::RawPtr; unsafe impl Sync for Device {} unsafe impl Send for Device {} +#[derive(Clone)] pub struct Device { handle: vk::Device, device_fn: vk::DeviceFn, diff --git a/src/entry.rs b/src/entry.rs index b988870..f43b377 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -33,14 +33,14 @@ pub struct Entry { #[derive(Debug)] pub enum LoadingError { - LibraryLoadFailure(String), - StaticLoadError(String), - EntryLoadError(String), + LibraryLoadError(String), + EntryLoadError(Vec<&'static str>), + StaticLoadError(Vec<&'static str>), } #[derive(Debug)] pub enum InstanceError { - LoadError(String), + LoadError(Vec<&'static str>), VkError(vk::Result), } @@ -58,7 +58,7 @@ impl Entry { }).map_err(|err| LoadingError::StaticLoadError(err))?; Ok(static_fn) } - Err(ref err) => Err(LoadingError::LibraryLoadFailure(err.clone())), + Err(ref err) => Err(LoadingError::LibraryLoadError(err.clone())), }?; let entry_fn = vk::EntryFn::load(|name| unsafe { mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr())) diff --git a/src/extensions/android_surface.rs b/src/extensions/android_surface.rs index 7fec956..876be1e 100644 --- a/src/extensions/android_surface.rs +++ b/src/extensions/android_surface.rs @@ -13,7 +13,7 @@ pub struct AndroidSurface { } impl AndroidSurface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::AndroidSurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/debug_report.rs b/src/extensions/debug_report.rs index 4f0b37d..d8f37cb 100644 --- a/src/extensions/debug_report.rs +++ b/src/extensions/debug_report.rs @@ -12,7 +12,7 @@ pub struct DebugReport { } impl DebugReport { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let debug_report_fn = vk::DebugReportFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/mir_surface.rs b/src/extensions/mir_surface.rs index bc54833..1f3da67 100644 --- a/src/extensions/mir_surface.rs +++ b/src/extensions/mir_surface.rs @@ -13,7 +13,7 @@ pub struct MirSurface { } impl MirSurface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::MirSurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index b782dbc..9ed6c99 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -11,8 +11,8 @@ pub use self::android_surface::AndroidSurface; mod swapchain; mod surface; mod xlibsurface; -mod debug_report; mod win32_surface; +mod debug_report; mod mir_surface; mod android_surface; mod wayland_surface; diff --git a/src/extensions/surface.rs b/src/extensions/surface.rs index e09910e..0807437 100644 --- a/src/extensions/surface.rs +++ b/src/extensions/surface.rs @@ -14,7 +14,7 @@ pub struct Surface { } impl Surface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::SurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/swapchain.rs b/src/extensions/swapchain.rs index 18746ab..c2fdf28 100644 --- a/src/extensions/swapchain.rs +++ b/src/extensions/swapchain.rs @@ -13,7 +13,7 @@ pub struct Swapchain { } impl Swapchain { - pub fn new(instance: &Instance, device: &Device) -> Result { + pub fn new(instance: &Instance, device: &Device) -> Result> { let swapchain_fn = vk::SwapchainFn::load(|name| { unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) } })?; diff --git a/src/extensions/wayland_surface.rs b/src/extensions/wayland_surface.rs index 8f59120..eb851c5 100644 --- a/src/extensions/wayland_surface.rs +++ b/src/extensions/wayland_surface.rs @@ -12,7 +12,7 @@ pub struct WaylandSurface { } impl WaylandSurface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::WaylandSurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/win32_surface.rs b/src/extensions/win32_surface.rs index dbffc9e..e5f2f86 100644 --- a/src/extensions/win32_surface.rs +++ b/src/extensions/win32_surface.rs @@ -13,7 +13,7 @@ pub struct Win32Surface { } impl Win32Surface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::Win32SurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/xcb_surface.rs b/src/extensions/xcb_surface.rs index 8b8f818..64890d0 100644 --- a/src/extensions/xcb_surface.rs +++ b/src/extensions/xcb_surface.rs @@ -13,7 +13,7 @@ pub struct XcbSurface { } impl XcbSurface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::XcbSurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/extensions/xlibsurface.rs b/src/extensions/xlibsurface.rs index 1ea3f8e..f8809fa 100644 --- a/src/extensions/xlibsurface.rs +++ b/src/extensions/xlibsurface.rs @@ -13,7 +13,7 @@ pub struct XlibSurface { } impl XlibSurface { - pub fn new(entry: &Entry, instance: &Instance) -> Result { + pub fn new(entry: &Entry, instance: &Instance) -> Result> { let surface_fn = vk::XlibSurfaceFn::load(|name| { unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) diff --git a/src/instance.rs b/src/instance.rs index bef667c..67a4e62 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -8,11 +8,11 @@ use ::RawPtr; #[derive(Debug)] pub enum DeviceError { - LoadError(String), + LoadError(Vec<&'static str>), VkError(vk::Result), } -#[derive(Debug)] +#[derive(Clone)] pub struct Instance { handle: vk::Instance, instance_fn: vk::InstanceFn, diff --git a/src/vk.rs b/src/vk.rs index 39f0057..df4e124 100644 --- a/src/vk.rs +++ b/src/vk.rs @@ -3658,48 +3658,40 @@ macro_rules! vk_functions { unsafe impl Sync for $struct_name {} impl $struct_name { - pub fn load(mut f: F) -> ::std::result::Result<$struct_name, String> + pub fn load(mut f: F) -> ::std::result::Result<$struct_name, Vec<&'static str>> where F: FnMut(&::std::ffi::CStr) -> *const c_void { use std::ffi::{CString}; use std::mem; + let mut err_str = Vec::new(); let s = $struct_name { $( $name: unsafe { let cname = CString::new($raw_name).unwrap(); let val = f(&cname); + if val.is_null(){ + err_str.push(stringify!($raw_name)); + } mem::transmute(val) }, )+ }; - ::std::result::Result::Ok(s) + + if err_str.is_empty() { + Ok(s) + } + else{ + Err(err_str) + } } $( #[inline] pub unsafe fn $name(&self $(, $param_name: $param)*) -> $ret { let fp = self.$name; - debug_assert!(!(self.$name as *const c_void).is_null(), "{} not loaded!.", stringify!($raw_name)); fp($($param_name),*) } )+ } - impl ::std::fmt::Debug for $struct_name { - #[inline] - fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { - writeln!(fmt, stringify!($struct_name))?; - $( - if !(self.$name as *const c_void).is_null() { - write!(fmt," Is loaded => " )?; - } - else{ - write!(fmt," Is not loaded => " )?; - } - write!(fmt, $raw_name)?; - writeln!(fmt, ", ")?; - )+ - write!(fmt, "") - } - } } } @@ -4830,7 +4822,6 @@ vk_functions!{ p_allocator: *const AllocationCallbacks, p_surface: *mut SurfaceKHR, ) -> Result; - } vk_functions!{ WaylandSurfaceFn,