Coverage Report

Created: 2026-01-10 07:02

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