1
0

SDL_vulkan.h 8.5 KB

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