1b8e80941Smrg//
2b8e80941Smrg// File: vk_layer.h
3b8e80941Smrg//
4b8e80941Smrg/*
5b8e80941Smrg * Copyright (c) 2015-2017 The Khronos Group Inc.
6b8e80941Smrg * Copyright (c) 2015-2017 Valve Corporation
7b8e80941Smrg * Copyright (c) 2015-2017 LunarG, Inc.
8b8e80941Smrg *
9b8e80941Smrg * Licensed under the Apache License, Version 2.0 (the "License");
10b8e80941Smrg * you may not use this file except in compliance with the License.
11b8e80941Smrg * You may obtain a copy of the License at
12b8e80941Smrg *
13b8e80941Smrg *     http://www.apache.org/licenses/LICENSE-2.0
14b8e80941Smrg *
15b8e80941Smrg * Unless required by applicable law or agreed to in writing, software
16b8e80941Smrg * distributed under the License is distributed on an "AS IS" BASIS,
17b8e80941Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18b8e80941Smrg * See the License for the specific language governing permissions and
19b8e80941Smrg * limitations under the License.
20b8e80941Smrg *
21b8e80941Smrg */
22b8e80941Smrg
23b8e80941Smrg/* Need to define dispatch table
24b8e80941Smrg * Core struct can then have ptr to dispatch table at the top
25b8e80941Smrg * Along with object ptrs for current and next OBJ
26b8e80941Smrg */
27b8e80941Smrg#pragma once
28b8e80941Smrg
29b8e80941Smrg#include "vulkan.h"
30b8e80941Smrg#if defined(__GNUC__) && __GNUC__ >= 4
31b8e80941Smrg#define VK_LAYER_EXPORT __attribute__((visibility("default")))
32b8e80941Smrg#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
33b8e80941Smrg#define VK_LAYER_EXPORT __attribute__((visibility("default")))
34b8e80941Smrg#else
35b8e80941Smrg#define VK_LAYER_EXPORT
36b8e80941Smrg#endif
37b8e80941Smrg
38b8e80941Smrg#define MAX_NUM_UNKNOWN_EXTS 250
39b8e80941Smrg
40b8e80941Smrg // Loader-Layer version negotiation API.  Versions add the following features:
41b8e80941Smrg //   Versions 0/1 - Initial.  Doesn't support vk_layerGetPhysicalDeviceProcAddr
42b8e80941Smrg //                  or vk_icdNegotiateLoaderLayerInterfaceVersion.
43b8e80941Smrg //   Version 2    - Add support for vk_layerGetPhysicalDeviceProcAddr and
44b8e80941Smrg //                  vk_icdNegotiateLoaderLayerInterfaceVersion.
45b8e80941Smrg#define CURRENT_LOADER_LAYER_INTERFACE_VERSION 2
46b8e80941Smrg#define MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION 1
47b8e80941Smrg
48b8e80941Smrg#define VK_CURRENT_CHAIN_VERSION 1
49b8e80941Smrg
50b8e80941Smrg// Typedef for use in the interfaces below
51b8e80941Smrgtypedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
52b8e80941Smrg
53b8e80941Smrg// Version negotiation values
54b8e80941Smrgtypedef enum VkNegotiateLayerStructType {
55b8e80941Smrg    LAYER_NEGOTIATE_UNINTIALIZED = 0,
56b8e80941Smrg    LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
57b8e80941Smrg} VkNegotiateLayerStructType;
58b8e80941Smrg
59b8e80941Smrg// Version negotiation structures
60b8e80941Smrgtypedef struct VkNegotiateLayerInterface {
61b8e80941Smrg    VkNegotiateLayerStructType sType;
62b8e80941Smrg    void *pNext;
63b8e80941Smrg    uint32_t loaderLayerInterfaceVersion;
64b8e80941Smrg    PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
65b8e80941Smrg    PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
66b8e80941Smrg    PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
67b8e80941Smrg} VkNegotiateLayerInterface;
68b8e80941Smrg
69b8e80941Smrg// Version negotiation functions
70b8e80941Smrgtypedef VkResult (VKAPI_PTR *PFN_vkNegotiateLoaderLayerInterfaceVersion)(VkNegotiateLayerInterface *pVersionStruct);
71b8e80941Smrg
72b8e80941Smrg// Function prototype for unknown physical device extension command
73b8e80941Smrgtypedef VkResult(VKAPI_PTR *PFN_PhysDevExt)(VkPhysicalDevice phys_device);
74b8e80941Smrg
75b8e80941Smrg// ------------------------------------------------------------------------------------------------
76b8e80941Smrg// CreateInstance and CreateDevice support structures
77b8e80941Smrg
78b8e80941Smrg/* Sub type of structure for instance and device loader ext of CreateInfo.
79b8e80941Smrg * When sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
80b8e80941Smrg * or sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO
81b8e80941Smrg * then VkLayerFunction indicates struct type pointed to by pNext
82b8e80941Smrg */
83b8e80941Smrgtypedef enum VkLayerFunction_ {
84b8e80941Smrg    VK_LAYER_LINK_INFO = 0,
85b8e80941Smrg    VK_LOADER_DATA_CALLBACK = 1
86b8e80941Smrg} VkLayerFunction;
87b8e80941Smrg
88b8e80941Smrgtypedef struct VkLayerInstanceLink_ {
89b8e80941Smrg    struct VkLayerInstanceLink_ *pNext;
90b8e80941Smrg    PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
91b8e80941Smrg    PFN_GetPhysicalDeviceProcAddr pfnNextGetPhysicalDeviceProcAddr;
92b8e80941Smrg} VkLayerInstanceLink;
93b8e80941Smrg
94b8e80941Smrg/*
95b8e80941Smrg * When creating the device chain the loader needs to pass
96b8e80941Smrg * down information about it's device structure needed at
97b8e80941Smrg * the end of the chain. Passing the data via the
98b8e80941Smrg * VkLayerDeviceInfo avoids issues with finding the
99b8e80941Smrg * exact instance being used.
100b8e80941Smrg */
101b8e80941Smrgtypedef struct VkLayerDeviceInfo_ {
102b8e80941Smrg    void *device_info;
103b8e80941Smrg    PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
104b8e80941Smrg} VkLayerDeviceInfo;
105b8e80941Smrg
106b8e80941Smrgtypedef VkResult (VKAPI_PTR *PFN_vkSetInstanceLoaderData)(VkInstance instance,
107b8e80941Smrg        void *object);
108b8e80941Smrgtypedef VkResult (VKAPI_PTR *PFN_vkSetDeviceLoaderData)(VkDevice device,
109b8e80941Smrg        void *object);
110b8e80941Smrg
111b8e80941Smrgtypedef struct {
112b8e80941Smrg    VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
113b8e80941Smrg    const void *pNext;
114b8e80941Smrg    VkLayerFunction function;
115b8e80941Smrg    union {
116b8e80941Smrg        VkLayerInstanceLink *pLayerInfo;
117b8e80941Smrg        PFN_vkSetInstanceLoaderData pfnSetInstanceLoaderData;
118b8e80941Smrg    } u;
119b8e80941Smrg} VkLayerInstanceCreateInfo;
120b8e80941Smrg
121b8e80941Smrgtypedef struct VkLayerDeviceLink_ {
122b8e80941Smrg    struct VkLayerDeviceLink_ *pNext;
123b8e80941Smrg    PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
124b8e80941Smrg    PFN_vkGetDeviceProcAddr pfnNextGetDeviceProcAddr;
125b8e80941Smrg} VkLayerDeviceLink;
126b8e80941Smrg
127b8e80941Smrgtypedef struct {
128b8e80941Smrg    VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO
129b8e80941Smrg    const void *pNext;
130b8e80941Smrg    VkLayerFunction function;
131b8e80941Smrg    union {
132b8e80941Smrg        VkLayerDeviceLink *pLayerInfo;
133b8e80941Smrg        PFN_vkSetDeviceLoaderData pfnSetDeviceLoaderData;
134b8e80941Smrg    } u;
135b8e80941Smrg} VkLayerDeviceCreateInfo;
136b8e80941Smrg
137b8e80941Smrg#ifdef __cplusplus
138b8e80941Smrgextern "C" {
139b8e80941Smrg#endif
140b8e80941Smrg
141b8e80941SmrgVKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct);
142b8e80941Smrg
143b8e80941Smrgtypedef enum VkChainType {
144b8e80941Smrg    VK_CHAIN_TYPE_UNKNOWN = 0,
145b8e80941Smrg    VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES = 1,
146b8e80941Smrg    VK_CHAIN_TYPE_ENUMERATE_INSTANCE_LAYER_PROPERTIES = 2,
147b8e80941Smrg    VK_CHAIN_TYPE_ENUMERATE_INSTANCE_VERSION = 3,
148b8e80941Smrg} VkChainType;
149b8e80941Smrg
150b8e80941Smrgtypedef struct VkChainHeader {
151b8e80941Smrg    VkChainType type;
152b8e80941Smrg    uint32_t version;
153b8e80941Smrg    uint32_t size;
154b8e80941Smrg} VkChainHeader;
155b8e80941Smrg
156b8e80941Smrgtypedef struct VkEnumerateInstanceExtensionPropertiesChain {
157b8e80941Smrg    VkChainHeader header;
158b8e80941Smrg    VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceExtensionPropertiesChain *, const char *, uint32_t *,
159b8e80941Smrg                                      VkExtensionProperties *);
160b8e80941Smrg    const struct VkEnumerateInstanceExtensionPropertiesChain *pNextLink;
161b8e80941Smrg
162b8e80941Smrg#if defined(__cplusplus)
163b8e80941Smrg    inline VkResult CallDown(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties) const {
164b8e80941Smrg        return pfnNextLayer(pNextLink, pLayerName, pPropertyCount, pProperties);
165b8e80941Smrg    }
166b8e80941Smrg#endif
167b8e80941Smrg} VkEnumerateInstanceExtensionPropertiesChain;
168b8e80941Smrg
169b8e80941Smrgtypedef struct VkEnumerateInstanceLayerPropertiesChain {
170b8e80941Smrg    VkChainHeader header;
171b8e80941Smrg    VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceLayerPropertiesChain *, uint32_t *, VkLayerProperties *);
172b8e80941Smrg    const struct VkEnumerateInstanceLayerPropertiesChain *pNextLink;
173b8e80941Smrg
174b8e80941Smrg#if defined(__cplusplus)
175b8e80941Smrg    inline VkResult CallDown(uint32_t *pPropertyCount, VkLayerProperties *pProperties) const {
176b8e80941Smrg        return pfnNextLayer(pNextLink, pPropertyCount, pProperties);
177b8e80941Smrg    }
178b8e80941Smrg#endif
179b8e80941Smrg} VkEnumerateInstanceLayerPropertiesChain;
180b8e80941Smrg
181b8e80941Smrgtypedef struct VkEnumerateInstanceVersionChain {
182b8e80941Smrg    VkChainHeader header;
183b8e80941Smrg    VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceVersionChain *, uint32_t *);
184b8e80941Smrg    const struct VkEnumerateInstanceVersionChain *pNextLink;
185b8e80941Smrg
186b8e80941Smrg#if defined(__cplusplus)
187b8e80941Smrg    inline VkResult CallDown(uint32_t *pApiVersion) const {
188b8e80941Smrg        return pfnNextLayer(pNextLink, pApiVersion);
189b8e80941Smrg    }
190b8e80941Smrg#endif
191b8e80941Smrg} VkEnumerateInstanceVersionChain;
192b8e80941Smrg
193b8e80941Smrg#ifdef __cplusplus
194b8e80941Smrg}
195b8e80941Smrg#endif
196