vk_layer.h 7.5 KB

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