Coverage Report

Created: 2023-06-07 06:30

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