vk_icd.h 8.0 KB

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