• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 qyering 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 } VkIcdWsiPlatform;
126 
127 typedef struct {
128     VkIcdWsiPlatform platform;
129 } VkIcdSurfaceBase;
130 
131 #ifdef VK_USE_PLATFORM_MIR_KHR
132 typedef struct {
133     VkIcdSurfaceBase base;
134     MirConnection *connection;
135     MirSurface *mirSurface;
136 } VkIcdSurfaceMir;
137 #endif  // VK_USE_PLATFORM_MIR_KHR
138 
139 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
140 typedef struct {
141     VkIcdSurfaceBase base;
142     struct wl_display *display;
143     struct wl_surface *surface;
144 } VkIcdSurfaceWayland;
145 #endif  // VK_USE_PLATFORM_WAYLAND_KHR
146 
147 #ifdef VK_USE_PLATFORM_WIN32_KHR
148 typedef struct {
149     VkIcdSurfaceBase base;
150     HINSTANCE hinstance;
151     HWND hwnd;
152 } VkIcdSurfaceWin32;
153 #endif  // VK_USE_PLATFORM_WIN32_KHR
154 
155 #ifdef VK_USE_PLATFORM_XCB_KHR
156 typedef struct {
157     VkIcdSurfaceBase base;
158     xcb_connection_t *connection;
159     xcb_window_t window;
160 } VkIcdSurfaceXcb;
161 #endif  // VK_USE_PLATFORM_XCB_KHR
162 
163 #ifdef VK_USE_PLATFORM_XLIB_KHR
164 typedef struct {
165     VkIcdSurfaceBase base;
166     Display *dpy;
167     Window window;
168 } VkIcdSurfaceXlib;
169 #endif  // VK_USE_PLATFORM_XLIB_KHR
170 
171 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
172 typedef struct {
173     VkIcdSurfaceBase base;
174     IDirectFB *dfb;
175     IDirectFBSurface *surface;
176 } VkIcdSurfaceDirectFB;
177 #endif  // VK_USE_PLATFORM_DIRECTFB_EXT
178 
179 #ifdef VK_USE_PLATFORM_ANDROID_KHR
180 typedef struct {
181     VkIcdSurfaceBase base;
182     struct ANativeWindow *window;
183 } VkIcdSurfaceAndroid;
184 #endif  // VK_USE_PLATFORM_ANDROID_KHR
185 
186 #ifdef VK_USE_PLATFORM_MACOS_MVK
187 typedef struct {
188     VkIcdSurfaceBase base;
189     const void *pView;
190 } VkIcdSurfaceMacOS;
191 #endif  // VK_USE_PLATFORM_MACOS_MVK
192 
193 #ifdef VK_USE_PLATFORM_IOS_MVK
194 typedef struct {
195     VkIcdSurfaceBase base;
196     const void *pView;
197 } VkIcdSurfaceIOS;
198 #endif  // VK_USE_PLATFORM_IOS_MVK
199 
200 #ifdef VK_USE_PLATFORM_GGP
201 typedef struct {
202     VkIcdSurfaceBase base;
203     GgpStreamDescriptor streamDescriptor;
204 } VkIcdSurfaceGgp;
205 #endif  // VK_USE_PLATFORM_GGP
206 
207 typedef struct {
208     VkIcdSurfaceBase base;
209     VkDisplayModeKHR displayMode;
210     uint32_t planeIndex;
211     uint32_t planeStackIndex;
212     VkSurfaceTransformFlagBitsKHR transform;
213     float globalAlpha;
214     VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
215     VkExtent2D imageExtent;
216 } VkIcdSurfaceDisplay;
217 
218 typedef struct {
219     VkIcdSurfaceBase base;
220 } VkIcdSurfaceHeadless;
221 
222 #ifdef VK_USE_PLATFORM_METAL_EXT
223 typedef struct {
224     VkIcdSurfaceBase base;
225     const CAMetalLayer *pLayer;
226 } VkIcdSurfaceMetal;
227 #endif // VK_USE_PLATFORM_METAL_EXT
228 
229 #ifdef VK_USE_PLATFORM_VI_NN
230 typedef struct {
231     VkIcdSurfaceBase base;
232     void *window;
233 } VkIcdSurfaceVi;
234 #endif // VK_USE_PLATFORM_VI_NN
235 
236 #endif  // VKICD_H
237