1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Redraw errors

use thiserror::Error;
use vulkano::{shader::spirv::SpirvBytesNotMultipleOf4, Validated, VulkanError as VulkanoError};

/// Errors that originate from Vulkan.
#[derive(Error, Debug)]
pub enum VulkanError {
    #[error("The swapchain is out of date and needs to be updated.")]
    SwapchainOutOfDate,
    #[error("Failed to flush future:\n{0}")]
    FlushFutureError(String),
    #[error("A Validated error:\n{0}")]
    Validated(Validated<VulkanoError>),
    #[error("An unexpected error with the shaders occured.")]
    ShaderError,
    #[error("An unexpected error occured:\n{0}")]
    Other(anyhow::Error),
}

impl From<Validated<VulkanoError>> for VulkanError {
    fn from(value: Validated<VulkanoError>) -> Self {
        Self::Validated(value)
    }
}

/// Errors that occur from the creation of Shaders.
#[derive(Error, Debug)]
pub enum ShaderError {
    #[error("The given entry point to those shaders is not present in the given shaders.")]
    ShaderEntryPoint,
    #[error("The provided bytes are not SpirV.")]
    InvalidSpirV,
    #[error("Something happened and the shader can not be made.: {0:?}")]
    Other(VulkanError),
}

impl From<Validated<VulkanoError>> for ShaderError {
    fn from(value: Validated<VulkanoError>) -> Self {
        Self::Other(value.into())
    }
}

impl From<SpirvBytesNotMultipleOf4> for ShaderError {
    fn from(_value: SpirvBytesNotMultipleOf4) -> Self {
        Self::InvalidSpirV
    }
}