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