🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
11 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 2017, Mark Callow
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_vulkan.h
  20. *
  21. * Header file for functions to creating Vulkan surfaces on SDL windows.
  22. */
  23. #ifndef SDL_vulkan_h_
  24. #define SDL_vulkan_h_
  25. #include "SDL_video.h"
  26. #include "begin_code.h"
  27. /* Set up for C function definitions, even when using C++ */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Avoid including vulkan.h, don't define VkInstance if it's already included */
  32. #ifdef VULKAN_H_
  33. #define NO_SDL_VULKAN_TYPEDEFS
  34. #endif
  35. #ifndef NO_SDL_VULKAN_TYPEDEFS
  36. #define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
  37. #if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
  38. #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
  39. #else
  40. #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
  41. #endif
  42. VK_DEFINE_HANDLE(VkInstance)
  43. VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
  44. #endif /* !NO_SDL_VULKAN_TYPEDEFS */
  45. typedef VkInstance SDL_vulkanInstance;
  46. typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
  47. /**
  48. * \name Vulkan support functions
  49. *
  50. * \note SDL_Vulkan_GetInstanceExtensions & SDL_Vulkan_CreateSurface API
  51. * is compatable with Tizen's implementation of Vulkan in SDL.
  52. */
  53. /* @{ */
  54. /**
  55. * \brief Dynamically load a Vulkan loader library.
  56. *
  57. * \param [in] path The platform dependent Vulkan loader library name, or
  58. * \c NULL.
  59. *
  60. * \return \c 0 on success, or \c -1 if the library couldn't be loaded.
  61. *
  62. * If \a path is NULL SDL will use the value of the environment variable
  63. * \c SDL_VULKAN_LIBRARY, if set, otherwise it loads the default Vulkan
  64. * loader library.
  65. *
  66. * This should be called after initializing the video driver, but before
  67. * creating any Vulkan windows. If no Vulkan loader library is loaded, the
  68. * default library will be loaded upon creation of the first Vulkan window.
  69. *
  70. * \note It is fairly common for Vulkan applications to link with \a libvulkan
  71. * instead of explicitly loading it at run time. This will work with
  72. * SDL provided the application links to a dynamic library and both it
  73. * and SDL use the same search path.
  74. *
  75. * \note If you specify a non-NULL \c path, an application should retrieve all
  76. * of the Vulkan functions it uses from the dynamic library using
  77. * \c SDL_Vulkan_GetVkGetInstanceProcAddr() unless you can guarantee
  78. * \c path points to the same vulkan loader library the application
  79. * linked to.
  80. *
  81. * \note On Apple devices, if \a path is NULL, SDL will attempt to find
  82. * the vkGetInstanceProcAddr address within all the mach-o images of
  83. * the current process. This is because it is fairly common for Vulkan
  84. * applications to link with libvulkan (and historically MoltenVK was
  85. * provided as a static library). If it is not found then, on macOS, SDL
  86. * will attempt to load \c vulkan.framework/vulkan, \c libvulkan.1.dylib,
  87. * followed by \c libvulkan.dylib, in that order.
  88. * On iOS SDL will attempt to load \c libvulkan.dylib only. Applications
  89. * using a dynamic framework or .dylib must ensure it is included in its
  90. * application bundle.
  91. *
  92. * \note On non-Apple devices, application linking with a static libvulkan is
  93. * not supported. Either do not link to the Vulkan loader or link to a
  94. * dynamic library version.
  95. *
  96. * \note This function will fail if there are no working Vulkan drivers
  97. * installed.
  98. *
  99. * \sa SDL_Vulkan_GetVkGetInstanceProcAddr()
  100. * \sa SDL_Vulkan_UnloadLibrary()
  101. */
  102. extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
  103. /**
  104. * \brief Get the address of the \c vkGetInstanceProcAddr function.
  105. *
  106. * \note This should be called after either calling SDL_Vulkan_LoadLibrary
  107. * or creating an SDL_Window with the SDL_WINDOW_VULKAN flag.
  108. */
  109. extern DECLSPEC void *SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
  110. /**
  111. * \brief Unload the Vulkan loader library previously loaded by
  112. * \c SDL_Vulkan_LoadLibrary().
  113. *
  114. * \sa SDL_Vulkan_LoadLibrary()
  115. */
  116. extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
  117. /**
  118. * \brief Get the names of the Vulkan instance extensions needed to create
  119. * a surface with \c SDL_Vulkan_CreateSurface().
  120. *
  121. * \param [in] \c NULL or window Window for which the required Vulkan instance
  122. * extensions should be retrieved
  123. * \param [in,out] pCount pointer to an \c unsigned related to the number of
  124. * required Vulkan instance extensions
  125. * \param [out] pNames \c NULL or a pointer to an array to be filled with the
  126. * required Vulkan instance extensions
  127. *
  128. * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
  129. *
  130. * If \a pNames is \c NULL, then the number of required Vulkan instance
  131. * extensions is returned in pCount. Otherwise, \a pCount must point to a
  132. * variable set to the number of elements in the \a pNames array, and on
  133. * return the variable is overwritten with the number of names actually
  134. * written to \a pNames. If \a pCount is less than the number of required
  135. * extensions, at most \a pCount structures will be written. If \a pCount
  136. * is smaller than the number of required extensions, \c SDL_FALSE will be
  137. * returned instead of \c SDL_TRUE, to indicate that not all the required
  138. * extensions were returned.
  139. *
  140. * \note If \c window is not NULL, it will be checked against its creation
  141. * flags to ensure that the Vulkan flag is present. This parameter
  142. * will be removed in a future major release.
  143. *
  144. * \note The returned list of extensions will contain \c VK_KHR_surface
  145. * and zero or more platform specific extensions
  146. *
  147. * \note The extension names queried here must be enabled when calling
  148. * VkCreateInstance, otherwise surface creation will fail.
  149. *
  150. * \note \c window should have been created with the \c SDL_WINDOW_VULKAN flag
  151. * or be \c NULL
  152. *
  153. * \code
  154. * unsigned int count;
  155. * // get count of required extensions
  156. * if(!SDL_Vulkan_GetInstanceExtensions(NULL, &count, NULL))
  157. * handle_error();
  158. *
  159. * static const char *const additionalExtensions[] =
  160. * {
  161. * VK_EXT_DEBUG_REPORT_EXTENSION_NAME, // example additional extension
  162. * };
  163. * size_t additionalExtensionsCount = sizeof(additionalExtensions) / sizeof(additionalExtensions[0]);
  164. * size_t extensionCount = count + additionalExtensionsCount;
  165. * const char **names = malloc(sizeof(const char *) * extensionCount);
  166. * if(!names)
  167. * handle_error();
  168. *
  169. * // get names of required extensions
  170. * if(!SDL_Vulkan_GetInstanceExtensions(NULL, &count, names))
  171. * handle_error();
  172. *
  173. * // copy additional extensions after required extensions
  174. * for(size_t i = 0; i < additionalExtensionsCount; i++)
  175. * names[i + count] = additionalExtensions[i];
  176. *
  177. * VkInstanceCreateInfo instanceCreateInfo = {};
  178. * instanceCreateInfo.enabledExtensionCount = extensionCount;
  179. * instanceCreateInfo.ppEnabledExtensionNames = names;
  180. * // fill in rest of instanceCreateInfo
  181. *
  182. * VkInstance instance;
  183. * // create the Vulkan instance
  184. * VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);
  185. * free(names);
  186. * \endcode
  187. *
  188. * \sa SDL_Vulkan_CreateSurface()
  189. */
  190. extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetInstanceExtensions(SDL_Window *window,
  191. unsigned int *pCount,
  192. const char **pNames);
  193. /**
  194. * \brief Create a Vulkan rendering surface for a window.
  195. *
  196. * \param [in] window SDL_Window to which to attach the rendering surface.
  197. * \param [in] instance handle to the Vulkan instance to use.
  198. * \param [out] surface pointer to a VkSurfaceKHR handle to receive the
  199. * handle of the newly created surface.
  200. *
  201. * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
  202. *
  203. * \code
  204. * VkInstance instance;
  205. * SDL_Window *window;
  206. *
  207. * // create instance and window
  208. *
  209. * // create the Vulkan surface
  210. * VkSurfaceKHR surface;
  211. * if(!SDL_Vulkan_CreateSurface(window, instance, &surface))
  212. * handle_error();
  213. * \endcode
  214. *
  215. * \note \a window should have been created with the \c SDL_WINDOW_VULKAN flag.
  216. *
  217. * \note \a instance should have been created with the extensions returned
  218. * by \c SDL_Vulkan_CreateSurface() enabled.
  219. *
  220. * \sa SDL_Vulkan_GetInstanceExtensions()
  221. */
  222. extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
  223. VkInstance instance,
  224. VkSurfaceKHR* surface);
  225. /**
  226. * \brief Get the size of a window's underlying drawable in pixels (for use
  227. * with setting viewport, scissor & etc).
  228. *
  229. * \param window SDL_Window from which the drawable size should be queried
  230. * \param w Pointer to variable for storing the width in pixels,
  231. * may be NULL
  232. * \param h Pointer to variable for storing the height in pixels,
  233. * may be NULL
  234. *
  235. * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
  236. * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
  237. * platform with high-DPI support (Apple calls this "Retina"), and not disabled
  238. * by the \c SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
  239. *
  240. * \note On macOS high-DPI support must be enabled for an application by
  241. * setting NSHighResolutionCapable to true in its Info.plist.
  242. *
  243. * \sa SDL_GetWindowSize()
  244. * \sa SDL_CreateWindow()
  245. */
  246. extern DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window,
  247. int *w, int *h);
  248. /* @} *//* Vulkan support functions */
  249. /* Ends C function definitions when using C++ */
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253. #include "close_code.h"
  254. #endif /* SDL_vulkan_h_ */