vk_icd.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //
  2. // File: vk_icd.h
  3. //
  4. /*
  5. * Copyright (c) 2015-2023 LunarG, Inc.
  6. * Copyright (c) 2015-2023 The Khronos Group Inc.
  7. * Copyright (c) 2015-2023 Valve Corporation
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. */
  22. #pragma once
  23. #include "vulkan.h"
  24. #include <stdbool.h>
  25. // Loader-ICD version negotiation API. Versions add the following features:
  26. // Version 0 - Initial. Doesn't support vk_icdGetInstanceProcAddr
  27. // or vk_icdNegotiateLoaderICDInterfaceVersion.
  28. // Version 1 - Add support for vk_icdGetInstanceProcAddr.
  29. // Version 2 - Add Loader/ICD Interface version negotiation
  30. // via vk_icdNegotiateLoaderICDInterfaceVersion.
  31. // Version 3 - Add ICD creation/destruction of KHR_surface objects.
  32. // Version 4 - Add unknown physical device extension querying via
  33. // vk_icdGetPhysicalDeviceProcAddr.
  34. // Version 5 - Tells ICDs that the loader is now paying attention to the
  35. // application version of Vulkan passed into the ApplicationInfo
  36. // structure during vkCreateInstance. This will tell the ICD
  37. // that if the loader is older, it should automatically fail a
  38. // call for any API version > 1.0. Otherwise, the loader will
  39. // manually determine if it can support the expected version.
  40. // Version 6 - Add support for vk_icdEnumerateAdapterPhysicalDevices.
  41. // Version 7 - If an ICD supports any of the following functions, they must be
  42. // queryable with vk_icdGetInstanceProcAddr:
  43. // vk_icdNegotiateLoaderICDInterfaceVersion
  44. // vk_icdGetPhysicalDeviceProcAddr
  45. // vk_icdEnumerateAdapterPhysicalDevices (Windows only)
  46. // In addition, these functions no longer need to be exported directly.
  47. // This version allows drivers provided through the extension
  48. // VK_LUNARG_direct_driver_loading be able to support the entire
  49. // Driver-Loader interface.
  50. #define CURRENT_LOADER_ICD_INTERFACE_VERSION 7
  51. #define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0
  52. #define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4
  53. // Old typedefs that don't follow a proper naming convention but are preserved for compatibility
  54. typedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion);
  55. // This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this
  56. // file directly, it won't be found.
  57. #ifndef PFN_GetPhysicalDeviceProcAddr
  58. typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
  59. #endif
  60. // Typedefs for loader/ICD interface
  61. typedef VkResult (VKAPI_PTR *PFN_vk_icdNegotiateLoaderICDInterfaceVersion)(uint32_t* pVersion);
  62. typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName);
  63. typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
  64. #if defined(VK_USE_PLATFORM_WIN32_KHR)
  65. typedef VkResult (VKAPI_PTR *PFN_vk_icdEnumerateAdapterPhysicalDevices)(VkInstance instance, LUID adapterLUID,
  66. uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
  67. #endif
  68. // Prototypes for loader/ICD interface
  69. #if !defined(VK_NO_PROTOTYPES)
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pVersion);
  74. VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
  75. VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName);
  76. #if defined(VK_USE_PLATFORM_WIN32_KHR)
  77. VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
  78. uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
  79. #endif
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif
  84. /*
  85. * The ICD must reserve space for a pointer for the loader's dispatch
  86. * table, at the start of <each object>.
  87. * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
  88. */
  89. #define ICD_LOADER_MAGIC 0x01CDC0DE
  90. typedef union {
  91. uintptr_t loaderMagic;
  92. void *loaderData;
  93. } VK_LOADER_DATA;
  94. static inline void set_loader_magic_value(void *pNewObject) {
  95. VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
  96. loader_info->loaderMagic = ICD_LOADER_MAGIC;
  97. }
  98. static inline bool valid_loader_magic_value(void *pNewObject) {
  99. const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
  100. return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
  101. }
  102. /*
  103. * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that
  104. * contains the platform-specific connection and surface information.
  105. */
  106. typedef enum {
  107. VK_ICD_WSI_PLATFORM_MIR,
  108. VK_ICD_WSI_PLATFORM_WAYLAND,
  109. VK_ICD_WSI_PLATFORM_WIN32,
  110. VK_ICD_WSI_PLATFORM_XCB,
  111. VK_ICD_WSI_PLATFORM_XLIB,
  112. VK_ICD_WSI_PLATFORM_ANDROID,
  113. VK_ICD_WSI_PLATFORM_MACOS,
  114. VK_ICD_WSI_PLATFORM_IOS,
  115. VK_ICD_WSI_PLATFORM_DISPLAY,
  116. VK_ICD_WSI_PLATFORM_HEADLESS,
  117. VK_ICD_WSI_PLATFORM_METAL,
  118. VK_ICD_WSI_PLATFORM_DIRECTFB,
  119. VK_ICD_WSI_PLATFORM_VI,
  120. VK_ICD_WSI_PLATFORM_GGP,
  121. VK_ICD_WSI_PLATFORM_SCREEN,
  122. VK_ICD_WSI_PLATFORM_FUCHSIA,
  123. } VkIcdWsiPlatform;
  124. typedef struct {
  125. VkIcdWsiPlatform platform;
  126. } VkIcdSurfaceBase;
  127. #ifdef VK_USE_PLATFORM_MIR_KHR
  128. typedef struct {
  129. VkIcdSurfaceBase base;
  130. MirConnection *connection;
  131. MirSurface *mirSurface;
  132. } VkIcdSurfaceMir;
  133. #endif // VK_USE_PLATFORM_MIR_KHR
  134. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  135. typedef struct {
  136. VkIcdSurfaceBase base;
  137. struct wl_display *display;
  138. struct wl_surface *surface;
  139. } VkIcdSurfaceWayland;
  140. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  141. #ifdef VK_USE_PLATFORM_WIN32_KHR
  142. typedef struct {
  143. VkIcdSurfaceBase base;
  144. HINSTANCE hinstance;
  145. HWND hwnd;
  146. } VkIcdSurfaceWin32;
  147. #endif // VK_USE_PLATFORM_WIN32_KHR
  148. #ifdef VK_USE_PLATFORM_XCB_KHR
  149. typedef struct {
  150. VkIcdSurfaceBase base;
  151. xcb_connection_t *connection;
  152. xcb_window_t window;
  153. } VkIcdSurfaceXcb;
  154. #endif // VK_USE_PLATFORM_XCB_KHR
  155. #ifdef VK_USE_PLATFORM_XLIB_KHR
  156. typedef struct {
  157. VkIcdSurfaceBase base;
  158. Display *dpy;
  159. Window window;
  160. } VkIcdSurfaceXlib;
  161. #endif // VK_USE_PLATFORM_XLIB_KHR
  162. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  163. typedef struct {
  164. VkIcdSurfaceBase base;
  165. IDirectFB *dfb;
  166. IDirectFBSurface *surface;
  167. } VkIcdSurfaceDirectFB;
  168. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  169. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  170. typedef struct {
  171. VkIcdSurfaceBase base;
  172. struct ANativeWindow *window;
  173. } VkIcdSurfaceAndroid;
  174. #endif // VK_USE_PLATFORM_ANDROID_KHR
  175. #ifdef VK_USE_PLATFORM_MACOS_MVK
  176. typedef struct {
  177. VkIcdSurfaceBase base;
  178. const void *pView;
  179. } VkIcdSurfaceMacOS;
  180. #endif // VK_USE_PLATFORM_MACOS_MVK
  181. #ifdef VK_USE_PLATFORM_IOS_MVK
  182. typedef struct {
  183. VkIcdSurfaceBase base;
  184. const void *pView;
  185. } VkIcdSurfaceIOS;
  186. #endif // VK_USE_PLATFORM_IOS_MVK
  187. #ifdef VK_USE_PLATFORM_GGP
  188. typedef struct {
  189. VkIcdSurfaceBase base;
  190. GgpStreamDescriptor streamDescriptor;
  191. } VkIcdSurfaceGgp;
  192. #endif // VK_USE_PLATFORM_GGP
  193. typedef struct {
  194. VkIcdSurfaceBase base;
  195. VkDisplayModeKHR displayMode;
  196. uint32_t planeIndex;
  197. uint32_t planeStackIndex;
  198. VkSurfaceTransformFlagBitsKHR transform;
  199. float globalAlpha;
  200. VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
  201. VkExtent2D imageExtent;
  202. } VkIcdSurfaceDisplay;
  203. typedef struct {
  204. VkIcdSurfaceBase base;
  205. } VkIcdSurfaceHeadless;
  206. #ifdef VK_USE_PLATFORM_METAL_EXT
  207. typedef struct {
  208. VkIcdSurfaceBase base;
  209. const CAMetalLayer *pLayer;
  210. } VkIcdSurfaceMetal;
  211. #endif // VK_USE_PLATFORM_METAL_EXT
  212. #ifdef VK_USE_PLATFORM_VI_NN
  213. typedef struct {
  214. VkIcdSurfaceBase base;
  215. void *window;
  216. } VkIcdSurfaceVi;
  217. #endif // VK_USE_PLATFORM_VI_NN
  218. #ifdef VK_USE_PLATFORM_SCREEN_QNX
  219. typedef struct {
  220. VkIcdSurfaceBase base;
  221. struct _screen_context *context;
  222. struct _screen_window *window;
  223. } VkIcdSurfaceScreen;
  224. #endif // VK_USE_PLATFORM_SCREEN_QNX
  225. #ifdef VK_USE_PLATFORM_FUCHSIA
  226. typedef struct {
  227. VkIcdSurfaceBase base;
  228. } VkIcdSurfaceImagePipe;
  229. #endif // VK_USE_PLATFORM_FUCHSIA