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