vk_icd.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. } VkIcdWsiPlatform;
  114. typedef struct {
  115. VkIcdWsiPlatform platform;
  116. } VkIcdSurfaceBase;
  117. #ifdef VK_USE_PLATFORM_MIR_KHR
  118. typedef struct {
  119. VkIcdSurfaceBase base;
  120. MirConnection *connection;
  121. MirSurface *mirSurface;
  122. } VkIcdSurfaceMir;
  123. #endif // VK_USE_PLATFORM_MIR_KHR
  124. #ifdef VK_USE_PLATFORM_WAYLAND_KHR
  125. typedef struct {
  126. VkIcdSurfaceBase base;
  127. struct wl_display *display;
  128. struct wl_surface *surface;
  129. } VkIcdSurfaceWayland;
  130. #endif // VK_USE_PLATFORM_WAYLAND_KHR
  131. #ifdef VK_USE_PLATFORM_WIN32_KHR
  132. typedef struct {
  133. VkIcdSurfaceBase base;
  134. HINSTANCE hinstance;
  135. HWND hwnd;
  136. } VkIcdSurfaceWin32;
  137. #endif // VK_USE_PLATFORM_WIN32_KHR
  138. #ifdef VK_USE_PLATFORM_XCB_KHR
  139. typedef struct {
  140. VkIcdSurfaceBase base;
  141. xcb_connection_t *connection;
  142. xcb_window_t window;
  143. } VkIcdSurfaceXcb;
  144. #endif // VK_USE_PLATFORM_XCB_KHR
  145. #ifdef VK_USE_PLATFORM_XLIB_KHR
  146. typedef struct {
  147. VkIcdSurfaceBase base;
  148. Display *dpy;
  149. Window window;
  150. } VkIcdSurfaceXlib;
  151. #endif // VK_USE_PLATFORM_XLIB_KHR
  152. #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
  153. typedef struct {
  154. VkIcdSurfaceBase base;
  155. IDirectFB *dfb;
  156. IDirectFBSurface *surface;
  157. } VkIcdSurfaceDirectFB;
  158. #endif // VK_USE_PLATFORM_DIRECTFB_EXT
  159. #ifdef VK_USE_PLATFORM_ANDROID_KHR
  160. typedef struct {
  161. VkIcdSurfaceBase base;
  162. struct ANativeWindow *window;
  163. } VkIcdSurfaceAndroid;
  164. #endif // VK_USE_PLATFORM_ANDROID_KHR
  165. #ifdef VK_USE_PLATFORM_MACOS_MVK
  166. typedef struct {
  167. VkIcdSurfaceBase base;
  168. const void *pView;
  169. } VkIcdSurfaceMacOS;
  170. #endif // VK_USE_PLATFORM_MACOS_MVK
  171. #ifdef VK_USE_PLATFORM_IOS_MVK
  172. typedef struct {
  173. VkIcdSurfaceBase base;
  174. const void *pView;
  175. } VkIcdSurfaceIOS;
  176. #endif // VK_USE_PLATFORM_IOS_MVK
  177. #ifdef VK_USE_PLATFORM_GGP
  178. typedef struct {
  179. VkIcdSurfaceBase base;
  180. GgpStreamDescriptor streamDescriptor;
  181. } VkIcdSurfaceGgp;
  182. #endif // VK_USE_PLATFORM_GGP
  183. typedef struct {
  184. VkIcdSurfaceBase base;
  185. VkDisplayModeKHR displayMode;
  186. uint32_t planeIndex;
  187. uint32_t planeStackIndex;
  188. VkSurfaceTransformFlagBitsKHR transform;
  189. float globalAlpha;
  190. VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
  191. VkExtent2D imageExtent;
  192. } VkIcdSurfaceDisplay;
  193. typedef struct {
  194. VkIcdSurfaceBase base;
  195. } VkIcdSurfaceHeadless;
  196. #ifdef VK_USE_PLATFORM_METAL_EXT
  197. typedef struct {
  198. VkIcdSurfaceBase base;
  199. const CAMetalLayer *pLayer;
  200. } VkIcdSurfaceMetal;
  201. #endif // VK_USE_PLATFORM_METAL_EXT
  202. #ifdef VK_USE_PLATFORM_VI_NN
  203. typedef struct {
  204. VkIcdSurfaceBase base;
  205. void *window;
  206. } VkIcdSurfaceVi;
  207. #endif // VK_USE_PLATFORM_VI_NN
  208. #endif // VKICD_H