🛠️🐜 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.

278 lines
10 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(
  191. SDL_Window *window,
  192. unsigned int *pCount,
  193. const char **pNames);
  194. /**
  195. * \brief Create a Vulkan rendering surface for a window.
  196. *
  197. * \param [in] window SDL_Window to which to attach the rendering surface.
  198. * \param [in] instance handle to the Vulkan instance to use.
  199. * \param [out] surface pointer to a VkSurfaceKHR handle to receive the
  200. * handle of the newly created surface.
  201. *
  202. * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
  203. *
  204. * \code
  205. * VkInstance instance;
  206. * SDL_Window *window;
  207. *
  208. * // create instance and window
  209. *
  210. * // create the Vulkan surface
  211. * VkSurfaceKHR surface;
  212. * if(!SDL_Vulkan_CreateSurface(window, instance, &surface))
  213. * handle_error();
  214. * \endcode
  215. *
  216. * \note \a window should have been created with the \c SDL_WINDOW_VULKAN flag.
  217. *
  218. * \note \a instance should have been created with the extensions returned
  219. * by \c SDL_Vulkan_CreateSurface() enabled.
  220. *
  221. * \sa SDL_Vulkan_GetInstanceExtensions()
  222. */
  223. extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(
  224. SDL_Window *window,
  225. VkInstance instance,
  226. VkSurfaceKHR* surface);
  227. /**
  228. * \brief Get the size of a window's underlying drawable in pixels (for use
  229. * with setting viewport, scissor & etc).
  230. *
  231. * \param window SDL_Window from which the drawable size should be queried
  232. * \param w Pointer to variable for storing the width in pixels,
  233. * may be NULL
  234. * \param h Pointer to variable for storing the height in pixels,
  235. * may be NULL
  236. *
  237. * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
  238. * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
  239. * platform with high-DPI support (Apple calls this "Retina"), and not disabled
  240. * by the \c SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
  241. *
  242. * \note On macOS high-DPI support must be enabled for an application by
  243. * setting NSHighResolutionCapable to true in its Info.plist.
  244. *
  245. * \sa SDL_GetWindowSize()
  246. * \sa SDL_CreateWindow()
  247. */
  248. extern DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window,
  249. int *w, int *h);
  250. /* @} *//* Vulkan support functions */
  251. /* Ends C function definitions when using C++ */
  252. #ifdef __cplusplus
  253. }
  254. #endif
  255. #include "close_code.h"
  256. #endif /* SDL_vulkan_h_ */