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