SDL_vulkan.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <SDL3/SDL_video.h>
  26. #include <SDL3/SDL_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. /* @{ */
  51. /**
  52. * Dynamically load the Vulkan loader library.
  53. *
  54. * This should be called after initializing the video driver, but before
  55. * creating any Vulkan windows. If no Vulkan loader library is loaded, the
  56. * default library will be loaded upon creation of the first Vulkan window.
  57. *
  58. * It is fairly common for Vulkan applications to link with libvulkan instead
  59. * of explicitly loading it at run time. This will work with SDL provided the
  60. * application links to a dynamic library and both it and SDL use the same
  61. * search path.
  62. *
  63. * If you specify a non-NULL `path`, an application should retrieve all of the
  64. * Vulkan functions it uses from the dynamic library using
  65. * SDL_Vulkan_GetVkGetInstanceProcAddr unless you can guarantee `path` points
  66. * to the same vulkan loader library the application linked to.
  67. *
  68. * On Apple devices, if `path` is NULL, SDL will attempt to find the
  69. * `vkGetInstanceProcAddr` address within all the Mach-O images of the current
  70. * process. This is because it is fairly common for Vulkan applications to
  71. * link with libvulkan (and historically MoltenVK was provided as a static
  72. * library). If it is not found, on macOS, SDL will attempt to load
  73. * `vulkan.framework/vulkan`, `libvulkan.1.dylib`,
  74. * `MoltenVK.framework/MoltenVK`, and `libMoltenVK.dylib`, in that order. On
  75. * iOS, SDL will attempt to load `libMoltenVK.dylib`. Applications using a
  76. * dynamic framework or .dylib must ensure it is included in its application
  77. * bundle.
  78. *
  79. * On non-Apple devices, application linking with a static libvulkan is not
  80. * supported. Either do not link to the Vulkan loader or link to a dynamic
  81. * library version.
  82. *
  83. * \param path The platform dependent Vulkan loader library name or NULL
  84. * \returns 0 on success or a negative error code on failure; call
  85. * SDL_GetError() for more information.
  86. *
  87. * \since This function is available since SDL 3.0.0.
  88. *
  89. * \sa SDL_Vulkan_GetVkInstanceProcAddr
  90. * \sa SDL_Vulkan_UnloadLibrary
  91. */
  92. extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
  93. /**
  94. * Get the address of the `vkGetInstanceProcAddr` function.
  95. *
  96. * This should be called after either calling SDL_Vulkan_LoadLibrary() or
  97. * creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
  98. *
  99. * The actual type of the returned function pointer is
  100. * PFN_vkGetInstanceProcAddr, but that isn't available because the Vulkan
  101. * headers are not included here. You should cast the return value of this
  102. * function to that type, e.g.
  103. *
  104. * `vkGetInstanceProcAddr =
  105. * (PFN_vkGetInstanceProcAddr)SDL_Vulkan_GetVkGetInstanceProcAddr();`
  106. *
  107. * \returns the function pointer for `vkGetInstanceProcAddr` or NULL on error.
  108. *
  109. * \since This function is available since SDL 3.0.0.
  110. */
  111. extern DECLSPEC SDL_FunctionPointer SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
  112. /**
  113. * Unload the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary()
  114. *
  115. * \since This function is available since SDL 3.0.0.
  116. *
  117. * \sa SDL_Vulkan_LoadLibrary
  118. */
  119. extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
  120. /**
  121. * Get the Vulkan instance extensions needed for vkCreateInstance.
  122. *
  123. * This should be called after either calling SDL_Vulkan_LoadLibrary() or
  124. * creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
  125. *
  126. * On return, the variable pointed to by `pCount` will be set to the number of
  127. * elements returned, suitable for using with
  128. * VkInstanceCreateInfo::enabledExtensionCount, and the returned array can be
  129. * used with VkInstanceCreateInfo::ppEnabledExtensionNames, for calling
  130. * Vulkan's vkCreateInstance API.
  131. *
  132. * You should not free the returned array; it is owned by SDL.
  133. *
  134. * \param pCount A pointer to Uint32 that will be filled with the number of
  135. * extensions returned.
  136. * \returns An array of extension name strings on success, NULL on error.
  137. *
  138. * \since This function is available since SDL 3.0.0.
  139. *
  140. * \sa SDL_Vulkan_CreateSurface
  141. */
  142. extern DECLSPEC char const* const* SDLCALL SDL_Vulkan_GetInstanceExtensions(Uint32 *pCount);
  143. /**
  144. * Create a Vulkan rendering surface for a window.
  145. *
  146. * The `window` must have been created with the `SDL_WINDOW_VULKAN` flag and
  147. * `instance` must have been created with extensions returned by
  148. * SDL_Vulkan_GetInstanceExtensions() enabled.
  149. *
  150. * \param window The window to which to attach the Vulkan surface
  151. * \param instance The Vulkan instance handle
  152. * \param surface A pointer to a VkSurfaceKHR handle to output the newly
  153. * created surface
  154. * \returns SDL_TRUE on success, SDL_FALSE on error.
  155. *
  156. * \since This function is available since SDL 3.0.0.
  157. *
  158. * \sa SDL_Vulkan_GetInstanceExtensions
  159. */
  160. extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
  161. VkInstance instance,
  162. VkSurfaceKHR* surface);
  163. /* @} *//* Vulkan support functions */
  164. /* Ends C function definitions when using C++ */
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #include <SDL3/SDL_close_code.h>
  169. #endif /* SDL_vulkan_h_ */