2
0

vk_layer.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // File: vk_layer.h
  3. //
  4. /*
  5. * Copyright (c) 2015-2017 The Khronos Group Inc.
  6. * Copyright (c) 2015-2017 Valve Corporation
  7. * Copyright (c) 2015-2017 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. /* Need to define dispatch table
  23. * Core struct can then have ptr to dispatch table at the top
  24. * Along with object ptrs for current and next OBJ
  25. */
  26. #pragma once
  27. #include "vulkan.h"
  28. #if defined(__GNUC__) && __GNUC__ >= 4
  29. #define VK_LAYER_EXPORT __attribute__((visibility("default")))
  30. #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
  31. #define VK_LAYER_EXPORT __attribute__((visibility("default")))
  32. #else
  33. #define VK_LAYER_EXPORT
  34. #endif
  35. #define MAX_NUM_UNKNOWN_EXTS 250
  36. // Loader-Layer version negotiation API. Versions add the following features:
  37. // Versions 0/1 - Initial. Doesn't support vk_layerGetPhysicalDeviceProcAddr
  38. // or vk_icdNegotiateLoaderLayerInterfaceVersion.
  39. // Version 2 - Add support for vk_layerGetPhysicalDeviceProcAddr and
  40. // vk_icdNegotiateLoaderLayerInterfaceVersion.
  41. #define CURRENT_LOADER_LAYER_INTERFACE_VERSION 2
  42. #define MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION 1
  43. #define VK_CURRENT_CHAIN_VERSION 1
  44. // Typedef for use in the interfaces below
  45. typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
  46. // Version negotiation values
  47. typedef enum VkNegotiateLayerStructType {
  48. LAYER_NEGOTIATE_UNINTIALIZED = 0,
  49. LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
  50. } VkNegotiateLayerStructType;
  51. // Version negotiation structures
  52. typedef struct VkNegotiateLayerInterface {
  53. VkNegotiateLayerStructType sType;
  54. void *pNext;
  55. uint32_t loaderLayerInterfaceVersion;
  56. PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
  57. PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
  58. PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
  59. } VkNegotiateLayerInterface;
  60. // Version negotiation functions
  61. typedef VkResult (VKAPI_PTR *PFN_vkNegotiateLoaderLayerInterfaceVersion)(VkNegotiateLayerInterface *pVersionStruct);
  62. // Function prototype for unknown physical device extension command
  63. typedef VkResult(VKAPI_PTR *PFN_PhysDevExt)(VkPhysicalDevice phys_device);
  64. // ------------------------------------------------------------------------------------------------
  65. // CreateInstance and CreateDevice support structures
  66. /* Sub type of structure for instance and device loader ext of CreateInfo.
  67. * When sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
  68. * or sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO
  69. * then VkLayerFunction indicates struct type pointed to by pNext
  70. */
  71. typedef enum VkLayerFunction_ {
  72. VK_LAYER_LINK_INFO = 0,
  73. VK_LOADER_DATA_CALLBACK = 1,
  74. VK_LOADER_LAYER_CREATE_DEVICE_CALLBACK = 2,
  75. VK_LOADER_FEATURES = 3,
  76. } VkLayerFunction;
  77. typedef struct VkLayerInstanceLink_ {
  78. struct VkLayerInstanceLink_ *pNext;
  79. PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
  80. PFN_GetPhysicalDeviceProcAddr pfnNextGetPhysicalDeviceProcAddr;
  81. } VkLayerInstanceLink;
  82. /*
  83. * When creating the device chain the loader needs to pass
  84. * down information about it's device structure needed at
  85. * the end of the chain. Passing the data via the
  86. * VkLayerDeviceInfo avoids issues with finding the
  87. * exact instance being used.
  88. */
  89. typedef struct VkLayerDeviceInfo_ {
  90. void *device_info;
  91. PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
  92. } VkLayerDeviceInfo;
  93. typedef VkResult (VKAPI_PTR *PFN_vkSetInstanceLoaderData)(VkInstance instance,
  94. void *object);
  95. typedef VkResult (VKAPI_PTR *PFN_vkSetDeviceLoaderData)(VkDevice device,
  96. void *object);
  97. typedef VkResult (VKAPI_PTR *PFN_vkLayerCreateDevice)(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
  98. const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA);
  99. typedef void (VKAPI_PTR *PFN_vkLayerDestroyDevice)(VkDevice physicalDevice, const VkAllocationCallbacks *pAllocator, PFN_vkDestroyDevice destroyFunction);
  100. typedef enum VkLoaderFeastureFlagBits {
  101. VK_LOADER_FEATURE_PHYSICAL_DEVICE_SORTING = 0x00000001,
  102. } VkLoaderFlagBits;
  103. typedef VkFlags VkLoaderFeatureFlags;
  104. typedef struct {
  105. VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
  106. const void *pNext;
  107. VkLayerFunction function;
  108. union {
  109. VkLayerInstanceLink *pLayerInfo;
  110. PFN_vkSetInstanceLoaderData pfnSetInstanceLoaderData;
  111. struct {
  112. PFN_vkLayerCreateDevice pfnLayerCreateDevice;
  113. PFN_vkLayerDestroyDevice pfnLayerDestroyDevice;
  114. } layerDevice;
  115. VkLoaderFeatureFlags loaderFeatures;
  116. } u;
  117. } VkLayerInstanceCreateInfo;
  118. typedef struct VkLayerDeviceLink_ {
  119. struct VkLayerDeviceLink_ *pNext;
  120. PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
  121. PFN_vkGetDeviceProcAddr pfnNextGetDeviceProcAddr;
  122. } VkLayerDeviceLink;
  123. typedef struct {
  124. VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO
  125. const void *pNext;
  126. VkLayerFunction function;
  127. union {
  128. VkLayerDeviceLink *pLayerInfo;
  129. PFN_vkSetDeviceLoaderData pfnSetDeviceLoaderData;
  130. } u;
  131. } VkLayerDeviceCreateInfo;
  132. #ifdef __cplusplus
  133. extern "C" {
  134. #endif
  135. VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct);
  136. typedef enum VkChainType {
  137. VK_CHAIN_TYPE_UNKNOWN = 0,
  138. VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES = 1,
  139. VK_CHAIN_TYPE_ENUMERATE_INSTANCE_LAYER_PROPERTIES = 2,
  140. VK_CHAIN_TYPE_ENUMERATE_INSTANCE_VERSION = 3,
  141. } VkChainType;
  142. typedef struct VkChainHeader {
  143. VkChainType type;
  144. uint32_t version;
  145. uint32_t size;
  146. } VkChainHeader;
  147. typedef struct VkEnumerateInstanceExtensionPropertiesChain {
  148. VkChainHeader header;
  149. VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceExtensionPropertiesChain *, const char *, uint32_t *,
  150. VkExtensionProperties *);
  151. const struct VkEnumerateInstanceExtensionPropertiesChain *pNextLink;
  152. #if defined(__cplusplus)
  153. inline VkResult CallDown(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties) const {
  154. return pfnNextLayer(pNextLink, pLayerName, pPropertyCount, pProperties);
  155. }
  156. #endif
  157. } VkEnumerateInstanceExtensionPropertiesChain;
  158. typedef struct VkEnumerateInstanceLayerPropertiesChain {
  159. VkChainHeader header;
  160. VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceLayerPropertiesChain *, uint32_t *, VkLayerProperties *);
  161. const struct VkEnumerateInstanceLayerPropertiesChain *pNextLink;
  162. #if defined(__cplusplus)
  163. inline VkResult CallDown(uint32_t *pPropertyCount, VkLayerProperties *pProperties) const {
  164. return pfnNextLayer(pNextLink, pPropertyCount, pProperties);
  165. }
  166. #endif
  167. } VkEnumerateInstanceLayerPropertiesChain;
  168. typedef struct VkEnumerateInstanceVersionChain {
  169. VkChainHeader header;
  170. VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceVersionChain *, uint32_t *);
  171. const struct VkEnumerateInstanceVersionChain *pNextLink;
  172. #if defined(__cplusplus)
  173. inline VkResult CallDown(uint32_t *pApiVersion) const {
  174. return pfnNextLayer(pNextLink, pApiVersion);
  175. }
  176. #endif
  177. } VkEnumerateInstanceVersionChain;
  178. #ifdef __cplusplus
  179. }
  180. #endif