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