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