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
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 #define CURRENT_LOADER_ICD_INTERFACE_VERSION 6
46 #define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0
47 #define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4
48
49 // Old typedefs that don't follow a proper naming convention but are preserved for compatibility
50 typedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion);
51 // This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this
52 // file directly, it won't be found.
53 #ifndef PFN_GetPhysicalDeviceProcAddr
54 typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
55 #endif
56
57 // Typedefs for loader/ICD interface
58 typedef VkResult (VKAPI_PTR *PFN_vk_icdNegotiateLoaderICDInterfaceVersion)(uint32_t* pVersion);
59 typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName);
60 typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
61 #if defined(VK_USE_PLATFORM_WIN32_KHR)
62 typedef VkResult (VKAPI_PTR *PFN_vk_icdEnumerateAdapterPhysicalDevices)(VkInstance instance, LUID adapterLUID,
63 uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
64 #endif
65
66 // Prototypes for loader/ICD interface
67 #if !defined(VK_NO_PROTOTYPES)
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pVersion);
72 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
73 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance isntance, const char* pName);
74 #if defined(VK_USE_PLATFORM_WIN32_KHR)
75 VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
76 uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
77 #endif
78 #ifdef __cplusplus
79 }
80 #endif
81 #endif
82
83 /*
84 * The ICD must reserve space for a pointer for the loader's dispatch
85 * table, at the start of <each object>.
86 * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
87 */
88
89 #define ICD_LOADER_MAGIC 0x01CDC0DE
90
91 typedef union {
92 uintptr_t loaderMagic;
93 void *loaderData;
94 } VK_LOADER_DATA;
95
set_loader_magic_value(void * pNewObject)96 static inline void set_loader_magic_value(void *pNewObject) {
97 VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
98 loader_info->loaderMagic = ICD_LOADER_MAGIC;
99 }
100
valid_loader_magic_value(void * pNewObject)101 static inline bool valid_loader_magic_value(void *pNewObject) {
102 const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
103 return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
104 }
105
106 /*
107 * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that
108 * contains the platform-specific connection and surface information.
109 */
110 typedef enum {
111 VK_ICD_WSI_PLATFORM_MIR,
112 VK_ICD_WSI_PLATFORM_WAYLAND,
113 VK_ICD_WSI_PLATFORM_WIN32,
114 VK_ICD_WSI_PLATFORM_XCB,
115 VK_ICD_WSI_PLATFORM_XLIB,
116 VK_ICD_WSI_PLATFORM_ANDROID,
117 VK_ICD_WSI_PLATFORM_MACOS,
118 VK_ICD_WSI_PLATFORM_IOS,
119 VK_ICD_WSI_PLATFORM_DISPLAY,
120 VK_ICD_WSI_PLATFORM_HEADLESS,
121 VK_ICD_WSI_PLATFORM_METAL,
122 VK_ICD_WSI_PLATFORM_DIRECTFB,
123 VK_ICD_WSI_PLATFORM_VI,
124 VK_ICD_WSI_PLATFORM_GGP,
125 VK_ICD_WSI_PLATFORM_SCREEN,
126 VK_ICD_WSI_PLATFORM_OHOS,
127 } VkIcdWsiPlatform;
128
129 typedef struct {
130 VkIcdWsiPlatform platform;
131 } VkIcdSurfaceBase;
132
133 #ifdef VK_USE_PLATFORM_MIR_KHR
134 typedef struct {
135 VkIcdSurfaceBase base;
136 MirConnection *connection;
137 MirSurface *mirSurface;
138 } VkIcdSurfaceMir;
139 #endif // VK_USE_PLATFORM_MIR_KHR
140
141 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
142 typedef struct {
143 VkIcdSurfaceBase base;
144 struct wl_display *display;
145 struct wl_surface *surface;
146 } VkIcdSurfaceWayland;
147 #endif // VK_USE_PLATFORM_WAYLAND_KHR
148
149 #ifdef VK_USE_PLATFORM_WIN32_KHR
150 typedef struct {
151 VkIcdSurfaceBase base;
152 HINSTANCE hinstance;
153 HWND hwnd;
154 } VkIcdSurfaceWin32;
155 #endif // VK_USE_PLATFORM_WIN32_KHR
156
157 #ifdef VK_USE_PLATFORM_XCB_KHR
158 typedef struct {
159 VkIcdSurfaceBase base;
160 xcb_connection_t *connection;
161 xcb_window_t window;
162 } VkIcdSurfaceXcb;
163 #endif // VK_USE_PLATFORM_XCB_KHR
164
165 #ifdef VK_USE_PLATFORM_XLIB_KHR
166 typedef struct {
167 VkIcdSurfaceBase base;
168 Display *dpy;
169 Window window;
170 } VkIcdSurfaceXlib;
171 #endif // VK_USE_PLATFORM_XLIB_KHR
172
173 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
174 typedef struct {
175 VkIcdSurfaceBase base;
176 IDirectFB *dfb;
177 IDirectFBSurface *surface;
178 } VkIcdSurfaceDirectFB;
179 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
180
181 #ifdef VK_USE_PLATFORM_ANDROID_KHR
182 typedef struct {
183 VkIcdSurfaceBase base;
184 struct ANativeWindow *window;
185 } VkIcdSurfaceAndroid;
186 #endif // VK_USE_PLATFORM_ANDROID_KHR
187
188 #ifdef VK_USE_PLATFORM_MACOS_MVK
189 typedef struct {
190 VkIcdSurfaceBase base;
191 const void *pView;
192 } VkIcdSurfaceMacOS;
193 #endif // VK_USE_PLATFORM_MACOS_MVK
194
195 #ifdef VK_USE_PLATFORM_IOS_MVK
196 typedef struct {
197 VkIcdSurfaceBase base;
198 const void *pView;
199 } VkIcdSurfaceIOS;
200 #endif // VK_USE_PLATFORM_IOS_MVK
201
202 #ifdef VK_USE_PLATFORM_GGP
203 typedef struct {
204 VkIcdSurfaceBase base;
205 GgpStreamDescriptor streamDescriptor;
206 } VkIcdSurfaceGgp;
207 #endif // VK_USE_PLATFORM_GGP
208
209 typedef struct {
210 VkIcdSurfaceBase base;
211 VkDisplayModeKHR displayMode;
212 uint32_t planeIndex;
213 uint32_t planeStackIndex;
214 VkSurfaceTransformFlagBitsKHR transform;
215 float globalAlpha;
216 VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
217 VkExtent2D imageExtent;
218 } VkIcdSurfaceDisplay;
219
220 typedef struct {
221 VkIcdSurfaceBase base;
222 } VkIcdSurfaceHeadless;
223
224 #ifdef VK_USE_PLATFORM_METAL_EXT
225 typedef struct {
226 VkIcdSurfaceBase base;
227 const CAMetalLayer *pLayer;
228 } VkIcdSurfaceMetal;
229 #endif // VK_USE_PLATFORM_METAL_EXT
230
231 #ifdef VK_USE_PLATFORM_VI_NN
232 typedef struct {
233 VkIcdSurfaceBase base;
234 void *window;
235 } VkIcdSurfaceVi;
236 #endif // VK_USE_PLATFORM_VI_NN
237
238 #ifdef VK_USE_PLATFORM_SCREEN_QNX
239 typedef struct {
240 VkIcdSurfaceBase base;
241 struct _screen_context *context;
242 struct _screen_window *window;
243 } VkIcdSurfaceScreen;
244 #endif // VK_USE_PLATFORM_SCREEN_QNX
245
246 #ifdef VK_USE_PLATFORM_OHOS
247 typedef struct {
248 VkIcdSurfaceBase base;
249 struct NativeWindow *window;
250 } VkIcdSurfaceOHOS;
251 #endif // VK_USE_PLATFORM_OHOS
252 #endif // VKICD_H
253