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# Application Interface to Loader 8[![Creative Commons][3]][4] 9 10<!-- Copyright © 2015-2021 LunarG, Inc. --> 11 12[3]: https://i.creativecommons.org/l/by-nd/4.0/88x31.png "Creative Commons License" 13[4]: https://creativecommons.org/licenses/by-nd/4.0/ 14 15## Table of Contents 16 17- [Overview](#overview) 18- [Interfacing with Vulkan Functions](#interfacing-with-vulkan-functions) 19 - [Vulkan Direct Exports](#vulkan-direct-exports) 20 - [Directly Linking to the Loader](#directly-linking-to-the-loader) 21 - [Dynamic Linking](#dynamic-linking) 22 - [Static Linking](#static-linking) 23 - [Indirectly Linking to the Loader](#indirectly-linking-to-the-loader) 24 - [Best Application Performance Setup](#best-application-performance-setup) 25 - [ABI Versioning](#abi-versioning) 26 - [Windows Dynamic Library Usage](#windows-dynamic-library-usage) 27 - [Linux Dynamic Library Usage](#linux-dynamic-library-usage) 28 - [MacOs Dynamic Library Usage](#macos-dynamic-library-usage) 29 - [Bundling the Loader With An Application](#bundling-the-loader-with-an-application) 30- [Application Layer Usage](#application-layer-usage) 31 - [Meta-Layers](#meta-layers) 32 - [Implicit vs Explicit Layers](#implicit-vs-explicit-layers) 33 - [Override Layer](#override-layer) 34 - [Forcing Layer Source Folders](#forcing-layer-source-folders) 35 - [Exception for Elevated Privileges](#exception-for-elevated-privileges) 36 - [Forcing Layers to be Enabled on Windows, Linux and macOS](#forcing-layers-to-be-enabled-on-windows-linux-and-macos) 37 - [Overall Layer Ordering](#overall-layer-ordering) 38 - [Debugging Possible Layer Issues](#debugging-possible-layer-issues) 39 - [Enable Loader Debug Layer Output](#enable-loader-debug-layer-output) 40 - [Disable All Layers](#disable-all-layers) 41 - [Enable More Loader Debug Output](#enable-more-loader-debug-output) 42- [Application Usage of Extensions](#application-usage-of-extensions) 43 - [Instance and Device Extensions](#instance-and-device-extensions) 44 - [WSI Extensions](#wsi-extensions) 45 - [Unknown Extensions](#unknown-extensions) 46 - [Filtering Out Unknown Instance Extension Names](#filtering-out-unknown-instance-extension-names) 47- [Physical Device Ordering](#physical-device-ordering) 48 49## Overview 50 51This is the Application-centric view of working with the Vulkan loader. 52For the complete overview of all sections of the loader, please refer 53to the [LoaderInterfaceArchitecture.md](LoaderInterfaceArchitecture.md) file. 54 55## Interfacing with Vulkan Functions 56 57There are several ways Vulkan functions may be interfaced through the loader: 58 59 60### Vulkan Direct Exports 61 62The loader library on Windows, Linux, Android, and macOS will export all core 63Vulkan entry-points and all appropriate Window System Interface (WSI) 64entry-points. 65This is done to make it simpler to get started with Vulkan development. 66When an application links directly to the loader library in this way, the 67Vulkan calls are simple *trampoline* functions that jump to the appropriate 68dispatch table entry for the object they are given. 69 70 71### Directly Linking to the Loader 72 73#### Dynamic Linking 74 75The loader is distributed as a dynamic library (.dll on Windows or .so on Linux 76or .dylib on macOS) which gets installed to the system path for dynamic 77libraries. 78Furthermore, the dynamic library is generally installed to Windows 79systems as part of driver installation and is generally provided on Linux 80through the system package manager. 81This means that applications can usually expect a copy of the loader to be 82present on a system. 83If applications want to be completely sure that a loader is present, they can 84include a loader or runtime installer with their application. 85 86#### Static Linking 87 88In previous versions of the loader, it was possible to statically link the 89loader. 90**This was removed and is no longer possible.** 91The decision to remove static linking was because of changes to the driver 92which made older applications that statically linked unable to find newer 93drivers. 94 95Additionally, static linking posed several problems: 96 - The loader can never be updated without re-linking the application 97 - The possibility that two included libraries could contain different versions 98 of the loader 99 - Could cause conflicts between the different loader versions 100 101The only exception to this is for macOS, but is not supported or tested. 102 103### Indirectly Linking to the Loader 104 105Applications are not required to link directly to the loader library, instead 106they can use the appropriate platform-specific dynamic symbol lookup on the 107loader library to initialize the application's own dispatch table. 108This allows an application to fail gracefully if the loader cannot be found. 109It also provides the fastest mechanism for the application to call Vulkan 110functions. 111An application only needs to query (via system calls such as `dlsym`) the 112address of `vkGetInstanceProcAddr` from the loader library. 113The application then uses `vkGetInstanceProcAddr` to load all functions 114available, such as `vkCreateInstance`, `vkEnumerateInstanceExtensionProperties` 115and `vkEnumerateInstanceLayerProperties` in a platform-independent way. 116 117### Best Application Performance Setup 118 119To get the best possible performance in a Vulkan application, the application 120should set up its own dispatch table for every Vulkan API entry-point. 121For every instance-level Vulkan command in the dispatch table, the function pointer 122should be queried and filled in by using the results of `vkGetInstanceProcAddr`. 123Additionally, for every device-level Vulkan command, the function pointer 124should be queried and filled in using the results of `vkGetDeviceProcAddr`. 125 126*Why do this?* 127 128The answer comes in how the call chain of instance functions are implemented 129versus the call chain of a device functions. 130Remember, a [Vulkan instance is a high-level construct used to provide Vulkan 131system-level information](LoaderInterfaceArchitecture.md#instance-specific). 132Because of this, instance functions need to be broadcast to every available 133driver on the system. 134The following diagram shows an approximate view of an instance call chain with 135three enabled layers: 136 137![Instance Call Chain](./images/loader_instance_chain.png) 138 139This is also how a Vulkan device function call chain looks if queried 140using `vkGetInstanceProcAddr`. 141On the other hand, a device function doesn't need to worry about the broadcast 142because it knows specifically which associated driver and which associated 143physical device the call should terminate at. 144Because of this, the loader doesn't need to get involved between any enabled 145layers and the driver. 146Thus, using a loader-exported Vulkan device function, the call chain 147in the same scenario as above would look like: 148 149![Loader Device Call Chain](./images/loader_device_chain_loader.png) 150 151An even better solution would be for an application to perform a 152`vkGetDeviceProcAddr` call on all device functions. 153This further optimizes the call chain by removing the loader all-together under 154most scenarios: 155 156![Application Device Call Chain](./images/loader_device_chain_app.png) 157 158Also, notice if no layers are enabled, the application function pointers point 159**directly to the driver**. 160With many function calls, the lack of indirection in each adds up to non-trivial 161performance savings. 162 163**NOTE:** There are some device functions which still require the loader to 164intercept them with a *trampoline* and *terminator*. 165There are very few of these, but they are typically functions which the loader 166wraps with its own data. 167In those cases, even the device call chain will continue to look like the 168instance call chain. 169One example of a device function requiring a *terminator* is 170`vkCreateSwapchainKHR`. 171For that function, the loader needs to potentially convert the KHR_surface 172object into an driver-specific KHR_surface object prior to passing down the rest 173of the function's information to the driver. 174 175Remember: 176 * `vkGetInstanceProcAddr` is used to query instance and physical device 177 functions, but can query all functions. 178 * `vkGetDeviceProcAddr` is only used to query device functions. 179 180 181### ABI Versioning 182 183The Vulkan loader library will be distributed in various ways including Vulkan 184SDKs, OS package distributions and Independent Hardware Vendor (IHV) driver 185packages. 186These details are beyond the scope of this document. 187However, the name and versioning of the Vulkan loader library is specified so 188an app can link to the correct Vulkan ABI library version. 189ABI backwards compatibility is guaranteed for all versions with the same major 190number (e.g. 1.0 and 1.1). 191 192#### Windows Dynamic Library Usage 193 194On Windows, the loader library encodes the ABI version in its name such that 195multiple ABI incompatible versions of the loader can peacefully coexist on a 196given system. 197The Vulkan loader library file name is `vulkan-<ABI version>.dll`. 198For example, for Vulkan version 1.X on Windows the library filename is 199`vulkan-1.dll`. 200This library file can typically be found in the `windows\system32` 201directory (on 64-bit Windows installs, the 32-bit version of the loader with 202the same name can be found in the `windows\sysWOW64` directory). 203 204#### Linux Dynamic Library Usage 205 206For Linux, shared libraries are versioned based on a suffix. 207Thus, the ABI number is not encoded in the base of the library filename as on 208Windows. 209 210On Linux, applications that have a hard dependency on Vulkan should request 211linking to the unversioned name `libvulkan.so` in their build system. 212For example by importing the CMake target `Vulkan::Vulkan` or by using the 213output of `pkg-config --cflags --libs vulkan` as compiler flags. 214As usual for Linux libraries, the compiler and linker will resolve this to 215a dependency on the correct versioned SONAME, currently `libvulkan.so.1`. 216Linux applications that load Vulkan-Loader dynamically at runtime do not 217benefit from this mechanism, and should instead make sure to pass the 218versioned name such as `libvulkan.so.1` to `dlopen()`, to ensure that they 219load a compatible version. 220 221#### MacOs Dynamic Library Usage 222 223MacOs linking is similar to Linux, with the exception being that the standard 224dynamic library is named `libvulkan.dylib` and the ABI versioned library is 225currently named `libvulkan.1.dylib`. 226 227 228### Bundling the Loader With An Application 229 230The Khronos loader is typically installed on platforms either in a 231platform-specific way (i.e. packages on Linux) or as part of a driver install 232(i.e. using the Vulkan Runtime installer on Windows). 233Applications or engines may desire to install the Vulkan loader locally to their 234execution tree as part of their own installation process. 235This may be because providing the specific loader: 236 237 1) Guarantees certain Vulkan API exports are available in the loader 238 2) Ensures certain loader behavior is well-known 239 3) Provides consistency across user installation 240 241However, this is **strongly discouraged** because: 242 243 1) The packaged loader may not be compatible with future driver revisions 244(this can be especially true on Windows where driver install locations can 245change during updates to the OS) 246 2) It can prevent the application/engine from taking advantage of new Vulkan 247API version/extension exports 248 3) The application/engine will miss out on important loader bug-fixes 249 4) The packaged loader will not contain useful feature updates (like 250improved loader debugability) 251 252Of course, even if an application/engine does initially release with a specific 253version of the Khronos loader, it may chose to update or remove that loader at 254some point in the future. 255This could be due to the exposure of needed functionality in the loader as time 256progresses. 257But, that relies upon end-users correctly performing whatever update process is 258necessary at that future time which may result in different behavior across 259different user's systems. 260 261One better alternative, at least on Windows, is to package the Vulkan Runtime 262installer for the desired version of the Vulkan loader with your product. 263Then, the installation process can use that to ensure the end-user's system 264is up to date. 265The Runtime installer will detect the version already installed and will only 266install a newer runtime if necessary. 267 268Another alternative is to write the application so it can fallback to earlier 269versions of Vulkan yet display a warning indicating functionality is disabled 270until the user updates their system to a specific runtime/driver. 271 272 273## Application Layer Usage 274 275Applications desiring Vulkan functionality beyond what Vulkan drivers 276on their system already expose, may use various layers to augment the API. 277A layer cannot add new Vulkan core API entry-points that are not exposed in 278Vulkan.h. 279However, layers may offer implementations of extensions that introduce 280additional entry-points beyond what is available without those layers. 281These additional extension entry-points can be queried through the Vulkan 282extension interface. 283 284A common use of layers is for API validation which can be enabled during 285application development and left out when releasing the application. 286This allows easy control of the overhead resulting from enabling validation of 287the application's usage of the API, which wasn't always possible in previous 288graphics APIs. 289 290To find out what layers are available to an application, use 291`vkEnumerateInstanceLayerProperties`. 292This will report all layers that have been discovered by the loader. 293The loader looks in various locations to find layers on the system. 294For more information see the 295[Layer discovery](LoaderLayerInterface.md#layer-discovery) 296section in the 297[LoaderLayerInterface.md document](LoaderLayerInterface.md) document. 298 299To enable specific layers, simply pass the names of the layers to 300enable in the `ppEnabledLayerNames` field of the `VkInstanceCreateInfo` during 301a call to `vkCreateInstance`. 302Once done, the layers that have been enabled will be active for all Vulkan functions 303using the created `VkInstance`, and any of its child objects. 304 305**NOTE:** Layer ordering is important in several cases since some layers 306interact with each other. 307Be careful when enabling layers as this may be the case. 308See the [Overall Layer Ordering](#overall-layer-ordering) section for more 309information. 310 311The following code section shows how to go about enabling the 312`VK_LAYER_KHRONOS_validation` layer. 313 314``` 315char *instance_layers[] = { 316 "VK_LAYER_KHRONOS_validation" 317}; 318const VkApplicationInfo app = { 319 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, 320 .pNext = NULL, 321 .pApplicationName = "TEST_APP", 322 .applicationVersion = 0, 323 .pEngineName = "TEST_ENGINE", 324 .engineVersion = 0, 325 .apiVersion = VK_API_VERSION_1_0, 326}; 327VkInstanceCreateInfo inst_info = { 328 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 329 .pNext = NULL, 330 .pApplicationInfo = &app, 331 .enabledLayerCount = 1, 332 .ppEnabledLayerNames = (const char *const *)instance_layers, 333 .enabledExtensionCount = 0, 334 .ppEnabledExtensionNames = NULL, 335}; 336err = vkCreateInstance(&inst_info, NULL, &demo->inst); 337if (VK_ERROR_LAYER_NOT_PRESENT == err) { 338 // Couldn't find the validation layer 339} 340``` 341 342At `vkCreateInstance` and `vkCreateDevice`, the loader constructs call chains 343that include the application specified (enabled) layers. 344Order is important in the `ppEnabledLayerNames` array; array element 0 is the 345topmost (closest to the application) layer inserted in the chain and the last 346array element is closest to the driver. 347See the [Overall Layer Ordering](#overall-layer-ordering) section for more 348information on layer ordering. 349 350**NOTE:** *Device Layers Are Now Deprecated* 351> `vkCreateDevice` originally was able to select layers in a similar manner to 352`vkCreateInstance`. 353> This led to the concept of "instance layers" and "device layers". 354> It was decided by Khronos to deprecate the "device layer" functionality and 355> only consider "instance layers". 356> Therefore, `vkCreateDevice` will use the layers specified at 357`vkCreateInstance`. 358> Because of this, the following items have been deprecated: 359> * `VkDeviceCreateInfo` fields: 360> * `ppEnabledLayerNames` 361> * `enabledLayerCount` 362> * The `vkEnumerateDeviceLayerProperties` function 363 364 365### Meta-Layers 366 367Meta-layers are layers which contain an ordered list of other layers to enable. 368This is to allow grouping layers together in a specified order so that they can 369interact properly. 370Originally, this was used to group together the individual Vulkan Validation 371layers in the proper order to avoid conflicts. 372It was necessary because instead of a single Validation layer, validation was 373split into multiple component layers. 374The new `VK_LAYER_KHRONOS_validation` layer pulled everything into a single 375layer, dropping the need for meta layers. 376While not necessary for validation anymore, VkConfig does use meta layers to 377group layers together based on user's preferences. 378More can be found out about this functionality through both the 379[VkConfig documentation](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md) 380and the section later on the [Override Layer](#override-layer). 381 382Meta-layers are detailed more in the 383[Meta-Layers](LoaderLayerInterface.md#meta-layers) section of the 384[LoaderLayerInterface.md](LoaderLayerInterface.md) file in this folder. 385 386 387### Implicit vs Explicit Layers 388 389![Different Types of Layers](./images/loader_layer_order.png) 390 391Explicit layers are layers which are enabled by an application (e.g. with the 392vkCreateInstance function as mentioned previously). 393 394Implicit layers are enabled automatically by their very existence, unless 395requiring an additional manual enable step, unlike explicit layers that must be 396enabled explicitly. 397For example, certain application environments (e.g. Steam or an automotive 398infotainment system) may have layers which they always want enabled for all 399applications that they start. 400Other implicit layers may be for all applications started on a given system 401(e.g. layers that overlay frames-per-second). 402 403Implicit layers have an additional requirement over explicit layers in that 404they require being able to be disabled by an environmental variable. 405This is due to the fact that they are not visible to the application and could 406cause issues. 407A good principle to keep in mind would be to define both an enable and disable 408environment variable so the users can deterministically enable the 409functionality. 410On Desktop platforms (Windows, Linux, and macOS), these enable/disable settings 411are defined in the layer's JSON file. 412 413Discovery of system-installed implicit and explicit layers is described later 414in the [Layer discovery](LoaderLayerInterface#layer-discovery) 415section in the 416[LoaderLayerInterface.md](LoaderLayerInterface.md) document. 417 418Implicit and explicit layers may be found in different locations based on the 419underlying operating system. 420The table below details more information: 421 422<table style="width:100%"> 423 <tr> 424 <th>Operating System</th> 425 <th>Implicit Layer Identification</th> 426 </tr> 427 <tr> 428 <td>Windows</td> 429 <td>Implicit layers are located in a different Windows registry location 430 than explicit layers.</td> 431 </tr> 432 <tr> 433 <td>Linux</td> 434 <td>Implicit layers are located in a different directory location than 435 explicit layers.</td> 436 </tr> 437 <tr> 438 <td>Android</td> 439 <td>There is **No Support For Implicit Layers** on Android.</td> 440 </tr> 441 <tr> 442 <td>macOS</td> 443 <td>Implicit layers are located in a different directory location than 444 explicit layers.</td> 445 </tr> 446</table> 447 448 449#### Override Layer 450 451The "Override Layer" is a special implicit meta-layer created by the 452[VkConfig](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md) 453tool and available by default when the tool is running. 454Once VkConfig exits, the override layer is removed, and the system should 455return to standard Vulkan behavior. 456Whenever the override layer is present in the layer search path, the loader will 457pull it into the layer call stack with the standard implicit layers along with 458all layers contained in the list of layers to load. 459This allows an end-user or developer to easily force on any number of layers 460and settings via VkConfig. 461 462The override layer is discussed more in the 463[Override Meta-Layer](LoaderLayerInterface.md#override-meta-layer) section of the 464[LoaderLayerInterface.md](LoaderLayerInterface.md) file in this folder. 465 466 467### Forcing Layer Source Folders 468 469Developers may need to use special, pre-production layers, without modifying 470the system-installed layers. 471 472This can be accomplished in one of two ways: 473 474 1. Selecting specific layer paths using the 475[VkConfig](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md) 476tool shipped with the Vulkan SDK. 477 2. Directing the loader to look for layers in specific folders by using the 478`VK_LAYER_PATH` environment variable. 479 480The `VK_LAYER_PATH` environment variable can contain multiple paths separated by 481the operating-system specific path separator. 482On Windows, this is a semicolon (`;`), while on Linux and macOS it is a colon 483(`:`). 484 485If `VK_LAYER_PATH` exists, the folders listed in it will be scanned for explicit 486layer manifest files. 487Implicit layer discovery is unaffected by this environment variable. 488Each directory listed should be the full pathname of a folder containing layer 489manifest files. 490 491See the 492[Table of Debug Environment Variables](LoaderInterfaceArchitecture.md#table-of-debug-environment-variables) 493in the [LoaderInterfaceArchitecture.md document](LoaderInterfaceArchitecture.md) 494for more details. 495 496 497#### Exception for Elevated Privileges 498 499For security reasons, `VK_LAYER_PATH` is ignored if running with elevated 500privileges. 501Because of this, `VK_LAYER_PATH` can only be used for applications that do not 502use elevated privileges. 503 504For more information see 505[Elevated Privilege Caveats](LoaderInterfaceArchitecture.md#elevated-privilege-caveats) 506in the top-level 507[LoaderInterfaceArchitecture.md][LoaderInterfaceArchitecture.md] document. 508 509 510### Forcing Layers to be Enabled on Windows, Linux and macOS 511 512Developers may want to enable layers that are not enabled by the given 513application they are using. 514 515This can be also be accomplished in one of two ways: 516 517 1. Selecting specific layers using the 518[VkConfig](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md) 519tool shipped with the Vulkan SDK. 520 2. Directing the loader to look for additional layers by name using the 521`VK_INSTANCE_LAYERS` environment variable. 522 523Both can be used to enable additional layers which are not specified (enabled) 524by the application at `vkCreateInstance`. 525 526The `VK_INSTANCE_LAYERS` environment variable is a list of layer names to enable 527separated by the operating-system specific path separator. 528On Windows, this is a semicolon (`;`), while on Linux and macOS it is a colon 529(`:`). 530The order of the names is relevant with the first layer name in the list being 531the top-most layer (closest to the application) and the last layer name in the 532list being the bottom-most layer (closest to the driver). 533See the [Overall Layer Ordering](#overall-layer-ordering) section for more 534information. 535 536Application specified layers and user specified layers (via environment 537variables) are aggregated and duplicates removed by the loader when enabling 538layers. 539Layers specified via environment variable are top-most (closest to the 540application) while layers specified by the application are bottom-most. 541 542An example of using these environment variables to activate the validation 543layer `VK_LAYER_KHRONOS_validation` on Linux or macOS is as follows: 544 545``` 546> $ export VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation 547``` 548 549See the 550[Table of Debug Environment Variables](LoaderInterfaceArchitecture.md#table-of-debug-environment-variables) 551in the [LoaderInterfaceArchitecture.md document](LoaderInterfaceArchitecture.md) 552for more details. 553 554 555### Overall Layer Ordering 556 557The overall ordering of all layers by the loader based on the above looks 558as follows: 559 560![Loader Layer Ordering](./images/loader_layer_order_calls.png) 561 562Ordering may also be important internally to the list of explicit layers. 563Some layers may be dependent on other behavior being implemented before 564or after the loader calls it. 565For example: An overlay layer may want to use `VK_LAYER_KHRONOS_validation` 566to verify that the overlay layer is behaving appropriately. 567This requires putting the overlay layer closer to the application so that the 568validation layer can intercept any Vulkan API calls the overlay layer needs to 569make to function. 570 571 572### Debugging Possible Layer Issues 573 574If it is possible that a layer is causing issues, there are several things that 575can be tried. 576 577 578#### Enable Loader Debug Layer Output 579 580First, enable the "layer" debug output option (`VK_LOADER_DEBUG`) in the loader, 581See the 582[Table of Debug Environment Variables](LoaderInterfaceArchitecture.md##table-of-debug-environment-variables) 583for more info. 584 585When enabled, the loader will output information on: 586 * Where it looks for implicit layers 587 * Where it looks for explicit layers 588 * What manifest files it finds 589 * Which layer manifest files are loaded 590 * What libraries are associated with a layer 591 * What the layer callstack looks like for both the instance and device chain 592 593For example, the layer output for searching for implicit layers on Linux may 594look like: 595 596``` 597LAYER: Searching for layer manifest files 598LAYER: In following folders: 599LAYER: /home/linust/.config/vulkan/implicit_layer.d 600LAYER: /etc/xdg/vulkan/implicit_layer.d 601LAYER: /usr/local/etc/vulkan/implicit_layer.d 602LAYER: /etc/vulkan/implicit_layer.d 603LAYER: /home/linust/.local/share/vulkan/implicit_layer.d 604LAYER: /home/linust/.local/share/flatpak/exports/share/vulkan/implicit_layer.d 605LAYER: /var/lib/flatpak/exports/share/vulkan/implicit_layer.d 606LAYER: /usr/local/share/vulkan/implicit_layer.d 607LAYER: /usr/share/vulkan/implicit_layer.d 608LAYER: Found the following files: 609LAYER: /home/linust/.local/share/vulkan/implicit_layer.d/renderdoc_capture.json 610LAYER: /home/linust/.local/share/vulkan/implicit_layer.d/steamfossilize_i386.json 611LAYER: /home/linust/.local/share/vulkan/implicit_layer.d/steamfossilize_x86_64.json 612LAYER: /home/linust/.local/share/vulkan/implicit_layer.d/steamoverlay_i386.json 613LAYER: /home/linust/.local/share/vulkan/implicit_layer.d/steamoverlay_x86_64.json 614LAYER: /usr/share/vulkan/implicit_layer.d/nvidia_layers.json 615LAYER: /usr/share/vulkan/implicit_layer.d/VkLayer_MESA_device_select.json 616``` 617 618In the above scenario, seven implicit layers were discovered in two different 619folders. 620Just because they were found does not mean that they will be loaded, but this 621information can be used to make sure a layer JSON file was properly discovered. 622 623When the loader actually loads a layer, the messages may look like the 624following: 625 626``` 627LAYER | DEBUG: Loading layer library libVkLayer_khronos_validation.so 628LAYER | INFO: Insert instance layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so) 629LAYER | DEBUG: Loading layer library libVkLayer_MESA_device_select.so 630LAYER | INFO: Insert instance layer VK_LAYER_MESA_device_select (libVkLayer_MESA_device_select.so) 631``` 632 633This information does not indicate the order the layers are used in. 634That information is displayed later showing all the callstack during both 635`vkCreateInstance` and `vkCreateDevice`. 636In the same sample above, the callstack for `vkCreateInstance` looks like the 637following: 638 639``` 640LAYER: vkCreateInstance layer callstack setup to: 641LAYER: <Application> 642LAYER: || 643LAYER: <Loader> 644LAYER: || 645LAYER: VK_LAYER_MESA_device_select 646LAYER: Type: Implicit 647LAYER: Disable Env Var: NODEVICE_SELECT 648LAYER: Manifest: /usr/share/vulkan/implicit_layer.d/VkLayer_MESA_device_select.json 649LAYER: Library: libVkLayer_MESA_device_select.so 650LAYER: || 651LAYER: VK_LAYER_KHRONOS_validation 652LAYER: Type: Explicit 653LAYER: Manifest: /usr/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json 654LAYER: Library: libVkLayer_khronos_validation.so 655LAYER: || 656LAYER: <Drivers> 657``` 658 659In this scenario, two layers were used (the same two that were loaded earlier): 660* `VK_LAYER_MESA_device_select` 661* `VK_LAYER_KHRONOS_validation` 662 663This information now shows us that the `VK_LAYER_MESA_device_select` is loaded 664first, followed by `VK_LAYER_KHRONOS_validation` which will then continue into 665any available drivers. 666It also shows that `VK_LAYER_MESA_device_select` is an implicit layer which 667implies that it wasn't directly enabled by the application. 668On the other hand, `VK_LAYER_KHRONOS_validation` is shown as an explicit layer 669which indicates that it was likely enabled by the application. 670 671Sometimes, implicit layers can cause issues with an application. 672Because of this, the next step is to try to disable one or more of the listed 673implicit layers. 674This can be done by defining the disable environment variable for that layer. 675Each layer has it's own disable environment variable as mentioned in the 676[Layer Manifest File Format](LoaderLayerInterface.md#layer-manifest-file-format). 677However, it can be difficult to find this variable in the manifest files, so 678the loader now outputs it as part of the callstack information. 679Looking at the above `vkCreateInstance` callstack output, under the 680section for `VK_LAYER_MESA_device_select` exists a section listed as 681"Disable Env Var:". 682This is the disable environment variable that can be used to disable the 683`VK_LAYER_MESA_device_select` layer from being loaded by the loader. 684In the above output, the disable environment variable is listed as 685"NODEVICE_SELECT" which can be defined to a non-zero value to cause the loader 686to ignore this layer. 687 688 689#### Disable All Layers 690 691Because implicit layers are virtually unknown to the application, it is best to 692next try to disable each one of them. 693Using the above debug output, define each environment variable to disable the 694corresponding implicit layer that was used. 695 696Once all are disabled, re-run the application again. 697 698If the failure still occurs, try disabling all explicit layers loaded by the 699application by modifying the application or using a tool such as 700[VkConfig](https://github.com/LunarG/VulkanTools/blob/master/vkconfig/README.md). 701 702 703#### Enable More Loader Debug Output 704 705If the failure continues after disabling all layers, then enable all loader 706debug warnings and errors by setting `VK_LOADER_DEBUG` to "error,warn" or 707even "all". 708This will output any other issues that the loader has encountered. 709 710 711## Application Usage of Extensions 712 713Extensions are optional functionality provided by a layer, the loader, or a 714driver. 715Extensions can modify the behavior of the Vulkan API and need to be specified 716and registered with Khronos. 717These extensions can be implemented by a Vulkan driver, the loader, or a layer 718to expose functionality not available in the core API. 719Information about various extensions can be found in the Vulkan Spec, and 720vulkan.h header file. 721 722 723### Instance and Device Extensions 724 725As hinted at in the 726[Instance Versus Device](LoaderInterfaceArchitecture.md#instance-versus-device) 727section of the main 728[LoaderInterfaceArchitecture.md](LoaderInterfaceArchitecture.md) document, 729there are two types of extensions: 730 * Instance Extensions 731 * Device Extensions 732 733An instance extension modifies existing behavior or implements new behavior on 734instance-level objects, such as `VkInstance` and `VkPhysicalDevice`. 735A device extension does the same for device-level objects, such as `VkDevice`, 736`VkQueue`, and `VkCommandBuffer` as well as any children of those objects. 737 738It is **very** important to know what the type of an extension is because 739instance extensions must be enabled with `vkCreateInstance` while device 740extensions are enabled with `vkCreateDevice`. 741 742When calling `vkEnumerateInstanceExtensionProperties` and 743`vkEnumerateDeviceExtensionProperties`, the loader discovers and aggregates all 744extensions of their respective type from layers (both explicit and implicit), 745drivers, and the loader before reporting them to the application. 746 747Looking at `vulkan.h`, both functions are very similar, 748for example, the `vkEnumerateInstanceExtensionProperties` prototype looks as 749follows: 750 751``` 752VkResult 753 vkEnumerateInstanceExtensionProperties( 754 const char *pLayerName, 755 uint32_t *pPropertyCount, 756 VkExtensionProperties *pProperties); 757``` 758 759While the `vkEnumerateDeviceExtensionProperties` prototype looks like: 760 761``` 762VkResult 763 vkEnumerateDeviceExtensionProperties( 764 VkPhysicalDevice physicalDevice, 765 const char *pLayerName, 766 uint32_t *pPropertyCount, 767 VkExtensionProperties *pProperties); 768``` 769 770The "pLayerName" parameter in these functions is used to select either a single 771layer or the Vulkan platform implementation. 772If "pLayerName" is NULL, extensions from Vulkan implementation components 773(including loader, implicit layers, and drivers) are enumerated. 774If "pLayerName" is equal to a discovered layer module name then only extensions 775from that layer (which may be implicit or explicit) are enumerated. 776 777**Note:** While device layers are deprecated, the instance enabled layers are 778still present in the device call-chain. 779 780Duplicate extensions (e.g. an implicit layer and driver might report support for 781the same extension) are eliminated by the loader. 782For duplicates, the driver version is reported and the layer version is culled. 783 784Also, extensions **must be enabled** (in `vkCreateInstance` or `vkCreateDevice`) 785before the functions associated with the extensions can be used. 786If an extension function is queried using either `vkGetInstanceProcAddr` or 787`vkGetDeviceProcAddr`, but the extension has not been enabled, undefined behavior 788could result. 789The Validation layers will catch this invalid API usage. 790 791 792### WSI Extensions 793 794Khronos-approved WSI extensions are available and provide Windows System 795Integration support for various execution environments. 796It is important to understand that some WSI extensions are valid for all 797targets, but others are particular to a given execution environment (and 798loader). 799This Khronos loader (currently targeting Windows, Linux, macOS, Stadia, and 800Fuchsia) only enables and directly exports those WSI extensions that are 801appropriate to the current environment. 802For the most part, the selection is done in the loader using compile-time 803preprocessor flags. 804All versions of the Khronos loader currently expose at least the following WSI 805extension support: 806- VK_KHR_surface 807- VK_KHR_swapchain 808- VK_KHR_display 809 810In addition, each of the following OS targets for the loader support target- 811specific extensions: 812 813| Windowing System | Extensions available | 814| ---------------- | ------------------------------------------ | 815| Windows | VK_KHR_win32_surface | 816| Linux (Wayland) | VK_KHR_wayland_surface | 817| Linux (X11) | VK_KHR_xcb_surface and VK_KHR_xlib_surface | 818| macOS (MoltenVK) | VK_MVK_macos_surface | 819| QNX (Screen) | VK_QNX_screen_surface | 820 821It is important to understand that while the loader may support the various 822entry-points for these extensions, there is a handshake required to actually 823use them: 824* At least one physical device must support the extension(s) 825* The application must use such a physical device when creating a logical 826device 827* The application must request the extension(s) be enabled while creating the 828instance or logical device (this depends on whether or not the given extension 829works with an instance or a device) 830 831Only then can the WSI extension be properly used in a Vulkan program. 832 833 834### Unknown Extensions 835 836With the ability to expand Vulkan so easily, extensions will be created that 837the loader knows nothing about. 838If the extension is a device extension, the loader will pass the unknown 839entry-point down the device call chain ending with the appropriate 840driver entry-points. 841The same thing will happen if the extension is an instance extension which 842takes a physical device parameter as its first component. 843However, for all other instance extensions the loader will fail to load it. 844 845*But why doesn't the loader support unknown instance extensions?* 846<br/> 847Let's look again at the instance call chain: 848 849![Instance call chain](./images/loader_instance_chain.png) 850 851Notice that for a normal instance function call, the loader has to handle 852passing along the function call to the available drivers. 853If the loader has no idea of the parameters or return value of the instance 854call, it can't properly pass information along to the drivers. 855There may be ways to do this, which will be explored in the future. 856However, for now, the loader does not support instance extensions which don't 857expose entry points that take a physical device as their first parameter. 858 859Because the device call-chain does not normally pass through the loader 860*terminator*, this is not a problem for device extensions. 861Additionally, since a physical device is associated with one driver, the loader 862can use a generic *terminator* pointing to one driver. 863This is because both of these extensions terminate directly in the 864driver they are associated with. 865 866*Is this a big problem?* 867<br/> 868No! 869Most extension functionality only affects either a physical or logical device 870and not an instance. 871Thus, the overwhelming majority of extensions should be supported with direct 872loader support. 873 874### Filtering Out Unknown Instance Extension Names 875 876In some cases, a driver may support instance extensions that are not supported 877by the loader. 878For the above reasons, the loader will filter out the names of these unknown 879instance extensions when an application calls 880`vkEnumerateInstanceExtensionProperties`. 881Additionally, this behavior will cause the loader to emit an error during 882`vkCreateInstance` if the application still attempts to use one of these 883extensions. 884The intent is to protect applications so that they don't inadvertently use 885functionality which could lead to a crash. 886 887On the other hand, if the extension must be forced on, the filtering may be 888disabled by defining the `VK_LOADER_DISABLE_INST_EXT_FILTER` environment 889variable to a non-zero number. 890This will effectively disable the loader's filtering of instance extension 891names. 892 893## Physical Device Ordering 894 895Prior to the 1.3.204 loader, physical devices on Linux could be returned in an 896inconsistent order. 897To remedy this, the Vulkan loader will now sort devices once they have been 898received from the drivers (before returning the information to any enabled 899layers) in the following fashion: 900 * Sort based on device type (Discrete, Integrated, Virtual, all others) 901 * Sort internal to the types based on PCI information (Domain, Bus, Device, and 902 Function). 903 904This allows for a consistent physical device order from run to run on the same 905system, unless the actual underlying hardware changes. 906 907A new environment variable is defined to give users the ability to force a 908specific device, `VK_LOADER_DEVICE_SELECT`. 909This environment variable should be set to the desired devices hex value for 910Vendor Id and Device Id (as returned from `vkGetPhysicalDeviceProperties` in 911the `VkPhysicalDeviceProperties` structure). 912It should look like the following: 913 914``` 915set VK_LOADER_DEVICE_SELECT=0x10de:0x1f91 916``` 917 918This will force on the device with a vendor ID of "0x10de" and a device ID 919of "0x1f91". 920If that device is not found, this is simply ignored. 921 922All device selection work done in the loader can be disabled by setting the 923environment variable `VK_LOADER_DISABLE_SELECT` to a non-zero value. 924This is intended for debug purposes to narrow down any issues with the loader 925device selection mechanism, but can be used by others. 926 927[Return to the top-level LoaderInterfaceArchitecture.md file.](LoaderInterfaceArchitecture.md) 928