sdl3_sys/generated/vulkan.rs
1//! Functions for creating Vulkan surfaces on SDL windows.
2//!
3//! For the most part, Vulkan operates independent of SDL, but it benefits from
4//! a little support during setup.
5//!
6//! Use [`SDL_Vulkan_GetInstanceExtensions()`] to get platform-specific bits for
7//! creating a VkInstance, then [`SDL_Vulkan_GetVkGetInstanceProcAddr()`] to get
8//! the appropriate function for querying Vulkan entry points. Then
9//! [`SDL_Vulkan_CreateSurface()`] will get you the final pieces you need to
10//! prepare for rendering into an [`SDL_Window`] with Vulkan.
11//!
12//! Unlike OpenGL, most of the details of "context" creation and window buffer
13//! swapping are handled by the Vulkan API directly, so SDL doesn't provide
14//! Vulkan equivalents of [`SDL_GL_SwapWindow()`], etc; they aren't necessary.
15
16use super::stdinc::*;
17
18use super::error::*;
19
20use super::video::*;
21
22apply_cfg!(#[cfg(any(all(not(target_pointer_width = "32"), target_arch = "x86_64"), all(target_arch = "riscv64", any(target_arch = "riscv32", target_arch = "riscv64")), any(/* always disabled: _M_IA64 */), target_arch = "x86_64", all(windows, target_pointer_width = "64"), all(not(windows), target_pointer_width = "64"), target_arch = "aarch64", any(/* always disabled: __ia64 */), target_arch = "powerpc64"))] => {
23});
24
25apply_cfg!(#[cfg(not(any(all(not(target_pointer_width = "32"), target_arch = "x86_64"), all(target_arch = "riscv64", any(target_arch = "riscv32", target_arch = "riscv64")), any(/* always disabled: _M_IA64 */), target_arch = "x86_64", all(windows, target_pointer_width = "64"), all(not(windows), target_pointer_width = "64"), target_arch = "aarch64", any(/* always disabled: __ia64 */), target_arch = "powerpc64")))] => {
26});
27
28apply_cfg!(#[cfg(feature = "use-ash-v0-38")] => {
29 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
30 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::Instance` from the `ash` crate. Otherwise it's a pointer to an opaque struct.
31 pub type VkInstance = ::ash_v0_38::vk::Instance;
32});
33
34apply_cfg!(#[cfg(not(feature = "use-ash-v0-38"))] => {
35 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
36 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::Instance` from the `ash` crate. Otherwise it's a pointer to an opaque struct.
37 pub type VkInstance = *mut __VkInstance;
38
39 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
40 #[doc(hidden)]
41 #[repr(C)]
42 pub struct __VkInstance { _opaque: [::core::primitive::u8; 0] }
43});
44
45apply_cfg!(#[cfg(feature = "use-ash-v0-38")] => {
46 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
47 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::PhysicalDevice` from the `ash` crate. Otherwise it's a pointer to an opaque struct.
48 pub type VkPhysicalDevice = ::ash_v0_38::vk::PhysicalDevice;
49});
50
51apply_cfg!(#[cfg(not(feature = "use-ash-v0-38"))] => {
52 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
53 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::PhysicalDevice` from the `ash` crate. Otherwise it's a pointer to an opaque struct.
54 pub type VkPhysicalDevice = *mut __VkPhysicalDevice;
55
56 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
57 #[doc(hidden)]
58 #[repr(C)]
59 pub struct __VkPhysicalDevice { _opaque: [::core::primitive::u8; 0] }
60});
61
62apply_cfg!(#[cfg(feature = "use-ash-v0-38")] => {
63 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
64 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::SurfaceKHR` from the `ash` crate. Otherwise it's a target dependent opaque type.
65 pub type VkSurfaceKHR = ::ash_v0_38::vk::SurfaceKHR;
66});
67
68apply_cfg!(#[cfg(not(feature = "use-ash-v0-38"))] => {
69 #[cfg(target_pointer_width = "64")]
70 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
71 pub type VkSurfaceKHR = *mut __VkSurfaceKHR;
72
73 #[cfg(target_pointer_width = "64")]
74 #[doc(hidden)]
75 #[repr(C)]
76 pub struct __VkSurfaceKHR { _opaque: [::core::primitive::u8; 0] }
77
78 #[cfg(not(target_pointer_width = "64"))]
79 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
80 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::SurfaceKHR` from the `ash` crate. Otherwise it's a target dependent opaque type.
81 pub type VkSurfaceKHR = ::core::primitive::u64;
82});
83
84unsafe extern "C" {
85 /// Dynamically load the Vulkan loader library.
86 ///
87 /// This should be called after initializing the video driver, but before
88 /// creating any Vulkan windows. If no Vulkan loader library is loaded, the
89 /// default library will be loaded upon creation of the first Vulkan window.
90 ///
91 /// SDL keeps a counter of how many times this function has been successfully
92 /// called, so it is safe to call this function multiple times, so long as it
93 /// is eventually paired with an equivalent number of calls to
94 /// [`SDL_Vulkan_UnloadLibrary`]. The `path` argument is ignored unless there is no
95 /// library currently loaded, and and the library isn't actually unloaded until
96 /// there have been an equivalent number of calls to [`SDL_Vulkan_UnloadLibrary`].
97 ///
98 /// It is fairly common for Vulkan applications to link with libvulkan instead
99 /// of explicitly loading it at run time. This will work with SDL provided the
100 /// application links to a dynamic library and both it and SDL use the same
101 /// search path.
102 ///
103 /// If you specify a non-NULL `path`, an application should retrieve all of the
104 /// Vulkan functions it uses from the dynamic library using
105 /// [`SDL_Vulkan_GetVkGetInstanceProcAddr`] unless you can guarantee `path` points
106 /// to the same vulkan loader library the application linked to.
107 ///
108 /// On Apple devices, if `path` is NULL, SDL will attempt to find the
109 /// `vkGetInstanceProcAddr` address within all the Mach-O images of the current
110 /// process. This is because it is fairly common for Vulkan applications to
111 /// link with libvulkan (and historically MoltenVK was provided as a static
112 /// library). If it is not found, on macOS, SDL will attempt to load
113 /// `vulkan.framework/vulkan`, `libvulkan.1.dylib`,
114 /// `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On
115 /// iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a
116 /// dynamic framework or .dylib must ensure it is included in its application
117 /// bundle.
118 ///
119 /// On non-Apple devices, application linking with a static libvulkan is not
120 /// supported. Either do not link to the Vulkan loader or link to a dynamic
121 /// library version.
122 ///
123 /// ## Parameters
124 /// - `path`: the platform dependent Vulkan loader library name or NULL.
125 ///
126 /// ## Return value
127 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
128 /// information.
129 ///
130 /// ## Thread safety
131 /// This function is not thread safe.
132 ///
133 /// ## Availability
134 /// This function is available since SDL 3.2.0.
135 ///
136 /// ## See also
137 /// - [`SDL_Vulkan_GetVkGetInstanceProcAddr`]
138 /// - [`SDL_Vulkan_UnloadLibrary`]
139 pub fn SDL_Vulkan_LoadLibrary(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
140}
141
142unsafe extern "C" {
143 /// Get the address of the `vkGetInstanceProcAddr` function.
144 ///
145 /// This should be called after either calling [`SDL_Vulkan_LoadLibrary()`] or
146 /// creating an [`SDL_Window`] with the [`SDL_WINDOW_VULKAN`] flag.
147 ///
148 /// The actual type of the returned function pointer is
149 /// PFN_vkGetInstanceProcAddr, but that isn't available because the Vulkan
150 /// headers are not included here. You should cast the return value of this
151 /// function to that type, e.g.
152 ///
153 /// `vkGetInstanceProcAddr =
154 /// (PFN_vkGetInstanceProcAddr)SDL_Vulkan_GetVkGetInstanceProcAddr();`
155 ///
156 /// ## Return value
157 /// Returns the function pointer for `vkGetInstanceProcAddr` or NULL on
158 /// failure; call [`SDL_GetError()`] for more information.
159 ///
160 /// ## Availability
161 /// This function is available since SDL 3.2.0.
162 ///
163 /// ## Notes for `sdl3-sys`
164 /// As of `sdl3-sys` 0.6, the return type is correct for known targets, so you don't have
165 /// to cast it before use. It's compatible with the `ash` crate if you enable an integration
166 /// feature for that, but note that the type alias this function returns is an Option.
167 ///
168 pub fn SDL_Vulkan_GetVkGetInstanceProcAddr() -> VkGetInstanceProcAddr;
169}
170
171/// (`sdl3-sys`) The definition of the `VkInstance` argument type can change based on enabled features. See [`VkInstance`].
172pub type VkGetInstanceProcAddr =
173 Option<unsafe extern "system" fn(VkInstance, *const ::core::ffi::c_char) -> VkVoidFunction>;
174
175/// (`sdl3-sys`) Generic Vulkan void function. Cast to the appropriate type before use.
176pub type VkVoidFunction = Option<unsafe extern "system" fn()>;
177
178unsafe extern "C" {
179 /// Unload the Vulkan library previously loaded by [`SDL_Vulkan_LoadLibrary()`].
180 ///
181 /// SDL keeps a counter of how many times this function has been called, so it
182 /// is safe to call this function multiple times, so long as it is paired with
183 /// an equivalent number of calls to [`SDL_Vulkan_LoadLibrary`]. The library isn't
184 /// actually unloaded until there have been an equivalent number of calls to
185 /// [`SDL_Vulkan_UnloadLibrary`].
186 ///
187 /// Once the library has actually been unloaded, if any Vulkan instances
188 /// remain, they will likely crash the program. Clean up any existing Vulkan
189 /// resources, and destroy appropriate windows, renderers and GPU devices
190 /// before calling this function.
191 ///
192 /// ## Thread safety
193 /// This function is not thread safe.
194 ///
195 /// ## Availability
196 /// This function is available since SDL 3.2.0.
197 ///
198 /// ## See also
199 /// - [`SDL_Vulkan_LoadLibrary`]
200 pub fn SDL_Vulkan_UnloadLibrary();
201}
202
203unsafe extern "C" {
204 /// Get the Vulkan instance extensions needed for vkCreateInstance.
205 ///
206 /// This should be called after either calling [`SDL_Vulkan_LoadLibrary()`] or
207 /// creating an [`SDL_Window`] with the [`SDL_WINDOW_VULKAN`] flag.
208 ///
209 /// On return, the variable pointed to by `count` will be set to the number of
210 /// elements returned, suitable for using with
211 /// VkInstanceCreateInfo::enabledExtensionCount, and the returned array can be
212 /// used with VkInstanceCreateInfo::ppEnabledExtensionNames, for calling
213 /// Vulkan's vkCreateInstance API.
214 ///
215 /// You should not free the returned array; it is owned by SDL.
216 ///
217 /// ## Parameters
218 /// - `count`: a pointer filled in with the number of extensions returned.
219 ///
220 /// ## Return value
221 /// Returns an array of extension name strings on success, NULL on failure;
222 /// call [`SDL_GetError()`] for more information.
223 ///
224 /// ## Availability
225 /// This function is available since SDL 3.2.0.
226 ///
227 /// ## See also
228 /// - [`SDL_Vulkan_CreateSurface`]
229 pub fn SDL_Vulkan_GetInstanceExtensions(
230 count: *mut Uint32,
231 ) -> *const *const ::core::ffi::c_char;
232}
233
234unsafe extern "C" {
235 /// Create a Vulkan rendering surface for a window.
236 ///
237 /// The `window` must have been created with the [`SDL_WINDOW_VULKAN`] flag and
238 /// `instance` must have been created with extensions returned by
239 /// [`SDL_Vulkan_GetInstanceExtensions()`] enabled.
240 ///
241 /// If `allocator` is NULL, Vulkan will use the system default allocator. This
242 /// argument is passed directly to Vulkan and isn't used by SDL itself.
243 ///
244 /// ## Parameters
245 /// - `window`: the window to which to attach the Vulkan surface.
246 /// - `instance`: the Vulkan instance handle.
247 /// - `allocator`: a VkAllocationCallbacks struct, which lets the app set the
248 /// allocator that creates the surface. Can be NULL.
249 /// - `surface`: a pointer to a VkSurfaceKHR handle to output the newly
250 /// created surface.
251 ///
252 /// ## Return value
253 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
254 /// information.
255 ///
256 /// ## Availability
257 /// This function is available since SDL 3.2.0.
258 ///
259 /// ## See also
260 /// - [`SDL_Vulkan_GetInstanceExtensions`]
261 /// - [`SDL_Vulkan_DestroySurface`]
262 pub fn SDL_Vulkan_CreateSurface(
263 window: *mut SDL_Window,
264 instance: VkInstance,
265 allocator: *const VkAllocationCallbacks,
266 surface: *mut VkSurfaceKHR,
267 ) -> ::core::primitive::bool;
268}
269
270unsafe extern "C" {
271 /// Destroy the Vulkan rendering surface of a window.
272 ///
273 /// This should be called before [`SDL_DestroyWindow`], if [`SDL_Vulkan_CreateSurface`]
274 /// was called after [`SDL_CreateWindow`].
275 ///
276 /// The `instance` must have been created with extensions returned by
277 /// [`SDL_Vulkan_GetInstanceExtensions()`] enabled and `surface` must have been
278 /// created successfully by an [`SDL_Vulkan_CreateSurface()`] call.
279 ///
280 /// If `allocator` is NULL, Vulkan will use the system default allocator. This
281 /// argument is passed directly to Vulkan and isn't used by SDL itself.
282 ///
283 /// ## Parameters
284 /// - `instance`: the Vulkan instance handle.
285 /// - `surface`: vkSurfaceKHR handle to destroy.
286 /// - `allocator`: a VkAllocationCallbacks struct, which lets the app set the
287 /// allocator that destroys the surface. Can be NULL.
288 ///
289 /// ## Availability
290 /// This function is available since SDL 3.2.0.
291 ///
292 /// ## See also
293 /// - [`SDL_Vulkan_GetInstanceExtensions`]
294 /// - [`SDL_Vulkan_CreateSurface`]
295 pub fn SDL_Vulkan_DestroySurface(
296 instance: VkInstance,
297 surface: VkSurfaceKHR,
298 allocator: *const VkAllocationCallbacks,
299 );
300}
301
302unsafe extern "C" {
303 /// Query support for presentation via a given physical device and queue
304 /// family.
305 ///
306 /// The `instance` must have been created with extensions returned by
307 /// [`SDL_Vulkan_GetInstanceExtensions()`] enabled.
308 ///
309 /// ## Parameters
310 /// - `instance`: the Vulkan instance handle.
311 /// - `physicalDevice`: a valid Vulkan physical device handle.
312 /// - `queueFamilyIndex`: a valid queue family index for the given physical
313 /// device.
314 ///
315 /// ## Return value
316 /// Returns true if supported, false if unsupported or an error occurred.
317 ///
318 /// ## Availability
319 /// This function is available since SDL 3.2.0.
320 ///
321 /// ## See also
322 /// - [`SDL_Vulkan_GetInstanceExtensions`]
323 pub fn SDL_Vulkan_GetPresentationSupport(
324 instance: VkInstance,
325 physicalDevice: VkPhysicalDevice,
326 queueFamilyIndex: Uint32,
327 ) -> ::core::primitive::bool;
328}
329
330apply_cfg!(#[cfg(feature = "use-ash-v0-38")] => {
331 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
332 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::AllocationCallbacks::<'static>` from the `ash` crate. Otherwise it's an opaque type. <div class="warning">The `'static` lifetime is too long. `ash` requires a lifetime for this, but as it's a C ffi type there's no way for `sdl3-sys` to set the correct lifetime.</div>
333 pub type VkAllocationCallbacks = ::ash_v0_38::vk::AllocationCallbacks::<'static>;
334});
335
336apply_cfg!(#[cfg(not(feature = "use-ash-v0-38"))] => {
337 #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
338 /// (`sdl3-sys`) Enable a `use-ash-*` feature to alias this to `vk::AllocationCallbacks::<'static>` from the `ash` crate. Otherwise it's an opaque type. <div class="warning">The `'static` lifetime is too long. `ash` requires a lifetime for this, but as it's a C ffi type there's no way for `sdl3-sys` to set the correct lifetime.</div>
339 #[repr(C)]
340 pub struct VkAllocationCallbacks { _opaque: [::core::primitive::u8; 0] }
341});
342
343#[cfg(doc)]
344use crate::everything::*;