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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! Runtime loader for the Vulkan shared library and per-scope dispatch tables.
//!
//! Vulkan function pointers are not statically linked. Instead, an application
//! loads them at runtime in three stages:
//!
//! 1. **Entry-level functions** (no instance needed): `vkCreateInstance`,
//! `vkEnumerateInstanceVersion`, etc. These are loaded from
//! `vkGetInstanceProcAddr(NULL, ...)`.
//! 2. **Instance-level functions**: everything that takes a `VkInstance` or
//! `VkPhysicalDevice` as its first argument. Loaded from
//! `vkGetInstanceProcAddr(instance, ...)` after `vkCreateInstance`.
//! 3. **Device-level functions**: everything that takes a `VkDevice`,
//! `VkCommandBuffer`, or `VkQueue` as its first argument. Loaded from
//! `vkGetDeviceProcAddr(device, ...)` after `vkCreateDevice`. Device-level
//! dispatch is faster than instance-level dispatch because it skips a
//! layer of internal indirection in the loader.
//!
//! Vulkane provides three generated dispatch table structs (one per stage),
//! each populated by [`VulkanLibrary`] from the running Vulkan implementation.
//! Every Vulkan command appears as an `Option<fn_ptr>` field — `None` if the
//! current driver doesn't expose it, `Some` if it can be called.
//!
//! # Typical usage
//!
//! ```no_run
//! use vulkane::raw::bindings::*;
//! use vulkane::raw::{VkResultExt, VulkanLibrary};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Stage 1: open vulkan-1.dll / libvulkan.so.1 / etc.
//! let library = VulkanLibrary::new()?;
//!
//! // Stage 2: load global functions
//! let entry = unsafe { library.load_entry() };
//!
//! // Create a VkInstance using the entry table
//! let info = VkInstanceCreateInfo::default();
//! let mut instance: VkInstance = std::ptr::null_mut();
//! unsafe { (entry.vkCreateInstance.unwrap())(&info, std::ptr::null(), &mut instance) }
//! .into_result()?;
//!
//! // Stage 3: load instance functions
//! let inst = unsafe { library.load_instance(instance) };
//!
//! // Optionally, after creating a VkDevice:
//! // let dev = unsafe { library.load_device(instance, device) };
//! # Ok(())
//! # }
//! ```
//!
//! All dispatch table contents are generated from `vk.xml`; no function names
//! are hardcoded in vulkane's source.
use crate*;
use c_void;
use Arc;
/// Loads the Vulkan shared library and provides `vkGetInstanceProcAddr`.
///
/// This is the entry point for runtime function loading. After construction,
/// use [`load_entry`](Self::load_entry), [`load_instance`](Self::load_instance),
/// and [`load_device`](Self::load_device) to obtain the per-stage dispatch tables.
///
/// `VulkanLibrary` keeps the underlying shared library loaded as long as it
/// (or any clone of it) is alive. Cloning is cheap — the library handle is
/// shared via `Arc`.