| 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 |
|
| 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 |
|
| 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 |
} VkIcdWsiPlatform; |
| 125 |
|
| 126 |
typedef struct { |
| 127 |
VkIcdWsiPlatform platform; |
| 128 |
} VkIcdSurfaceBase; |
| 129 |
|
| 130 |
#ifdef VK_USE_PLATFORM_MIR_KHR |
| 131 |
typedef struct { |
| 132 |
VkIcdSurfaceBase base; |
| 133 |
MirConnection *connection; |
| 134 |
MirSurface *mirSurface; |
| 135 |
} VkIcdSurfaceMir; |
| 136 |
#endif // VK_USE_PLATFORM_MIR_KHR |
| 137 |
|
| 138 |
#ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 139 |
typedef struct { |
| 140 |
VkIcdSurfaceBase base; |
| 141 |
struct wl_display *display; |
| 142 |
struct wl_surface *surface; |
| 143 |
} VkIcdSurfaceWayland; |
| 144 |
#endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 145 |
|
| 146 |
#ifdef VK_USE_PLATFORM_WIN32_KHR |
| 147 |
typedef struct { |
| 148 |
VkIcdSurfaceBase base; |
| 149 |
HINSTANCE hinstance; |
| 150 |
HWND hwnd; |
| 151 |
} VkIcdSurfaceWin32; |
| 152 |
#endif // VK_USE_PLATFORM_WIN32_KHR |
| 153 |
|
| 154 |
#ifdef VK_USE_PLATFORM_XCB_KHR |
| 155 |
typedef struct { |
| 156 |
VkIcdSurfaceBase base; |
| 157 |
xcb_connection_t *connection; |
| 158 |
xcb_window_t window; |
| 159 |
} VkIcdSurfaceXcb; |
| 160 |
#endif // VK_USE_PLATFORM_XCB_KHR |
| 161 |
|
| 162 |
#ifdef VK_USE_PLATFORM_XLIB_KHR |
| 163 |
typedef struct { |
| 164 |
VkIcdSurfaceBase base; |
| 165 |
Display *dpy; |
| 166 |
Window window; |
| 167 |
} VkIcdSurfaceXlib; |
| 168 |
#endif // VK_USE_PLATFORM_XLIB_KHR |
| 169 |
|
| 170 |
#ifdef VK_USE_PLATFORM_DIRECTFB_EXT |
| 171 |
typedef struct { |
| 172 |
VkIcdSurfaceBase base; |
| 173 |
IDirectFB *dfb; |
| 174 |
IDirectFBSurface *surface; |
| 175 |
} VkIcdSurfaceDirectFB; |
| 176 |
#endif // VK_USE_PLATFORM_DIRECTFB_EXT |
| 177 |
|
| 178 |
#ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 179 |
typedef struct { |
| 180 |
VkIcdSurfaceBase base; |
| 181 |
struct ANativeWindow *window; |
| 182 |
} VkIcdSurfaceAndroid; |
| 183 |
#endif // VK_USE_PLATFORM_ANDROID_KHR |
| 184 |
|
| 185 |
#ifdef VK_USE_PLATFORM_MACOS_MVK |
| 186 |
typedef 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 |
| 193 |
typedef struct { |
| 194 |
VkIcdSurfaceBase base; |
| 195 |
const void *pView; |
| 196 |
} VkIcdSurfaceIOS; |
| 197 |
#endif // VK_USE_PLATFORM_IOS_MVK |
| 198 |
|
| 199 |
typedef 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 |
|
| 210 |
typedef struct { |
| 211 |
VkIcdSurfaceBase base; |
| 212 |
} VkIcdSurfaceHeadless; |
| 213 |
|
| 214 |
#ifdef VK_USE_PLATFORM_METAL_EXT |
| 215 |
typedef struct { |
| 216 |
VkIcdSurfaceBase base; |
| 217 |
const CAMetalLayer *pLayer; |
| 218 |
} VkIcdSurfaceMetal; |
| 219 |
#endif // VK_USE_PLATFORM_METAL_EXT |
| 220 |
|
| 221 |
#ifdef VK_USE_PLATFORM_VI_NN |
| 222 |
typedef struct { |
| 223 |
VkIcdSurfaceBase base; |
| 224 |
void *window; |
| 225 |
} VkIcdSurfaceVi; |
| 226 |
#endif // VK_USE_PLATFORM_VI_NN |
| 227 |
|
| 228 |
#endif // VKICD_H |