1<!-- markdownlint-disable MD041 --> 2[![Khronos Vulkan][1]][2] 3 4[1]: https://vulkan.lunarg.com/img/Vulkan_100px_Dec16.png "https://www.khronos.org/vulkan/" 5[2]: https://www.khronos.org/vulkan/ 6 7# Layer Interface to the Loader 8[![Creative Commons][3]][4] 9 10<!-- Copyright © 2015-2021 LunarG, Inc. --> 11 12[3]: https://i.creativecommons.org/l/by-nd/4.0/88x31.png "Creative Commons License" 13[4]: https://creativecommons.org/licenses/by-nd/4.0/ 14 15 16## Table of Contents 17 18- [Overview](#overview) 19- [Layer Discovery](#layer-discovery) 20 - [Layer Manifest File Usage](#layer-manifest-file-usage) 21 - [Android Layer Discovery](#android-layer-discovery) 22 - [Windows Layer Discovery](#windows-layer-discovery) 23 - [Linux Layer Discovery](#linux-layer-discovery) 24 - [Example Linux Explicit Layer Search Path](#example-linux-explicit-layer-search-path) 25 - [Fuchsia Layer Discovery](#fuchsia-layer-discovery) 26 - [macOS Layer Discovery](#macos-layer-discovery) 27 - [Example macOS Implicit Layer Search Path](#example-macos-implicit-layer-search-path) 28 - [Exception for Elevated Privileges](#exception-for-elevated-privileges) 29- [Layer Version Negotiation](#layer-version-negotiation) 30- [Layer Call Chains and Distributed Dispatch](#layer-call-chains-and-distributed-dispatch) 31- [Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions) 32 - [Reason for adding `vk_layerGetPhysicalDeviceProcAddr`](#reason-for-adding-vk_layergetphysicaldeviceprocaddr) 33- [Layer Intercept Requirements](#layer-intercept-requirements) 34- [Distributed Dispatching Requirements](#distributed-dispatching-requirements) 35- [Layer Conventions and Rules](#layer-conventions-and-rules) 36- [Layer Dispatch Initialization](#layer-dispatch-initialization) 37- [Example Code for CreateInstance](#example-code-for-createinstance) 38- [Example Code for CreateDevice](#example-code-for-createdevice) 39- [Meta-layers](#meta-layers) 40 - [Override Meta-Layer](#override-meta-layer) 41- [Pre-Instance Functions](#pre-instance-functions) 42- [Special Considerations](#special-considerations) 43 - [Associating Private Data with Vulkan Objects Within a Layer](#associating-private-data-with-vulkan-objects-within-a-layer) 44 - [Wrapping](#wrapping) 45 - [Cautions About Wrapping](#cautions-about-wrapping) 46 - [Hash Maps](#hash-maps) 47 - [Creating New Dispatchable Objects](#creating-new-dispatchable-objects) 48 - [Versioning and Activation Interactions](#versioning-and-activation-interactions) 49- [Layer Manifest File Format](#layer-manifest-file-format) 50 - [Layer Manifest File Version History](#layer-manifest-file-version-history) 51 - [Layer Manifest File Version 1.2.0](#layer-manifest-file-version-120) 52 - [Layer Manifest File Version 1.1.2](#layer-manifest-file-version-112) 53 - [Layer Manifest File Version 1.1.1](#layer-manifest-file-version-111) 54 - [Layer Manifest File Version 1.1.0](#layer-manifest-file-version-110) 55 - [Layer Manifest File Version 1.0.1](#layer-manifest-file-version-101) 56 - [Layer Manifest File Version 1.0.0](#layer-manifest-file-version-100) 57- [Layer Interface Versions](#layer-interface-versions) 58 - [Layer Interface Version 2](#layer-interface-version-2) 59 - [Layer Interface Version 1](#layer-interface-version-1) 60 - [Layer Interface Version 0](#layer-interface-version-0) 61- [Loader and Layer Interface Policy](#loader-and-layer-interface-policy) 62 - [Number Format](#number-format) 63 - [Android Differences](#android-differences) 64 - [Requirements of Well-Behaved Layers](#requirements-of-well-behaved-layers) 65 - [Requirements of a Well-Behaved Loader](#requirements-of-a-well-behaved-loader) 66 67 68## Overview 69 70This is the Layer-centric view of working with the Vulkan loader. 71For the complete overview of all sections of the loader, please refer 72to the [LoaderInterfaceArchitecture.md](LoaderInterfaceArchitecture.md) file. 73 74 75## Layer Discovery 76 77As mentioned in the 78[Implicit versus Explicit](LoaderApplicationInterface.md#implicit-vs-explicit-layers), 79section of the 80[LoaderApplicationInterface.md](LoaderApplicationInterface.md) document, layers 81can be categorized into two categories: 82 * Implicit Layers 83 * Explicit Layers 84 85The main difference between the two is that implicit layers are automatically 86enabled, unless overridden, and explicit layers must be enabled. 87Remember, implicit layers are not present on all Operating Systems (like 88Android). 89 90On any system, the loader looks in specific areas for information on the layers 91that it can load at a user's request. 92The process of finding the available layers on a system is known as Layer 93Discovery. 94During discovery, the loader determines what layers are available, the layer 95name, the layer version, and any extensions supported by the layer. 96This information is provided back to an application through 97`vkEnumerateInstanceLayerProperties`. 98 99The group of layers available to the loader is known as the `Layer Library`. 100This section defines an extensible interface to discover what layers are 101contained in the `Layer Library`. 102 103This section also specifies the minimal conventions and rules a layer must 104follow, especially with regards to interacting with the loader and other 105layers. 106 107When searching for a layer, the loader will look through the `Layer Library` in 108the order it detected them and load the layer if the name matches. 109If multiple instances of the same library exist in different locations 110throughout the user's system, then the one appearing first in the search order 111will be used. 112Each OS has its own search order that is defined in its layer discovery 113section below. 114If multiple manifest files in the same directory define the same layer, but 115point to different library files, the order which the layers is loaded is 116[random due to the behavior of readdir](https://www.ibm.com/support/pages/order-directory-contents-returned-calls-readdir). 117 118Additionally, any duplicate layer names in either the component layer list, or 119globally among all enabled layers, during calls to `vkCreateInstance` or 120`vkCreateDevice` will simply be ignored by the loader. 121Only the first occurrence of any layer name will be used. 122 123 124### Layer Manifest File Usage 125 126On Windows, Linux, and macOS systems, JSON-formatted manifest files are used to 127store layer information. 128In order to find system-installed layers, the Vulkan loader will read the JSON 129files to identify the names and attributes of layers and their extensions. 130The use of manifest files allows the loader to avoid loading any shared library 131files when the application does not query nor request any extensions. 132The format of [Layer Manifest File](#layer-manifest-file-format) is detailed 133below. 134 135The Android loader does not use manifest files. 136Instead, the loader queries the layer properties using special functions known 137as "introspection" functions. 138The intent of these functions is to determine the same required information 139gathered from reading the manifest files. 140These introspection functions are not used by the Khronos loader but should be 141present in layers to maintain consistency. 142The specific "introspection" functions are called out in the 143[Layer Manifest File Format](#layer-manifest-file-format) table. 144 145 146### Android Layer Discovery 147 148On Android, the loader looks for layers to enumerate in the 149`/data/local/debug/vulkan` folder. 150An application enabled for debug has the ability to enumerate and enable any 151layers in that location. 152 153 154### Windows Layer Discovery 155 156In order to find system-installed layers, the Vulkan loader will scan the 157values in the following Windows registry keys: 158 159``` 160HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers 161HKEY_CURRENT_USER\SOFTWARE\Khronos\Vulkan\ExplicitLayers 162HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ImplicitLayers 163HKEY_CURRENT_USER\SOFTWARE\Khronos\Vulkan\ImplicitLayers 164``` 165 166Except when running a 32-bit application on 64-bit Windows, when the loader 167will instead scan the 32-bit registry location: 168 169``` 170HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers 171HKEY_CURRENT_USER\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers 172HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\ImplicitLayers 173HKEY_CURRENT_USER\SOFTWARE\WOW6432Node\Khronos\Vulkan\ImplicitLayers 174``` 175 176For each value in these keys which has DWORD data set to 0, the loader opens 177the JSON manifest file specified by the name of the value. 178Each name must be an absolute path to the manifest file. 179Additionally, the `HKEY_CURRENT_USER` locations will only be searched if an 180application is not being executed with administrative privileges. 181This is done to ensure that an application with administrative privileges does 182not run layers that did not need administrator access to install. 183 184Because some layers are installed alongside drivers, the loader will scan 185through registry keys specific to Display Adapters and all Software Components 186associated with these adapters for the locations of JSON manifest files. 187These keys are located in device keys created during driver installation and 188contain configuration information for base settings, including Vulkan, OpenGL, 189and Direct3D ICD location. 190 191The Device Adapter and Software Component key paths should be obtained through 192the PnP Configuration Manager API. 193The `000X` key will be a numbered key, where each device is assigned a 194different number. 195 196``` 197HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanExplicitLayers 198HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanImplicitLayers 199HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanExplicitLayers 200HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanImplicitLayers 201``` 202 203In addition, on 64-bit systems there may be another set of registry values, 204listed below. 205These values record the locations of 32-bit layers on 64-bit operating systems, 206in the same way as the Windows-on-Windows functionality. 207 208``` 209HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanExplicitLayersWow 210HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanImplicitLayersWow 211HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanExplicitLayersWow 212HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanImplicitLayersWow 213``` 214 215If any of the above values exist and is of type `REG_SZ`, the loader will open 216the JSON manifest file specified by the key value. 217Each value must be an absolute path to a JSON manifest file. 218A key value may also be of type `REG_MULTI_SZ`, in which case the value will be 219interpreted as a list of paths to JSON manifest files. 220 221In general, applications should install layers into the 222`SOFTWARE\Khronos\Vulkan` paths. 223The PnP registry locations are intended specifically for layers that are 224distributed as part of a driver installation. 225An application installer should not modify the device-specific registries, 226while a device driver should not modify the system registries. 227 228The Vulkan loader will open each manifest file to obtain information about the 229layer, including the name or pathname of a shared library (".dll") file. 230 231If `VK_LAYER_PATH` is defined, then the loader will look at the paths defined by 232that variable for explicit layer manifest files instead of using the information 233provided by the explicit layer registry keys. 234 235If `VK_ADD_LAYER_PATH` is defined, then the loader will look at the provided 236paths for explicit layer manifest files in addition to using the information 237provided by the explicit layer registry keys. 238The paths provided by `VK_ADD_LAYER_PATH` are added before the standard list 239of search folders and will therefore be searched first. 240 241If `VK_LAYER_PATH` is present, then `VK_ADD_LAYER_PATH` will not be used by the 242loader and any values will be ignored. 243 244For security reasons, both `VK_LAYER_PATH` and `VK_ADD_LAYER_PATH` are ignored 245if running with elevated privileges. 246See [Exception for Elevated Privileges](#exception-for-elevated-privileges) 247for more info. 248 249See 250[Forcing Layer Source Folders](LoaderApplicationInterface.md#forcing-layer-source-folders) 251in the [LoaderApplicationInterface.md document](LoaderApplicationInterface.md) 252for more information on this. 253 254 255### Linux Layer Discovery 256 257On Linux, the Vulkan loader will scan for manifest files using environment 258variables or corresponding fallback values if the corresponding environment 259variable is not defined: 260 261<table style="width:100%"> 262 <tr> 263 <th>Search Order</th> 264 <th>Directory/Environment Variable</th> 265 <th>Fallback</th> 266 <th>Additional Notes</th> 267 </tr> 268 <tr> 269 <td>1</td> 270 <td>$XDG_CONFIG_HOME</td> 271 <td>$HOME/.config</td> 272 <td><b>This path is ignored when running with elevated privileges such as 273 setuid, setgid, or filesystem capabilities</b>.<br/> 274 This is done because under these scenarios it is not safe to trust 275 that the environment variables are non-malicious. 276 </td> 277 </tr> 278 <tr> 279 <td>1</td> 280 <td>$XDG_CONFIG_DIRS</td> 281 <td>/etc/xdg</td> 282 <td></td> 283 </tr> 284 <tr> 285 <td>2</td> 286 <td>SYSCONFDIR</td> 287 <td>/etc</td> 288 <td>Compile-time option set to possible location of layers installed from 289 non-Linux-distribution-provided packages. 290 </td> 291 </tr> 292 <tr> 293 <td>3</td> 294 <td>EXTRASYSCONFDIR</td> 295 <td>/etc</td> 296 <td>Compile-time option set to possible location of layers installed from 297 non-Linux-distribution-provided packages. 298 Typically only set if SYSCONFDIR is set to something other than /etc 299 </td> 300 </tr> 301 <tr> 302 <td>4</td> 303 <td>$XDG_DATA_HOME</td> 304 <td>$HOME/.local/share</td> 305 <td><b>This path is ignored when running with elevated privileges such as 306 setuid, setgid, or filesystem capabilities</b>.<br/> 307 This is done because under these scenarios it is not safe to trust 308 that the environment variables are non-malicious. 309 </td> 310 </tr> 311 <tr> 312 <td>5</td> 313 <td>$XDG_DATA_DIRS</td> 314 <td>/usr/local/share/:/usr/share/</td> 315 <td></td> 316 </tr> 317</table> 318 319The directory lists are concatenated together using the standard platform path 320separator (:). 321The loader then selects each path, and applies a suffix onto it for the specific 322type of layer being searched for and looks in that specific folder for 323manifest files: 324 325 * Implicit Layers: Suffix = /vulkan/implicit_layer.d 326 * Explicit Layers: Suffix = /vulkan/explicit_layer.d 327 328If `VK_LAYER_PATH` is defined, then the loader will look at the paths defined by 329that variable for explicit layer manifest files instead of using the information 330provided by the standard explicit layer paths mentioned above. 331 332If `VK_ADD_LAYER_PATH` is defined, then the loader will look at the provided 333paths for explicit layer manifest files in addition to using the information 334provided by the standard explicit layer paths mentioned above. 335The paths provided by `VK_ADD_LAYER_PATH` are added before the standard list 336of search folders and will therefore be searched first. 337 338For security reasons, both `VK_LAYER_PATH` and `VK_ADD_LAYER_PATH` are ignored 339if running with elevated privileges. 340See [Exception for Elevated Privileges](#exception-for-elevated-privileges) 341for more info. 342 343**NOTE** While the order of folders searched for manifest files is well 344defined, the order contents are read by the loader in each directory is 345[random due to the behavior of readdir](https://www.ibm.com/support/pages/order-directory-contents-returned-calls-readdir). 346 347See 348[Forcing Layer Source Folders](LoaderApplicationInterface.md#forcing-layer-source-folders) 349in the [LoaderApplicationInterface.md document](LoaderApplicationInterface.md) 350for more information on this. 351 352It is also important to note that while both `VK_LAYER_PATH` and 353`VK_ADD_LAYER_PATH` will point the loader paths to search for finding the 354manifest files, it does not guarantee the library files mentioned by the 355manifest will immediately be found. 356Often, the layer manifest file will point to the library file using a relative 357or absolute path. 358When a relative or absolute path is used, the loader can typically find the 359library file without querying the operating system. 360However, if a library is listed only by name, the loader may not find it. 361If problems occur finding a library file associated with a layer, try updating 362the `LD_LIBRARY_PATH` environment variable to point at the location of the 363corresponding `.so` file. 364 365 366#### Example Linux Explicit Layer Search Path 367 368For a fictional user "me" the layer manifest search path might look like the 369following: 370 371``` 372 /home/me/.config/vulkan/explicit_layer.d 373 /etc/xdg/vulkan/explicit_layer.d 374 /usr/local/etc/vulkan/explicit_layer.d 375 /etc/vulkan/explicit_layer.d 376 /home/me/.local/share/vulkan/explicit_layer.d 377 /usr/local/share/vulkan/explicit_layer.d 378 /usr/share/vulkan/explicit_layer.d 379``` 380 381### Fuchsia Layer Discovery 382 383On Fuchsia, the Vulkan loader will scan for manifest files using environment 384variables or corresponding fallback values if the corresponding environment 385variable is not defined in the same way as [Linux](#linux-layer-discovery). 386The **only** difference is that Fuchsia does not allow fallback values for 387*$XDG_DATA_DIRS* or *$XDG_HOME_DIRS*. 388 389 390### macOS Layer Discovery 391 392On macOS, the Vulkan loader will scan for manifest files using the application 393resource folder as well as environment variables or corresponding fallback 394values if the corresponding environment variable is not defined. 395The order is similar to the search path on Linux with the exception that 396the application's bundle resources are searched first: 397`(bundle)/Contents/Resources/`. 398 399#### Example macOS Implicit Layer Search Path 400 401For a fictional user "Me" the layer manifest search path might look like the 402following: 403 404``` 405 <bundle>/Contents/Resources/vulkan/implicit_layer.d 406 /Users/Me/.config/vulkan/implicit_layer.d 407 /etc/xdg/vulkan/implicit_layer.d 408 /usr/local/etc/vulkan/implicit_layer.d 409 /etc/vulkan/implicit_layer.d 410 /Users/Me/.local/share/vulkan/implicit_layer.d 411 /usr/local/share/vulkan/implicit_layer.d 412 /usr/share/vulkan/implicit_layer.d 413``` 414 415### Exception for Elevated Privileges 416 417There is an exception to when either `VK_LAYER_PATH` or `VK_ADD_LAYER_PATH` are 418available for use. 419For security reasons, both `VK_LAYER_PATH` and `VK_ADD_LAYER_PATH` are ignored 420if running the Vulkan application with elevated privileges. 421Because of this, both `VK_LAYER_PATH` and `VK_ADD_LAYER_PATH` can only be used 422for applications that do not use elevated privileges. 423 424For more information see 425[Elevated Privilege Caveats](LoaderInterfaceArchitecture.md#elevated-privilege-caveats) 426in the top-level 427[LoaderInterfaceArchitecture.md][LoaderInterfaceArchitecture.md] document. 428 429## Layer Version Negotiation 430 431Now that a layer has been discovered, an application can choose to load it, or 432in the case of implicit layers, it can be loaded by default. 433When the loader attempts to load the layer, the first thing it does is attempt 434to negotiate the version of the loader to layer interface. 435In order to negotiate the loader/layer interface version, the layer must 436implement the `vkNegotiateLoaderLayerInterfaceVersion` function. 437The following information is provided for this interface in 438include/vulkan/vk_layer.h: 439 440```cpp 441typedef enum VkNegotiateLayerStructType { 442 LAYER_NEGOTIATE_INTERFACE_STRUCT = 1, 443} VkNegotiateLayerStructType; 444 445typedef struct VkNegotiateLayerInterface { 446 VkNegotiateLayerStructType sType; 447 void *pNext; 448 uint32_t loaderLayerInterfaceVersion; 449 PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr; 450 PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr; 451 PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr; 452} VkNegotiateLayerInterface; 453 454VkResult 455 vkNegotiateLoaderLayerInterfaceVersion( 456 VkNegotiateLayerInterface *pVersionStruct); 457``` 458 459The `VkNegotiateLayerInterface` structure is similar to other Vulkan structures. 460The "sType" field, in this case takes a new enum defined just for internal 461loader/layer interfacing use. 462The valid values for "sType" could grow in the future, but right now only 463has the one value "LAYER_NEGOTIATE_INTERFACE_STRUCT". 464 465This function (`vkNegotiateLoaderLayerInterfaceVersion`) should be exported by 466the layer so that using "GetProcAddress" on Windows or "dlsym" on Linux or 467macOS, should return a valid function pointer to it. 468Once the loader has grabbed a valid address to the layers function, the loader 469will create a variable of type `VkNegotiateLayerInterface` and initialize it 470in the following ways: 471 1. Set the structure "sType" to "LAYER_NEGOTIATE_INTERFACE_STRUCT" 472 2. Set pNext to NULL. 473 - This is for future growth 474 3. Set "loaderLayerInterfaceVersion" to the current version the loader desires 475to set the interface to. 476 - The minimum value sent by the loader will be 2 since it is the first 477version supporting this function. 478 479The loader will then individually call each layer’s 480`vkNegotiateLoaderLayerInterfaceVersion` function with the filled out 481“VkNegotiateLayerInterface”. 482 483This function allows the loader and layer to agree on an interface version to 484use. 485The "loaderLayerInterfaceVersion" field is both an input and output parameter. 486"loaderLayerInterfaceVersion" is filled in by the loader with the desired 487latest interface version supported by the loader (typically the latest). 488The layer receives this and returns back the version it desires in the same 489field. 490Because it is setting up the interface version between the loader and layer, 491this should be the first call made by a loader to the layer (even prior to any 492calls to `vkGetInstanceProcAddr`). 493 494If the layer receiving the call no longer supports the interface version 495provided by the loader (due to deprecation), then it should report a 496`VK_ERROR_INITIALIZATION_FAILED` error. 497Otherwise it sets the value pointed by "loaderLayerInterfaceVersion" to the 498latest interface version supported by both the layer and the loader and returns 499`VK_SUCCESS`. 500 501The layer should report `VK_SUCCESS` in case the loader-provided interface 502version is newer than that supported by the layer, as it's the loader's 503responsibility to determine whether it can support the older interface version 504supported by the layer. 505The layer should also report `VK_SUCCESS` in the case its interface version is 506greater than the loader's, but return the loader's version. 507Thus, upon return of `VK_SUCCESS` the "loaderLayerInterfaceVersion" will contain 508the desired interface version to be used by the layer. 509 510If the loader receives `VK_ERROR_INITIALIZATION_FAILED` instead of `VK_SUCCESS`, 511then the loader will treat the layer as unusable and will not load it. 512In this case, the application will not see the layer during enumeration. 513*Note that the loader is currently backwards compatible with all layer 514interface versions, so a layer should not be able to request a version 515older than what the loader supports.* 516 517This function **MUST NOT** call down the layer chain to the next layer. 518The loader will work with each layer individually. 519 520If the layer supports the new interface and reports version 2 or greater, then 521The layer should fill in the function pointer values to its internal 522functions: 523 - "pfnGetInstanceProcAddr" should be set to the layer’s internal 524`GetInstanceProcAddr` function. 525 - "pfnGetDeviceProcAddr" should be set to the layer’s internal 526`GetDeviceProcAddr` function. 527 - "pfnGetPhysicalDeviceProcAddr" should be set to the layer’s internal 528`GetPhysicalDeviceProcAddr` function. 529 - If the layer supports no physical device extensions, it may set the 530value to NULL. 531 - More on this function later 532the loader will use the “fpGetInstanceProcAddr” and “fpGetDeviceProcAddr” 533functions from the “VkNegotiateLayerInterface” structure. 534Prior to these changes, the loader would query each of those functions using 535"GetProcAddress" on Windows or "dlsym" on Linux or macOS. 536 537 538## Layer Call Chains and Distributed Dispatch 539 540There are two key architectural features that drive the loader to 541`Layer Library` interface: 542 1. Separate and distinct instance and device call chains 543 2. Distributed dispatch. 544 545For further information, read the overview of dispatch tables and call chains 546above in the 547[Dispatch Tables and Call Chains](LoaderInterfaceArchitecture.md#dispatch-tables-and-call-chains) 548section of the 549[LoaderInterfaceArchitecture.md document](LoaderInterfaceArchitecture.md). 550 551What's important to note here is that a layer can intercept Vulkan instance 552functions, device functions or both. 553For a layer to intercept instance functions, it must participate in the 554instance call chain. 555For a layer to intercept device functions, it must participate in the device 556call chain. 557 558Remember, a layer does not need to intercept all instance or device functions, 559instead, it can choose to intercept only a subset of those functions. 560 561Normally, when a layer intercepts a given Vulkan function, it will call down 562the instance or device call chain as needed. 563The loader and all layer libraries that participate in a call chain cooperate 564to ensure the correct sequencing of calls from one entity to the next. 565This group effort for call chain sequencing is hereinafter referred to as 566**distributed dispatch**. 567 568In distributed dispatch each layer is responsible for properly calling the next 569entity in the call chain. 570This means that a dispatch mechanism is required for all Vulkan functions that 571a layer intercepts. 572If a Vulkan function is not intercepted by a layer, or if a layer chooses to 573terminate the function by not calling down the chain, then no dispatch is 574needed for that particular function. 575 576For example, if the enabled layers intercepted only certain instance functions, 577the call chain would look as follows: 578 579 580Likewise, if the enabled layers intercepted only a few of the device functions, 581the call chain could look this way: 582 583 584The loader is responsible for dispatching all core and instance extension Vulkan 585functions to the first entity in the call chain. 586 587 588## Layer Unknown Physical Device Extensions 589 590Layers that intercept entrypoints which take a `VkPhysicalDevice` as the first 591parameter *should* support `vk_layerGetPhysicalDeviceProcAddr`. This function 592is added to the Layer Interface Version 2 and allows the loader to distinguish 593between entrypoints which take `VkDevice` and `VkPhysicalDevice` as the first 594parameter. This allows the loader to properly support entrypoints that are 595unknown to it gracefully. 596 597```cpp 598PFN_vkVoidFunction 599 vk_layerGetPhysicalDeviceProcAddr( 600 VkInstance instance, 601 const char* pName); 602``` 603 604This function behaves similar to `vkGetInstanceProcAddr` and 605`vkGetDeviceProcAddr` except it should only return values for physical device 606extension entry-points. 607In this way, it compares "pName" to every physical device function supported 608in the layer. 609 610Implementations of the function should have the following behavior: 611 * If it is the name of a physical device function supported by the layer, 612the pointer to the layer's corresponding function should be returned. 613 * If it is the name of a valid function which is **not** a physical device 614function (i.e. an instance, device, or other function implemented by the 615layer), then the value of NULL should be returned. 616 * The layer doesn't call down since the command is not a physical device 617 extension. 618 * If the layer has no idea what this function is, it should call down the 619layer chain to the next `vk_layerGetPhysicalDeviceProcAddr` call. 620 * This can be retrieved in one of two ways: 621 * During `vkCreateInstance`, it is passed to a layer in the chain 622information passed to a layer in the `VkLayerInstanceCreateInfo` structure. 623 * Use `get_chain_info()` to get the pointer to the 624`VkLayerInstanceCreateInfo` structure. Let's call it chain_info. 625 * The address is then under 626chain_info->u.pLayerInfo->pfnNextGetPhysicalDeviceProcAddr 627 * See 628[Example Code for CreateInstance](#example-code-for-createinstance) 629 * Using the next layer’s `GetInstanceProcAddr` function to query for 630`vk_layerGetPhysicalDeviceProcAddr`. 631 632If a layer intends to support functions that take VkPhysicalDevice as the 633dispatchable parameter, then layer should support `vk_layerGetPhysicalDeviceProcAddr`. 634This is because if these functions aren't known to the loader, such as those 635from unreleased extensions or because the loader is an older build thus doesn't 636know about them _yet_, the loader won't be able to distinguish whether this is 637a device or physical device function. 638 639If a layer does implement `vk_layerGetPhysicalDeviceProcAddr`, it should return 640the address of its `vk_layerGetPhysicalDeviceProcAddr` function in the 641"pfnGetPhysicalDeviceProcAddr" member of the `VkNegotiateLayerInterface` 642structure during [Layer Version Negotiation](#layer-version-negotiation). 643Additionally, the layer should also make sure `vkGetInstanceProcAddr` returns a 644valid function pointer to a query of `vk_layerGetPhysicalDeviceProcAddr`. 645 646Note: If a layer wraps the VkInstance handle, support for 647`vk_layerGetPhysicalDeviceProcAddr` is *NOT* optional and must be implemented. 648 649The behavior of the loader's `vkGetInstanceProcAddr` with support for the 650`vk_layerGetPhysicalDeviceProcAddr` function is as follows: 651 1. Check if core function: 652 - If it is, return the function pointer 653 2. Check if known instance or device extension function: 654 - If it is, return the function pointer 655 3. Call the layer/driver `GetPhysicalDeviceProcAddr` 656 - If it returns non-NULL, return a trampoline to a generic physical device 657function, and set up a generic terminator which will pass it to the proper 658driver. 659 4. Call down using `GetInstanceProcAddr` 660 - If it returns non-NULL, treat it as an unknown logical device command. 661This means setting up a generic trampoline function that takes in a `VkDevice` as 662the first parameter and adjusting the dispatch table to call the 663driver/layer's function after getting the dispatch table from the `VkDevice`. 664Then, return the pointer to corresponding trampoline function. 665 5. Return NULL 666 667Then, if the command gets promoted to core later, it will no 668longer be set up using `vk_layerGetPhysicalDeviceProcAddr`. 669Additionally, if the loader adds direct support for the extension, it will no 670longer get to step 3, because step 2 will return a valid function pointer. 671However, the layer should continue to support the command query via 672`vk_layerGetPhysicalDeviceProcAddr`, until at least a Vulkan version bump, 673because an older loader may still be attempting to use the commands. 674 675### Reason for adding `vk_layerGetPhysicalDeviceProcAddr` 676 677Originally, if `vkGetInstanceProcAddr` was called in the loader, it would 678result in the following behavior: 679 1. The loader would check if core function: 680 - If it was, it would return the function pointer 681 2. The loader would check if known extension function: 682 - If it was, it would return the function pointer 683 3. If the loader knew nothing about it, it would call down using 684`GetInstanceProcAddr` 685 - If it returned non-NULL, treat it as an unknown logical device command. 686 - This meant setting up a generic trampoline function that takes in a 687VkDevice as the first parameter and adjusting the dispatch table to call the 688Driver/Layer's function after getting the dispatch table from the `VkDevice`. 689 4. If all the above failed, the loader would return NULL to the application. 690 691This caused problems when a layer attempted to expose new physical device 692extensions the loader knew nothing about, but an application did. 693Because the loader knew nothing about it, the loader would get to step 3 in the 694above process and would treat the function as an unknown logical device 695command. 696The problem is, this would create a generic VkDevice trampoline function which, 697on the first call, would attempt to dereference the VkPhysicalDevice as a 698VkDevice. 699This would lead to a crash or corruption. 700 701 702## Layer Intercept Requirements 703 704 * Layers intercept a Vulkan function by defining a C/C++ function with 705signature **identical** to the Vulkan API for that function. 706 * A layer **must intercept at least** `vkGetInstanceProcAddr` and 707`vkCreateInstance` to participate in the instance call chain. 708 * A layer **may also intercept** `vkGetDeviceProcAddr` and `vkCreateDevice` 709to participate in the device call chain. 710 * For any Vulkan function a layer intercepts which has a non-void return 711value, **an appropriate value must be returned** by the layer intercept 712function. 713 * Most functions a layer intercepts **should call down the chain** to the 714corresponding Vulkan function in the next entity. 715 * The common behavior for a layer is to intercept a call, perform some 716behavior, then pass it down to the next entity. 717 * If a layer doesn't pass the information down, undefined behavior may occur. 718 * This is because the function will not be received by layers further 719down the chain, or any drivers. 720 * One function that **must never call down the chain** is: 721 * `vkNegotiateLoaderLayerInterfaceVersion` 722 * Three common functions that **may not call down the chain** are: 723 * `vkGetInstanceProcAddr` 724 * `vkGetDeviceProcAddr` 725 * `vk_layerGetPhysicalDeviceProcAddr` 726 * These functions only call down the chain for Vulkan functions that they 727do not intercept. 728 * Layer intercept functions **may insert extra calls** to Vulkan functions in 729addition to the intercept. 730 * For example, a layer intercepting `vkQueueSubmit` may want to add a call 731to `vkQueueWaitIdle` after calling down the chain for `vkQueueSubmit`. 732 * This would result in two calls down the chain: First a call down the 733`vkQueueSubmit` chain, followed by a call down the `vkQueueWaitIdle` chain. 734 * Any additional calls inserted by a layer must be on the same chain 735 * If the function is a device function, only other device functions 736should be added. 737 * Likewise, if the function is an instance function, only other instance 738functions should be added. 739 740 741## Distributed Dispatching Requirements 742 743- For each entry-point a layer intercepts, it must keep track of the 744entry-point residing in the next entity in the chain it will call down into. 745 * In other words, the layer must have a list of pointers to functions of the 746appropriate type to call into the next entity. 747 * This can be implemented in various ways but 748for clarity, will be referred to as a dispatch table. 749- A layer can use the `VkLayerDispatchTable` structure as a device dispatch 750table (see include/vulkan/vk_dispatch_table_helper.h). 751- A layer can use the `VkLayerInstanceDispatchTable` structure as a instance 752dispatch table (see include/vulkan/vk_dispatch_table_helper.h). 753- A Layer's `vkGetInstanceProcAddr` function uses the next entity's 754`vkGetInstanceProcAddr` to call down the chain for unknown (i.e. 755non-intercepted) functions. 756- A Layer's `vkGetDeviceProcAddr` function uses the next entity's 757`vkGetDeviceProcAddr` to call down the chain for unknown (i.e. non-intercepted) 758functions. 759- A Layer's `vk_layerGetPhysicalDeviceProcAddr` function uses the next entity's 760`vk_layerGetPhysicalDeviceProcAddr` to call down the chain for unknown (i.e. 761non-intercepted) functions. 762 763 764## Layer Conventions and Rules 765 766A layer, when inserted into an otherwise compliant Vulkan driver, <b>must</b> 767still result in a compliant Vulkan driver. 768The intention is for layers to have a well-defined baseline behavior. 769Therefore, it must follow some conventions and rules defined below. 770 771In order for layers to have unique names, and reduce the chance of conflicts 772that could occur when the loader attempts to load these layers, layers 773<b>must</b> adhere to the following naming standard: 774 * Start with `VK_LAYER_` prefix 775 * Follow the prefix with either an organization or company name (LunarG), 776 a unique company identifier (NV for Nvidia) or a software product name 777 (RenderDoc) in ALL CAPS 778 * Follow that with the specific name of the layer (typically lower-case but not 779 required to be) 780 * NOTE: The specific name, if more than one word, <b>must</b> be underscore 781 delimited 782 783Examples of valid layer names include: 784 * <b>VK_LAYER_KHRONOS_validation</b> 785 * Organization = "KHRONOS" 786 * Specific name = "validation" 787 * <b>VK_LAYER_RENDERDOC_Capture</b> 788 * Application = "RENDERDOC" 789 * Specific name = "Capture" 790 * <b>VK_LAYER_VALVE_steam_fossilize_32</b> 791 * Organization = "VALVE" 792 * Application = "steam" 793 * Specific name = "fossilize" 794 * OS-modifier = "32" (for 32-bit version) 795 * <b>VK_LAYER_NV_nsight</b> 796 * Organization Acronym = "NV" (for Nvidia) 797 * Specific name = "nsight" 798 799More details on layer naming can be found in the 800[Vulkan style-guide](https://www.khronos.org/registry/vulkan/specs/1.2/styleguide.html#extensions-naming-conventions) 801under section 3.4 "Version, Extension, and Layer Naming Conventions". 802 803A layer is always chained with other layers. 804It must not make invalid calls to, or rely on undefined behaviors of, its lower 805layers. 806When it changes the behavior of a function, it must make sure its upper layers 807do not make invalid calls to or rely on undefined behaviors of its lower layers 808because of the changed behavior. 809For example, when a layer intercepts an object creation function to wrap the 810objects created by its lower layers, it must make sure its lower layers never 811see the wrapping objects, directly from itself or indirectly from its upper 812layers. 813 814When a layer requires host memory, it may ignore the provided allocators. 815It is preferred that the layer use any provided memory allocators if the layer 816is intended to run in a production environment. 817For example, this usually applies to implicit layers that are always enabled. 818That will allow applications to include the layer's memory usage. 819 820Additional rules include: 821 - `vkEnumerateInstanceLayerProperties` **must** enumerate and **only** 822enumerate the layer itself. 823 - `vkEnumerateInstanceExtensionProperties` **must** handle the case where 824`pLayerName` is itself. 825 - It **must** return `VK_ERROR_LAYER_NOT_PRESENT` otherwise, including when 826`pLayerName` is `NULL`. 827 - `vkEnumerateDeviceLayerProperties` **is deprecated and may be omitted**. 828 - Using this will result in undefined behavior. 829 - `vkEnumerateDeviceExtensionProperties` **must** handle the case where 830`pLayerName` is itself. 831 - In other cases, it should chain to other layers. 832 - `vkCreateInstance` **must not** generate an error for unrecognized layer 833names and extension names. 834 - It may assume the layer names and extension names have been validated. 835 - `vkGetInstanceProcAddr` intercepts a Vulkan function by returning a local 836entry-point 837 - Otherwise it returns the value obtained by calling down the instance call 838chain. 839 - `vkGetDeviceProcAddr` intercepts a Vulkan function by returning a local 840entry-point 841 - Otherwise it returns the value obtained by calling down the device call 842chain. 843 - These additional functions must be intercepted if the layer implements 844device-level call chaining: 845 - `vkGetDeviceProcAddr` 846 - `vkCreateDevice`(only required for any device-level chaining) 847 - **NOTE:** older layer libraries may expect that 848 `vkGetInstanceProcAddr` 849ignore `instance` when `pName` is `vkCreateDevice`. 850 - The specification **requires** `NULL` to be returned from 851`vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` for disabled functions. 852 - A layer may return `NULL` itself or rely on the following layers to do so. 853 854 855## Layer Dispatch Initialization 856 857- A layer initializes its instance dispatch table within its `vkCreateInstance` 858function. 859- A layer initializes its device dispatch table within its `vkCreateDevice` 860function. 861- The loader passes a linked list of initialization structures to layers via 862the "pNext" field in the `VkInstanceCreateInfo` and `VkDeviceCreateInfo` 863structures for `vkCreateInstance` and `VkCreateDevice` respectively. 864- The head node in this linked list is of type `VkLayerInstanceCreateInfo` for 865instance and VkLayerDeviceCreateInfo for device. 866See file `include/vulkan/vk_layer.h` for details. 867- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the 868"sType" field in `VkLayerInstanceCreateInfo`. 869- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the 870"sType" field in `VkLayerDeviceCreateInfo`. 871- The "function" field indicates how the union field "u" should be interpreted 872within `VkLayer*CreateInfo`. 873The loader will set the "function" field to VK_LAYER_LINK_INFO. 874This indicates "u" field should be `VkLayerInstanceLink` or 875`VkLayerDeviceLink`. 876- The `VkLayerInstanceLink` and `VkLayerDeviceLink` structures are the list 877nodes. 878- The `VkLayerInstanceLink` contains the next entity's `vkGetInstanceProcAddr` 879used by a layer. 880- The `VkLayerDeviceLink` contains the next entity's `vkGetInstanceProcAddr` 881and `vkGetDeviceProcAddr` used by a layer. 882- Given the above structures set up by the loader, layer must initialize their 883dispatch table as follows: 884 - Find the `VkLayerInstanceCreateInfo`/`VkLayerDeviceCreateInfo` structure in 885the `VkInstanceCreateInfo`/`VkDeviceCreateInfo` structure. 886 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field. 887 - For CreateInstance get the next entity's `vkCreateInstance` by calling the 888"pfnNextGetInstanceProcAddr": 889 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance"). 890 - For CreateDevice get the next entity's `vkCreateDevice` by calling the 891"pfnNextGetInstanceProcAddr": 892pfnNextGetInstanceProcAddr(instance, "vkCreateDevice"), passing the 893already created instance handle. 894 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext. 895 - Call down the chain either `vkCreateDevice` or `vkCreateInstance` 896 - Initialize the layer dispatch table by calling the next entity's 897Get*ProcAddr function once for each Vulkan function needed in the dispatch 898table 899 900## Example Code for CreateInstance 901 902```cpp 903VkResult 904 vkCreateInstance( 905 const VkInstanceCreateInfo *pCreateInfo, 906 const VkAllocationCallbacks *pAllocator, 907 VkInstance *pInstance) 908{ 909 VkLayerInstanceCreateInfo *chain_info = 910 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); 911 912 assert(chain_info->u.pLayerInfo); 913 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = 914 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; 915 PFN_vkCreateInstance fpCreateInstance = 916 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); 917 if (fpCreateInstance == NULL) { 918 return VK_ERROR_INITIALIZATION_FAILED; 919 } 920 921 // Advance the link info for the next element of the chain. 922 // This ensures that the next layer gets it's layer info and not 923 // the info for our current layer. 924 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; 925 926 // Continue call down the chain 927 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); 928 if (result != VK_SUCCESS) 929 return result; 930 931 // Init layer's dispatch table using GetInstanceProcAddr of 932 // next layer in the chain. 933 instance_dispatch_table = new VkLayerInstanceDispatchTable; 934 layer_init_instance_dispatch_table( 935 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); 936 937 // Other layer initialization 938 ... 939 940 return VK_SUCCESS; 941} 942``` 943 944## Example Code for CreateDevice 945 946```cpp 947VkResult 948 vkCreateDevice( 949 VkPhysicalDevice gpu, 950 const VkDeviceCreateInfo *pCreateInfo, 951 const VkAllocationCallbacks *pAllocator, 952 VkDevice *pDevice) 953{ 954 VkInstance instance = GetInstanceFromPhysicalDevice(gpu); 955 VkLayerDeviceCreateInfo *chain_info = 956 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); 957 958 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = 959 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; 960 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = 961 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; 962 PFN_vkCreateDevice fpCreateDevice = 963 (PFN_vkCreateDevice)fpGetInstanceProcAddr(instance, "vkCreateDevice"); 964 if (fpCreateDevice == NULL) { 965 return VK_ERROR_INITIALIZATION_FAILED; 966 } 967 968 // Advance the link info for the next element on the chain. 969 // This ensures that the next layer gets it's layer info and not 970 // the info for our current layer. 971 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; 972 973 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); 974 if (result != VK_SUCCESS) { 975 return result; 976 } 977 978 // initialize layer's dispatch table 979 device_dispatch_table = new VkLayerDispatchTable; 980 layer_init_device_dispatch_table( 981 *pDevice, device_dispatch_table, fpGetDeviceProcAddr); 982 983 // Other layer initialization 984 ... 985 986 return VK_SUCCESS; 987} 988``` 989In this case the function `GetInstanceFromPhysicalDevice` is called to get the 990instance handle. 991In practice, this would be done by any method a layer chooses to get an 992instance handle from the physical device. 993 994 995## Meta-layers 996 997Meta-layers are a special kind of layer which is only available through the 998Khronos loader. 999While normal layers are associated with one particular library, a meta-layer 1000is actually a collection layer which contains an ordered list of other layers 1001(called component layers). 1002 1003The benefits of a meta-layer are: 1004 1. More than one layer may be activated using a single layer name by simply 1005grouping multiple layers in a meta-layer. 1006 2. The order of individual component layers is loaded can be defined within 1007the meta-layer. 1008 3. Layer configurations (internal to the meta-layer manifest file) can easily 1009be shared with others. 1010 4. The loader will automatically collate all instance and device extensions in 1011a meta-layer's component layers, and report them as the meta-layer's properties 1012to the application when queried. 1013 1014Restrictions to defining and using a meta-layer are: 1015 1. A Meta-layer Manifest file **must** be a properly formatted that contains 1016one or more component layers. 1017 3. All component layers **must be** present on a system for the meta-layer to 1018be used. 1019 4. All component layers **must be** at the same Vulkan API major and minor 1020version as the meta-layer for the meta-layer to be used. 1021 1022The ordering of a meta-layer's component layers in the instance or device call- 1023chain is simple: 1024 * The first layer listed will be the layer closest to the application. 1025 * The last layer listed will be the layer closest to the drivers. 1026 1027Inside the meta-layer Manifest file, each component layer is listed by its 1028layer name. 1029This is the "name" tag's value associated with each component layer's Manifest 1030file under the "layer" or "layers" tag. 1031This is also the name that would normally be used when activating a layer 1032during `vkCreateInstance`. 1033 1034Any duplicate layer names in either the component layer list, or globally among 1035all enabled layers, will simply be ignored by the loader. 1036Only the first instance of any layer name will be used. 1037 1038For example, if a layer is enabled using the environment variable 1039`VK_INSTANCE_LAYERS` and have that same layer listed in a meta-layer, then the 1040environment-variable-enabled layer will be used and the component layer will 1041be dropped. 1042Likewise, if a person were to enable a meta-layer and then separately enable 1043one of the component layers afterwards, the second instantiation of the layer 1044name would be ignored. 1045 1046The Manifest file formatting necessary to define a meta-layer can be found in 1047the [Layer Manifest File Format](#layer-manifest-file-format) section. 1048 1049### Override Meta-Layer 1050 1051If an implicit meta-layer was found on the system with the name 1052`VK_LAYER_LUNARG_override`, the loader uses it as an 'override' layer. 1053This is used to selectively enable and disable other layers from being loaded. 1054It can be applied globally or to a specific application or applications. 1055The override meta layer can have the following additional keys: 1056 * `blacklisted_layers` - List of explicit layer names that should not be 1057loaded even if requested by the application. 1058 * `app_keys` - List of paths to executables that the override layer applies 1059to. 1060 * `override_paths` - List of paths which will be used as the search location 1061for component layers. 1062 1063When an application starts up and the override layer is present, the loader 1064first checks to see if the application is in the list. 1065If it isn't, the override layer is not applied. 1066If the list is empty or if `app_keys` doesn't exist, the loader makes the 1067override layer global and applies it to every application upon startup. 1068 1069If the override layer contains `override_paths`, then it uses this list of 1070paths exclusively for component layers. 1071Thus, it ignores both the default explicit and implicit layer layer search 1072locations as well as paths set by environment variables like `VK_LAYER_PATH`. 1073If any component layer is not present in the provided override paths, the meta 1074layer is disabled. 1075 1076The override meta-layer is primarily enabled when using the 1077[VkConfig](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md) 1078tool included in the Vulkan SDK. 1079It is typically only available while the VkConfig tool is actually executing. 1080Please refer to that documentation for more information. 1081 1082## Pre-Instance Functions 1083 1084Vulkan includes a small number of functions which are called without any 1085dispatchable object. 1086<b>Most layers do not intercept these functions</b>, as layers are enabled when an 1087instance is created. 1088However, under certain conditions it is possible for a layer to intercept 1089these functions. 1090 1091One reason why a layer may desire to intercept these pre-instance functions is 1092to filter out extensions that would normally be returned from Vulkan drivers to 1093the application. 1094[RenderDoc](https://renderdoc.org/) is one such layer which intercepts these 1095pre-instance functions so that it may disable extensions it doesn't support. 1096 1097In order to intercept the pre-instance functions, several conditions must be 1098met: 1099* The layer must be implicit 1100* The layer manifest version must be 1.1.2 or later 1101* The layer must export the entry-point symbols for each intercepted function 1102* The layer manifest must specify the name of each intercepted function in a 1103`pre_instance_functions` JSON object 1104 1105The functions that may be intercepted in this way are: 1106* `vkEnumerateInstanceExtensionProperties` 1107* `vkEnumerateInstanceLayerProperties` 1108* `vkEnumerateInstanceVersion` 1109 1110Pre-instance functions work differently from all other layer intercept 1111functions. 1112Other intercept functions have a function prototype identical to that of the 1113function they are intercepting. 1114They then rely on data that was passed to the layer at instance or device 1115creation so that layers can call down the chain. 1116Because there is no need to create an instance before calling the pre-instance 1117functions, these functions must use a separate mechanism for constructing the 1118call chain. 1119This mechanism consists of an extra parameter that will be passed to the layer 1120intercept function when it is called. 1121This parameter will be a pointer to a struct, defined as follows: 1122 1123```cpp 1124typedef struct Vk...Chain 1125{ 1126 struct { 1127 VkChainType type; 1128 uint32_t version; 1129 uint32_t size; 1130 } header; 1131 PFN_vkVoidFunction pfnNextLayer; 1132 const struct Vk...Chain* pNextLink; 1133} Vk...Chain; 1134``` 1135 1136These structs are defined in the `vk_layer.h` file so that it is not necessary 1137to redefine the chain structs in any external code. 1138The name of each struct is be similar to the name of the function it 1139corresponds to, but the leading "V" is capitalized, and the word "Chain" is 1140added to the end. 1141For example, the struct for `vkEnumerateInstanceExtensionProperties` is called 1142`VkEnumerateInstanceExtensionPropertiesChain`. 1143Furthermore, the `pfnNextLayer` struct member is not actually a void function 1144pointer — its type will be the actual type of each function in the call 1145chain. 1146 1147Each layer intercept function must have a prototype that is the same as the 1148prototype of the function being intercepted, except that the first parameter 1149must be that function's chain struct (passed as a const pointer). 1150For example, a function that wishes to intercept 1151`vkEnumerateInstanceExtensionProperties` would have the prototype: 1152 1153```cpp 1154VkResult 1155 InterceptFunctionName( 1156 const VkEnumerateInstanceExtensionPropertiesChain* pChain, 1157 const char* pLayerName, 1158 uint32_t* pPropertyCount, 1159 VkExtensionProperties* pProperties); 1160``` 1161 1162The name of the function is arbitrary; it can be anything provided that it is 1163given in the layer manifest file (see 1164[Layer Manifest File Format](#layer-manifest-file-format)). 1165The implementation of each intercept function is responsible for calling the 1166next item in the call chain, using the chain parameter. 1167This is done by calling the `pfnNextLayer` member of the chain struct, passing 1168`pNextLink` as the first argument, and passing the remaining function arguments 1169after that. 1170For example, a simple implementation for 1171`vkEnumerateInstanceExtensionProperties` that does nothing but call down the 1172chain would look like: 1173 1174```cpp 1175VkResult 1176 InterceptFunctionName( 1177 const VkEnumerateInstanceExtensionPropertiesChain* pChain, 1178 const char* pLayerName, 1179 uint32_t* pPropertyCount, 1180 VkExtensionProperties* pProperties) 1181{ 1182 return pChain->pfnNextLayer( 1183 pChain->pNextLink, pLayerName, pPropertyCount, pProperties); 1184} 1185``` 1186 1187When using a C++ compiler, each chain type also defines a function named 1188`CallDown` which can be used to automatically handle the first argument. 1189Implementing the above function using this method would look like: 1190 1191```cpp 1192VkResult 1193 InterceptFunctionName( 1194 const VkEnumerateInstanceExtensionPropertiesChain* pChain, 1195 const char* pLayerName, 1196 uint32_t* pPropertyCount, 1197 VkExtensionProperties* pProperties) 1198{ 1199 return pChain->CallDown(pLayerName, pPropertyCount, pProperties); 1200} 1201``` 1202 1203Unlike with other functions in layers, the layer may not save any global data 1204between these function calls. 1205Because Vulkan does not store any state until an instance has been created, all 1206layer libraries are released at the end of each pre-instance call. 1207This means that implicit layers can use pre-instance intercepts to modify data 1208that is returned by the functions, but they cannot be used to record that data. 1209 1210## Special Considerations 1211 1212 1213### Associating Private Data with Vulkan Objects Within a Layer 1214 1215A layer may want to associate its own private data with one or more Vulkan 1216objects. 1217Two common methods to do this are hash maps and object wrapping. 1218 1219 1220#### Wrapping 1221 1222The loader supports layers wrapping any Vulkan object, including dispatchable 1223objects. 1224For functions that return object handles, each layer does not touch the value 1225passed down the call chain. 1226This is because lower items may need to use the original value. 1227However, when the value is returned from a lower-level layer (possibly the 1228driver), the layer saves the handle and returns its own handle to the 1229layer above it (possibly the application). 1230When a layer receives a Vulkan function using something that it previously 1231returned a handle for, the layer is required to unwrap the handle and pass 1232along the saved handle to the layer below it. 1233This means that the layer **must intercept every Vulkan function which uses** 1234**the object in question**, and wrap or unwrap the object, as appropriate. 1235This includes adding support for all extensions with functions using any 1236object the layer wraps as well as any loader-layer interface functions such as 1237`vk_layerGetPhysicalDeviceProcAddr`. 1238 1239Layers above the object wrapping layer will see the wrapped object. 1240Layers which wrap dispatchable objects must ensure that the first field in the 1241wrapping structure is a pointer to a dispatch table as defined in `vk_layer.h`. 1242Specifically, an instance wrapped dispatchable object could be as follows: 1243 1244```cpp 1245struct my_wrapped_instance_obj_ { 1246 VkLayerInstanceDispatchTable *disp; 1247 // whatever data layer wants to add to this object 1248}; 1249``` 1250A device wrapped dispatchable object could be as follows: 1251```cpp 1252struct my_wrapped_instance_obj_ { 1253 VkLayerDispatchTable *disp; 1254 // whatever data layer wants to add to this object 1255}; 1256``` 1257 1258Layers that wrap dispatchable objects must follow the guidelines for creating 1259new dispatchable objects (below). 1260 1261#### Cautions About Wrapping 1262 1263Layers are generally discouraged from wrapping objects, because of the 1264potential for incompatibilities with new extensions. 1265For example, let's say that a layer wraps `VkImage` objects, and properly wraps 1266and unwraps `VkImage` object handles for all core functions. 1267If a new extension is created which has functions that take `VkImage` objects 1268as parameters, and if the layer does not support those new functions, an 1269application that uses both the layer and the new extension will have undefined 1270behavior when those new functions are called (e.g. the application may crash). 1271This is because the lower-level layers and drivers won't receive the handle that 1272they generated. 1273Instead, they will receive a handle that is only known by the layer that is 1274wrapping the object. 1275 1276Because of the potential for incompatibilities with unsupported extensions, 1277layers that wrap objects must check which extensions are being used by the 1278application, and take appropriate action if the layer is used with unsupported 1279extensions such as issuing a warning/error message to the user. 1280 1281The reason that the validation layers wrap objects is to track the proper use 1282and destruction of each object. 1283They issue a validation error if used with unsupported extensions, alerting the 1284user to the potential for undefined behavior. 1285 1286 1287#### Hash Maps 1288 1289Alternatively, a layer may want to use a hash map to associate data with a 1290given object. 1291The key to the map could be the object. Alternatively, for dispatchable objects 1292at a given level (eg device or instance) the layer may want data associated 1293with the `VkDevice` or `VkInstance` objects. 1294Since there are multiple dispatchable objects for a given `VkInstance` or 1295`VkDevice`, the `VkDevice` or `VkInstance` object is not a great map key. 1296Instead the layer should use the dispatch table pointer within the `VkDevice` 1297or `VkInstance` since that will be unique for a given `VkInstance` or 1298`VkDevice`. 1299 1300 1301### Creating New Dispatchable Objects 1302 1303Layers which create dispatchable objects must take special care. 1304Remember that loader *trampoline* code normally fills in the dispatch table 1305pointer in the newly created object. 1306Thus, the layer must fill in the dispatch table pointer if the loader 1307*trampoline* will not do so. 1308Common cases where a layer (or driver) may create a dispatchable object without 1309loader *trampoline* code is as follows: 1310- Layers that wrap dispatchable objects 1311- Layers which add extensions that create dispatchable objects 1312- Layers which insert extra Vulkan functions in the stream of functions they 1313intercept from the application 1314- Drivers which add extensions that create dispatchable objects 1315 1316The Khronos loader provides a callback that can be used for initializing a 1317dispatchable object. 1318The callback is passed as an extension structure via the `pNext` field in the 1319create info structure when creating an instance (`VkInstanceCreateInfo`) or 1320device (`VkDeviceCreateInfo`). 1321The callback prototype is defined as follows for instance and device callbacks 1322respectively (see `vk_layer.h`): 1323 1324```cpp 1325VKAPI_ATTR VkResult VKAPI_CALL 1326 vkSetInstanceLoaderData( 1327 VkInstance instance, 1328 void *object); 1329 1330VKAPI_ATTR VkResult VKAPI_CALL 1331 vkSetDeviceLoaderData( 1332 VkDevice device, 1333 void *object); 1334``` 1335 1336To obtain these callbacks the layer must search through the list of structures 1337pointed to by the "pNext" field in the `VkInstanceCreateInfo` and 1338`VkDeviceCreateInfo` parameters to find any callback structures inserted by the 1339loader. 1340The salient details are as follows: 1341- For `VkInstanceCreateInfo` the callback structure pointed to by "pNext" is 1342`VkLayerInstanceCreateInfo` as defined in `include/vulkan/vk_layer.h`. 1343- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within 1344`VkInstanceCreateInfo` parameter indicates a loader structure. 1345- Within `VkLayerInstanceCreateInfo`, the "function" field indicates how the 1346union field "u" should be interpreted. 1347- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will 1348contain the callback in "pfnSetInstanceLoaderData". 1349- For `VkDeviceCreateInfo` the callback structure pointed to by "pNext" is 1350`VkLayerDeviceCreateInfo` as defined in `include/vulkan/vk_layer.h`. 1351- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within 1352`VkDeviceCreateInfo` parameter indicates a loader structure. 1353- Within `VkLayerDeviceCreateInfo`, the "function" field indicates how the union 1354field "u" should be interpreted. 1355- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will 1356contain the callback in "pfnSetDeviceLoaderData". 1357 1358Alternatively, if an older loader is being used that doesn't provide these 1359callbacks, the layer may manually initialize the newly created dispatchable 1360object. 1361To fill in the dispatch table pointer in newly created dispatchable object, the 1362layer should copy the dispatch pointer, which is always the first entry in the 1363structure, from an existing parent object of the same level (instance versus 1364device). 1365 1366For example, if there is a newly created `VkCommandBuffer` object, then the 1367dispatch pointer from the `VkDevice` object, which is the parent of the 1368`VkCommandBuffer` object, should be copied into the newly created object. 1369 1370### Versioning and Activation Interactions 1371 1372There are several interacting rules concerning the activation of layers with 1373non-obvious results. 1374This not an exhaustive list but should better clarify the behavior of the 1375loader in complex situations. 1376 1377* The Vulkan Loader in versions 1.3.228 and above will enable implicit layers 1378regardless of the API version specified by the application in 1379`VkApplicationInfo::apiVersion`. 1380Previous loader versions (1.3.227 and below) used to have a requirement where 1381implicit layer's API version must be equal to or greater than the API version 1382of the application for the layer to be enabled. 1383The change relaxed the implicit layer loading requirements because it was 1384determined that the perceived protection of preventing older layers running 1385with newer applications wasn't enough to justify the friction it caused. 1386This was due to older layers no longer working with newer applications 1387for no apparent reason, as well as older layers having to update the manifest 1388to work with newer applications. 1389The layer didn't need to do anything else to get their layer working again, 1390which meant that a layer didn't need to prove that their layer worked with 1391newer API versions. 1392Thus, the disabling caused confusion for users but didn't protect them from 1393potentially badly behaving layers. 1394 1395* An implicit layer will ignore its disable environment variable being set if 1396it is a component in an active meta layer. 1397 1398* The environment `VK_LAYER_PATH` only affects explicit layer searching, not 1399implicit. 1400Layers found in this path are treated as explicit, even if they contain all the 1401requisite fields to be an implicit layer. 1402This means they will not be implicitly enabled. 1403 1404* Meta layers do not have to be implicit - they can be explicit. 1405It cannot be assumed that because a meta layer is present that it will be active. 1406 1407* The `blacklisted_layers` member of the override meta layer will prevent both 1408implicitly enabled and explicitely enabled layers from activating. 1409Any layers in an application's `VkInstanceCreateInfo::ppEnabledLayerNames` that 1410are in the blacklist will not be enabled. 1411 1412* The `app_keys` member of the override meta layer will make a meta layer apply 1413to only applications found in this list. 1414If there are any items in the app keys list, the meta layer isn't enabled for any application except those found in the list. 1415 1416* The `override_paths` member of the override meta layer, if present, will 1417replace the search paths the loader uses to find component layers. 1418If any component layer isn't present in the override paths, the override meta 1419layer is not applied. 1420So if an override meta layer wants to mix default and custom layer locations, 1421the override paths must contain both custom and default layer locations. 1422 1423* If the override layer is both present and contains `override_paths`, the 1424paths from the environment variable `VK_LAYER_PATH` are ignored when searching 1425for explicit layers. 1426For example, when both the meta layer override paths and `VK_LAYER_PATH` are 1427present, none of the layers in `VK_LAYER_PATH` are discoverable, and the 1428loader will not find them. 1429 1430 1431## Layer Manifest File Format 1432 1433The Khronos loader uses manifest files to discover available layer libraries 1434and layers. 1435It doesn't directly query the layer's dynamic library except during chaining. 1436This is to reduce the likelihood of loading a malicious layer into memory. 1437Instead, details are read from the Manifest file, which are then provided 1438for applications to determine what layers should actually be loaded. 1439 1440The following section discusses the details of the Layer Manifest JSON file 1441format. 1442The JSON file itself does not have any requirements for naming. 1443The only requirement is that the extension suffix of the file is ".json". 1444 1445Here is an example layer JSON Manifest file with a single layer: 1446 1447```json 1448{ 1449 "file_format_version" : "1.2.1", 1450 "layer": { 1451 "name": "VK_LAYER_LUNARG_overlay", 1452 "type": "INSTANCE", 1453 "library_path": "vkOverlayLayer.dll", 1454 "library_arch" : "64", 1455 "api_version" : "1.0.5", 1456 "implementation_version" : "2", 1457 "description" : "LunarG HUD layer", 1458 "functions": { 1459 "vkNegotiateLoaderLayerInterfaceVersion": 1460 "OverlayLayer_NegotiateLoaderLayerInterfaceVersion" 1461 }, 1462 "instance_extensions": [ 1463 { 1464 "name": "VK_EXT_debug_report", 1465 "spec_version": "1" 1466 }, 1467 { 1468 "name": "VK_VENDOR_ext_x", 1469 "spec_version": "3" 1470 } 1471 ], 1472 "device_extensions": [ 1473 { 1474 "name": "VK_EXT_debug_marker", 1475 "spec_version": "1", 1476 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"] 1477 } 1478 ], 1479 "enable_environment": { 1480 "ENABLE_LAYER_OVERLAY_1": "1" 1481 }, 1482 "disable_environment": { 1483 "DISABLE_LAYER_OVERLAY_1": "" 1484 } 1485 } 1486} 1487``` 1488 1489Here's a snippet with the changes required to support multiple layers per 1490manifest file: 1491```json 1492{ 1493 "file_format_version" : "1.0.1", 1494 "layers": [ 1495 { 1496 "name": "VK_LAYER_layer_name1", 1497 "type": "INSTANCE", 1498 ... 1499 }, 1500 { 1501 "name": "VK_LAYER_layer_name2", 1502 "type": "INSTANCE", 1503 ... 1504 } 1505 ] 1506} 1507``` 1508 1509Here's an example of a meta-layer manifest file: 1510```json 1511{ 1512 "file_format_version" : "1.1.1", 1513 "layer": { 1514 "name": "VK_LAYER_META_layer", 1515 "type": "GLOBAL", 1516 "api_version" : "1.0.40", 1517 "implementation_version" : "1", 1518 "description" : "LunarG Meta-layer example", 1519 "component_layers": [ 1520 "VK_LAYER_KHRONOS_validation", 1521 "VK_LAYER_LUNARG_api_dump" 1522 ] 1523 } 1524} 1525``` 1526 1527 1528<table style="width:100%"> 1529 <tr> 1530 <th>JSON Node</th> 1531 <th>Description and Notes</th> 1532 <th>Restrictions</th> 1533 <th>Parent</th> 1534 <th>Introspection Query</th> 1535 </tr> 1536 <tr> 1537 <td>"api_version"</td> 1538 <td>The major.minor.patch version number of the Vulkan API that the layer 1539 supports. 1540 It does not require the application to make use of that API version. 1541 It simply is an indication that the layer can support Vulkan API 1542 instance and device functions up to and including that API version. </br> 1543 For example: 1.0.33. 1544 </td> 1545 <td>None</td> 1546 <td>"layer"/"layers"</td> 1547 <td><small>vkEnumerateInstanceLayerProperties</small></td> 1548 </tr> 1549 <tr> 1550 <td>"app_keys"</td> 1551 <td>List of paths to executables that the meta-layer applies to. 1552 </td> 1553 <td><b>Meta-layers Only</b></td> 1554 <td>"layer"/"layers"</td> 1555 <td><small>N/A</small></td> 1556 </tr> 1557 <tr> 1558 <td>"blacklisted_layers"</td> 1559 <td>List of explicit layer names that should not be loaded even if 1560 requested by the application. 1561 </td> 1562 <td><b>Meta-layers Only</b></td> 1563 <td>"layer"/"layers"</td> 1564 <td><small>N/A</small></td> 1565 </tr> 1566 <tr> 1567 <td>"component_layers"</td> 1568 <td>Indicates the component layer names that are 1569 part of a meta-layer. 1570 The names listed must be the "name" identified in each of the component 1571 layer's Mainfest file "name" tag (this is the same as the name of the 1572 layer that is passed to the `vkCreateInstance` command). 1573 All component layers must be present on the system and found by the 1574 loader in order for this meta-layer to be available and activated. <br/> 1575 <b>This field must not be present if "library_path" is defined</b>. 1576 </td> 1577 <td><b>Meta-layers Only</b></td> 1578 <td>"layer"/"layers"</td> 1579 <td><small>N/A</small></td> 1580 </tr> 1581 <tr> 1582 <td>"description"</td> 1583 <td>A high-level description of the layer and its intended use.</td> 1584 <td>None</td> 1585 <td>"layer"/"layers"</td> 1586 <td><small>vkEnumerateInstanceLayerProperties</small></td> 1587 </tr> 1588 <tr> 1589 <td>"device_extensions"</td> 1590 <td><b>OPTIONAL:</b> Contains the list of device extension names supported 1591 by this layer. One "device\_extensions" node with an array of one or 1592 more elements is required if any device extensions are supported by a 1593 layer; otherwise the node is optional. 1594 Each element of the array must have the nodes "name" and "spec_version" 1595 which correspond to `VkExtensionProperties` "extensionName" and 1596 "specVersion" respectively. 1597 Additionally, each element of the array of device extensions must have 1598 the node "entrypoints" if the device extension adds Vulkan API 1599 functions; otherwise this node is not required. 1600 The "entrypoint" node is an array of the names of all entry-points added 1601 by the supported extension. 1602 </td> 1603 <td>None</td> 1604 <td>"layer"/"layers"</td> 1605 <td><small>vkEnumerateDeviceExtensionProperties</small></td> 1606 </tr> 1607 <tr> 1608 <td>"disable_environment"</td> 1609 <td><b>REQUIRED:</b> Indicates an environment variable used to disable the 1610 Implicit Layer (when defined to any non-empty string value).<br/> 1611 In rare cases of an application not working with an implicit layer, the 1612 application can set this environment variable (before calling Vulkan 1613 functions) in order to "blacklist" the layer. 1614 This environment variable (which may vary with each variation of the 1615 layer) must be set (not particularly to any value). 1616 If both the "enable_environment" and "disable_environment" variables are 1617 set, the implicit layer is disabled. 1618 </td> 1619 <td><b>Implicit Layers Only</b></td> 1620 <td>"layer"/"layers"</td> 1621 <td><small>N/A</small></td> 1622 </tr> 1623 <tr> 1624 <td>"enable_environment"</td> 1625 <td><b>OPTIONAL:</b> Indicates an environment variable used to enable the 1626 Implicit Layer (when defined to any non-empty string value).<br/> 1627 This environment variable (which may vary with each variation of the 1628 layer) must be set to the given value or else the implicit layer is not 1629 loaded. 1630 This is for application environments (e.g. Steam) which want to enable a 1631 layer(s) only for applications that they launch, and allows for 1632 applications run outside of an application environment to not get that 1633 implicit layer(s). 1634 </td> 1635 <td><b>Implicit Layers Only</b></td> 1636 <td>"layer"/"layers"</td> 1637 <td><small>N/A</small></td> 1638 </tr> 1639 <tr> 1640 <td>"file_format_version"</td> 1641 <td>Manifest format major.minor.patch version number.<br/> 1642 Supported versions are: 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.1.2 and 1.2.0. 1643 </td> 1644 <td>None</td> 1645 <td>None</td> 1646 <td><small>N/A</small></td> 1647 </tr> 1648 <tr> 1649 <td>"functions"</td> 1650 <td><b>OPTIONAL:</b> This section can be used to identify a different 1651 function name for the loader to use in place of standard layer interface 1652 functions. 1653 The "functions" node is required if the layer is using an alternative 1654 name for `vkNegotiateLoaderLayerInterfaceVersion`. 1655 </td> 1656 <td>None</td> 1657 <td>"layer"/"layers"</td> 1658 <td><small>vkGet*ProcAddr</small></td> 1659 </tr> 1660 <tr> 1661 <td>"implementation_version"</td> 1662 <td>The version of the layer implemented. 1663 If the layer itself has any major changes, this number should change so 1664 the loader and/or application can identify it properly. 1665 </td> 1666 <td>None</td> 1667 <td>"layer"/"layers"</td> 1668 <td><small>vkEnumerateInstanceLayerProperties</small></td> 1669 </tr> 1670 <tr> 1671 <td>"instance_extensions"</td> 1672 <td><b>OPTIONAL:</b> Contains the list of instance extension names 1673 supported by this layer. 1674 One "instance_extensions" node with an array of one or more elements is 1675 required if any instance extensions are supported by a layer; otherwise 1676 the node is optional. 1677 Each element of the array must have the nodes "name" and "spec_version" 1678 which correspond to `VkExtensionProperties` "extensionName" and 1679 "specVersion" respectively. 1680 </td> 1681 <td>None</td> 1682 <td>"layer"/"layers"</td> 1683 <td><small>vkEnumerateInstanceExtensionProperties</small></td> 1684 </tr> 1685 <tr> 1686 <td>"layer"</td> 1687 <td>The identifier used to group a single layer's information together. 1688 </td> 1689 <td>None</td> 1690 <td>None</td> 1691 <td><small>vkEnumerateInstanceLayerProperties</small></td> 1692 </tr> 1693 <tr> 1694 <td>"layers"</td> 1695 <td>The identifier used to group multiple layers' information together. 1696 This requires a minimum Manifest file format version of 1.0.1. 1697 </td> 1698 <td>None</td> 1699 <td>None</td> 1700 <td><small>vkEnumerateInstanceLayerProperties</small></td> 1701 </tr> 1702 <tr> 1703 <td>"library_path"</td> 1704 <td>Specifies either a filename, a relative pathname, or a full pathname to 1705 a layer shared library file. 1706 If "library_path" specifies a relative pathname, it is relative to the 1707 path of the JSON manifest file (e.g. for cases when an application 1708 provides a layer that is in the same folder hierarchy as the rest of the 1709 application files). 1710 If "library_path" specifies a filename, the library must live in the 1711 system's shared object search path. 1712 There are no rules about the name of the layer shared library files 1713 other than it should end with the appropriate suffix (".DLL" on Windows, 1714 ".so" on Linux, and ".dylib" on macOS).<br/> 1715 <b>This field must not be present if "component_layers" is defined</b>. 1716 </td> 1717 <td><b>Not Valid For Meta-layers</b></td> 1718 <td>"layer"/"layers"</td> 1719 <td><small>N/A</small></td> 1720 </tr> 1721 <td>"library_arch"</td> 1722 <td>Optional field which specifies the architecture of the binary associated 1723 with "library_path". <br /> 1724 Allows the loader to quickly determine if the architecture of the layer 1725 matches that of the running application. <br /> 1726 The only valid values are "32" and "64".</td> 1727 <td><small>N/A</small></td> 1728 </tr> 1729 <tr> 1730 <tr> 1731 <td>"name"</td> 1732 <td>The string used to uniquely identify this layer to applications.</td> 1733 <td>None</td> 1734 <td>"layer"/"layers"</td> 1735 <td><small>vkEnumerateInstanceLayerProperties</small></td> 1736 </tr> 1737 <tr> 1738 <td>"override_paths"</td> 1739 <td>List of paths which will be used as the search location for component 1740 layers. 1741 </td> 1742 <td><b>Meta-layers Only</b></td> 1743 <td>"layer"/"layers"</td> 1744 <td><small>N/A</small></td> 1745 </tr> 1746 <tr> 1747 <td>"pre_instance_functions"</td> 1748 <td><b>OPTIONAL:</b> Indicates which functions the layer wishes to 1749 intercept, that do not require that an instance has been created. 1750 This should be an object where each function to be intercepted is 1751 defined as a string entry where the key is the Vulkan function name and 1752 the value is the name of the intercept function in the layer's dynamic 1753 library. 1754 Available in layer manifest versions 1.1.2 and up. <br/> 1755 See <a href="#pre-instance-functions">Pre-Instance Functions</a> for 1756 more information. 1757 </td> 1758 <td><b>Implicit Layers Only</b></td> 1759 <td>"layer"/"layers"</td> 1760 <td><small>vkEnumerateInstance*Properties</small></td> 1761 </tr> 1762 <tr> 1763 <td>"type"</td> 1764 <td>This field indicates the type of layer. The values can be: GLOBAL, or 1765 INSTANCE.<br/> 1766 <b> NOTE: </b> Prior to deprecation, the "type" node was used to 1767 indicate which layer chain(s) to activate the layer upon: instance, 1768 device, or both. 1769 Distinct instance and device layers are deprecated; there are now just 1770 instance layers. 1771 Originally, allowable values were "INSTANCE", "GLOBAL" and, "DEVICE." 1772 But now "DEVICE" layers are skipped over by the loader as if they were 1773 not found. 1774 </td> 1775 <td>None</td> 1776 <td>"layer"/"layers"</td> 1777 <td><small>vkEnumerate*LayerProperties</small></td> 1778 </tr> 1779</table> 1780 1781### Layer Manifest File Version History 1782 1783The current highest supported Layer Manifest file format supported is 1.2.0. 1784Information about each version is detailed in the following sub-sections: 1785 1786### Layer Manifest File Version 1.2.1 1787 1788Added the "library\_arch" field to the layer manifest to allow the loader to 1789quickly determine if the layer matches the architecture of the current running 1790application. 1791 1792#### Layer Manifest File Version 1.2.0 1793 1794The ability to define the layer settings as defined by the 1795[layer manifest schema](https://github.com/LunarG/VulkanTools/blob/master/vkconfig_core/layers/layers_schema.json). 1796 1797The ability to briefly document the layer thanks to the fields: 1798 * "introduction": Presentation of the purpose of the layer in a paragraph. 1799 * "url": A link the the layer home page. 1800 * "platforms": The list of supported platforms of the layer 1801 * "status": The life cycle of the layer: Alpha, Beta, Stable, or Deprecated 1802 1803These changes were made to enable third-party layers to expose their features 1804within 1805[Vulkan Configurator](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md) 1806or other tools. 1807 1808#### Layer Manifest File Version 1.1.2 1809 1810Version 1.1.2 introduced the ability of layers to intercept function calls that 1811do not have an instance. 1812 1813#### Layer Manifest File Version 1.1.1 1814 1815The ability to define custom metalayers was added. 1816To support metalayers, the "component_layers" section was added, and the 1817requirement for a "library_path" section to be present was removed when the 1818"component_layers" section is present. 1819 1820#### Layer Manifest File Version 1.1.0 1821 1822Layer Manifest File Version 1.1.0 is tied to changes exposed by the 1823Loader/Layer interface version 2. 1824 1. Renaming "vkGetInstanceProcAddr" in the "functions" section is deprecated 1825since the loader no longer needs to query the layer about 1826"vkGetInstanceProcAddr" directly. 1827It is now returned during the layer negotiation, so this field will be 1828ignored. 1829 2. Renaming "vkGetDeviceProcAddr" in the "functions" section is 1830deprecated since the loader no longer needs to query the layer about 1831"vkGetDeviceProcAddr" directly. 1832It too is now returned during the layer negotiation, so this field will be 1833ignored. 1834 3. Renaming the "vkNegotiateLoaderLayerInterfaceVersion" function is being 1835added to the "functions" section, since this is now the only function the 1836loader needs to query using OS-specific calls. 1837 - NOTE: This is an optional field and, as the two previous fields, only 1838needed if the layer requires changing the name of the function for some reason. 1839 1840The layer manifest file does not need to to be updated if the names of any listed 1841functions has not changed. 1842 1843#### Layer Manifest File Version 1.0.1 1844 1845The ability to define multiple layers using the "layers" array was added. 1846This JSON array field can be used when defining a single layer or multiple 1847layers. 1848The "layer" field is still present and valid for a single layer definition. 1849 1850#### Layer Manifest File Version 1.0.0 1851 1852The initial version of the layer manifest file specified the basic format and 1853fields of a layer JSON file. 1854The fields of the 1.0.0 file format include: 1855 * "file\_format\_version" 1856 * "layer" 1857 * "name" 1858 * "type" 1859 * "library\_path" 1860 * "api\_version" 1861 * "implementation\_version" 1862 * "description" 1863 * "functions" 1864 * "instance\_extensions" 1865 * "device\_extensions" 1866 * "enable\_environment" 1867 * "disable\_environment" 1868 1869It was also during this time that the value of "DEVICE" was deprecated from 1870the "type" field. 1871 1872 1873## Layer Interface Versions 1874 1875The current loader/layer interface is at version 2. 1876The following sections detail the differences between the various versions. 1877 1878### Layer Interface Version 2 1879 1880Introduced the concept of 1881[loader and layer interface](#layer-version-negotiation) using the new 1882`vkNegotiateLoaderLayerInterfaceVersion` function. 1883Additionally, it introduced the concept of 1884[Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions) 1885and the associated `vk_layerGetPhysicalDeviceProcAddr` function. 1886Finally, it changed the manifest file definition to 1.1.0. 1887 1888Note: If a layer wraps the VkInstance handle, support for 1889`vk_layerGetPhysicalDeviceProcAddr` is *NOT* optional and must be implemented. 1890 1891### Layer Interface Version 1 1892 1893A layer supporting interface version 1 had the following behavior: 1894 1. `GetInstanceProcAddr` and `GetDeviceProcAddr` were directly exported 1895 2. The layer manifest file was able to override the names of the 1896`GetInstanceProcAddr` and `GetDeviceProcAddr`functions. 1897 1898### Layer Interface Version 0 1899 1900A layer supporting interface version 0 must define and export these 1901introspection functions, unrelated to any Vulkan function despite the names, 1902signatures, and other similarities: 1903 1904- `vkEnumerateInstanceLayerProperties` enumerates all layers in a 1905`Layer Library`. 1906 - This function never fails. 1907 - When the `Layer Library` contains only one layer, this function may be an 1908 alias to that one layer's `vkEnumerateInstanceLayerProperties`. 1909- `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of 1910 layers in the `Layer Library`. 1911 - "pLayerName" is always a valid layer name. 1912 - This function never fails. 1913 - When the `Layer Library` contains only one layer, this function may be an 1914 alias to the one layer's `vkEnumerateInstanceExtensionProperties`. 1915- `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full, 1916 proper, or empty subset) of layers in the `Layer Library`. 1917 - "physicalDevice" is always `VK_NULL_HANDLE`. 1918 - This function never fails. 1919 - If a layer is not enumerated by this function, it will not participate in 1920 device function interception. 1921- `vkEnumerateDeviceExtensionProperties` enumerates device extensions of 1922 layers in the `Layer Library`. 1923 - "physicalDevice" is always `VK_NULL_HANDLE`. 1924 - "pLayerName" is always a valid layer name. 1925 - This function never fails. 1926 1927It must also define and export these functions once for each layer in the 1928library: 1929 1930- `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a 1931layer's vkGetInstanceProcAddr except it is exported. 1932 1933 When the `Layer Library` contains only one layer, this function may 1934 alternatively be named `vkGetInstanceProcAddr`. 1935 1936- `<layerName>GetDeviceProcAddr` behaves identically to a layer's 1937vkGetDeviceProcAddr except it is exported. 1938 1939 When the `Layer Library` contains only one layer, this function may 1940 alternatively be named `vkGetDeviceProcAddr`. 1941 1942All layers contained within a library must support `vk_layer.h`. 1943They do not need to implement functions that they do not intercept. 1944They are recommended not to export any functions. 1945 1946 1947## Loader and Layer Interface Policy 1948 1949This section is intended to define proper behavior expected between the loader 1950and layers. 1951Much of this section is additive to the Vulkan spec, and necessary for 1952maintaining consistency across platforms. 1953In fact, much of the language can be found throughout this document, but is 1954summarized here for convenience. 1955Additionally, there should be a way to identify bad or non-conformant behavior 1956in a layer and remedy it as soon as possible. 1957Therefore, a policy numbering system is provided to clearly identify each 1958policy statement in a unique way. 1959 1960Finally, based on the goal of making the loader efficient and performant, 1961some of these policy statements defining proper layer behavior may not be 1962testable (and therefore aren't enforceable by the loader). 1963However, that should not detract from the requirement in order to provide the 1964best experience to end-users and developers. 1965 1966 1967### Number Format 1968 1969Loader/Layer policy items start with the prefix `LLP_` (short for 1970Loader/Layer Policy) which is followed by an identifier based on what 1971component the policy is targeted against. 1972In this case there are only two possible components: 1973 - Layers: which will have the string `LAYER_` as part of the policy number. 1974 - The Loader: which will have the string `LOADER_` as part of the policy 1975 number. 1976 1977 1978### Android Differences 1979 1980As stated before, the Android Loader is actually separate from the Khronos 1981Loader. 1982Because of this and other platform requirements, not all of these policy 1983statements apply to Android. 1984Each table also has a column titled "Applicable to Android?" 1985which indicates which policy statements apply to layers that are focused 1986only on Android support. 1987Further information on the Android loader can be found in the 1988<a href="https://source.android.com/devices/graphics/implement-vulkan"> 1989Android Vulkan documentation</a>. 1990 1991 1992### Requirements of Well-Behaved Layers 1993 1994<table style="width:100%"> 1995 <tr> 1996 <th>Requirement Number</th> 1997 <th>Requirement Description</th> 1998 <th>Result of Non-Compliance</th> 1999 <th>Applicable to Android?</th> 2000 <th>Enforceable by Loader?</th> 2001 <th>Reference Section</th> 2002 </tr> 2003 <tr> 2004 <td><small><b>LLP_LAYER_1</b></small></td> 2005 <td>A layer, when inserted into an otherwise compliant Vulkan 2006 environment, <b>must</b> still result in a compliant Vulkan environment 2007 unless it intends to mimic non-compliant behavior (such as a device 2008 simulation layer). 2009 </td> 2010 <td>The behavior is undefined and may result in crashes or corruption.</td> 2011 <td>Yes</td> 2012 <td>No<br/> 2013 It is not a simple task for the loader to find the cause of failure 2014 in a layer chain.</td> 2015 <td><small> 2016 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2017 </small> 2018 </td> 2019 </tr> 2020 <tr> 2021 <td><small><b>LLP_LAYER_2</b></small></td> 2022 <td>A layer <b>must not</b> cause other layers or drivers to fail, crash, or 2023 otherwise misbehave.<br/> 2024 It <b>must not</b> make invalid calls to, or rely on undefined behaviors 2025 of the layers or drivers below it. 2026 </td> 2027 <td>The behavior is undefined and may result in crashes or corruption.</td> 2028 <td>Yes</td> 2029 <td>No<br/> 2030 It is not a simple task for the loader to find the cause of failure 2031 in a layer chain.</td> 2032 <td><small> 2033 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2034 </small> 2035 </td> 2036 </tr> 2037 <tr> 2038 <td><small><b>LLP_LAYER_3</b></small></td> 2039 <td>Any new layer developed <b>should</b> adhere to the naming rules defined 2040 in the "Layer Conventions and Rules" section which also correspond to 2041 the naming rules defined in the Vulkan Style Guide section 3.4 on 2042 "Version, Extension, and Layer Naming Conventions". 2043 </td> 2044 <td>Layer developers could produce conflicting names causing unexpected 2045 behavior if more than one layer with the same name is available on a 2046 user's platform. 2047 </td> 2048 <td>Yes</td> 2049 <td>Yes<br/> 2050 Can not immediately enforce since it will cause some shipping layers 2051 to stop working.</td> 2052 <td><small> 2053 <a href="https://www.khronos.org/registry/vulkan/specs/1.2/styleguide.html#extensions-naming-conventions"> 2054 Vulkan Style Guide section 3.4</a> <br/> 2055 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2056 </small> 2057 </td> 2058 </tr> 2059 <tr> 2060 <td><small><b>LLP_LAYER_4</b></small></td> 2061 <td>A layer <b>should</b> export the 2062 <i>vkNegotiateLoaderLayerInterfaceVersion</i> entry-point to negotiate 2063 an interface version.<br/> 2064 A layer using interface 2 or newer <b>must</b> export this function.<br/> 2065 </td> 2066 <td>The layer will not be loaded.</td> 2067 <td>No</td> 2068 <td>Yes</td> 2069 <td><small> 2070 <a href="#layer-version-negotiation">Layer Version Negotiation</a> 2071 </small> 2072 </td> 2073 </tr> 2074 <tr> 2075 <td><small><b>LLP_LAYER_5</b></small></td> 2076 <td>A layer <b>must</b> be able to negotiate a supported version of the 2077 loader/layer interface with the loader in accordance with the stated 2078 negotiation process. 2079 </td> 2080 <td>The layer will not be loaded.</td> 2081 <td>No</td> 2082 <td>Yes</td> 2083 <td><small> 2084 <a href="#loader-and-layer-interface-negotiation"> 2085 Interface Negotiation</a></small> 2086 </td> 2087 </tr> 2088 <tr> 2089 <td><small><b>LLP_LAYER_6</b></small></td> 2090 <td>A layer <b>must</b> have a valid JSON manifest file for the 2091 loader to process that ends with the ".json" suffix. 2092 It is recommended validating the layer manifest file against 2093 <a href="https://github.com/LunarG/VulkanTools/blob/master/vkconfig_core/layers/layers_schema.json"> 2094 the layer schema</a> prior to publication.</br> 2095 The <b>only</b> exception is on Android which determines layer 2096 functionality through the introspection functions defined in 2097 <a href="#layer-library-api-version-0">Layer Library API Version 0</a> 2098 section and in the 2099 <a href="#layer-manifest-file-format">Layer Manifest File Format</a> 2100 table. 2101 </td> 2102 <td>The layer will not be loaded.</td> 2103 <td>No</td> 2104 <td>Yes</td> 2105 <td><small> 2106 <a href="#layer-manifest-file-usage">Manifest File Usage</a></small> 2107 </td> 2108 </tr> 2109 <tr> 2110 <td><small><b>LLP_LAYER_7</b></small></td> 2111 <td>If a layer is a Meta-layer, each component layer in its manifest file 2112 <b>must</b> be present on the system. 2113 </td> 2114 <td>The layer will not be loaded.</td> 2115 <td>No</td> 2116 <td>Yes</td> 2117 <td><small> 2118 <a href="#meta-layers">Meta-Layers</a></small> 2119 </td> 2120 </tr> 2121 <tr> 2122 <td><small><b>LLP_LAYER_8</b></small></td> 2123 <td>If a layer is a Meta-layer, each component layer in its manifest file 2124 <b>must</b> report the same or a newer Vulkan API major and minor 2125 version than the meta-layer. 2126 </td> 2127 <td>The layer will not be loaded.</td> 2128 <td>No</td> 2129 <td>Yes</td> 2130 <td><small> 2131 <a href="#meta-layers">Meta-Layers</a></small> 2132 </td> 2133 </tr> 2134 <tr> 2135 <td><small><b>LLP_LAYER_9</b></small></td> 2136 <td>A layer installed as an Implicit Layer <b>must</b> define a disable 2137 environment variable so it can be disabled globally. 2138 </td> 2139 <td>The layer will not be loaded if it does not define the environment 2140 variable. 2141 </td> 2142 <td>Yes</td> 2143 <td>Yes</td> 2144 <td><small> 2145 <a href="#layer-manifest-file-format">Manifest File Format</a>, see 2146 "disable_environment" variable</small> 2147 </td> 2148 </tr> 2149 <tr> 2150 <td><small><b>LLP_LAYER_10</b></small></td> 2151 <td>If a layer wraps individual object handles, it <b>must</b> unwrap those 2152 handles when passing the handles down the chain to the next layer. 2153 </td> 2154 <td>The behavior is undefined and may result in crashes or corruption.</td> 2155 </td> 2156 <td>Yes</td> 2157 <td>No</td> 2158 <td><small> 2159 <a href="#cautions-about-wrapping">Cautions About Wrapping</a></small> 2160 </td> 2161 </tr> 2162 <tr> 2163 <td><small><b>LLP_LAYER_11</b></small></td> 2164 <td>Any layer shipped with a driver <b>must</b> be validated against 2165 conformance with the corresponding driver. 2166 </td> 2167 <td>The behavior is undefined and may result in crashes or corruption.</td> 2168 <td>Yes</td> 2169 <td>No</td> 2170 <td><small> 2171 <a href="https://github.com/KhronosGroup/VK-GL-CTS/blob/master/external/openglcts/README.md"> 2172 Vulkan CTS Documentation</a> 2173 </small> 2174 </td> 2175 </tr> 2176 <tr> 2177 <td><small><b>LLP_LAYER_12</b></small></td> 2178 <td> During <i>vkCreateInstance</i>, a layer <b>must</b> process the 2179 <i>VkLayerInstanceCreateInfo</i> chain links appropriately.<br/> 2180 This includes getting the next layer's <i>vkGetInstanceProcAddr</i> 2181 function for building a dispatch table as well as updating the 2182 <i>VkLayerInstanceCreateInfo</i> chain link to point to the next 2183 structure in the chain for the next layer prior to calling down to the 2184 next layer's <i>vkCreateInstance</i> function. <br/> 2185 An example of such usage is shown in detail in the 2186 <a href=#example-code-for-createinstance>Example Code for 2187 CreateInstance</a> section. 2188 </td> 2189 <td>The behavior will result in crashes or corruption as any following 2190 layers will access incorrect content.</td> 2191 <td>Yes</td> 2192 <td>No<br/> 2193 With the current loader/layer design, it is difficult for the loader 2194 to diagnose this without adding additional overhead that could impact 2195 performance.<br/> 2196 This is because the loader calls all layers at once and has no data on 2197 the intermediate state of the <i>pNext</i> chain contents. 2198 This could be done in the future, but requires re-designing the layer 2199 initialization process. 2200 </td> 2201 <td><small> 2202 <a href=""#layer-dispatch-initialization"> 2203 Layer Dispatch Initialization</a> 2204 </small> 2205 </td> 2206 </tr> 2207 <td><small><b>LLP_LAYER_13</b></small></td> 2208 <td> During <i>vkCreateDevice</i>, a layer <b>must</b> process the 2209 <i>VkLayerDeviceCreateInfo</i> chain links appropriately.<br/> 2210 This includes updating the <i>VkLayerDeviceCreateInfo</i> chain link to 2211 point to the next structure in the chain for the next layer prior to 2212 calling down to the next layer's <i>vkCreateDevice</i> function. <br/> 2213 An example of such usage is shown in detail in the 2214 <a href="#example-code-for-createdevice">Example Code for 2215 CreateDevice</a> section. 2216 </td> 2217 <td>The behavior will result in crashes or corruption as any following 2218 layers will access incorrect content.</td> 2219 <td>Yes</td> 2220 <td>No<br/> 2221 With the current loader/layer design, it is difficult for the loader 2222 to diagnose this without adding additional overhead that could impact 2223 performance.</td> 2224 <td><small> 2225 <a href="#layer-dispatch-initialization"> 2226 Layer Dispatch Initialization</a> 2227 </small> 2228 </td> 2229 </tr> 2230 <tr> 2231 <td><small><b>LLP_LAYER_14</b></small></td> 2232 <td>A layer <b>should</b> use the application provided memory allocator 2233 functions when they are provided so that applications can keep track of 2234 allocated memory. 2235 </td> 2236 <td>The allocator functions may be provided for the purpose of limiting 2237 or tracking the memory used by the Vulkan components. 2238 Because of this, if a layer ignores these allocators, it may result in 2239 undefined behavior possibly including crashes or corruption. 2240 </td> 2241 <td>Yes</td> 2242 <td>No</td> 2243 <td><small> 2244 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2245 </small> 2246 </td> 2247 </tr> 2248 <tr> 2249 <td><small><b>LLP_LAYER_15</b></small></td> 2250 <td>A layer <b>must</b> enumerate only its own extension properties during a 2251 call of <i>vkEnumerateInstanceExtensionProperties</i> when 2252 <i>pLayerName</i> refers to itself.<br/> 2253 Otherwise, it <b>must</b> return <i>VK_ERROR_LAYER_NOT_PRESENT</i>, 2254 including when <i>pLayerName</i> is <b>NULL</b>. 2255 </td> 2256 <td>The loader could become confused on what support is present in a 2257 specific layer which will result in undefined behavior possibly 2258 including crashes or corruption. 2259 </td> 2260 <td>Yes</td> 2261 <td>No</td> 2262 <td><small> 2263 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2264 </small> 2265 </td> 2266 </tr> 2267 <tr> 2268 <td><small><b>LLP_LAYER_16</b></small></td> 2269 <td>A layer <b>must</b> enumerate only its own extension properties during a 2270 call of <i>vkEnumerateDeviceExtensionProperties</i> when 2271 <i>pLayerName</i> refers to itself.<br/> 2272 Otherwise, it <b>must</b> ignore the call other than passing it down 2273 the standard call chain. 2274 </td> 2275 <td>The loader could become confused on what support is present in a 2276 specific layer which will result in undefined behavior possibly 2277 including crashes or corruption. 2278 </td> 2279 <td>Yes</td> 2280 <td>No</td> 2281 <td><small> 2282 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2283 </small> 2284 </td> 2285 </tr> 2286 <tr> 2287 <td><small><b>LLP_LAYER_17</b></small></td> 2288 <td>A layer's <i>vkCreateInstance</i> <b>must not</b> generate an error for 2289 unrecognized extension names as the extension could be implemented by 2290 a lower layer or driver. 2291 </td> 2292 <td>The behavior is undefined and may result in crashes or corruption.</td> 2293 <td>Yes</td> 2294 <td>Yes</td> 2295 <td><small> 2296 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2297 </small> 2298 </td> 2299 </tr> 2300 <tr> 2301 <td><small><b>LLP_LAYER_18</b></small></td> 2302 <td>A layer <b>must</b> return <b>NULL</b> from <i>vkGetInstanceProcAddr</i> 2303 or <i>vkGetDeviceProcAddr</i> for entry-points that it does not support 2304 or that have not been enabled properly (for example not enabling the 2305 extension certain entry-points are associated with should result in 2306 <i>vkGetInstanceProcAddr</i> returning <b>NULL</b> when requesting 2307 them). 2308 </td> 2309 <td>The behavior is undefined and may result in crashes or corruption.</td> 2310 <td>Yes</td> 2311 <td>No<br/> 2312 With the current loader/layer design, it is difficult for the loader 2313 to determine this without adding additional overhead that could impact 2314 performance.</td> 2315 <td><small> 2316 <a href="#layer-conventions-and-rules">Layer Conventions and Rules</a> 2317 </small> 2318 </td> 2319 </tr> 2320 <tr> 2321 <td><small><b>LLP_LAYER_19</b></small></td> 2322 <td>If a layer creates dispatchable objects, either because it is 2323 wrapping objects or implementing an extension not supported by 2324 the loader or underlying drivers, it <b>must</b> create the dispatch 2325 table appropriately for all created dispatchable objects. 2326 </td> 2327 <td>The behavior is undefined and may result in crashes or corruption.</td> 2328 <td>Yes</td> 2329 <td>No</td> 2330 <td><small> 2331 <a href="#creating-new-dispatchable-objects"> 2332 Creating New Dispatchable Objects</a> 2333 </small> 2334 </td> 2335 </tr> 2336 <tr> 2337 <td><small><b>LLP_LAYER_20</b></small></td> 2338 <td>A layer <b>must</b> remove all manifest files and references 2339 to those files (i.e. Registry entries on Windows) when uninstalling. 2340 <br/> 2341 Similarly, on updating the layer files, the old files <b>must</b> be all 2342 updated or removed. 2343 </td> 2344 <td>The loader ignores duplicate attempts to load the same manifest file, 2345 but if an old file is left pointing to an incorrect library, it will 2346 result in undefined behavior which may include crashes or corruption. 2347 </td> 2348 <td>No</td> 2349 <td>No<br/> 2350 The loader has no idea what layer files are new, old, or incorrect. 2351 Any type of layer file verification would quickly become very complex 2352 since it would require the loader to maintain an internal database 2353 tracking badly behaving layers based on the layer name, version, 2354 targeted platform(s), and possibly other criteria. 2355 <td><small>N/A</small></td> 2356 </tr> 2357 <tr> 2358 <td><small><b>LLP_LAYER_21</b></small></td> 2359 <td>During <i>vkCreateInstance</i>, a layer <b>must not</b> modify the 2360 <i>pInstance</i> pointer during prior to calling down to the lower 2361 layers.<br/> 2362 This is because the loader passes information in this pointer that is 2363 necessary for the initialization code in the loader's terminator 2364 function.<br/> 2365 Instead, if the layer is overriding the <i>pInstance</i> pointer, it 2366 <b>must</b> do so only after the call to the lower layers returns. 2367 </td> 2368 <td>The loader will likely crash.</td> 2369 <td>No</td> 2370 <td>Yes</td> 2371 <td><small>N/A</small></td> 2372 </tr> 2373</table> 2374 2375 2376### Requirements of a Well-Behaved Loader 2377 2378<table style="width:100%"> 2379 <tr> 2380 <th>Requirement Number</th> 2381 <th>Requirement Description</th> 2382 <th>Result of Non-Compliance</th> 2383 <th>Applicable to Android?</th> 2384 <th>Reference Section</th> 2385 </tr> 2386 <tr> 2387 <td><small><b>LLP_LOADER_1</b></small></td> 2388 <td>A loader <b>must</b> support Vulkan layers.</td> 2389 <td>Users will not have access to critical parts of the Vulkan ecosystem 2390 such as Validation Layers, GfxReconstruct, or RenderDoc.</td> 2391 <td>Yes</td> 2392 <td><small>N/A</small></td> 2393 </tr> 2394 <tr> 2395 <td><small><b>LLP_LOADER_2</b></small></td> 2396 <td>A loader <b>must</b> support a mechanism to load layers in one or 2397 more non-standard locations.<br/> 2398 This is to allow application/engine-specific layers as well as 2399 evaluating in-development layers without global installation. 2400 </td> 2401 <td>It will be more difficult to use a Vulkan loader by certain 2402 tools and driver developers.</td> 2403 <td>No</td> 2404 <td><small><a href="#layer-discovery">Layer Discovery</a></small></td> 2405 </tr> 2406 <tr> 2407 <td><small><b>LLP_LOADER_3</b></small></td> 2408 <td>A loader <b>must</b> filter out duplicate layer names in the various 2409 enable lists, keeping only the first occurrence. 2410 </td> 2411 <td>The behavior is undefined and may result in crashes or corruption.</td> 2412 <td>Yes</td> 2413 <td><small><a href="#layer-discovery">Layer Discovery</a></small></td> 2414 </tr> 2415 <tr> 2416 <td><small><b>LLP_LOADER_4</b></small></td> 2417 <td>A loader <b>must not</b> load a Vulkan layer which defines an 2418 API version that is incompatible with itself. 2419 </td> 2420 <td>The behavior is undefined and may result in crashes or corruption.</td> 2421 <td>Yes</td> 2422 <td><small><a href="#layer-discovery">Layer Discovery</a></small></td> 2423 </tr> 2424 <tr> 2425 <td><small><b>LLP_LOADER_5</b></small></td> 2426 <td>A loader <b>must</b> ignore any layer for which a compatible interface 2427 version can not be negotiated. 2428 </td> 2429 <td>The loader would load a layer improperly resulting in undefined behavior 2430 which may include crashes or corruption.</td> 2431 <td>No</td> 2432 <td><small> 2433 <a href="#loader-and-layer-interface-negotiation"> 2434 Interface Negotiation</a></small> 2435 </td> 2436 </tr> 2437 <tr> 2438 <td><small><b>LLP_LOADER_6</b></small></td> 2439 <td>If a layer is implicit, and it has an enable environment variable, 2440 then a loader <b>must not</b> consider the layer enabled unless that 2441 enable environment variable is defined.<br/> 2442 If an implicit layer does not have an enable environment variable, 2443 it will be considered enabled by default. 2444 </td> 2445 <td>Some layers may be used when not intended.</td> 2446 <td>No</td> 2447 <td><small> 2448 <a href="#layer-manifest-file-format">Manifest File Format</a>, see 2449 "enable_environment" variable</small> 2450 </td> 2451 </tr> 2452 <tr> 2453 <td><small><b>LLP_LOADER_7</b></small></td> 2454 <td>If an implicit layer is enabled, but has been disabled by some other 2455 mechanism (such as the defining of the layer's disable environment 2456 variable or through the blacklisting mechanism of the Override Layer), 2457 then a loader <b>must not</b> load that layer. 2458 </td> 2459 <td>Some layers may be used when not intended.</td> 2460 <td>No</td> 2461 <td><small> 2462 <a href="#layer-manifest-file-format">Manifest File Format</a>, see 2463 "disable_environment" variable</small> 2464 </td> 2465 </tr> 2466 <tr> 2467 <td><small><b>LLP_LOADER_8</b></small></td> 2468 <td>A loader <b>must</b> pass a linked list of initialization structures 2469 to each layer via the <i>VkLayerInstanceCreateInfo</i> structure in the 2470 <i>pNext</i> field of the <i>VkInstanceCreateInfo</i> structure. 2471 This contains necessary information for setting up the instance call 2472 chain including providing a function pointer to the next links 2473 <i>vkGetInstanceProcAddr</i>. 2474 </td> 2475 <td>Layers will crash as they attempt to load invalid data.</td> 2476 <td>Yes</td> 2477 <td><small> 2478 <a href="#layer-dispatch-initialization"> 2479 Layer Dispatch Initialization</a> 2480 </small> 2481 </td> 2482 </tr> 2483 <tr> 2484 <td><small><b>LLP_LOADER_9</b></small></td> 2485 <td>A loader <b>must</b> pass a linked list of initialization structures 2486 to each layer via the <i>VkLayerDeviceCreateInfo</i> structure in the 2487 <i>pNext</i> field of the <i>VkDeviceCreateInfo</i> structure. 2488 This contains necessary information for setting up the device call chain 2489 including providing a function pointer to the next links 2490 <i>vkGetDeviceProcAddr</i>. 2491 <td>Layers will crash as they attempt to load invalid data.</td> 2492 <td>Yes</td> 2493 <td><small> 2494 <a href="#layer-dispatch-initialization"> 2495 Layer Dispatch Initialization</a> 2496 </small> 2497 </td> 2498 </tr> 2499 <tr> 2500 <td><small><b>LLP_LOADER_10</b></small></td> 2501 <td>A loader <b>must</b> verify that all meta-layers contain valid 2502 component layers that the loader can find on the system and that also 2503 report the same Vulkan API version as the meta-layer itself before it 2504 loads the meta-layer. 2505 </td> 2506 <td>The behavior is undefined and may result in crashes or corruption.</td> 2507 <td>No</td> 2508 <td><small> 2509 <a href="#meta-layers">Meta-Layers</a></small> 2510 </td> 2511 </tr> 2512 <tr> 2513 <td><small><b>LLP_LOADER_11</b></small></td> 2514 <td>If the override meta-layer is present, a loader <b>must</b> load it 2515 and corresponding component layers after all other implicit layers have 2516 been added to the call chain. 2517 </td> 2518 <td>The behavior is undefined and may result in crashes or corruption.</td> 2519 <td>No</td> 2520 <td><small> 2521 <a href="#override-meta-layer">Override Meta-Layer</a></small> 2522 </td> 2523 </tr> 2524 <tr> 2525 <td><small><b>LLP_LOADER_12</b></small></td> 2526 <td>If the override meta-layer is present and has a blacklist of layers to 2527 remove, a loader <b>must</b> disable all layers listed in the blacklist. 2528 </td> 2529 <td>The behavior is undefined and may result in crashes or corruption.</td> 2530 <td>No</td> 2531 <td><small> 2532 <a href="#override-meta-layer">Override Meta-Layer</a></small> 2533 </td> 2534 </tr> 2535 <tr> 2536 <td><small><b>LLP_LOADER_13</b></small></td> 2537 <td>A loader <b>must</b> not load from user-defined paths (including the 2538 use of either <i>VK_LAYER_PATH</i> or <i>VK_ADD_LAYER_PATH</i> 2539 environment variables) when running elevated (Administrator/Super-user) 2540 applications.<br/> 2541 <b>This is for security reasons.</b> 2542 </td> 2543 <td>The behavior is undefined and may result in computer security lapses, 2544 crashes or corruption. 2545 </td> 2546 <td>No</td> 2547 <td><small><a href="#layer-discovery">Layer Discovery</a></small></td> 2548 </tr> 2549</table> 2550 2551<br/> 2552 2553[Return to the top-level LoaderInterfaceArchitecture.md file.](LoaderInterfaceArchitecture.md) 2554