use std::error::Error;
use std::ffi::NulError;
use std::fmt;
#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum Code {
Success = 0,
NotReady = 1,
Timeout = 2,
EventSet = 3,
EventReset = 4,
Incomplete = 5,
ErrorOutOfHostMemory = -1,
ErrorOutOfDeviceMemory = -2,
ErrorInitializationFailed = -3,
ErrorDeviceLost = -4,
ErrorMemoryMapFailed = -5,
ErrorLayerNotPresent = -6,
ErrorExtensionNotPresent = -7,
ErrorFeatureNotPresent = -8,
ErrorIncompatibleDriver = -9,
ErrorTooManyObjects = -10,
ErrorFormatNotSupported = -11,
ErrorFragmentedPool = -12,
ErrorOutOfPoolMemory = -1_000_069_000,
ErrorInvalidExternalHandle = -1_000_072_003,
ErrorSurfaceLostKhr = -1_000_000_000,
ErrorNativeWindowInUseKhr = -1_000_000_001,
SuboptimalKhr = 1_000_001_003,
ErrorOutOfDateKhr = -1_000_001_004,
ErrorIncompatibleDisplayKhr = -1_000_003_001,
ErrorValidationFailedExt = -1_000_011_001,
ErrorInvalidShaderNv = -1_000_012_000,
ErrorFragmentationExt = -1_000_161_000,
ErrorNotPermittedExt = -1_000_174_001,
}
impl fmt::Display for Code {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Success => write!(f, "Command successfully completed"),
Self::NotReady => write!(f, "A fence or query has not yet completed"),
Self::Timeout => write!(f, "A wait operation has not completed in the specified time"),
Self::EventSet => write!(f, "An event is signaled"),
Self::EventReset => write!(f, "An event is unsignaled"),
Self::Incomplete => write!(f, "A return array was too small for the result"),
Self::ErrorOutOfHostMemory => write!(f, "A host memory allocation has failed."),
Self::ErrorOutOfDeviceMemory => write!(f, "A device memory allocation has failed."),
Self::ErrorInitializationFailed => write!(f, "Initialization of an object could not be completed for implementation-specific reasons."),
Self::ErrorDeviceLost => write!(f, "The logical or physical device has been lost. See Lost Device"),
Self::ErrorMemoryMapFailed => write!(f, "Mapping of a memory object has failed."),
Self::ErrorLayerNotPresent => write!(f, "A requested layer is not present or could not be loaded."),
Self::ErrorExtensionNotPresent => write!(f, "A requested extension is not supported."),
Self::ErrorFeatureNotPresent => write!(f, "A requested feature is not supported."),
Self::ErrorIncompatibleDriver => write!(f, "The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons."),
Self::ErrorTooManyObjects => write!(f, "Too many objects of the type have already been created."),
Self::ErrorFormatNotSupported => write!(f, "A requested format is not supported on this device."),
Self::ErrorFragmentedPool => write!(f, "A pool allocation has failed due to fragmentation of the pool's memory.
This must only be returned if no attempt to allocate host or device memory was made to accomodate the new allocation.
This should be returned in preference to VK_ERROR_OUT_OF_POOL_MEMORY,
but only if the implementation is certain that the pool allocation failure was due to fragmentation."),
Self::ErrorOutOfPoolMemory => write!(f, "A pool memory allocation has failed.
This must only be returned if no attempt to allocate host or device memory was made to accomodate the new allocation.
If the failure was definitely due to fragmentation of the pool, VK_ERROR_FRAGMENTED_POOL should be returned instead."),
Self::ErrorInvalidExternalHandle => write!(f, "An external handle is not a valid handle of the specified type."),
Self::ErrorSurfaceLostKhr => write!(f, "A surface is no longer available."),
Self::ErrorNativeWindowInUseKhr => write!(f, "The requested window is already in use by Vulkan or another API in a manner which prevents it from being used again."),
Self::SuboptimalKhr => write!(f, "A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully."),
Self::ErrorOutOfDateKhr => write!(f, "A surface has changed in such a way that it is no longer compatible with the swapchain,
and further presentation requests using the swapchain will fail.
Applications must query the new surface properties and recreate their swapchain if they wish to continue presenting to the surface."),
Self::ErrorIncompatibleDisplayKhr => write!(f, "
The display used by a swapchain does not use the same presentable image layout,
or is incompatible in a way that prevents sharing an image."),
Self::ErrorValidationFailedExt => write!(f, "ErrorValidationFailedExt"),
Self::ErrorInvalidShaderNv => write!(f, "One or more shaders failed to compile or link."),
Self::ErrorFragmentationExt => write!(f, "A descriptor pool creation has failed due to fragmentation."),
Self::ErrorNotPermittedExt => write!(f, "ErrorNotPermittedExt"),
}
}
}
impl Error for Code {
#[must_use]
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
#[derive(Debug, Clone)]
pub enum ApplicationError {
NulError(NulError),
}
impl Error for ApplicationError {
#[must_use]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
Self::NulError(ref e) => Some(e),
}
}
}
impl fmt::Display for ApplicationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::NulError(ref e) => e.fmt(f),
}
}
}
impl From<NulError> for ApplicationError {
#[must_use]
fn from(error: NulError) -> Self {
Self::NulError(error)
}
}
#[derive(Debug, Clone)]
pub enum InstanceError {
Application(ApplicationError),
Vulkan(Code),
NulError(NulError),
NotFoundCommand(String),
}
impl Error for InstanceError {
#[must_use]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
Self::Vulkan(ref e) => Some(e),
Self::NulError(ref e) => Some(e),
Self::Application(ref e) => Some(e),
Self::NotFoundCommand(_) => None,
}
}
}
impl fmt::Display for InstanceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Vulkan(ref e) => e.fmt(f),
Self::NulError(ref e) => e.fmt(f),
Self::Application(ref e) => e.fmt(f),
Self::NotFoundCommand(ref e) => write!(f, "The {} Vulkan command has not found", e),
}
}
}
impl From<NulError> for InstanceError {
#[must_use]
fn from(error: NulError) -> Self {
Self::NulError(error)
}
}
impl From<ApplicationError> for InstanceError {
#[must_use]
fn from(error: ApplicationError) -> Self {
Self::Application(error)
}
}
#[derive(Debug, Clone)]
pub enum DebugError {
Vulkan(Code),
Instance(InstanceError),
NulError(NulError),
}
impl Error for DebugError {
#[must_use]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
Self::Vulkan(ref e) => Some(e),
Self::Instance(ref e) => Some(e),
Self::NulError(ref e) => Some(e),
}
}
}
impl fmt::Display for DebugError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Vulkan(ref e) => e.fmt(f),
Self::Instance(ref e) => e.fmt(f),
Self::NulError(ref e) => e.fmt(f),
}
}
}
impl From<NulError> for DebugError {
#[must_use]
fn from(error: NulError) -> Self {
Self::NulError(error)
}
}
impl From<InstanceError> for DebugError {
#[must_use]
fn from(error: InstanceError) -> Self {
Self::Instance(error)
}
}
#[derive(Debug, Clone)]
pub enum BuilderError {
Instance(InstanceError),
Debug(DebugError),
}
impl Error for BuilderError {
#[must_use]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
Self::Instance(ref e) => Some(e),
Self::Debug(ref e) => Some(e),
}
}
}
impl fmt::Display for BuilderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Instance(ref e) => e.fmt(f),
Self::Debug(ref e) => e.fmt(f),
}
}
}
impl From<InstanceError> for BuilderError {
#[must_use]
fn from(error: InstanceError) -> Self {
Self::Instance(error)
}
}
impl From<DebugError> for BuilderError {
#[must_use]
fn from(error: DebugError) -> Self {
Self::Debug(error)
}
}