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