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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Ergonomic conversion of `VkResult` into Rust's `Result` type.
//!
//! Vulkan functions return a `VkResult` enum where:
//!
//! - `SUCCESS` (0) means the call completed.
//! - **Positive** values are non-fatal status codes (`NOT_READY`, `TIMEOUT`,
//! `INCOMPLETE`, `SUBOPTIMAL_KHR`, etc.) — the call did something useful but
//! not necessarily what you asked for.
//! - **Negative** values are errors (`ERROR_OUT_OF_HOST_MEMORY`, `ERROR_DEVICE_LOST`,
//! etc.) — the call failed and any output parameters are invalid.
//!
//! Vulkane provides:
//!
//! - The [`VkResultExt`] extension trait, with `into_result()`, `is_success()`,
//! and `is_error()` methods.
//! - A `std::error::Error` implementation for [`VkResult`] so you can use `?`
//! in functions returning `Result<_, Box<dyn Error>>`.
//! - The [`vk_check!`](crate::vk_check) macro for one-line Vulkan call validation.
//!
//! `into_result()` only treats `SUCCESS` as `Ok`. If you need to distinguish
//! between non-fatal status codes (like `INCOMPLETE`) and outright errors,
//! use the raw `VkResult` value directly.
//!
//! # Example: propagating errors with `?`
//!
//! ```ignore
//! use vulkane::raw::bindings::*;
//! use vulkane::raw::VkResultExt;
//!
//! fn create_instance(entry: &VkEntryDispatchTable) -> Result<VkInstance, Box<dyn std::error::Error>> {
//! let info = VkInstanceCreateInfo::default();
//! let mut instance: VkInstance = std::ptr::null_mut();
//! let create = entry.vkCreateInstance.ok_or("vkCreateInstance not loaded")?;
//! unsafe { create(&info, std::ptr::null(), &mut instance) }.into_result()?;
//! Ok(instance)
//! }
//! ```
use crateVkResult;
/// Extension trait that converts `VkResult` into a Rust `Result`.
///
/// `VkResult` is `#[repr(i32)]` and `Copy`, so the extension methods take
/// `self` by value rather than `&self`.
// Implement std::error::Error for VkResult so it works with `?` in functions
// returning Box<dyn std::error::Error>. The generated VkResult already has
// Debug + Display impls from the codegen.
/// Convenience macro that calls a Vulkan function and propagates errors via `?`.
///
/// # Example
///
/// ```ignore
/// use vulkane::vk_check;
/// // Inside an unsafe fn that returns Result<_, VkResult>:
/// vk_check!(create_instance(&info, std::ptr::null(), &mut instance))?;
/// ```