SDL 3.0
SDL_vulkan.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 2017, Mark Callow
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * # CategoryVulkan
24 *
25 * Functions for creating Vulkan surfaces on SDL windows.
26 */
27
28#ifndef SDL_vulkan_h_
29#define SDL_vulkan_h_
30
31#include <SDL3/SDL_error.h>
32#include <SDL3/SDL_video.h>
33
34#include <SDL3/SDL_begin_code.h>
35/* Set up for C function definitions, even when using C++ */
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/* Avoid including vulkan.h, don't define VkInstance if it's already included */
41#ifdef VULKAN_H_
42#define NO_SDL_VULKAN_TYPEDEFS
43#endif
44#ifndef NO_SDL_VULKAN_TYPEDEFS
45#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
46
47#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
48#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
49#else
50#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
51#endif
52
53VK_DEFINE_HANDLE(VkInstance)
54VK_DEFINE_HANDLE(VkPhysicalDevice)
56struct VkAllocationCallbacks;
57
58#endif /* !NO_SDL_VULKAN_TYPEDEFS */
59
60/**
61 * \name Vulkan support functions
62 */
63/* @{ */
64
65/**
66 * Dynamically load the Vulkan loader library.
67 *
68 * This should be called after initializing the video driver, but before
69 * creating any Vulkan windows. If no Vulkan loader library is loaded, the
70 * default library will be loaded upon creation of the first Vulkan window.
71 *
72 * It is fairly common for Vulkan applications to link with libvulkan instead
73 * of explicitly loading it at run time. This will work with SDL provided the
74 * application links to a dynamic library and both it and SDL use the same
75 * search path.
76 *
77 * If you specify a non-NULL `path`, an application should retrieve all of the
78 * Vulkan functions it uses from the dynamic library using
79 * SDL_Vulkan_GetVkGetInstanceProcAddr unless you can guarantee `path` points
80 * to the same vulkan loader library the application linked to.
81 *
82 * On Apple devices, if `path` is NULL, SDL will attempt to find the
83 * `vkGetInstanceProcAddr` address within all the Mach-O images of the current
84 * process. This is because it is fairly common for Vulkan applications to
85 * link with libvulkan (and historically MoltenVK was provided as a static
86 * library). If it is not found, on macOS, SDL will attempt to load
87 * `vulkan.framework/vulkan`, `libvulkan.1.dylib`,
88 * `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On
89 * iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a
90 * dynamic framework or .dylib must ensure it is included in its application
91 * bundle.
92 *
93 * On non-Apple devices, application linking with a static libvulkan is not
94 * supported. Either do not link to the Vulkan loader or link to a dynamic
95 * library version.
96 *
97 * \param path the platform dependent Vulkan loader library name or NULL.
98 * \returns 0 on success or a negative error code on failure; call
99 * SDL_GetError() for more information.
100 *
101 * \since This function is available since SDL 3.0.0.
102 *
103 * \sa SDL_Vulkan_GetVkGetInstanceProcAddr
104 * \sa SDL_Vulkan_UnloadLibrary
105 */
106extern SDL_DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
107
108/**
109 * Get the address of the `vkGetInstanceProcAddr` function.
110 *
111 * This should be called after either calling SDL_Vulkan_LoadLibrary() or
112 * creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
113 *
114 * The actual type of the returned function pointer is
115 * PFN_vkGetInstanceProcAddr, but that isn't available because the Vulkan
116 * headers are not included here. You should cast the return value of this
117 * function to that type, e.g.
118 *
119 * `vkGetInstanceProcAddr =
120 * (PFN_vkGetInstanceProcAddr)SDL_Vulkan_GetVkGetInstanceProcAddr();`
121 *
122 * \returns the function pointer for `vkGetInstanceProcAddr` or NULL on
123 * failure; call SDL_GetError() for more information.
124 *
125 * \since This function is available since SDL 3.0.0.
126 */
128
129/**
130 * Unload the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary().
131 *
132 * \since This function is available since SDL 3.0.0.
133 *
134 * \sa SDL_Vulkan_LoadLibrary
135 */
136extern SDL_DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
137
138/**
139 * Get the Vulkan instance extensions needed for vkCreateInstance.
140 *
141 * This should be called after either calling SDL_Vulkan_LoadLibrary() or
142 * creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
143 *
144 * On return, the variable pointed to by `count` will be set to the number of
145 * elements returned, suitable for using with
146 * VkInstanceCreateInfo::enabledExtensionCount, and the returned array can be
147 * used with VkInstanceCreateInfo::ppEnabledExtensionNames, for calling
148 * Vulkan's vkCreateInstance API.
149 *
150 * You should not free the returned array; it is owned by SDL.
151 *
152 * \param count a pointer filled in with the number of extensions returned.
153 * \returns an array of extension name strings on success, NULL on failure;
154 * call SDL_GetError() for more information.
155 *
156 * \since This function is available since SDL 3.0.0.
157 *
158 * \sa SDL_Vulkan_CreateSurface
159 */
160extern SDL_DECLSPEC char const * const * SDLCALL SDL_Vulkan_GetInstanceExtensions(Uint32 *count);
161
162/**
163 * Create a Vulkan rendering surface for a window.
164 *
165 * The `window` must have been created with the `SDL_WINDOW_VULKAN` flag and
166 * `instance` must have been created with extensions returned by
167 * SDL_Vulkan_GetInstanceExtensions() enabled.
168 *
169 * If `allocator` is NULL, Vulkan will use the system default allocator. This
170 * argument is passed directly to Vulkan and isn't used by SDL itself.
171 *
172 * \param window the window to which to attach the Vulkan surface.
173 * \param instance the Vulkan instance handle.
174 * \param allocator a VkAllocationCallbacks struct, which lets the app set the
175 * allocator that creates the surface. Can be NULL.
176 * \param surface a pointer to a VkSurfaceKHR handle to output the newly
177 * created surface.
178 * \returns 0 on success or a negative error code on failure; call
179 * SDL_GetError() for more information.
180 *
181 * \since This function is available since SDL 3.0.0.
182 *
183 * \sa SDL_Vulkan_GetInstanceExtensions
184 * \sa SDL_Vulkan_DestroySurface
185 */
186extern SDL_DECLSPEC int SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
187 VkInstance instance,
188 const struct VkAllocationCallbacks *allocator,
189 VkSurfaceKHR* surface);
190
191/**
192 * Destroy the Vulkan rendering surface of a window.
193 *
194 * This should be called before SDL_DestroyWindow, if SDL_Vulkan_CreateSurface
195 * was called after SDL_CreateWindow.
196 *
197 * The `instance` must have been created with extensions returned by
198 * SDL_Vulkan_GetInstanceExtensions() enabled and `surface` must have been
199 * created successfully by an SDL_Vulkan_CreateSurface() call.
200 *
201 * If `allocator` is NULL, Vulkan will use the system default allocator. This
202 * argument is passed directly to Vulkan and isn't used by SDL itself.
203 *
204 * \param instance the Vulkan instance handle.
205 * \param surface vkSurfaceKHR handle to destroy.
206 * \param allocator a VkAllocationCallbacks struct, which lets the app set the
207 * allocator that destroys the surface. Can be NULL.
208 *
209 * \since This function is available since SDL 3.0.0.
210 *
211 * \sa SDL_Vulkan_GetInstanceExtensions
212 * \sa SDL_Vulkan_CreateSurface
213 */
214extern SDL_DECLSPEC void SDLCALL SDL_Vulkan_DestroySurface(VkInstance instance,
215 VkSurfaceKHR surface,
216 const struct VkAllocationCallbacks *allocator);
217
218/**
219 * Query support for presentation via a given physical device and queue
220 * family.
221 *
222 * The `instance` must have been created with extensions returned by
223 * SDL_Vulkan_GetInstanceExtensions() enabled.
224 *
225 * \param instance the Vulkan instance handle.
226 * \param physicalDevice a valid Vulkan physical device handle.
227 * \param queueFamilyIndex a valid queue family index for the given physical
228 * device.
229 * \returns SDL_TRUE if supported, SDL_FALSE if unsupported or an error
230 * occurred.
231 *
232 * \since This function is available since SDL 3.0.0.
233 *
234 * \sa SDL_Vulkan_GetInstanceExtensions
235 */
236extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetPresentationSupport(VkInstance instance,
237 VkPhysicalDevice physicalDevice,
238 Uint32 queueFamilyIndex);
239
240/* @} *//* Vulkan support functions */
241
242/* Ends C function definitions when using C++ */
243#ifdef __cplusplus
244}
245#endif
246#include <SDL3/SDL_close_code.h>
247
248#endif /* SDL_vulkan_h_ */
int SDL_bool
Definition SDL_stdinc.h:213
void(* SDL_FunctionPointer)(void)
uint32_t Uint32
Definition SDL_stdinc.h:265
struct SDL_Window SDL_Window
Definition SDL_video.h:127
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object)
Definition SDL_vulkan.h:50
SDL_FunctionPointer SDL_Vulkan_GetVkGetInstanceProcAddr(void)
SDL_bool SDL_Vulkan_GetPresentationSupport(VkInstance instance, VkPhysicalDevice physicalDevice, Uint32 queueFamilyIndex)
#define VK_DEFINE_HANDLE(object)
Definition SDL_vulkan.h:45
int SDL_Vulkan_CreateSurface(SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
char const *const * SDL_Vulkan_GetInstanceExtensions(Uint32 *count)
int SDL_Vulkan_LoadLibrary(const char *path)
void SDL_Vulkan_DestroySurface(VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator)
void SDL_Vulkan_UnloadLibrary(void)