SDL_vulkan.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. * Dynamically load the Vulkan loader library.
  56. *
  57. * This should be called after initializing the video driver, but before
  58. * creating any Vulkan windows. If no Vulkan loader library is loaded, the
  59. * default library will be loaded upon creation of the first Vulkan window.
  60. *
  61. * It is fairly common for Vulkan applications to link with libvulkan instead
  62. * of explicitly loading it at run time. This will work with SDL provided the
  63. * application links to a dynamic library and both it and SDL use the same
  64. * search path.
  65. *
  66. * If you specify a non-NULL `path`, an application should retrieve all of the
  67. * Vulkan functions it uses from the dynamic library using
  68. * SDL_Vulkan_GetVkGetInstanceProcAddr unless you can guarantee `path` points
  69. * to the same vulkan loader library the application linked to.
  70. *
  71. * On Apple devices, if `path` is NULL, SDL will attempt to find the
  72. * `vkGetInstanceProcAddr` address within all the Mach-O images of the current
  73. * process. This is because it is fairly common for Vulkan applications to
  74. * link with libvulkan (and historically MoltenVK was provided as a static
  75. * library). If it is not found, on macOS, SDL will attempt to load
  76. * `vulkan.framework/vulkan`, `libvulkan.1.dylib`,
  77. * `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On
  78. * iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a
  79. * dynamic framework or .dylib must ensure it is included in its application
  80. * bundle.
  81. *
  82. * On non-Apple devices, application linking with a static libvulkan is not
  83. * supported. Either do not link to the Vulkan loader or link to a dynamic
  84. * library version.
  85. *
  86. * \param path The platform dependent Vulkan loader library name or NULL
  87. * \returns 0 on success or -1 if the library couldn't be loaded; call
  88. * SDL_GetError() for more information.
  89. *
  90. * \since This function is available in SDL 2.0.8
  91. *
  92. * \sa SDL_Vulkan_GetVkInstanceProcAddr
  93. * \sa SDL_Vulkan_UnloadLibrary
  94. */
  95. extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
  96. /**
  97. * Get the address of the `vkGetInstanceProcAddr` function.
  98. *
  99. * This should be called after either calling SDL_Vulkan_LoadLibrary() or
  100. * creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
  101. *
  102. * \returns the function pointer for `vkGetInstanceProcAddr` or NULL on error.
  103. */
  104. extern DECLSPEC void *SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
  105. /**
  106. * Unload the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary()
  107. *
  108. * \since This function is available in SDL 2.0.8
  109. *
  110. * \sa SDL_Vulkan_LoadLibrary
  111. */
  112. extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
  113. /**
  114. * Get the names of the Vulkan instance extensions needed to create a surface
  115. * with SDL_Vulkan_CreateSurface.
  116. *
  117. * If `pNames` is NULL, then the number of required Vulkan instance extensions
  118. * is returned in `pCount`. Otherwise, `pCount` must point to a variable set
  119. * to the number of elements in the `pNames` array, and on return the variable
  120. * is overwritten with the number of names actually written to `pNames`. If
  121. * `pCount` is less than the number of required extensions, at most `pCount`
  122. * structures will be written. If `pCount` is smaller than the number of
  123. * required extensions, SDL_FALSE will be returned instead of SDL_TRUE, to
  124. * indicate that not all the required extensions were returned.
  125. *
  126. * The `window` parameter is currently needed to be valid as of SDL 2.0.8,
  127. * however, this parameter will likely be removed in future releases
  128. *
  129. * \param window A window for which the required Vulkan instance extensions
  130. * should be retrieved (will be deprecated in a future release)
  131. * \param pCount A pointer to an unsigned int corresponding to the number of
  132. * extensions to be returned
  133. * \param pNames NULL or a pointer to an array to be filled with required
  134. * Vulkan instance extensions
  135. * \returns SDL_TRUE on success, SDL_FALSE on error.
  136. *
  137. * \since This function is available in SDL 2.0.8
  138. *
  139. * \sa SDL_Vulkan_CreateSurface
  140. */
  141. extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetInstanceExtensions(SDL_Window *window,
  142. unsigned int *pCount,
  143. const char **pNames);
  144. /**
  145. * Create a Vulkan rendering surface for a window.
  146. *
  147. * The `window` must have been created with the `SDL_WINDOW_VULKAN` flag and
  148. * `instance` must have been created with extensions returned by
  149. * SDL_Vulkan_GetInstanceExtensions() enabled.
  150. *
  151. * \param window The window to which to attach the Vulkan surface
  152. * \param instance The Vulkan instance handle
  153. * \param surface A pointer to a VkSurfaceKHR handle to output the newly
  154. * created surface
  155. * \returns SDL_TRUE on success, SDL_FALSE on error.
  156. *
  157. * \since This function is available in SDL 2.0.8
  158. *
  159. * \sa SDL_Vulkan_GetInstanceExtensions
  160. * \sa SDL_Vulkan_GetDrawableSize
  161. */
  162. extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
  163. VkInstance instance,
  164. VkSurfaceKHR* surface);
  165. /**
  166. * Get the size of the window's underlying drawable dimensions in pixels.
  167. *
  168. * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
  169. * drawable, i.e. the window was created with `SDL_WINDOW_ALLOW_HIGHDPI` on a
  170. * platform with high-DPI support (Apple calls this "Retina"), and not
  171. * disabled by the `SDL_HINT_VIDEO_HIGHDPI_DISABLED` hint.
  172. *
  173. * \param window an SDL_Window for which the size is to be queried
  174. * \param w Pointer to the variable to write the width to or NULL
  175. * \param h Pointer to the variable to write the height to or NULL
  176. *
  177. * \since This function is available in SDL 2.0.8
  178. *
  179. * \sa SDL_GetWindowSize
  180. * \sa SDL_CreateWindow
  181. * \sa SDL_Vulkan_CreateSurface
  182. */
  183. extern DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window,
  184. int *w, int *h);
  185. /* @} *//* Vulkan support functions */
  186. /* Ends C function definitions when using C++ */
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #include "close_code.h"
  191. #endif /* SDL_vulkan_h_ */