vk_icd.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 IS_DEFINED_PFN_GetPhysicalDeviceProcAddr
  44. typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
  45. #define IS_DEFINED_PFN_GetPhysicalDeviceProcAddr
  46. #endif
  47. // Typedefs for loader/ICD interface
  48. typedef VkResult (VKAPI_PTR *PFN_vk_icdNegotiateLoaderICDInterfaceVersion)(uint32_t* pVersion);
  49. typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName);
  50. typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
  51. #if defined(VK_USE_PLATFORM_WIN32_KHR)
  52. typedef VkResult (VKAPI_PTR *PFN_vk_icdEnumerateAdapterPhysicalDevices)(VkInstance instance, LUID adapterLUID,
  53. uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
  54. #endif
  55. // Prototypes for loader/ICD interface
  56. #if !defined(VK_NO_PROTOTYPES)
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pVersion);
  61. VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
  62. VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName);
  63. #if defined(VK_USE_PLATFORM_WIN32_KHR)
  64. VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
  65. uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
  66. #endif
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif
  71. /*
  72. * The ICD must reserve space for a pointer for the loader's dispatch
  73. * table, at the start of <each object>.
  74. * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
  75. */
  76. #define ICD_LOADER_MAGIC 0x01CDC0DE
  77. typedef union {
  78. uintptr_t loaderMagic;
  79. void *loaderData;
  80. } VK_LOADER_DATA;
  81. static inline void set_loader_magic_value(void *pNewObject) {
  82. VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
  83. loader_info->loaderMagic = ICD_LOADER_MAGIC;
  84. }
  85. static inline bool valid_loader_magic_value(void *pNewObject) {
  86. const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
  87. return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
  88. }
  89. /*
  90. * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that
  91. * contains the platform-specific connection and surface information.
  92. */
  93. typedef enum {
  94. VK_ICD_WSI_PLATFORM_MIR,
  95. VK_ICD_WSI_PLATFORM_WAYLAND,
  96. VK_ICD_WSI_PLATFORM_WIN32,
  97. VK_ICD_WSI_PLATFORM_XCB,
  98. VK_ICD_WSI_PLATFORM_XLIB,
  99. VK_ICD_WSI_PLATFORM_ANDROID,
  100. VK_ICD_WSI_PLATFORM_MACOS,
  101. VK_ICD_WSI_PLATFORM_IOS,
  102. VK_ICD_WSI_PLATFORM_DISPLAY,
  103. VK_ICD_WSI_PLATFORM_HEADLESS,
  104. VK_ICD_WSI_PLATFORM_METAL,
  105. VK_ICD_WSI_PLATFORM_DIRECTFB,
  106. VK_ICD_WSI_PLATFORM_VI,
  107. VK_ICD_WSI_PLATFORM_GGP,
  108. VK_ICD_WSI_PLATFORM_SCREEN,
  109. VK_ICD_WSI_PLATFORM_FUCHSIA,
  110. } VkIcdWsiPlatform;
  111. typedef struct {
  112. VkIcdWsiPlatform platform;
  113. } VkIcdSurfaceBase;
  114. #ifdef VK_USE_PLATFORM_MIR_KHR
  115. typedef struct {
  116. VkIcdSurfaceBase base;
  117. MirConnection *connection;
  118. MirSurface *mirSurface;
  119. } VkIcdSurfaceMir;
  120. #endif // VK_USE_PLATFORM_MIR_KHR
  121. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  122. typedef struct {
  123. VkIcdSurfaceBase base;
  124. struct wl_display *display;
  125. struct wl_surface *surface;
  126. } VkIcdSurfaceWayland;
  127. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  128. #ifdef VK_USE_PLATFORM_WIN32_KHR
  129. typedef struct {
  130. VkIcdSurfaceBase base;
  131. HINSTANCE hinstance;
  132. HWND hwnd;
  133. } VkIcdSurfaceWin32;
  134. #endif // VK_USE_PLATFORM_WIN32_KHR
  135. #ifdef VK_USE_PLATFORM_XCB_KHR
  136. typedef struct {
  137. VkIcdSurfaceBase base;
  138. xcb_connection_t *connection;
  139. xcb_window_t window;
  140. } VkIcdSurfaceXcb;
  141. #endif // VK_USE_PLATFORM_XCB_KHR
  142. #ifdef VK_USE_PLATFORM_XLIB_KHR
  143. typedef struct {
  144. VkIcdSurfaceBase base;
  145. Display *dpy;
  146. Window window;
  147. } VkIcdSurfaceXlib;
  148. #endif // VK_USE_PLATFORM_XLIB_KHR
  149. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  150. typedef struct {
  151. VkIcdSurfaceBase base;
  152. IDirectFB *dfb;
  153. IDirectFBSurface *surface;
  154. } VkIcdSurfaceDirectFB;
  155. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  156. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  157. typedef struct {
  158. VkIcdSurfaceBase base;
  159. struct ANativeWindow *window;
  160. } VkIcdSurfaceAndroid;
  161. #endif // VK_USE_PLATFORM_ANDROID_KHR
  162. #ifdef VK_USE_PLATFORM_MACOS_MVK
  163. typedef struct {
  164. VkIcdSurfaceBase base;
  165. const void *pView;
  166. } VkIcdSurfaceMacOS;
  167. #endif // VK_USE_PLATFORM_MACOS_MVK
  168. #ifdef VK_USE_PLATFORM_IOS_MVK
  169. typedef struct {
  170. VkIcdSurfaceBase base;
  171. const void *pView;
  172. } VkIcdSurfaceIOS;
  173. #endif // VK_USE_PLATFORM_IOS_MVK
  174. #ifdef VK_USE_PLATFORM_GGP
  175. typedef struct {
  176. VkIcdSurfaceBase base;
  177. GgpStreamDescriptor streamDescriptor;
  178. } VkIcdSurfaceGgp;
  179. #endif // VK_USE_PLATFORM_GGP
  180. typedef struct {
  181. VkIcdSurfaceBase base;
  182. VkDisplayModeKHR displayMode;
  183. uint32_t planeIndex;
  184. uint32_t planeStackIndex;
  185. VkSurfaceTransformFlagBitsKHR transform;
  186. float globalAlpha;
  187. VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
  188. VkExtent2D imageExtent;
  189. } VkIcdSurfaceDisplay;
  190. typedef struct {
  191. VkIcdSurfaceBase base;
  192. } VkIcdSurfaceHeadless;
  193. #ifdef VK_USE_PLATFORM_METAL_EXT
  194. typedef struct {
  195. VkIcdSurfaceBase base;
  196. const CAMetalLayer *pLayer;
  197. } VkIcdSurfaceMetal;
  198. #endif // VK_USE_PLATFORM_METAL_EXT
  199. #ifdef VK_USE_PLATFORM_VI_NN
  200. typedef struct {
  201. VkIcdSurfaceBase base;
  202. void *window;
  203. } VkIcdSurfaceVi;
  204. #endif // VK_USE_PLATFORM_VI_NN
  205. #ifdef VK_USE_PLATFORM_SCREEN_QNX
  206. typedef struct {
  207. VkIcdSurfaceBase base;
  208. struct _screen_context *context;
  209. struct _screen_window *window;
  210. } VkIcdSurfaceScreen;
  211. #endif // VK_USE_PLATFORM_SCREEN_QNX
  212. #ifdef VK_USE_PLATFORM_FUCHSIA
  213. typedef struct {
  214. VkIcdSurfaceBase base;
  215. } VkIcdSurfaceImagePipe;
  216. #endif // VK_USE_PLATFORM_FUCHSIA