vk_icd.h revision 01e04c3f
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.
4401e04c3fSmrg#define CURRENT_LOADER_ICD_INTERFACE_VERSION 5
4501e04c3fSmrg#define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0
4601e04c3fSmrg#define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4
4701e04c3fSmrgtypedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion);
4801e04c3fSmrg
4901e04c3fSmrg// This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this
5001e04c3fSmrg// file directly, it won't be found.
5101e04c3fSmrg#ifndef PFN_GetPhysicalDeviceProcAddr
5201e04c3fSmrgtypedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
5301e04c3fSmrg#endif
5401e04c3fSmrg
5501e04c3fSmrg/*
5601e04c3fSmrg * The ICD must reserve space for a pointer for the loader's dispatch
5701e04c3fSmrg * table, at the start of <each object>.
5801e04c3fSmrg * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
5901e04c3fSmrg */
6001e04c3fSmrg
6101e04c3fSmrg#define ICD_LOADER_MAGIC 0x01CDC0DE
6201e04c3fSmrg
6301e04c3fSmrgtypedef union {
6401e04c3fSmrg    uintptr_t loaderMagic;
6501e04c3fSmrg    void *loaderData;
6601e04c3fSmrg} VK_LOADER_DATA;
6701e04c3fSmrg
6801e04c3fSmrgstatic inline void set_loader_magic_value(void *pNewObject) {
6901e04c3fSmrg    VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
7001e04c3fSmrg    loader_info->loaderMagic = ICD_LOADER_MAGIC;
7101e04c3fSmrg}
7201e04c3fSmrg
7301e04c3fSmrgstatic inline bool valid_loader_magic_value(void *pNewObject) {
7401e04c3fSmrg    const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
7501e04c3fSmrg    return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
7601e04c3fSmrg}
7701e04c3fSmrg
7801e04c3fSmrg/*
7901e04c3fSmrg * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that
8001e04c3fSmrg * contains the platform-specific connection and surface information.
8101e04c3fSmrg */
8201e04c3fSmrgtypedef enum {
8301e04c3fSmrg    VK_ICD_WSI_PLATFORM_MIR,
8401e04c3fSmrg    VK_ICD_WSI_PLATFORM_WAYLAND,
8501e04c3fSmrg    VK_ICD_WSI_PLATFORM_WIN32,
8601e04c3fSmrg    VK_ICD_WSI_PLATFORM_XCB,
8701e04c3fSmrg    VK_ICD_WSI_PLATFORM_XLIB,
8801e04c3fSmrg    VK_ICD_WSI_PLATFORM_ANDROID,
8901e04c3fSmrg    VK_ICD_WSI_PLATFORM_MACOS,
9001e04c3fSmrg    VK_ICD_WSI_PLATFORM_IOS,
9101e04c3fSmrg    VK_ICD_WSI_PLATFORM_DISPLAY
9201e04c3fSmrg} VkIcdWsiPlatform;
9301e04c3fSmrg
9401e04c3fSmrgtypedef struct {
9501e04c3fSmrg    VkIcdWsiPlatform platform;
9601e04c3fSmrg} VkIcdSurfaceBase;
9701e04c3fSmrg
9801e04c3fSmrg#ifdef VK_USE_PLATFORM_MIR_KHR
9901e04c3fSmrgtypedef struct {
10001e04c3fSmrg    VkIcdSurfaceBase base;
10101e04c3fSmrg    MirConnection *connection;
10201e04c3fSmrg    MirSurface *mirSurface;
10301e04c3fSmrg} VkIcdSurfaceMir;
10401e04c3fSmrg#endif  // VK_USE_PLATFORM_MIR_KHR
10501e04c3fSmrg
10601e04c3fSmrg#ifdef VK_USE_PLATFORM_WAYLAND_KHR
10701e04c3fSmrgtypedef struct {
10801e04c3fSmrg    VkIcdSurfaceBase base;
10901e04c3fSmrg    struct wl_display *display;
11001e04c3fSmrg    struct wl_surface *surface;
11101e04c3fSmrg} VkIcdSurfaceWayland;
11201e04c3fSmrg#endif  // VK_USE_PLATFORM_WAYLAND_KHR
11301e04c3fSmrg
11401e04c3fSmrg#ifdef VK_USE_PLATFORM_WIN32_KHR
11501e04c3fSmrgtypedef struct {
11601e04c3fSmrg    VkIcdSurfaceBase base;
11701e04c3fSmrg    HINSTANCE hinstance;
11801e04c3fSmrg    HWND hwnd;
11901e04c3fSmrg} VkIcdSurfaceWin32;
12001e04c3fSmrg#endif  // VK_USE_PLATFORM_WIN32_KHR
12101e04c3fSmrg
12201e04c3fSmrg#ifdef VK_USE_PLATFORM_XCB_KHR
12301e04c3fSmrgtypedef struct {
12401e04c3fSmrg    VkIcdSurfaceBase base;
12501e04c3fSmrg    xcb_connection_t *connection;
12601e04c3fSmrg    xcb_window_t window;
12701e04c3fSmrg} VkIcdSurfaceXcb;
12801e04c3fSmrg#endif  // VK_USE_PLATFORM_XCB_KHR
12901e04c3fSmrg
13001e04c3fSmrg#ifdef VK_USE_PLATFORM_XLIB_KHR
13101e04c3fSmrgtypedef struct {
13201e04c3fSmrg    VkIcdSurfaceBase base;
13301e04c3fSmrg    Display *dpy;
13401e04c3fSmrg    Window window;
13501e04c3fSmrg} VkIcdSurfaceXlib;
13601e04c3fSmrg#endif  // VK_USE_PLATFORM_XLIB_KHR
13701e04c3fSmrg
13801e04c3fSmrg#ifdef VK_USE_PLATFORM_ANDROID_KHR
13901e04c3fSmrgtypedef struct {
14001e04c3fSmrg    VkIcdSurfaceBase base;
14101e04c3fSmrg    struct ANativeWindow *window;
14201e04c3fSmrg} VkIcdSurfaceAndroid;
14301e04c3fSmrg#endif  // VK_USE_PLATFORM_ANDROID_KHR
14401e04c3fSmrg
14501e04c3fSmrg#ifdef VK_USE_PLATFORM_MACOS_MVK
14601e04c3fSmrgtypedef struct {
14701e04c3fSmrg    VkIcdSurfaceBase base;
14801e04c3fSmrg    const void *pView;
14901e04c3fSmrg} VkIcdSurfaceMacOS;
15001e04c3fSmrg#endif  // VK_USE_PLATFORM_MACOS_MVK
15101e04c3fSmrg
15201e04c3fSmrg#ifdef VK_USE_PLATFORM_IOS_MVK
15301e04c3fSmrgtypedef struct {
15401e04c3fSmrg    VkIcdSurfaceBase base;
15501e04c3fSmrg    const void *pView;
15601e04c3fSmrg} VkIcdSurfaceIOS;
15701e04c3fSmrg#endif  // VK_USE_PLATFORM_IOS_MVK
15801e04c3fSmrg
15901e04c3fSmrgtypedef struct {
16001e04c3fSmrg    VkIcdSurfaceBase base;
16101e04c3fSmrg    VkDisplayModeKHR displayMode;
16201e04c3fSmrg    uint32_t planeIndex;
16301e04c3fSmrg    uint32_t planeStackIndex;
16401e04c3fSmrg    VkSurfaceTransformFlagBitsKHR transform;
16501e04c3fSmrg    float globalAlpha;
16601e04c3fSmrg    VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
16701e04c3fSmrg    VkExtent2D imageExtent;
16801e04c3fSmrg} VkIcdSurfaceDisplay;
16901e04c3fSmrg
17001e04c3fSmrg#endif  // VKICD_H
171