101e04c3fSmrg//
201e04c3fSmrg// File: vk_icd.h
301e04c3fSmrg//
401e04c3fSmrg/*
501e04c3fSmrg * Copyright (c) 2015-2016 The Khronos Group Inc.
601e04c3fSmrg * Copyright (c) 2015-2016 Valve Corporation
701e04c3fSmrg * Copyright (c) 2015-2016 LunarG, Inc.
801e04c3fSmrg *
901e04c3fSmrg * Licensed under the Apache License, Version 2.0 (the "License");
1001e04c3fSmrg * you may not use this file except in compliance with the License.
1101e04c3fSmrg * You may obtain a copy of the License at
1201e04c3fSmrg *
1301e04c3fSmrg *     http://www.apache.org/licenses/LICENSE-2.0
1401e04c3fSmrg *
1501e04c3fSmrg * Unless required by applicable law or agreed to in writing, software
1601e04c3fSmrg * distributed under the License is distributed on an "AS IS" BASIS,
1701e04c3fSmrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1801e04c3fSmrg * See the License for the specific language governing permissions and
1901e04c3fSmrg * limitations under the License.
2001e04c3fSmrg *
2101e04c3fSmrg */
2201e04c3fSmrg
2301e04c3fSmrg#ifndef VKICD_H
2401e04c3fSmrg#define VKICD_H
2501e04c3fSmrg
2601e04c3fSmrg#include "vulkan.h"
2701e04c3fSmrg#include <stdbool.h>
2801e04c3fSmrg
2901e04c3fSmrg// Loader-ICD version negotiation API.  Versions add the following features:
3001e04c3fSmrg//   Version 0 - Initial.  Doesn't support vk_icdGetInstanceProcAddr
3101e04c3fSmrg//               or vk_icdNegotiateLoaderICDInterfaceVersion.
3201e04c3fSmrg//   Version 1 - Add support for vk_icdGetInstanceProcAddr.
3301e04c3fSmrg//   Version 2 - Add Loader/ICD Interface version negotiation
3401e04c3fSmrg//               via vk_icdNegotiateLoaderICDInterfaceVersion.
3501e04c3fSmrg//   Version 3 - Add ICD creation/destruction of KHR_surface objects.
3601e04c3fSmrg//   Version 4 - Add unknown physical device extension qyering via
3701e04c3fSmrg//               vk_icdGetPhysicalDeviceProcAddr.
3801e04c3fSmrg//   Version 5 - Tells ICDs that the loader is now paying attention to the
3901e04c3fSmrg//               application version of Vulkan passed into the ApplicationInfo
4001e04c3fSmrg//               structure during vkCreateInstance.  This will tell the ICD
4101e04c3fSmrg//               that if the loader is older, it should automatically fail a
4201e04c3fSmrg//               call for any API version > 1.0.  Otherwise, the loader will
4301e04c3fSmrg//               manually determine if it can support the expected version.
447ec681f3Smrg//   Version 6 - Add support for vk_icdEnumerateAdapterPhysicalDevices.
457ec681f3Smrg#define CURRENT_LOADER_ICD_INTERFACE_VERSION 6
4601e04c3fSmrg#define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0
4701e04c3fSmrg#define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4
4801e04c3fSmrg
497ec681f3Smrg// Old typedefs that don't follow a proper naming convention but are preserved for compatibility
507ec681f3Smrgtypedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion);
5101e04c3fSmrg// This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this
5201e04c3fSmrg// file directly, it won't be found.
5301e04c3fSmrg#ifndef PFN_GetPhysicalDeviceProcAddr
5401e04c3fSmrgtypedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
5501e04c3fSmrg#endif
5601e04c3fSmrg
577ec681f3Smrg// Typedefs for loader/ICD interface
587ec681f3Smrgtypedef VkResult (VKAPI_PTR *PFN_vk_icdNegotiateLoaderICDInterfaceVersion)(uint32_t* pVersion);
597ec681f3Smrgtypedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName);
607ec681f3Smrgtypedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
617ec681f3Smrg#if defined(VK_USE_PLATFORM_WIN32_KHR)
627ec681f3Smrgtypedef VkResult (VKAPI_PTR *PFN_vk_icdEnumerateAdapterPhysicalDevices)(VkInstance instance, LUID adapterLUID,
637ec681f3Smrg    uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
647ec681f3Smrg#endif
657ec681f3Smrg
667ec681f3Smrg// Prototypes for loader/ICD interface
677ec681f3Smrg#if !defined(VK_NO_PROTOTYPES)
687ec681f3Smrg#ifdef __cplusplus
697ec681f3Smrgextern "C" {
707ec681f3Smrg#endif
717ec681f3Smrg    VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pVersion);
727ec681f3Smrg    VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
737ec681f3Smrg    VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance isntance, const char* pName);
747ec681f3Smrg#if defined(VK_USE_PLATFORM_WIN32_KHR)
757ec681f3Smrg    VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
767ec681f3Smrg        uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
777ec681f3Smrg#endif
787ec681f3Smrg#ifdef __cplusplus
797ec681f3Smrg}
807ec681f3Smrg#endif
817ec681f3Smrg#endif
827ec681f3Smrg
8301e04c3fSmrg/*
8401e04c3fSmrg * The ICD must reserve space for a pointer for the loader's dispatch
8501e04c3fSmrg * table, at the start of <each object>.
8601e04c3fSmrg * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
8701e04c3fSmrg */
8801e04c3fSmrg
8901e04c3fSmrg#define ICD_LOADER_MAGIC 0x01CDC0DE
9001e04c3fSmrg
9101e04c3fSmrgtypedef union {
9201e04c3fSmrg    uintptr_t loaderMagic;
9301e04c3fSmrg    void *loaderData;
9401e04c3fSmrg} VK_LOADER_DATA;
9501e04c3fSmrg
9601e04c3fSmrgstatic inline void set_loader_magic_value(void *pNewObject) {
9701e04c3fSmrg    VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
9801e04c3fSmrg    loader_info->loaderMagic = ICD_LOADER_MAGIC;
9901e04c3fSmrg}
10001e04c3fSmrg
10101e04c3fSmrgstatic inline bool valid_loader_magic_value(void *pNewObject) {
10201e04c3fSmrg    const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
10301e04c3fSmrg    return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
10401e04c3fSmrg}
10501e04c3fSmrg
10601e04c3fSmrg/*
10701e04c3fSmrg * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that
10801e04c3fSmrg * contains the platform-specific connection and surface information.
10901e04c3fSmrg */
11001e04c3fSmrgtypedef enum {
11101e04c3fSmrg    VK_ICD_WSI_PLATFORM_MIR,
11201e04c3fSmrg    VK_ICD_WSI_PLATFORM_WAYLAND,
11301e04c3fSmrg    VK_ICD_WSI_PLATFORM_WIN32,
11401e04c3fSmrg    VK_ICD_WSI_PLATFORM_XCB,
11501e04c3fSmrg    VK_ICD_WSI_PLATFORM_XLIB,
11601e04c3fSmrg    VK_ICD_WSI_PLATFORM_ANDROID,
11701e04c3fSmrg    VK_ICD_WSI_PLATFORM_MACOS,
11801e04c3fSmrg    VK_ICD_WSI_PLATFORM_IOS,
1197ec681f3Smrg    VK_ICD_WSI_PLATFORM_DISPLAY,
1207ec681f3Smrg    VK_ICD_WSI_PLATFORM_HEADLESS,
1217ec681f3Smrg    VK_ICD_WSI_PLATFORM_METAL,
1227ec681f3Smrg    VK_ICD_WSI_PLATFORM_DIRECTFB,
1237ec681f3Smrg    VK_ICD_WSI_PLATFORM_VI,
1247ec681f3Smrg    VK_ICD_WSI_PLATFORM_GGP,
1257ec681f3Smrg    VK_ICD_WSI_PLATFORM_SCREEN,
12601e04c3fSmrg} VkIcdWsiPlatform;
12701e04c3fSmrg
12801e04c3fSmrgtypedef struct {
12901e04c3fSmrg    VkIcdWsiPlatform platform;
13001e04c3fSmrg} VkIcdSurfaceBase;
13101e04c3fSmrg
13201e04c3fSmrg#ifdef VK_USE_PLATFORM_MIR_KHR
13301e04c3fSmrgtypedef struct {
13401e04c3fSmrg    VkIcdSurfaceBase base;
13501e04c3fSmrg    MirConnection *connection;
13601e04c3fSmrg    MirSurface *mirSurface;
13701e04c3fSmrg} VkIcdSurfaceMir;
13801e04c3fSmrg#endif  // VK_USE_PLATFORM_MIR_KHR
13901e04c3fSmrg
14001e04c3fSmrg#ifdef VK_USE_PLATFORM_WAYLAND_KHR
14101e04c3fSmrgtypedef struct {
14201e04c3fSmrg    VkIcdSurfaceBase base;
14301e04c3fSmrg    struct wl_display *display;
14401e04c3fSmrg    struct wl_surface *surface;
14501e04c3fSmrg} VkIcdSurfaceWayland;
14601e04c3fSmrg#endif  // VK_USE_PLATFORM_WAYLAND_KHR
14701e04c3fSmrg
14801e04c3fSmrg#ifdef VK_USE_PLATFORM_WIN32_KHR
14901e04c3fSmrgtypedef struct {
15001e04c3fSmrg    VkIcdSurfaceBase base;
15101e04c3fSmrg    HINSTANCE hinstance;
15201e04c3fSmrg    HWND hwnd;
15301e04c3fSmrg} VkIcdSurfaceWin32;
15401e04c3fSmrg#endif  // VK_USE_PLATFORM_WIN32_KHR
15501e04c3fSmrg
15601e04c3fSmrg#ifdef VK_USE_PLATFORM_XCB_KHR
15701e04c3fSmrgtypedef struct {
15801e04c3fSmrg    VkIcdSurfaceBase base;
15901e04c3fSmrg    xcb_connection_t *connection;
16001e04c3fSmrg    xcb_window_t window;
16101e04c3fSmrg} VkIcdSurfaceXcb;
16201e04c3fSmrg#endif  // VK_USE_PLATFORM_XCB_KHR
16301e04c3fSmrg
16401e04c3fSmrg#ifdef VK_USE_PLATFORM_XLIB_KHR
16501e04c3fSmrgtypedef struct {
16601e04c3fSmrg    VkIcdSurfaceBase base;
16701e04c3fSmrg    Display *dpy;
16801e04c3fSmrg    Window window;
16901e04c3fSmrg} VkIcdSurfaceXlib;
17001e04c3fSmrg#endif  // VK_USE_PLATFORM_XLIB_KHR
17101e04c3fSmrg
1727ec681f3Smrg#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
1737ec681f3Smrgtypedef struct {
1747ec681f3Smrg    VkIcdSurfaceBase base;
1757ec681f3Smrg    IDirectFB *dfb;
1767ec681f3Smrg    IDirectFBSurface *surface;
1777ec681f3Smrg} VkIcdSurfaceDirectFB;
1787ec681f3Smrg#endif  // VK_USE_PLATFORM_DIRECTFB_EXT
1797ec681f3Smrg
18001e04c3fSmrg#ifdef VK_USE_PLATFORM_ANDROID_KHR
18101e04c3fSmrgtypedef struct {
18201e04c3fSmrg    VkIcdSurfaceBase base;
18301e04c3fSmrg    struct ANativeWindow *window;
18401e04c3fSmrg} VkIcdSurfaceAndroid;
18501e04c3fSmrg#endif  // VK_USE_PLATFORM_ANDROID_KHR
18601e04c3fSmrg
18701e04c3fSmrg#ifdef VK_USE_PLATFORM_MACOS_MVK
18801e04c3fSmrgtypedef struct {
18901e04c3fSmrg    VkIcdSurfaceBase base;
19001e04c3fSmrg    const void *pView;
19101e04c3fSmrg} VkIcdSurfaceMacOS;
19201e04c3fSmrg#endif  // VK_USE_PLATFORM_MACOS_MVK
19301e04c3fSmrg
19401e04c3fSmrg#ifdef VK_USE_PLATFORM_IOS_MVK
19501e04c3fSmrgtypedef struct {
19601e04c3fSmrg    VkIcdSurfaceBase base;
19701e04c3fSmrg    const void *pView;
19801e04c3fSmrg} VkIcdSurfaceIOS;
19901e04c3fSmrg#endif  // VK_USE_PLATFORM_IOS_MVK
20001e04c3fSmrg
2017ec681f3Smrg#ifdef VK_USE_PLATFORM_GGP
2027ec681f3Smrgtypedef struct {
2037ec681f3Smrg    VkIcdSurfaceBase base;
2047ec681f3Smrg    GgpStreamDescriptor streamDescriptor;
2057ec681f3Smrg} VkIcdSurfaceGgp;
2067ec681f3Smrg#endif  // VK_USE_PLATFORM_GGP
2077ec681f3Smrg
20801e04c3fSmrgtypedef struct {
20901e04c3fSmrg    VkIcdSurfaceBase base;
21001e04c3fSmrg    VkDisplayModeKHR displayMode;
21101e04c3fSmrg    uint32_t planeIndex;
21201e04c3fSmrg    uint32_t planeStackIndex;
21301e04c3fSmrg    VkSurfaceTransformFlagBitsKHR transform;
21401e04c3fSmrg    float globalAlpha;
21501e04c3fSmrg    VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
21601e04c3fSmrg    VkExtent2D imageExtent;
21701e04c3fSmrg} VkIcdSurfaceDisplay;
21801e04c3fSmrg
2197ec681f3Smrgtypedef struct {
2207ec681f3Smrg    VkIcdSurfaceBase base;
2217ec681f3Smrg} VkIcdSurfaceHeadless;
2227ec681f3Smrg
2237ec681f3Smrg#ifdef VK_USE_PLATFORM_METAL_EXT
2247ec681f3Smrgtypedef struct {
2257ec681f3Smrg    VkIcdSurfaceBase base;
2267ec681f3Smrg    const CAMetalLayer *pLayer;
2277ec681f3Smrg} VkIcdSurfaceMetal;
2287ec681f3Smrg#endif // VK_USE_PLATFORM_METAL_EXT
2297ec681f3Smrg
2307ec681f3Smrg#ifdef VK_USE_PLATFORM_VI_NN
2317ec681f3Smrgtypedef struct {
2327ec681f3Smrg    VkIcdSurfaceBase base;
2337ec681f3Smrg    void *window;
2347ec681f3Smrg} VkIcdSurfaceVi;
2357ec681f3Smrg#endif // VK_USE_PLATFORM_VI_NN
2367ec681f3Smrg
2377ec681f3Smrg#ifdef VK_USE_PLATFORM_SCREEN_QNX
2387ec681f3Smrgtypedef struct {
2397ec681f3Smrg    VkIcdSurfaceBase base;
2407ec681f3Smrg    struct _screen_context *context;
2417ec681f3Smrg    struct _screen_window *window;
2427ec681f3Smrg} VkIcdSurfaceScreen;
2437ec681f3Smrg#endif  // VK_USE_PLATFORM_SCREEN_QNX
2447ec681f3Smrg
24501e04c3fSmrg#endif  // VKICD_H
246