2017-08-27 22:15:57 -04:00
|
|
|
/*
|
2017-08-27 23:13:15 -07:00
|
|
|
Simple DirectMedia Layer
|
|
|
|
|
Copyright (C) 2017, Mark Callow
|
|
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
|
appreciated but is not required.
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
misrepresented as being the original software.
|
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
*/
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
|
/**
|
2024-05-16 10:44:37 -04:00
|
|
|
* # CategoryVulkan
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2024-05-16 10:44:37 -04:00
|
|
|
* Functions for creating Vulkan surfaces on SDL windows.
|
2024-10-04 16:55:33 -04:00
|
|
|
*
|
|
|
|
|
* For the most part, Vulkan operates independent of SDL, but it benefits from
|
|
|
|
|
* a little support during setup.
|
|
|
|
|
*
|
|
|
|
|
* Use SDL_Vulkan_GetInstanceExtensions() to get platform-specific bits for
|
|
|
|
|
* creating a VkInstance, then SDL_Vulkan_GetVkGetInstanceProcAddr() to get
|
|
|
|
|
* the appropriate function for querying Vulkan entry points. Then
|
|
|
|
|
* SDL_Vulkan_CreateSurface() will get you the final pieces you need to
|
|
|
|
|
* prepare for rendering into an SDL_Window with Vulkan.
|
|
|
|
|
*
|
|
|
|
|
* Unlike OpenGL, most of the details of "context" creation and window buffer
|
|
|
|
|
* swapping are handled by the Vulkan API directly, so SDL doesn't provide
|
|
|
|
|
* Vulkan equivalents of SDL_GL_SwapWindow(), etc; they aren't necessary.
|
2017-08-27 22:15:57 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SDL_vulkan_h_
|
|
|
|
|
#define SDL_vulkan_h_
|
|
|
|
|
|
2024-09-07 17:20:59 +02:00
|
|
|
#include <SDL3/SDL_stdinc.h>
|
2024-04-04 18:38:21 +02:00
|
|
|
#include <SDL3/SDL_error.h>
|
2022-11-26 20:43:38 -08:00
|
|
|
#include <SDL3/SDL_video.h>
|
2017-08-27 22:15:57 -04:00
|
|
|
|
2022-12-22 11:38:59 -05:00
|
|
|
#include <SDL3/SDL_begin_code.h>
|
2017-08-27 22:15:57 -04:00
|
|
|
/* Set up for C function definitions, even when using C++ */
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-06-12 18:32:07 +02:00
|
|
|
/* Avoid including vulkan_core.h, don't define VkInstance if it's already included */
|
|
|
|
|
#ifdef VULKAN_CORE_H_
|
2017-08-27 23:13:15 -07:00
|
|
|
#define NO_SDL_VULKAN_TYPEDEFS
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef NO_SDL_VULKAN_TYPEDEFS
|
2017-08-27 22:15:57 -04:00
|
|
|
#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
|
|
|
|
|
|
2025-06-12 18:32:07 +02:00
|
|
|
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) || (defined(__riscv) && __riscv_xlen == 64)
|
2017-08-27 22:15:57 -04:00
|
|
|
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
|
|
|
|
|
#else
|
|
|
|
|
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
VK_DEFINE_HANDLE(VkInstance)
|
2024-07-11 12:58:28 -04:00
|
|
|
VK_DEFINE_HANDLE(VkPhysicalDevice)
|
2017-08-27 22:15:57 -04:00
|
|
|
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
|
2023-11-06 13:30:56 -05:00
|
|
|
struct VkAllocationCallbacks;
|
2017-08-27 22:15:57 -04:00
|
|
|
|
2024-10-29 18:30:10 +01:00
|
|
|
/* Make sure to undef to avoid issues in case of later vulkan include */
|
|
|
|
|
#undef VK_DEFINE_HANDLE
|
|
|
|
|
#undef VK_DEFINE_NON_DISPATCHABLE_HANDLE
|
|
|
|
|
|
2017-08-27 23:13:15 -07:00
|
|
|
#endif /* !NO_SDL_VULKAN_TYPEDEFS */
|
2017-08-27 22:27:45 -07:00
|
|
|
|
2017-08-27 22:15:57 -04:00
|
|
|
/**
|
|
|
|
|
* \name Vulkan support functions
|
|
|
|
|
*/
|
|
|
|
|
/* @{ */
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-21 14:18:39 -04:00
|
|
|
* Dynamically load the Vulkan loader library.
|
|
|
|
|
*
|
|
|
|
|
* This should be called after initializing the video driver, but before
|
|
|
|
|
* creating any Vulkan windows. If no Vulkan loader library is loaded, the
|
|
|
|
|
* default library will be loaded upon creation of the first Vulkan window.
|
|
|
|
|
*
|
2025-01-04 03:22:34 -05:00
|
|
|
* SDL keeps a counter of how many times this function has been successfully
|
|
|
|
|
* called, so it is safe to call this function multiple times, so long as it
|
|
|
|
|
* is eventually paired with an equivalent number of calls to
|
2025-01-04 08:24:05 +00:00
|
|
|
* SDL_Vulkan_UnloadLibrary. The `path` argument is ignored unless there is no
|
|
|
|
|
* library currently loaded, and and the library isn't actually unloaded until
|
|
|
|
|
* there have been an equivalent number of calls to SDL_Vulkan_UnloadLibrary.
|
2025-01-04 03:22:34 -05:00
|
|
|
*
|
2021-03-21 14:18:39 -04:00
|
|
|
* It is fairly common for Vulkan applications to link with libvulkan instead
|
|
|
|
|
* of explicitly loading it at run time. This will work with SDL provided the
|
|
|
|
|
* application links to a dynamic library and both it and SDL use the same
|
|
|
|
|
* search path.
|
|
|
|
|
*
|
2021-07-14 17:07:04 -04:00
|
|
|
* If you specify a non-NULL `path`, an application should retrieve all of the
|
|
|
|
|
* Vulkan functions it uses from the dynamic library using
|
|
|
|
|
* SDL_Vulkan_GetVkGetInstanceProcAddr unless you can guarantee `path` points
|
|
|
|
|
* to the same vulkan loader library the application linked to.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
|
|
|
|
* On Apple devices, if `path` is NULL, SDL will attempt to find the
|
2021-07-14 17:07:04 -04:00
|
|
|
* `vkGetInstanceProcAddr` address within all the Mach-O images of the current
|
|
|
|
|
* process. This is because it is fairly common for Vulkan applications to
|
|
|
|
|
* link with libvulkan (and historically MoltenVK was provided as a static
|
|
|
|
|
* library). If it is not found, on macOS, SDL will attempt to load
|
|
|
|
|
* `vulkan.framework/vulkan`, `libvulkan.1.dylib`,
|
|
|
|
|
* `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On
|
|
|
|
|
* iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a
|
|
|
|
|
* dynamic framework or .dylib must ensure it is included in its application
|
|
|
|
|
* bundle.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
|
|
|
|
* On non-Apple devices, application linking with a static libvulkan is not
|
|
|
|
|
* supported. Either do not link to the Vulkan loader or link to a dynamic
|
|
|
|
|
* library version.
|
|
|
|
|
*
|
2024-06-14 02:09:55 -04:00
|
|
|
* \param path the platform dependent Vulkan loader library name or NULL.
|
2024-09-18 15:33:11 +00:00
|
|
|
* \returns true on success or false on failure; call SDL_GetError() for more
|
|
|
|
|
* information.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
2025-01-04 03:22:34 -05:00
|
|
|
* \threadsafety This function is not thread safe.
|
|
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
2024-05-08 03:52:31 -04:00
|
|
|
* \sa SDL_Vulkan_GetVkGetInstanceProcAddr
|
2021-03-21 14:18:39 -04:00
|
|
|
* \sa SDL_Vulkan_UnloadLibrary
|
2017-08-27 22:15:57 -04:00
|
|
|
*/
|
2024-09-18 07:52:28 -07:00
|
|
|
extern SDL_DECLSPEC bool SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
|
/**
|
2021-03-21 14:18:39 -04:00
|
|
|
* Get the address of the `vkGetInstanceProcAddr` function.
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2021-07-14 17:07:04 -04:00
|
|
|
* This should be called after either calling SDL_Vulkan_LoadLibrary() or
|
|
|
|
|
* creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
2023-01-25 12:58:29 -05:00
|
|
|
* The actual type of the returned function pointer is
|
|
|
|
|
* PFN_vkGetInstanceProcAddr, but that isn't available because the Vulkan
|
|
|
|
|
* headers are not included here. You should cast the return value of this
|
|
|
|
|
* function to that type, e.g.
|
2023-01-09 14:55:12 -08:00
|
|
|
*
|
2023-01-25 12:58:29 -05:00
|
|
|
* `vkGetInstanceProcAddr =
|
|
|
|
|
* (PFN_vkGetInstanceProcAddr)SDL_Vulkan_GetVkGetInstanceProcAddr();`
|
2023-01-09 14:55:12 -08:00
|
|
|
*
|
2024-07-19 19:23:24 +00:00
|
|
|
* \returns the function pointer for `vkGetInstanceProcAddr` or NULL on
|
|
|
|
|
* failure; call SDL_GetError() for more information.
|
2021-10-27 01:36:05 +00:00
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2017-08-27 22:15:57 -04:00
|
|
|
*/
|
2024-05-17 16:52:36 -07:00
|
|
|
extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
|
/**
|
2024-04-08 22:36:57 -04:00
|
|
|
* Unload the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary().
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
2025-01-04 03:22:34 -05:00
|
|
|
* SDL keeps a counter of how many times this function has been called, so it
|
|
|
|
|
* is safe to call this function multiple times, so long as it is paired with
|
|
|
|
|
* an equivalent number of calls to SDL_Vulkan_LoadLibrary. The library isn't
|
|
|
|
|
* actually unloaded until there have been an equivalent number of calls to
|
|
|
|
|
* SDL_Vulkan_UnloadLibrary.
|
|
|
|
|
*
|
|
|
|
|
* Once the library has actually been unloaded, if any Vulkan instances
|
|
|
|
|
* remain, they will likely crash the program. Clean up any existing Vulkan
|
|
|
|
|
* resources, and destroy appropriate windows, renderers and GPU devices
|
|
|
|
|
* before calling this function.
|
|
|
|
|
*
|
|
|
|
|
* \threadsafety This function is not thread safe.
|
|
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2021-03-21 14:18:39 -04:00
|
|
|
* \sa SDL_Vulkan_LoadLibrary
|
2017-08-27 22:15:57 -04:00
|
|
|
*/
|
2024-05-17 16:52:36 -07:00
|
|
|
extern SDL_DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
|
/**
|
2023-11-02 15:12:24 -04:00
|
|
|
* Get the Vulkan instance extensions needed for vkCreateInstance.
|
2021-07-14 17:07:04 -04:00
|
|
|
*
|
2023-01-07 11:17:16 -06:00
|
|
|
* This should be called after either calling SDL_Vulkan_LoadLibrary() or
|
|
|
|
|
* creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
|
|
|
|
|
*
|
2024-03-05 21:11:32 +01:00
|
|
|
* On return, the variable pointed to by `count` will be set to the number of
|
2023-11-03 10:13:46 -04:00
|
|
|
* elements returned, suitable for using with
|
2023-11-02 15:12:24 -04:00
|
|
|
* VkInstanceCreateInfo::enabledExtensionCount, and the returned array can be
|
|
|
|
|
* used with VkInstanceCreateInfo::ppEnabledExtensionNames, for calling
|
|
|
|
|
* Vulkan's vkCreateInstance API.
|
|
|
|
|
*
|
|
|
|
|
* You should not free the returned array; it is owned by SDL.
|
|
|
|
|
*
|
2024-03-05 13:39:42 -08:00
|
|
|
* \param count a pointer filled in with the number of extensions returned.
|
2024-07-19 19:23:24 +00:00
|
|
|
* \returns an array of extension name strings on success, NULL on failure;
|
|
|
|
|
* call SDL_GetError() for more information.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2021-03-21 14:18:39 -04:00
|
|
|
*
|
|
|
|
|
* \sa SDL_Vulkan_CreateSurface
|
2017-08-27 22:15:57 -04:00
|
|
|
*/
|
Standardize placement of '*' in function declarations
Implemented using these sed commands on the headers:
sed -E -i'' '/SDLCALL|;/ s,([a-z])\* ,\1 *,g' *
sed -E -i'' 's,(\(.*[^\*])\* ([a-z])(.*\)),\1*\2\3,g' *
sed -E -i'' 's,\*const,* const,g' *
sed -E -i'' 's,\*SDLCALL,* SDLCALL,g' *
sed -E -i'' 's,void\(,void (,g' *
git checkout *gl*
2024-07-18 08:54:50 -07:00
|
|
|
extern SDL_DECLSPEC char const * const * SDLCALL SDL_Vulkan_GetInstanceExtensions(Uint32 *count);
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
|
/**
|
2021-03-21 14:18:39 -04:00
|
|
|
* Create a Vulkan rendering surface for a window.
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2021-03-21 14:18:39 -04:00
|
|
|
* The `window` must have been created with the `SDL_WINDOW_VULKAN` flag and
|
|
|
|
|
* `instance` must have been created with extensions returned by
|
|
|
|
|
* SDL_Vulkan_GetInstanceExtensions() enabled.
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2023-11-06 18:32:15 +00:00
|
|
|
* If `allocator` is NULL, Vulkan will use the system default allocator. This
|
|
|
|
|
* argument is passed directly to Vulkan and isn't used by SDL itself.
|
2023-11-06 13:30:56 -05:00
|
|
|
*
|
2024-06-14 02:09:55 -04:00
|
|
|
* \param window the window to which to attach the Vulkan surface.
|
|
|
|
|
* \param instance the Vulkan instance handle.
|
|
|
|
|
* \param allocator a VkAllocationCallbacks struct, which lets the app set the
|
2023-11-06 18:32:15 +00:00
|
|
|
* allocator that creates the surface. Can be NULL.
|
2024-06-14 02:09:55 -04:00
|
|
|
* \param surface a pointer to a VkSurfaceKHR handle to output the newly
|
|
|
|
|
* created surface.
|
2024-09-18 15:33:11 +00:00
|
|
|
* \returns true on success or false on failure; call SDL_GetError() for more
|
|
|
|
|
* information.
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2017-08-27 22:15:57 -04:00
|
|
|
*
|
2021-03-21 14:18:39 -04:00
|
|
|
* \sa SDL_Vulkan_GetInstanceExtensions
|
2024-05-17 03:41:15 +03:00
|
|
|
* \sa SDL_Vulkan_DestroySurface
|
2017-08-27 22:15:57 -04:00
|
|
|
*/
|
2024-09-18 07:52:28 -07:00
|
|
|
extern SDL_DECLSPEC bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
|
2024-08-22 17:33:49 -07:00
|
|
|
VkInstance instance,
|
|
|
|
|
const struct VkAllocationCallbacks *allocator,
|
2025-02-04 01:14:56 +01:00
|
|
|
VkSurfaceKHR *surface);
|
2017-08-27 22:15:57 -04:00
|
|
|
|
2024-05-17 03:41:15 +03:00
|
|
|
/**
|
|
|
|
|
* Destroy the Vulkan rendering surface of a window.
|
|
|
|
|
*
|
|
|
|
|
* This should be called before SDL_DestroyWindow, if SDL_Vulkan_CreateSurface
|
|
|
|
|
* was called after SDL_CreateWindow.
|
|
|
|
|
*
|
|
|
|
|
* The `instance` must have been created with extensions returned by
|
|
|
|
|
* SDL_Vulkan_GetInstanceExtensions() enabled and `surface` must have been
|
|
|
|
|
* created successfully by an SDL_Vulkan_CreateSurface() call.
|
|
|
|
|
*
|
|
|
|
|
* If `allocator` is NULL, Vulkan will use the system default allocator. This
|
|
|
|
|
* argument is passed directly to Vulkan and isn't used by SDL itself.
|
|
|
|
|
*
|
2024-06-14 02:09:55 -04:00
|
|
|
* \param instance the Vulkan instance handle.
|
|
|
|
|
* \param surface vkSurfaceKHR handle to destroy.
|
|
|
|
|
* \param allocator a VkAllocationCallbacks struct, which lets the app set the
|
2024-05-17 03:41:15 +03:00
|
|
|
* allocator that destroys the surface. Can be NULL.
|
|
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2024-05-17 03:41:15 +03:00
|
|
|
*
|
|
|
|
|
* \sa SDL_Vulkan_GetInstanceExtensions
|
|
|
|
|
* \sa SDL_Vulkan_CreateSurface
|
|
|
|
|
*/
|
2024-05-17 16:52:36 -07:00
|
|
|
extern SDL_DECLSPEC void SDLCALL SDL_Vulkan_DestroySurface(VkInstance instance,
|
2024-05-17 03:41:15 +03:00
|
|
|
VkSurfaceKHR surface,
|
|
|
|
|
const struct VkAllocationCallbacks *allocator);
|
|
|
|
|
|
2024-07-11 12:58:28 -04:00
|
|
|
/**
|
2024-07-11 19:01:27 +00:00
|
|
|
* Query support for presentation via a given physical device and queue
|
|
|
|
|
* family.
|
2024-07-11 12:58:28 -04:00
|
|
|
*
|
|
|
|
|
* The `instance` must have been created with extensions returned by
|
|
|
|
|
* SDL_Vulkan_GetInstanceExtensions() enabled.
|
|
|
|
|
*
|
|
|
|
|
* \param instance the Vulkan instance handle.
|
|
|
|
|
* \param physicalDevice a valid Vulkan physical device handle.
|
2024-07-11 19:01:27 +00:00
|
|
|
* \param queueFamilyIndex a valid queue family index for the given physical
|
|
|
|
|
* device.
|
2024-09-18 15:33:11 +00:00
|
|
|
* \returns true if supported, false if unsupported or an error occurred.
|
2024-07-11 12:58:28 -04:00
|
|
|
*
|
2025-01-21 13:12:25 -05:00
|
|
|
* \since This function is available since SDL 3.2.0.
|
2024-07-11 12:58:28 -04:00
|
|
|
*
|
|
|
|
|
* \sa SDL_Vulkan_GetInstanceExtensions
|
|
|
|
|
*/
|
2024-09-18 07:52:28 -07:00
|
|
|
extern SDL_DECLSPEC bool SDLCALL SDL_Vulkan_GetPresentationSupport(VkInstance instance,
|
2024-07-11 12:58:28 -04:00
|
|
|
VkPhysicalDevice physicalDevice,
|
|
|
|
|
Uint32 queueFamilyIndex);
|
|
|
|
|
|
2017-08-27 22:15:57 -04:00
|
|
|
/* @} *//* Vulkan support functions */
|
|
|
|
|
|
|
|
|
|
/* Ends C function definitions when using C++ */
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-12-22 11:38:59 -05:00
|
|
|
#include <SDL3/SDL_close_code.h>
|
2017-08-27 22:15:57 -04:00
|
|
|
|
|
|
|
|
#endif /* SDL_vulkan_h_ */
|