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 querying 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 50typedef 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 54typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName); 55#endif 56 57// 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 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 91typedef union { 92 uintptr_t loaderMagic; 93 void *loaderData; 94} VK_LOADER_DATA; 95 96static 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 101static 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 */ 110typedef 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 VK_ICD_WSI_PLATFORM_SCREEN, 126} VkIcdWsiPlatform; 127 128typedef struct { 129 VkIcdWsiPlatform platform; 130} VkIcdSurfaceBase; 131 132#ifdef VK_USE_PLATFORM_MIR_KHR 133typedef struct { 134 VkIcdSurfaceBase base; 135 MirConnection *connection; 136 MirSurface *mirSurface; 137} VkIcdSurfaceMir; 138#endif // VK_USE_PLATFORM_MIR_KHR 139 140#ifdef VK_USE_PLATFORM_WAYLAND_KHR 141typedef struct { 142 VkIcdSurfaceBase base; 143 struct wl_display *display; 144 struct wl_surface *surface; 145} VkIcdSurfaceWayland; 146#endif // VK_USE_PLATFORM_WAYLAND_KHR 147 148#ifdef VK_USE_PLATFORM_WIN32_KHR 149typedef struct { 150 VkIcdSurfaceBase base; 151 HINSTANCE hinstance; 152 HWND hwnd; 153} VkIcdSurfaceWin32; 154#endif // VK_USE_PLATFORM_WIN32_KHR 155 156#ifdef VK_USE_PLATFORM_XCB_KHR 157typedef struct { 158 VkIcdSurfaceBase base; 159 xcb_connection_t *connection; 160 xcb_window_t window; 161} VkIcdSurfaceXcb; 162#endif // VK_USE_PLATFORM_XCB_KHR 163 164#ifdef VK_USE_PLATFORM_XLIB_KHR 165typedef struct { 166 VkIcdSurfaceBase base; 167 Display *dpy; 168 Window window; 169} VkIcdSurfaceXlib; 170#endif // VK_USE_PLATFORM_XLIB_KHR 171 172#ifdef VK_USE_PLATFORM_DIRECTFB_EXT 173typedef struct { 174 VkIcdSurfaceBase base; 175 IDirectFB *dfb; 176 IDirectFBSurface *surface; 177} VkIcdSurfaceDirectFB; 178#endif // VK_USE_PLATFORM_DIRECTFB_EXT 179 180#ifdef VK_USE_PLATFORM_ANDROID_KHR 181typedef struct { 182 VkIcdSurfaceBase base; 183 struct ANativeWindow *window; 184} VkIcdSurfaceAndroid; 185#endif // VK_USE_PLATFORM_ANDROID_KHR 186 187#ifdef VK_USE_PLATFORM_MACOS_MVK 188typedef struct { 189 VkIcdSurfaceBase base; 190 const void *pView; 191} VkIcdSurfaceMacOS; 192#endif // VK_USE_PLATFORM_MACOS_MVK 193 194#ifdef VK_USE_PLATFORM_IOS_MVK 195typedef struct { 196 VkIcdSurfaceBase base; 197 const void *pView; 198} VkIcdSurfaceIOS; 199#endif // VK_USE_PLATFORM_IOS_MVK 200 201#ifdef VK_USE_PLATFORM_GGP 202typedef struct { 203 VkIcdSurfaceBase base; 204 GgpStreamDescriptor streamDescriptor; 205} VkIcdSurfaceGgp; 206#endif // VK_USE_PLATFORM_GGP 207 208typedef struct { 209 VkIcdSurfaceBase base; 210 VkDisplayModeKHR displayMode; 211 uint32_t planeIndex; 212 uint32_t planeStackIndex; 213 VkSurfaceTransformFlagBitsKHR transform; 214 float globalAlpha; 215 VkDisplayPlaneAlphaFlagBitsKHR alphaMode; 216 VkExtent2D imageExtent; 217} VkIcdSurfaceDisplay; 218 219typedef struct { 220 VkIcdSurfaceBase base; 221} VkIcdSurfaceHeadless; 222 223#ifdef VK_USE_PLATFORM_METAL_EXT 224typedef struct { 225 VkIcdSurfaceBase base; 226 const CAMetalLayer *pLayer; 227} VkIcdSurfaceMetal; 228#endif // VK_USE_PLATFORM_METAL_EXT 229 230#ifdef VK_USE_PLATFORM_VI_NN 231typedef struct { 232 VkIcdSurfaceBase base; 233 void *window; 234} VkIcdSurfaceVi; 235#endif // VK_USE_PLATFORM_VI_NN 236 237#ifdef VK_USE_PLATFORM_SCREEN_QNX 238typedef struct { 239 VkIcdSurfaceBase base; 240 struct _screen_context *context; 241 struct _screen_window *window; 242} VkIcdSurfaceScreen; 243#endif // VK_USE_PLATFORM_SCREEN_QNX 244 245#endif // VKICD_H 246