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 * \file SDL_vulkan.h
24 *
25 * Header file for functions to creating Vulkan surfaces on SDL windows.
26 */
27
28#ifndef SDL_vulkan_h_
29#define SDL_vulkan_h_
30
31#include <SDL3/SDL_video.h>
32
33#include <SDL3/SDL_begin_code.h>
34/* Set up for C function definitions, even when using C++ */
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* Avoid including vulkan.h, don't define VkInstance if it's already included */
40#ifdef VULKAN_H_
41#define NO_SDL_VULKAN_TYPEDEFS
42#endif
43#ifndef NO_SDL_VULKAN_TYPEDEFS
44#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
45
46#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
47#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
48#else
49#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
50#endif
51
52VK_DEFINE_HANDLE(VkInstance)
54struct VkAllocationCallbacks;
55
56#endif /* !NO_SDL_VULKAN_TYPEDEFS */
57
58typedef VkInstance SDL_vulkanInstance;
59typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
60
61/**
62 * \name Vulkan support functions
63 */
64/* @{ */
65
66/**
67 * Dynamically load the Vulkan loader library.
68 *
69 * This should be called after initializing the video driver, but before
70 * creating any Vulkan windows. If no Vulkan loader library is loaded, the
71 * default library will be loaded upon creation of the first Vulkan window.
72 *
73 * It is fairly common for Vulkan applications to link with libvulkan instead
74 * of explicitly loading it at run time. This will work with SDL provided the
75 * application links to a dynamic library and both it and SDL use the same
76 * search path.
77 *
78 * If you specify a non-NULL `path`, an application should retrieve all of the
79 * Vulkan functions it uses from the dynamic library using
80 * SDL_Vulkan_GetVkGetInstanceProcAddr unless you can guarantee `path` points
81 * to the same vulkan loader library the application linked to.
82 *
83 * On Apple devices, if `path` is NULL, SDL will attempt to find the
84 * `vkGetInstanceProcAddr` address within all the Mach-O images of the current
85 * process. This is because it is fairly common for Vulkan applications to
86 * link with libvulkan (and historically MoltenVK was provided as a static
87 * library). If it is not found, on macOS, SDL will attempt to load
88 * `vulkan.framework/vulkan`, `libvulkan.1.dylib`,
89 * `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On
90 * iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a
91 * dynamic framework or .dylib must ensure it is included in its application
92 * bundle.
93 *
94 * On non-Apple devices, application linking with a static libvulkan is not
95 * supported. Either do not link to the Vulkan loader or link to a dynamic
96 * library version.
97 *
98 * \param path The platform dependent Vulkan loader library name or NULL
99 * \returns 0 on success or a negative error code on failure; call
100 * SDL_GetError() for more information.
101 *
102 * \since This function is available since SDL 3.0.0.
103 *
104 * \sa SDL_Vulkan_GetVkInstanceProcAddr
105 * \sa SDL_Vulkan_UnloadLibrary
106 */
107extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
108
109/**
110 * Get the address of the `vkGetInstanceProcAddr` function.
111 *
112 * This should be called after either calling SDL_Vulkan_LoadLibrary() or
113 * creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
114 *
115 * The actual type of the returned function pointer is
116 * PFN_vkGetInstanceProcAddr, but that isn't available because the Vulkan
117 * headers are not included here. You should cast the return value of this
118 * function to that type, e.g.
119 *
120 * `vkGetInstanceProcAddr =
121 * (PFN_vkGetInstanceProcAddr)SDL_Vulkan_GetVkGetInstanceProcAddr();`
122 *
123 * \returns the function pointer for `vkGetInstanceProcAddr` or NULL on error.
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 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 `pCount` 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 pCount A pointer to Uint32 that will be filled with the number of
153 * extensions returned.
154 * \returns An array of extension name strings on success, NULL on error.
155 *
156 * \since This function is available since SDL 3.0.0.
157 *
158 * \sa SDL_Vulkan_CreateSurface
159 */
160extern DECLSPEC char const* const* SDLCALL SDL_Vulkan_GetInstanceExtensions(Uint32 *pCount);
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 SDL_TRUE on success, SDL_FALSE on error.
179 *
180 * \since This function is available since SDL 3.0.0.
181 *
182 * \sa SDL_Vulkan_GetInstanceExtensions
183 */
184extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
185 VkInstance instance,
186 const struct VkAllocationCallbacks *allocator,
187 VkSurfaceKHR* surface);
188
189/* @} *//* Vulkan support functions */
190
191/* Ends C function definitions when using C++ */
192#ifdef __cplusplus
193}
194#endif
195#include <SDL3/SDL_close_code.h>
196
197#endif /* SDL_vulkan_h_ */
int SDL_bool
Definition SDL_stdinc.h:137
void(* SDL_FunctionPointer)(void)
Definition SDL_stdinc.h:854
uint32_t Uint32
Definition SDL_stdinc.h:174
struct SDL_Window SDL_Window
Definition SDL_video.h:137
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object)
Definition SDL_vulkan.h:49
SDL_FunctionPointer SDL_Vulkan_GetVkGetInstanceProcAddr(void)
#define VK_DEFINE_HANDLE(object)
Definition SDL_vulkan.h:44
char const *const * SDL_Vulkan_GetInstanceExtensions(Uint32 *pCount)
int SDL_Vulkan_LoadLibrary(const char *path)
VkInstance SDL_vulkanInstance
Definition SDL_vulkan.h:58
VkSurfaceKHR SDL_vulkanSurface
Definition SDL_vulkan.h:59
SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
void SDL_Vulkan_UnloadLibrary(void)