Added error handling for optional extension loading

This commit is contained in:
maik klein 2016-12-23 21:43:41 +01:00
parent e706df027f
commit f39baa7e34
6 changed files with 39 additions and 43 deletions

View file

@ -42,7 +42,7 @@ fn create_surface(instance: &Instance,
window: x11_window as vk::Window,
dpy: x11_display as *mut vk::Display,
};
let xlib_surface_loader = XlibSurface::new(&entry, &instance);
let xlib_surface_loader = XlibSurface::new(&entry, &instance).expect("Unable to load xlib surface");
xlib_surface_loader.create_xlib_surface_khr(&x11_create_info)
}
@ -154,12 +154,13 @@ fn main() {
pfn_callback: vulkan_debug_callback,
p_user_data: ptr::null_mut(),
};
let debug_report_loader = DebugReport::new(&entry, &instance);
let debug_report_loader = DebugReport::new(&entry, &instance).expect("Unable to load debug report");
let debug_call_back = debug_report_loader.create_debug_report_callback_ext(&debug_info)
.unwrap();
let surface = create_surface(&instance, &entry, &window).unwrap();
let pdevices = instance.enumerate_physical_devices().expect("Physical device error");
let surface_loader = Surface::new(&entry, &instance);
let surface_loader = Surface::new(&entry, &instance)
.expect("Unable to load the Surface extension");
let (pdevice, queue_family_index) = pdevices.iter()
.map(|pdevice| {
instance.get_physical_device_queue_family_properties(*pdevice)
@ -257,7 +258,7 @@ fn main() {
.cloned()
.find(|&mode| mode == vk::PresentModeKHR::Mailbox)
.unwrap_or(vk::PresentModeKHR::Fifo);
let swapchain_loader = Swapchain::new(&instance, &device);
let swapchain_loader = Swapchain::new(&instance, &device).expect("Unable to load swapchain");
let swapchain_create_info = vk::SwapchainCreateInfoKHR {
s_type: vk::StructureType::SwapchainCreateInfoKhr,
p_next: ptr::null(),

View file

@ -12,18 +12,17 @@ pub struct DebugReport {
}
impl DebugReport {
pub fn new(entry: &Entry, instance: &Instance) -> DebugReport {
pub fn new(entry: &Entry, instance: &Instance) -> Result<DebugReport, String> {
let debug_report_fn = vk::DebugReportFn::load(|name| {
unsafe {
mem::transmute(entry.static_fn
.get_instance_proc_addr(instance.handle, name.as_ptr()))
}
})
.unwrap();
DebugReport {
})?;
Ok(DebugReport {
handle: instance.handle,
debug_report_fn: debug_report_fn,
}
})
}
pub fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT) {

View file

@ -11,18 +11,17 @@ pub struct Surface {
}
impl Surface {
pub fn new(entry: &Entry, instance: &Instance) -> Surface {
pub fn new(entry: &Entry, instance: &Instance) -> Result<Surface, String> {
let surface_fn = vk::SurfaceFn::load(|name| {
unsafe {
mem::transmute(entry.static_fn
.get_instance_proc_addr(instance.handle, name.as_ptr()))
}
})
.unwrap();
Surface {
})?;
Ok(Surface {
handle: instance.handle,
surface_fn: surface_fn,
}
})
}
pub fn get_physical_device_surface_support_khr(&self,
@ -111,4 +110,3 @@ impl Surface {
}
}
}

View file

@ -4,24 +4,24 @@ use std::mem;
use instance::Instance;
use device::Device;
use vk;
pub struct Swapchain {
handle: vk::Device,
swapchain_fn: vk::SwapchainFn,
}
impl Swapchain {
pub fn new(instance: &Instance, device: &Device) -> Swapchain {
pub fn new(instance: &Instance, device: &Device) -> Result<Swapchain, String> {
let swapchain_fn = vk::SwapchainFn::load(|name| {
unsafe {
mem::transmute(instance.instance_fn
.get_device_proc_addr(device.handle, name.as_ptr()))
}
})
.unwrap();
Swapchain {
})?;
Ok(Swapchain {
handle: device.handle,
swapchain_fn: swapchain_fn,
}
})
}
pub fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) {

View file

@ -11,18 +11,17 @@ pub struct XlibSurface {
}
impl XlibSurface {
pub fn new(entry: &Entry, instance: &Instance) -> XlibSurface {
pub fn new(entry: &Entry, instance: &Instance) -> Result<XlibSurface, String> {
let surface_fn = vk::XlibSurfaceFn::load(|name| {
unsafe {
mem::transmute(entry.static_fn
.get_instance_proc_addr(instance.handle, name.as_ptr()))
}
})
.unwrap();
XlibSurface {
})?;
Ok(XlibSurface {
handle: instance.handle,
xlib_surface_fn: surface_fn,
}
})
}
pub fn create_xlib_surface_khr(&self,

View file

@ -19,7 +19,6 @@ pub struct Instance {
pub instance_fn: vk::InstanceFn,
}
impl Instance {
pub unsafe fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self {
Instance {