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
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 }),
}
}