vk_icd.h 7.8 KB

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