mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2025-02-21 11:32:34 +00:00
Merge pull request #200 from tomaka/loading-error
Report loading errors when creating an Instance or loading layers
This commit is contained in:
commit
594a915bbf
@ -19,8 +19,8 @@ use std::slice;
|
||||
use std::sync::Arc;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
//use alloc::Alloc;
|
||||
use instance::loader;
|
||||
use instance::loader::LoadingError;
|
||||
use check_errors;
|
||||
use Error;
|
||||
use OomError;
|
||||
@ -98,7 +98,7 @@ impl Instance {
|
||||
extension.as_ptr()
|
||||
}).collect::<SmallVec<[_; 32]>>();
|
||||
|
||||
let entry_points = loader::entry_points().unwrap(); // TODO: return proper error
|
||||
let entry_points = try!(loader::entry_points());
|
||||
|
||||
// Creating the Vulkan instance.
|
||||
let instance = unsafe {
|
||||
@ -299,8 +299,10 @@ impl<'a> Default for ApplicationInfo<'a> {
|
||||
}
|
||||
|
||||
/// Error that can happen when creating an instance.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum InstanceCreationError {
|
||||
/// Failed to load the Vulkan shared library.
|
||||
LoadingError(LoadingError),
|
||||
/// Not enough memory.
|
||||
OomError(OomError),
|
||||
/// Failed to initialize for an implementation-specific reason.
|
||||
@ -317,6 +319,7 @@ impl error::Error for InstanceCreationError {
|
||||
#[inline]
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
InstanceCreationError::LoadingError(_) => "failed to load the Vulkan shared library",
|
||||
InstanceCreationError::OomError(_) => "not enough memory available",
|
||||
InstanceCreationError::InitializationFailed => "initialization failed",
|
||||
InstanceCreationError::LayerNotPresent => "layer not present",
|
||||
@ -328,6 +331,7 @@ impl error::Error for InstanceCreationError {
|
||||
#[inline]
|
||||
fn cause(&self) -> Option<&error::Error> {
|
||||
match *self {
|
||||
InstanceCreationError::LoadingError(ref err) => Some(err),
|
||||
InstanceCreationError::OomError(ref err) => Some(err),
|
||||
_ => None
|
||||
}
|
||||
@ -348,6 +352,13 @@ impl From<OomError> for InstanceCreationError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LoadingError> for InstanceCreationError {
|
||||
#[inline]
|
||||
fn from(err: LoadingError) -> InstanceCreationError {
|
||||
InstanceCreationError::LoadingError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for InstanceCreationError {
|
||||
#[inline]
|
||||
fn from(err: Error) -> InstanceCreationError {
|
||||
|
@ -7,21 +7,24 @@
|
||||
// notice may not be copied, modified, or distributed except
|
||||
// according to those terms.
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::ffi::CStr;
|
||||
use std::ptr;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
//use alloc::Alloc;
|
||||
use check_errors;
|
||||
use OomError;
|
||||
use Error;
|
||||
use vk;
|
||||
use instance::loader;
|
||||
use instance::loader::LoadingError;
|
||||
use version::Version;
|
||||
|
||||
/// Queries the list of layers that are available when creating an instance.
|
||||
pub fn layers_list() -> Result<LayersIterator, OomError> {
|
||||
pub fn layers_list() -> Result<LayersIterator, LayersListError> {
|
||||
unsafe {
|
||||
let entry_points = loader::entry_points().unwrap(); // TODO: return proper error
|
||||
let entry_points = try!(loader::entry_points());
|
||||
|
||||
let mut num = 0;
|
||||
try!(check_errors(entry_points.EnumerateInstanceLayerProperties(&mut num, ptr::null_mut())));
|
||||
@ -68,6 +71,65 @@ impl LayerProperties {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error that can happen when loading the list of layers.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum LayersListError {
|
||||
/// Failed to load the Vulkan shared library.
|
||||
LoadingError(LoadingError),
|
||||
/// Not enough memory.
|
||||
OomError(OomError),
|
||||
}
|
||||
|
||||
impl error::Error for LayersListError {
|
||||
#[inline]
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
LayersListError::LoadingError(_) => "failed to load the Vulkan shared library",
|
||||
LayersListError::OomError(_) => "not enough memory available",
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn cause(&self) -> Option<&error::Error> {
|
||||
match *self {
|
||||
LayersListError::LoadingError(ref err) => Some(err),
|
||||
LayersListError::OomError(ref err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for LayersListError {
|
||||
#[inline]
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(fmt, "{}", error::Error::description(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OomError> for LayersListError {
|
||||
#[inline]
|
||||
fn from(err: OomError) -> LayersListError {
|
||||
LayersListError::OomError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LoadingError> for LayersListError {
|
||||
#[inline]
|
||||
fn from(err: LoadingError) -> LayersListError {
|
||||
LayersListError::LoadingError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for LayersListError {
|
||||
#[inline]
|
||||
fn from(err: Error) -> LayersListError {
|
||||
match err {
|
||||
err @ Error::OutOfHostMemory => LayersListError::OomError(OomError::from(err)),
|
||||
err @ Error::OutOfDeviceMemory => LayersListError::OomError(OomError::from(err)),
|
||||
_ => panic!("unexpected error: {:?}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator that produces the list of layers that are available.
|
||||
// TODO: #[derive(Debug, Clone)]
|
||||
pub struct LayersIterator {
|
||||
|
Loading…
Reference in New Issue
Block a user