Theme

alex/volcanic-mem

BRANCH main
main
SNAPSHOT Initial commit
DOWNLOAD
Download file

root / src / error.rs

use volcanic::VkResult;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("Vulkan command `{0}` is not loaded")]
    MissingCommand(&'static str),
    #[error("{call} failed with {result:?}")]
    Vulkan {
        call: &'static str,
        result: VkResult,
    },
    #[error("no memory type satisfies the requirements")]
    NoMemoryType,
    #[error("out of memory")]
    OutOfMemory,
    #[error("allocation size must be non-zero")]
    ZeroSize,
    #[error("alignment {0} is not a power of two")]
    InvalidAlignment(u64),
    #[error("descriptor heap of {size} bytes exceeds the device limit of {max} bytes")]
    HeapTooLarge { size: u64, max: u64 },
    #[error("descriptor heap address {address:#x} is not aligned to {alignment}")]
    MisalignedHeap { address: u64, alignment: u64 },
}

pub type Result<T, E = Error> = core::result::Result<T, E>;

#[inline]
pub(crate) fn check(call: &'static str, result: VkResult) -> Result<()> {
    match result {
        VkResult::Success => Ok(()),
        VkResult::ErrorOutOfDeviceMemory | VkResult::ErrorOutOfHostMemory => {
            Err(Error::OutOfMemory)
        }
        result => Err(Error::Vulkan { call, result }),
    }
}