diff options
Diffstat (limited to 'src/renderer/error.rs')
-rw-r--r-- | src/renderer/error.rs | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/src/renderer/error.rs b/src/renderer/error.rs new file mode 100644 index 0000000..f1418e8 --- /dev/null +++ b/src/renderer/error.rs @@ -0,0 +1,132 @@ +#![allow(unused)] + +use winit::error as werror; + +use vulkanalia::{bytecode::BytecodeError, loader::LoaderError, prelude::v1_0::*}; + +pub(super) enum MainError { + NotSupported(werror::NotSupportedError), + Os(werror::OsError), + Event(werror::EventLoopError), + Code(i32), + LibLoadError(String), + BoxLoadError(Box<dyn LoaderError>), + ValidationNotSupported, + Suitability(SuitabilityError), + NoDevice, + NoExtension, + InsufficientSwapchainSupport, + InvalidBytecode(usize), + AllocBytecode, +} + +impl std::fmt::Debug for MainError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Code(code) => write!(f, "{:?}", vk::ErrorCode::from_raw(*code)), + Self::NotSupported(e) => write!(f, "{e:?}"), + Self::Os(e) => write!(f, "{e:?}"), + Self::Event(e) => write!(f, "{e:?}"), + Self::BoxLoadError(e) => write!(f, "{e:?}"), + Self::LibLoadError(e) => write!(f, "{e:?}"), + Self::ValidationNotSupported => write!(f, "ValidationNotSupported"), + Self::Suitability(e) => write!(f, "suitability: {e:?}"), + Self::NoDevice => write!(f, "No suitable device is found"), + Self::NoExtension => write!(f, "Some required device extension is not supported"), + Self::InsufficientSwapchainSupport => { + write!(f, "The swapchain support is insufficient.") + } + Self::InvalidBytecode(len) => write!( + f, + "The length of the SPIRV byte code should be a multiple of four, but got {len}" + ), + Self::AllocBytecode => write!(f, "Failed to allocate space to store SPIRV byte codes"), + } + } +} + +impl std::fmt::Display for MainError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + MainError::Event(e) => write!(f, "Event loop error: {e}"), + MainError::NotSupported(not) => write!(f, "Not supported: {not}"), + MainError::Os(e) => write!(f, "Oeration system: {e}"), + MainError::Code(code) => write!(f, "{}", vk::ErrorCode::from_raw(*code)), + MainError::BoxLoadError(e) => write!(f, "Boxed loading error: {e}"), + MainError::LibLoadError(e) => write!(f, "Library loading error: {e}"), + MainError::ValidationNotSupported => write!( + f, + "The validation layers are requested but are not available." + ), + MainError::Suitability(e) => write!(f, "Suitability error: {e}"), + MainError::NoDevice => write!(f, "No suitable device is found"), + MainError::NoExtension => write!(f, "Some required device extension is not supported"), + MainError::InsufficientSwapchainSupport => { + write!(f, "The swapchain support is insufficient.") + } + MainError::InvalidBytecode(len) => write!( + f, + "The length of the SPIRV byte code should be a multiple of four, but got {len}" + ), + MainError::AllocBytecode => { + write!(f, "Failed to allocate space to store SPIRV byte codes") + } + } + } +} + +impl std::error::Error for MainError {} + +impl From<werror::OsError> for MainError { + fn from(value: werror::OsError) -> Self { + MainError::Os(value) + } +} + +impl From<werror::NotSupportedError> for MainError { + fn from(value: werror::NotSupportedError) -> Self { + MainError::NotSupported(value) + } +} + +impl From<werror::EventLoopError> for MainError { + fn from(value: werror::EventLoopError) -> Self { + MainError::Event(value) + } +} + +impl From<vk::ErrorCode> for MainError { + fn from(value: vk::ErrorCode) -> Self { + MainError::Code(value.as_raw()) + } +} + +impl From<Box<dyn LoaderError>> for MainError { + fn from(value: Box<dyn LoaderError>) -> Self { + MainError::BoxLoadError(value) + } +} + +impl From<BytecodeError> for MainError { + fn from(value: BytecodeError) -> Self { + match value { + BytecodeError::Alloc => Self::AllocBytecode, + BytecodeError::Length(len) => Self::InvalidBytecode(len), + } + } +} + +#[derive(Debug)] +pub(super) enum SuitabilityError { + NoQueuefamily, +} + +impl std::fmt::Display for SuitabilityError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SuitabilityError::NoQueuefamily => write!(f, "missing required queue families"), + } + } +} + +impl std::error::Error for SuitabilityError {} |