bedrock/
error.rs

1use crate::vk::*;
2
3impl core::fmt::Debug for VkResult {
4    fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
5        let msg = match *self {
6            // Success Codes //
7            VK_SUCCESS => "Command successfully completed",
8            VK_NOT_READY => "A fence or query has not yet completed",
9            VK_TIMEOUT => "A wait operation has not completed in the specified time",
10            VK_EVENT_SET => "An event is signaled",
11            VK_EVENT_RESET => "An event is unsignaled",
12            VK_INCOMPLETE => "A return array was too small for the result",
13            #[cfg(feature = "VK_KHR_swapchain")]
14            VK_SUBOPTIMAL_KHR => "Sub-optimal swapchain",
15            // Error Codes //
16            VK_ERROR_OUT_OF_HOST_MEMORY => "A host memory allocation has failed",
17            VK_ERROR_OUT_OF_DEVICE_MEMORY => "A device memory allocation has failed",
18            VK_ERROR_INITIALIZATION_FAILED => {
19                "Initialization of an object could not be completed for implementation-specific reasons"
20            }
21            VK_ERROR_DEVICE_LOST => "The logical or physical device has been lost",
22            VK_ERROR_MEMORY_MAP_FAILED => "Mapping of a memory object has failed",
23            VK_ERROR_LAYER_NOT_PRESENT => "A requested layer is not presented or could not be loaded",
24            VK_ERROR_EXTENSION_NOT_PRESENT => "A requested extension is not supported",
25            VK_ERROR_FEATURE_NOT_PRESENT => "A requested feature is not supported",
26            VK_ERROR_INCOMPATIBLE_DRIVER => {
27                "The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons"
28            }
29            VK_ERROR_TOO_MANY_OBJECTS => "Too many objects of the type have already been created",
30            VK_ERROR_FORMAT_NOT_SUPPORTED => "A requested format is not supported on this device",
31            VK_ERROR_FRAGMENTED_POOL => "A pool allocation has failed due to fragmentation of the pool's memory",
32            #[cfg(feature = "VK_KHR_surface")]
33            VK_ERROR_SURFACE_LOST_KHR => "Surface lost",
34            #[cfg(feature = "VK_KHR_surface")]
35            VK_ERROR_NATIVE_WINDOW_IN_USE_KHR => "Native window is in use",
36            #[cfg(feature = "VK_KHR_swapchain")]
37            VK_ERROR_OUT_OF_DATE_KHR => "Out of date",
38            #[cfg(feature = "VK_KHR_display_swapchain")]
39            VK_ERROR_INCOMPATIBLE_DISPLAY_KHR => {
40                "The display used by a swapchain does not use the same presentable image layout"
41            }
42            #[cfg(feature = "VK_EXT_debug_report")]
43            VK_ERROR_VALIDATION_FAILED_EXT => "Validation failed",
44            #[cfg(feature = "VK_NV_glsl_shader")]
45            VK_ERROR_INVALID_SHADER_NV => "Invalid GLSL shader",
46            #[cfg(feature = "VK_KHR_maintenance1")]
47            VK_ERROR_OUT_OF_POOL_MEMORY_KHR => "A pool memory allocation has failed",
48            #[cfg(feature = "VK_KHR_external_memory")]
49            VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR => "An external handle is not a valid handle of ths specified type",
50            #[cfg(feature = "VK_KHR_buffer_device_address")]
51            VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR => {
52                "A buffer creation or memory allocation failed because the requested address is not available"
53            }
54            #[cfg(feature = "VK_EXT_descriptor_indexing")]
55            VK_ERROR_FRAGMENTATION_EXT => "A descriptor pool creation has failed due to fragmentation",
56            _ => "Unknown or extension-specific error",
57        };
58
59        write!(fmt, "[{:?}] {msg}", self.0)
60    }
61}
62impl core::fmt::Display for VkResult {
63    #[inline(always)]
64    fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
65        core::fmt::Debug::fmt(self, fmt)
66    }
67}
68impl core::error::Error for VkResult {}
69impl VkResult {
70    #[inline]
71    pub const fn is_err(&self) -> bool {
72        self.0 < 0
73    }
74
75    #[inline]
76    pub const fn into_result(self) -> Result<Self, Self> {
77        if self.is_err() { Err(self) } else { Ok(self) }
78    }
79}