blob: fde5bf6214bdb3997dc94f6c6fd2e77c5296ef8b [file] [log] [blame]
Chad Versace98cf0892017-01-10 12:40:55 -08001//
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
Jason Ekstrandd4953fb2016-01-28 13:36:41 -080023#ifndef VKICD_H
24#define VKICD_H
25
Chad Versace98cf0892017-01-10 12:40:55 -080026#include "vulkan.h"
Tapani Pälli437acae2018-05-18 08:01:39 +030027#include <stdbool.h>
Jason Ekstrandd4953fb2016-01-28 13:36:41 -080028
Tapani Pälli437acae2018-05-18 08:01:39 +030029// 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.
Lionel Landwerlin4c1c5462020-07-15 11:03:10 +030044// Version 6 - Add support for vk_icdEnumerateAdapterPhysicalDevices.
45#define CURRENT_LOADER_ICD_INTERFACE_VERSION 6
Chad Versace98cf0892017-01-10 12:40:55 -080046#define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0
Tapani Pälli437acae2018-05-18 08:01:39 +030047#define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4
Tapani Pälli437acae2018-05-18 08:01:39 +030048
Lionel Landwerlin4c1c5462020-07-15 11:03:10 +030049// Old typedefs that don't follow a proper naming convention but are preserved for compatibility
50typedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion);
Tapani Pälli437acae2018-05-18 08:01:39 +030051// 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
54typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
55#endif
56
Lionel Landwerlin4c1c5462020-07-15 11:03:10 +030057// Typedefs for loader/ICD interface
58typedef VkResult (VKAPI_PTR *PFN_vk_icdNegotiateLoaderICDInterfaceVersion)(uint32_t* pVersion);
59typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName);
60typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
61#if defined(VK_USE_PLATFORM_WIN32_KHR)
62typedef 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
69extern "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
Chad Versace98cf0892017-01-10 12:40:55 -080083/*
Jason Ekstrandd4953fb2016-01-28 13:36:41 -080084 * 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
Chad Versace98cf0892017-01-10 12:40:55 -080089#define ICD_LOADER_MAGIC 0x01CDC0DE
Jason Ekstrandd4953fb2016-01-28 13:36:41 -080090
Chad Versace98cf0892017-01-10 12:40:55 -080091typedef union {
92 uintptr_t loaderMagic;
93 void *loaderData;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -080094} VK_LOADER_DATA;
95
Chad Versace98cf0892017-01-10 12:40:55 -080096static inline void set_loader_magic_value(void *pNewObject) {
97 VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -080098 loader_info->loaderMagic = ICD_LOADER_MAGIC;
99}
100
Chad Versace98cf0892017-01-10 12:40:55 -0800101static inline bool valid_loader_magic_value(void *pNewObject) {
102 const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800103 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 */
Chad Versace98cf0892017-01-10 12:40:55 -0800110typedef enum {
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800111 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,
Tapani Pälli437acae2018-05-18 08:01:39 +0300116 VK_ICD_WSI_PLATFORM_ANDROID,
117 VK_ICD_WSI_PLATFORM_MACOS,
118 VK_ICD_WSI_PLATFORM_IOS,
Andres Gomez40004282019-07-03 17:02:42 +0300119 VK_ICD_WSI_PLATFORM_DISPLAY,
Caio Marcelo de Oliveira Filho3f304612019-10-07 08:19:20 -0700120 VK_ICD_WSI_PLATFORM_HEADLESS,
121 VK_ICD_WSI_PLATFORM_METAL,
Lionel Landwerlin4c1c5462020-07-15 11:03:10 +0300122 VK_ICD_WSI_PLATFORM_DIRECTFB,
123 VK_ICD_WSI_PLATFORM_VI,
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800124} VkIcdWsiPlatform;
125
Chad Versace98cf0892017-01-10 12:40:55 -0800126typedef struct {
127 VkIcdWsiPlatform platform;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800128} VkIcdSurfaceBase;
129
130#ifdef VK_USE_PLATFORM_MIR_KHR
Chad Versace98cf0892017-01-10 12:40:55 -0800131typedef struct {
132 VkIcdSurfaceBase base;
133 MirConnection *connection;
134 MirSurface *mirSurface;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800135} VkIcdSurfaceMir;
Tapani Pälli437acae2018-05-18 08:01:39 +0300136#endif // VK_USE_PLATFORM_MIR_KHR
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800137
138#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Chad Versace98cf0892017-01-10 12:40:55 -0800139typedef struct {
140 VkIcdSurfaceBase base;
141 struct wl_display *display;
142 struct wl_surface *surface;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800143} VkIcdSurfaceWayland;
Tapani Pälli437acae2018-05-18 08:01:39 +0300144#endif // VK_USE_PLATFORM_WAYLAND_KHR
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800145
146#ifdef VK_USE_PLATFORM_WIN32_KHR
Chad Versace98cf0892017-01-10 12:40:55 -0800147typedef struct {
148 VkIcdSurfaceBase base;
149 HINSTANCE hinstance;
150 HWND hwnd;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800151} VkIcdSurfaceWin32;
Tapani Pälli437acae2018-05-18 08:01:39 +0300152#endif // VK_USE_PLATFORM_WIN32_KHR
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800153
154#ifdef VK_USE_PLATFORM_XCB_KHR
Chad Versace98cf0892017-01-10 12:40:55 -0800155typedef struct {
156 VkIcdSurfaceBase base;
157 xcb_connection_t *connection;
158 xcb_window_t window;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800159} VkIcdSurfaceXcb;
Tapani Pälli437acae2018-05-18 08:01:39 +0300160#endif // VK_USE_PLATFORM_XCB_KHR
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800161
162#ifdef VK_USE_PLATFORM_XLIB_KHR
Chad Versace98cf0892017-01-10 12:40:55 -0800163typedef struct {
164 VkIcdSurfaceBase base;
165 Display *dpy;
166 Window window;
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800167} VkIcdSurfaceXlib;
Tapani Pälli437acae2018-05-18 08:01:39 +0300168#endif // VK_USE_PLATFORM_XLIB_KHR
Jason Ekstrandd4953fb2016-01-28 13:36:41 -0800169
Lionel Landwerlin4c1c5462020-07-15 11:03:10 +0300170#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
171typedef struct {
172 VkIcdSurfaceBase base;
173 IDirectFB *dfb;
174 IDirectFBSurface *surface;
175} VkIcdSurfaceDirectFB;
176#endif // VK_USE_PLATFORM_DIRECTFB_EXT
177
Chad Versace98cf0892017-01-10 12:40:55 -0800178#ifdef VK_USE_PLATFORM_ANDROID_KHR
179typedef struct {
Tapani Pälli437acae2018-05-18 08:01:39 +0300180 VkIcdSurfaceBase base;
181 struct ANativeWindow *window;
Chad Versace98cf0892017-01-10 12:40:55 -0800182} VkIcdSurfaceAndroid;
Tapani Pälli437acae2018-05-18 08:01:39 +0300183#endif // VK_USE_PLATFORM_ANDROID_KHR
184
185#ifdef VK_USE_PLATFORM_MACOS_MVK
186typedef struct {
187 VkIcdSurfaceBase base;
188 const void *pView;
189} VkIcdSurfaceMacOS;
190#endif // VK_USE_PLATFORM_MACOS_MVK
191
192#ifdef VK_USE_PLATFORM_IOS_MVK
193typedef struct {
194 VkIcdSurfaceBase base;
195 const void *pView;
196} VkIcdSurfaceIOS;
197#endif // VK_USE_PLATFORM_IOS_MVK
Chad Versace98cf0892017-01-10 12:40:55 -0800198
199typedef struct {
200 VkIcdSurfaceBase base;
201 VkDisplayModeKHR displayMode;
202 uint32_t planeIndex;
203 uint32_t planeStackIndex;
204 VkSurfaceTransformFlagBitsKHR transform;
205 float globalAlpha;
206 VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
207 VkExtent2D imageExtent;
208} VkIcdSurfaceDisplay;
209
Andres Gomez40004282019-07-03 17:02:42 +0300210typedef struct {
211 VkIcdSurfaceBase base;
212} VkIcdSurfaceHeadless;
213
Caio Marcelo de Oliveira Filho3f304612019-10-07 08:19:20 -0700214#ifdef VK_USE_PLATFORM_METAL_EXT
215typedef struct {
216 VkIcdSurfaceBase base;
217 const CAMetalLayer *pLayer;
218} VkIcdSurfaceMetal;
219#endif // VK_USE_PLATFORM_METAL_EXT
220
Lionel Landwerlin4c1c5462020-07-15 11:03:10 +0300221#ifdef VK_USE_PLATFORM_VI_NN
222typedef struct {
223 VkIcdSurfaceBase base;
224 void *window;
225} VkIcdSurfaceVi;
226#endif // VK_USE_PLATFORM_VI_NN
227
Tapani Pälli437acae2018-05-18 08:01:39 +0300228#endif // VKICD_H