1use std::error::Error;
20use std::ffi::NulError;
21use std::fmt;
22
23#[repr(i32)]
25#[derive(Debug, Clone, Copy)]
26pub enum Code {
27 Success = 0,
29
30 NotReady = 1,
32
33 Timeout = 2,
35
36 EventSet = 3,
38
39 EventReset = 4,
41
42 Incomplete = 5,
44
45 ErrorOutOfHostMemory = -1,
47
48 ErrorOutOfDeviceMemory = -2,
50
51 ErrorInitializationFailed = -3,
53
54 ErrorDeviceLost = -4,
56
57 ErrorMemoryMapFailed = -5,
59
60 ErrorLayerNotPresent = -6,
62
63 ErrorExtensionNotPresent = -7,
65
66 ErrorFeatureNotPresent = -8,
68
69 ErrorIncompatibleDriver = -9,
71
72 ErrorTooManyObjects = -10,
74
75 ErrorFormatNotSupported = -11,
77
78 ErrorFragmentedPool = -12,
83
84 ErrorOutOfPoolMemory = -1_000_069_000,
88
89 ErrorInvalidExternalHandle = -1_000_072_003,
91
92 ErrorSurfaceLostKhr = -1_000_000_000,
94
95 ErrorNativeWindowInUseKhr = -1_000_000_001,
97
98 SuboptimalKhr = 1_000_001_003,
100
101 ErrorOutOfDateKhr = -1_000_001_004,
105
106 ErrorIncompatibleDisplayKhr = -1_000_003_001,
109
110 ErrorValidationFailedExt = -1_000_011_001,
112
113 ErrorInvalidShaderNv = -1_000_012_000,
115
116 ErrorFragmentationExt = -1_000_161_000,
118
119 ErrorNotPermittedExt = -1_000_174_001,
121}
122
123impl fmt::Display for Code {
124 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
125 match *self {
126 Self::Success => write!(f, "Command successfully completed"),
127 Self::NotReady => write!(f, "A fence or query has not yet completed"),
128 Self::Timeout => write!(f, "A wait operation has not completed in the specified time"),
129 Self::EventSet => write!(f, "An event is signaled"),
130 Self::EventReset => write!(f, "An event is unsignaled"),
131 Self::Incomplete => write!(f, "A return array was too small for the result"),
132 Self::ErrorOutOfHostMemory => write!(f, "A host memory allocation has failed."),
133 Self::ErrorOutOfDeviceMemory => write!(f, "A device memory allocation has failed."),
134 Self::ErrorInitializationFailed => write!(f, "Initialization of an object could not be completed for implementation-specific reasons."),
135 Self::ErrorDeviceLost => write!(f, "The logical or physical device has been lost. See Lost Device"),
136 Self::ErrorMemoryMapFailed => write!(f, "Mapping of a memory object has failed."),
137 Self::ErrorLayerNotPresent => write!(f, "A requested layer is not present or could not be loaded."),
138 Self::ErrorExtensionNotPresent => write!(f, "A requested extension is not supported."),
139 Self::ErrorFeatureNotPresent => write!(f, "A requested feature is not supported."),
140 Self::ErrorIncompatibleDriver => write!(f, "The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons."),
141 Self::ErrorTooManyObjects => write!(f, "Too many objects of the type have already been created."),
142 Self::ErrorFormatNotSupported => write!(f, "A requested format is not supported on this device."),
143
144 Self::ErrorFragmentedPool => write!(f, "A pool allocation has failed due to fragmentation of the pool's memory.
145 This must only be returned if no attempt to allocate host or device memory was made to accomodate the new allocation.
146 This should be returned in preference to VK_ERROR_OUT_OF_POOL_MEMORY,
147 but only if the implementation is certain that the pool allocation failure was due to fragmentation."),
148
149 Self::ErrorOutOfPoolMemory => write!(f, "A pool memory allocation has failed.
150 This must only be returned if no attempt to allocate host or device memory was made to accomodate the new allocation.
151 If the failure was definitely due to fragmentation of the pool, VK_ERROR_FRAGMENTED_POOL should be returned instead."),
152
153 Self::ErrorInvalidExternalHandle => write!(f, "An external handle is not a valid handle of the specified type."),
154 Self::ErrorSurfaceLostKhr => write!(f, "A surface is no longer available."),
155 Self::ErrorNativeWindowInUseKhr => write!(f, "The requested window is already in use by Vulkan or another API in a manner which prevents it from being used again."),
156 Self::SuboptimalKhr => write!(f, "A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully."),
157
158 Self::ErrorOutOfDateKhr => write!(f, "A surface has changed in such a way that it is no longer compatible with the swapchain,
159 and further presentation requests using the swapchain will fail.
160 Applications must query the new surface properties and recreate their swapchain if they wish to continue presenting to the surface."),
161
162 Self::ErrorIncompatibleDisplayKhr => write!(f, "
163 The display used by a swapchain does not use the same presentable image layout,
164 or is incompatible in a way that prevents sharing an image."),
165 Self::ErrorValidationFailedExt => write!(f, "ErrorValidationFailedExt"),
166 Self::ErrorInvalidShaderNv => write!(f, "One or more shaders failed to compile or link."),
167 Self::ErrorFragmentationExt => write!(f, "A descriptor pool creation has failed due to fragmentation."),
168 Self::ErrorNotPermittedExt => write!(f, "ErrorNotPermittedExt"),
169 }
170 }
171}
172
173impl Error for Code {
174 #[must_use]
175 fn source(&self) -> Option<&(dyn Error + 'static)> {
176 None
177 }
178}
179
180#[derive(Debug, Clone)]
182pub enum ApplicationError {
183 NulError(NulError),
185}
186
187impl Error for ApplicationError {
188 #[must_use]
189 fn source(&self) -> Option<&(dyn Error + 'static)> {
190 match *self {
191 Self::NulError(ref e) => Some(e),
192 }
193 }
194}
195
196impl fmt::Display for ApplicationError {
197 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
198 match *self {
199 Self::NulError(ref e) => e.fmt(f),
200 }
201 }
202}
203
204impl From<NulError> for ApplicationError {
205 #[must_use]
206 fn from(error: NulError) -> Self {
207 Self::NulError(error)
208 }
209}
210
211#[derive(Debug, Clone)]
213pub enum InstanceError {
214 Application(ApplicationError),
216
217 Vulkan(Code),
219
220 NulError(NulError),
222
223 NotFoundCommand(String),
225}
226
227impl Error for InstanceError {
228 #[must_use]
229 fn source(&self) -> Option<&(dyn Error + 'static)> {
230 match *self {
231 Self::Vulkan(ref e) => Some(e),
232 Self::NulError(ref e) => Some(e),
233 Self::Application(ref e) => Some(e),
234 Self::NotFoundCommand(_) => None,
235 }
236 }
237}
238
239impl fmt::Display for InstanceError {
240 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
241 match *self {
242 Self::Vulkan(ref e) => e.fmt(f),
243 Self::NulError(ref e) => e.fmt(f),
244 Self::Application(ref e) => e.fmt(f),
245 Self::NotFoundCommand(ref e) => write!(f, "The {} Vulkan command has not found", e),
246 }
247 }
248}
249
250impl From<NulError> for InstanceError {
251 #[must_use]
252 fn from(error: NulError) -> Self {
253 Self::NulError(error)
254 }
255}
256
257impl From<ApplicationError> for InstanceError {
258 #[must_use]
259 fn from(error: ApplicationError) -> Self {
260 Self::Application(error)
261 }
262}
263
264#[derive(Debug, Clone)]
266pub enum DebugError {
267 Vulkan(Code),
269
270 Instance(InstanceError),
272
273 NulError(NulError),
275}
276
277impl Error for DebugError {
278 #[must_use]
279 fn source(&self) -> Option<&(dyn Error + 'static)> {
280 match *self {
281 Self::Vulkan(ref e) => Some(e),
282 Self::Instance(ref e) => Some(e),
283 Self::NulError(ref e) => Some(e),
284 }
285 }
286}
287
288impl fmt::Display for DebugError {
289 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
290 match *self {
291 Self::Vulkan(ref e) => e.fmt(f),
292 Self::Instance(ref e) => e.fmt(f),
293 Self::NulError(ref e) => e.fmt(f),
294 }
295 }
296}
297
298impl From<NulError> for DebugError {
299 #[must_use]
300 fn from(error: NulError) -> Self {
301 Self::NulError(error)
302 }
303}
304
305impl From<InstanceError> for DebugError {
306 #[must_use]
307 fn from(error: InstanceError) -> Self {
308 Self::Instance(error)
309 }
310}
311
312#[derive(Debug, Clone)]
314pub enum BuilderError {
315 Instance(InstanceError),
317
318 Debug(DebugError),
320}
321
322impl Error for BuilderError {
323 #[must_use]
324 fn source(&self) -> Option<&(dyn Error + 'static)> {
325 match *self {
326 Self::Instance(ref e) => Some(e),
327 Self::Debug(ref e) => Some(e),
328 }
329 }
330}
331
332impl fmt::Display for BuilderError {
333 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
334 match *self {
335 Self::Instance(ref e) => e.fmt(f),
336 Self::Debug(ref e) => e.fmt(f),
337 }
338 }
339}
340
341impl From<InstanceError> for BuilderError {
342 #[must_use]
343 fn from(error: InstanceError) -> Self {
344 Self::Instance(error)
345 }
346}
347
348impl From<DebugError> for BuilderError {
349 #[must_use]
350 fn from(error: DebugError) -> Self {
351 Self::Debug(error)
352 }
353}