15db71995Sopenharmony_ci<!-- markdownlint-disable MD041 --> 25db71995Sopenharmony_ci[![Khronos Vulkan][1]][2] 35db71995Sopenharmony_ci 45db71995Sopenharmony_ci[1]: https://vulkan.lunarg.com/img/Vulkan_100px_Dec16.png "https://www.khronos.org/vulkan/" 55db71995Sopenharmony_ci[2]: https://www.khronos.org/vulkan/ 65db71995Sopenharmony_ci 75db71995Sopenharmony_ci# Application Interface to Loader <!-- omit from toc --> 85db71995Sopenharmony_ci[![Creative Commons][3]][4] 95db71995Sopenharmony_ci 105db71995Sopenharmony_ci<!-- Copyright © 2015-2023 LunarG, Inc. --> 115db71995Sopenharmony_ci 125db71995Sopenharmony_ci[3]: https://i.creativecommons.org/l/by-nd/4.0/88x31.png "Creative Commons License" 135db71995Sopenharmony_ci[4]: https://creativecommons.org/licenses/by-nd/4.0/ 145db71995Sopenharmony_ci 155db71995Sopenharmony_ci## Table of Contents <!-- omit from toc --> 165db71995Sopenharmony_ci 175db71995Sopenharmony_ci- [Overview](#overview) 185db71995Sopenharmony_ci- [Interfacing with Vulkan Functions](#interfacing-with-vulkan-functions) 195db71995Sopenharmony_ci - [Vulkan Direct Exports](#vulkan-direct-exports) 205db71995Sopenharmony_ci - [Directly Linking to the Loader](#directly-linking-to-the-loader) 215db71995Sopenharmony_ci - [Dynamic Linking](#dynamic-linking) 225db71995Sopenharmony_ci - [Static Linking](#static-linking) 235db71995Sopenharmony_ci - [Indirectly Linking to the Loader](#indirectly-linking-to-the-loader) 245db71995Sopenharmony_ci - [Best Application Performance Setup](#best-application-performance-setup) 255db71995Sopenharmony_ci - [ABI Versioning](#abi-versioning) 265db71995Sopenharmony_ci - [Windows Dynamic Library Usage](#windows-dynamic-library-usage) 275db71995Sopenharmony_ci - [Linux Dynamic Library Usage](#linux-dynamic-library-usage) 285db71995Sopenharmony_ci - [MacOs Dynamic Library Usage](#macos-dynamic-library-usage) 295db71995Sopenharmony_ci - [Bundling the Loader With An Application](#bundling-the-loader-with-an-application) 305db71995Sopenharmony_ci- [Application Layer Usage](#application-layer-usage) 315db71995Sopenharmony_ci - [Meta-Layers](#meta-layers) 325db71995Sopenharmony_ci - [Implicit vs Explicit Layers](#implicit-vs-explicit-layers) 335db71995Sopenharmony_ci - [Override Layer](#override-layer) 345db71995Sopenharmony_ci - [Forcing Layer Source Folders](#forcing-layer-source-folders) 355db71995Sopenharmony_ci - [Exception for Elevated Privileges](#exception-for-elevated-privileges) 365db71995Sopenharmony_ci - [Forcing Layers to be Enabled on Windows, Linux and macOS](#forcing-layers-to-be-enabled-on-windows-linux-and-macos) 375db71995Sopenharmony_ci - [Overall Layer Ordering](#overall-layer-ordering) 385db71995Sopenharmony_ci - [Debugging Possible Layer Issues](#debugging-possible-layer-issues) 395db71995Sopenharmony_ci- [Application Usage of Extensions](#application-usage-of-extensions) 405db71995Sopenharmony_ci - [Instance and Device Extensions](#instance-and-device-extensions) 415db71995Sopenharmony_ci - [WSI Extensions](#wsi-extensions) 425db71995Sopenharmony_ci - [Unknown Extensions](#unknown-extensions) 435db71995Sopenharmony_ci - [Filtering Out Unknown Instance Extension Names](#filtering-out-unknown-instance-extension-names) 445db71995Sopenharmony_ci- [Physical Device Ordering](#physical-device-ordering) 455db71995Sopenharmony_ci 465db71995Sopenharmony_ci## Overview 475db71995Sopenharmony_ci 485db71995Sopenharmony_ciThis is the Application-centric view of working with the Vulkan loader. 495db71995Sopenharmony_ciFor the complete overview of all sections of the loader, please refer 505db71995Sopenharmony_cito the [LoaderInterfaceArchitecture.md](LoaderInterfaceArchitecture.md) file. 515db71995Sopenharmony_ci 525db71995Sopenharmony_ci## Interfacing with Vulkan Functions 535db71995Sopenharmony_ci 545db71995Sopenharmony_ciThere are several ways Vulkan functions may be interfaced through the loader: 555db71995Sopenharmony_ci 565db71995Sopenharmony_ci 575db71995Sopenharmony_ci### Vulkan Direct Exports 585db71995Sopenharmony_ci 595db71995Sopenharmony_ciThe loader library on Windows, Linux, Android, and macOS will export all core 605db71995Sopenharmony_ciVulkan entry-points and all appropriate Window System Interface (WSI) 615db71995Sopenharmony_cientry-points. 625db71995Sopenharmony_ciThis is done to make it simpler to get started with Vulkan development. 635db71995Sopenharmony_ciWhen an application links directly to the loader library in this way, the 645db71995Sopenharmony_ciVulkan calls are simple *trampoline* functions that jump to the appropriate 655db71995Sopenharmony_cidispatch table entry for the object they are given. 665db71995Sopenharmony_ci 675db71995Sopenharmony_ci 685db71995Sopenharmony_ci### Directly Linking to the Loader 695db71995Sopenharmony_ci 705db71995Sopenharmony_ci#### Dynamic Linking 715db71995Sopenharmony_ci 725db71995Sopenharmony_ciThe loader is distributed as a dynamic library (.dll on Windows or .so on Linux 735db71995Sopenharmony_cior .dylib on macOS) which gets installed to the system path for dynamic 745db71995Sopenharmony_cilibraries. 755db71995Sopenharmony_ciFurthermore, the dynamic library is generally installed to Windows 765db71995Sopenharmony_cisystems as part of driver installation and is generally provided on Linux 775db71995Sopenharmony_cithrough the system package manager. 785db71995Sopenharmony_ciThis means that applications can usually expect a copy of the loader to be 795db71995Sopenharmony_cipresent on a system. 805db71995Sopenharmony_ciIf applications want to be completely sure that a loader is present, they can 815db71995Sopenharmony_ciinclude a loader or runtime installer with their application. 825db71995Sopenharmony_ci 835db71995Sopenharmony_ci#### Static Linking 845db71995Sopenharmony_ci 855db71995Sopenharmony_ciIn previous versions of the loader, it was possible to statically link the 865db71995Sopenharmony_ciloader. 875db71995Sopenharmony_ci**This was removed and is no longer possible.** 885db71995Sopenharmony_ciThe decision to remove static linking was because of changes to the driver 895db71995Sopenharmony_ciwhich made older applications that statically linked unable to find newer 905db71995Sopenharmony_cidrivers. 915db71995Sopenharmony_ci 925db71995Sopenharmony_ciAdditionally, static linking posed several problems: 935db71995Sopenharmony_ci - The loader can never be updated without re-linking the application 945db71995Sopenharmony_ci - The possibility that two included libraries could contain different versions 955db71995Sopenharmony_ci of the loader 965db71995Sopenharmony_ci - Could cause conflicts between the different loader versions 975db71995Sopenharmony_ci 985db71995Sopenharmony_ciThe only exception to this is for macOS, but is not supported or tested. 995db71995Sopenharmony_ci 1005db71995Sopenharmony_ci### Indirectly Linking to the Loader 1015db71995Sopenharmony_ci 1025db71995Sopenharmony_ciApplications are not required to link directly to the loader library, instead 1035db71995Sopenharmony_cithey can use the appropriate platform-specific dynamic symbol lookup on the 1045db71995Sopenharmony_ciloader library to initialize the application's own dispatch table. 1055db71995Sopenharmony_ciThis allows an application to fail gracefully if the loader cannot be found. 1065db71995Sopenharmony_ciIt also provides the fastest mechanism for the application to call Vulkan 1075db71995Sopenharmony_cifunctions. 1085db71995Sopenharmony_ciAn application only needs to query (via system calls such as `dlsym`) the 1095db71995Sopenharmony_ciaddress of `vkGetInstanceProcAddr` from the loader library. 1105db71995Sopenharmony_ciThe application then uses `vkGetInstanceProcAddr` to load all functions 1115db71995Sopenharmony_ciavailable, such as `vkCreateInstance`, `vkEnumerateInstanceExtensionProperties` 1125db71995Sopenharmony_ciand `vkEnumerateInstanceLayerProperties` in a platform-independent way. 1135db71995Sopenharmony_ci 1145db71995Sopenharmony_ci### Best Application Performance Setup 1155db71995Sopenharmony_ci 1165db71995Sopenharmony_ciTo get the best possible performance in a Vulkan application, the application 1175db71995Sopenharmony_cishould set up its own dispatch table for every Vulkan API entry-point. 1185db71995Sopenharmony_ciFor every instance-level Vulkan command in the dispatch table, the function pointer 1195db71995Sopenharmony_cishould be queried and filled in by using the results of `vkGetInstanceProcAddr`. 1205db71995Sopenharmony_ciAdditionally, for every device-level Vulkan command, the function pointer 1215db71995Sopenharmony_cishould be queried and filled in using the results of `vkGetDeviceProcAddr`. 1225db71995Sopenharmony_ci 1235db71995Sopenharmony_ci*Why do this?* 1245db71995Sopenharmony_ci 1255db71995Sopenharmony_ciThe answer comes in how the call chain of instance functions are implemented 1265db71995Sopenharmony_civersus the call chain of a device functions. 1275db71995Sopenharmony_ciRemember, a [Vulkan instance is a high-level construct used to provide Vulkan 1285db71995Sopenharmony_cisystem-level information](LoaderInterfaceArchitecture.md#instance-specific). 1295db71995Sopenharmony_ciBecause of this, instance functions need to be broadcast to every available 1305db71995Sopenharmony_cidriver on the system. 1315db71995Sopenharmony_ciThe following diagram shows an approximate view of an instance call chain with 1325db71995Sopenharmony_cithree enabled layers: 1335db71995Sopenharmony_ci 1345db71995Sopenharmony_ci 1355db71995Sopenharmony_ci 1365db71995Sopenharmony_ciThis is also how a Vulkan device function call chain looks if queried 1375db71995Sopenharmony_ciusing `vkGetInstanceProcAddr`. 1385db71995Sopenharmony_ciOn the other hand, a device function doesn't need to worry about the broadcast 1395db71995Sopenharmony_cibecause it knows specifically which associated driver and which associated 1405db71995Sopenharmony_ciphysical device the call should terminate at. 1415db71995Sopenharmony_ciBecause of this, the loader doesn't need to get involved between any enabled 1425db71995Sopenharmony_cilayers and the driver. 1435db71995Sopenharmony_ciThus, using a loader-exported Vulkan device function, the call chain 1445db71995Sopenharmony_ciin the same scenario as above would look like: 1455db71995Sopenharmony_ci 1465db71995Sopenharmony_ci 1475db71995Sopenharmony_ci 1485db71995Sopenharmony_ciAn even better solution would be for an application to perform a 1495db71995Sopenharmony_ci`vkGetDeviceProcAddr` call on all device functions. 1505db71995Sopenharmony_ciThis further optimizes the call chain by removing the loader all-together under 1515db71995Sopenharmony_cimost scenarios: 1525db71995Sopenharmony_ci 1535db71995Sopenharmony_ci 1545db71995Sopenharmony_ci 1555db71995Sopenharmony_ciAlso, notice if no layers are enabled, the application function pointers point 1565db71995Sopenharmony_ci**directly to the driver**. 1575db71995Sopenharmony_ciWith many function calls, the lack of indirection in each adds up to non-trivial 1585db71995Sopenharmony_ciperformance savings. 1595db71995Sopenharmony_ci 1605db71995Sopenharmony_ci**NOTE:** There are some device functions which still require the loader to 1615db71995Sopenharmony_ciintercept them with a *trampoline* and *terminator*. 1625db71995Sopenharmony_ciThere are very few of these, but they are typically functions which the loader 1635db71995Sopenharmony_ciwraps with its own data. 1645db71995Sopenharmony_ciIn those cases, even the device call chain will continue to look like the 1655db71995Sopenharmony_ciinstance call chain. 1665db71995Sopenharmony_ciOne example of a device function requiring a *terminator* is 1675db71995Sopenharmony_ci`vkCreateSwapchainKHR`. 1685db71995Sopenharmony_ciFor that function, the loader needs to potentially convert the KHR_surface 1695db71995Sopenharmony_ciobject into an driver-specific KHR_surface object prior to passing down the rest 1705db71995Sopenharmony_ciof the function's information to the driver. 1715db71995Sopenharmony_ci 1725db71995Sopenharmony_ciRemember: 1735db71995Sopenharmony_ci * `vkGetInstanceProcAddr` is used to query instance and physical device 1745db71995Sopenharmony_ci functions, but can query all functions. 1755db71995Sopenharmony_ci * `vkGetDeviceProcAddr` is only used to query device functions. 1765db71995Sopenharmony_ci 1775db71995Sopenharmony_ci 1785db71995Sopenharmony_ci### ABI Versioning 1795db71995Sopenharmony_ci 1805db71995Sopenharmony_ciThe Vulkan loader library will be distributed in various ways including Vulkan 1815db71995Sopenharmony_ciSDKs, OS package distributions and Independent Hardware Vendor (IHV) driver 1825db71995Sopenharmony_cipackages. 1835db71995Sopenharmony_ciThese details are beyond the scope of this document. 1845db71995Sopenharmony_ciHowever, the name and versioning of the Vulkan loader library is specified so 1855db71995Sopenharmony_cian app can link to the correct Vulkan ABI library version. 1865db71995Sopenharmony_ciABI backwards compatibility is guaranteed for all versions with the same major 1875db71995Sopenharmony_cinumber (e.g. 1.0 and 1.1). 1885db71995Sopenharmony_ci 1895db71995Sopenharmony_ci#### Windows Dynamic Library Usage 1905db71995Sopenharmony_ci 1915db71995Sopenharmony_ciOn Windows, the loader library encodes the ABI version in its name such that 1925db71995Sopenharmony_cimultiple ABI incompatible versions of the loader can peacefully coexist on a 1935db71995Sopenharmony_cigiven system. 1945db71995Sopenharmony_ciThe Vulkan loader library file name is `vulkan-<ABI version>.dll`. 1955db71995Sopenharmony_ciFor example, for Vulkan version 1.X on Windows the library filename is 1965db71995Sopenharmony_ci`vulkan-1.dll`. 1975db71995Sopenharmony_ciThis library file can typically be found in the `windows\system32` 1985db71995Sopenharmony_cidirectory (on 64-bit Windows installs, the 32-bit version of the loader with 1995db71995Sopenharmony_cithe same name can be found in the `windows\sysWOW64` directory). 2005db71995Sopenharmony_ci 2015db71995Sopenharmony_ci#### Linux Dynamic Library Usage 2025db71995Sopenharmony_ci 2035db71995Sopenharmony_ciFor Linux, shared libraries are versioned based on a suffix. 2045db71995Sopenharmony_ciThus, the ABI number is not encoded in the base of the library filename as on 2055db71995Sopenharmony_ciWindows. 2065db71995Sopenharmony_ci 2075db71995Sopenharmony_ciOn Linux, applications that have a hard dependency on Vulkan should request 2085db71995Sopenharmony_cilinking to the unversioned name `libvulkan.so` in their build system. 2095db71995Sopenharmony_ciFor example by importing the CMake target `Vulkan::Vulkan` or by using the 2105db71995Sopenharmony_cioutput of `pkg-config --cflags --libs vulkan` as compiler flags. 2115db71995Sopenharmony_ciAs usual for Linux libraries, the compiler and linker will resolve this to 2125db71995Sopenharmony_cia dependency on the correct versioned SONAME, currently `libvulkan.so.1`. 2135db71995Sopenharmony_ciLinux applications that load Vulkan-Loader dynamically at runtime do not 2145db71995Sopenharmony_cibenefit from this mechanism, and should instead make sure to pass the 2155db71995Sopenharmony_civersioned name such as `libvulkan.so.1` to `dlopen()`, to ensure that they 2165db71995Sopenharmony_ciload a compatible version. 2175db71995Sopenharmony_ci 2185db71995Sopenharmony_ci#### MacOs Dynamic Library Usage 2195db71995Sopenharmony_ci 2205db71995Sopenharmony_ciMacOs linking is similar to Linux, with the exception being that the standard 2215db71995Sopenharmony_cidynamic library is named `libvulkan.dylib` and the ABI versioned library is 2225db71995Sopenharmony_cicurrently named `libvulkan.1.dylib`. 2235db71995Sopenharmony_ci 2245db71995Sopenharmony_ci 2255db71995Sopenharmony_ci### Bundling the Loader With An Application 2265db71995Sopenharmony_ci 2275db71995Sopenharmony_ciThe Khronos loader is typically installed on platforms either in a 2285db71995Sopenharmony_ciplatform-specific way (i.e. packages on Linux) or as part of a driver install 2295db71995Sopenharmony_ci(i.e. using the Vulkan Runtime installer on Windows). 2305db71995Sopenharmony_ciApplications or engines may desire to install the Vulkan loader locally to their 2315db71995Sopenharmony_ciexecution tree as part of their own installation process. 2325db71995Sopenharmony_ciThis may be because providing the specific loader: 2335db71995Sopenharmony_ci 2345db71995Sopenharmony_ci 1) Guarantees certain Vulkan API exports are available in the loader 2355db71995Sopenharmony_ci 2) Ensures certain loader behavior is well-known 2365db71995Sopenharmony_ci 3) Provides consistency across user installation 2375db71995Sopenharmony_ci 2385db71995Sopenharmony_ciHowever, this is **strongly discouraged** because: 2395db71995Sopenharmony_ci 2405db71995Sopenharmony_ci 1) The packaged loader may not be compatible with future driver revisions 2415db71995Sopenharmony_ci(this can be especially true on Windows where driver install locations can 2425db71995Sopenharmony_cichange during updates to the OS) 2435db71995Sopenharmony_ci 2) It can prevent the application/engine from taking advantage of new Vulkan 2445db71995Sopenharmony_ciAPI version/extension exports 2455db71995Sopenharmony_ci 3) The application/engine will miss out on important loader bug-fixes 2465db71995Sopenharmony_ci 4) The packaged loader will not contain useful feature updates (like 2475db71995Sopenharmony_ciimproved loader debugability) 2485db71995Sopenharmony_ci 2495db71995Sopenharmony_ciOf course, even if an application/engine does initially release with a specific 2505db71995Sopenharmony_civersion of the Khronos loader, it may chose to update or remove that loader at 2515db71995Sopenharmony_cisome point in the future. 2525db71995Sopenharmony_ciThis could be due to the exposure of needed functionality in the loader as time 2535db71995Sopenharmony_ciprogresses. 2545db71995Sopenharmony_ciBut, that relies upon end-users correctly performing whatever update process is 2555db71995Sopenharmony_cinecessary at that future time which may result in different behavior across 2565db71995Sopenharmony_cidifferent user's systems. 2575db71995Sopenharmony_ci 2585db71995Sopenharmony_ciOne better alternative, at least on Windows, is to package the Vulkan Runtime 2595db71995Sopenharmony_ciinstaller for the desired version of the Vulkan loader with your product. 2605db71995Sopenharmony_ciThen, the installation process can use that to ensure the end-user's system 2615db71995Sopenharmony_ciis up to date. 2625db71995Sopenharmony_ciThe Runtime installer will detect the version already installed and will only 2635db71995Sopenharmony_ciinstall a newer runtime if necessary. 2645db71995Sopenharmony_ci 2655db71995Sopenharmony_ciAnother alternative is to write the application so it can fallback to earlier 2665db71995Sopenharmony_civersions of Vulkan yet display a warning indicating functionality is disabled 2675db71995Sopenharmony_ciuntil the user updates their system to a specific runtime/driver. 2685db71995Sopenharmony_ci 2695db71995Sopenharmony_ci 2705db71995Sopenharmony_ci## Application Layer Usage 2715db71995Sopenharmony_ci 2725db71995Sopenharmony_ciApplications desiring Vulkan functionality beyond what Vulkan drivers 2735db71995Sopenharmony_cion their system already expose, may use various layers to augment the API. 2745db71995Sopenharmony_ciA layer cannot add new Vulkan core API entry-points that are not exposed in 2755db71995Sopenharmony_ciVulkan.h. 2765db71995Sopenharmony_ciHowever, layers may offer implementations of extensions that introduce 2775db71995Sopenharmony_ciadditional entry-points beyond what is available without those layers. 2785db71995Sopenharmony_ciThese additional extension entry-points can be queried through the Vulkan 2795db71995Sopenharmony_ciextension interface. 2805db71995Sopenharmony_ci 2815db71995Sopenharmony_ciA common use of layers is for API validation which can be enabled during 2825db71995Sopenharmony_ciapplication development and left out when releasing the application. 2835db71995Sopenharmony_ciThis allows easy control of the overhead resulting from enabling validation of 2845db71995Sopenharmony_cithe application's usage of the API, which wasn't always possible in previous 2855db71995Sopenharmony_cigraphics APIs. 2865db71995Sopenharmony_ci 2875db71995Sopenharmony_ciTo find out what layers are available to an application, use 2885db71995Sopenharmony_ci`vkEnumerateInstanceLayerProperties`. 2895db71995Sopenharmony_ciThis will report all layers that have been discovered by the loader. 2905db71995Sopenharmony_ciThe loader looks in various locations to find layers on the system. 2915db71995Sopenharmony_ciFor more information see the 2925db71995Sopenharmony_ci[Layer discovery](LoaderLayerInterface.md#layer-discovery) 2935db71995Sopenharmony_cisection in the 2945db71995Sopenharmony_ci[LoaderLayerInterface.md document](LoaderLayerInterface.md) document. 2955db71995Sopenharmony_ci 2965db71995Sopenharmony_ciTo enable specific layers, simply pass the names of the layers to 2975db71995Sopenharmony_cienable in the `ppEnabledLayerNames` field of the `VkInstanceCreateInfo` during 2985db71995Sopenharmony_cia call to `vkCreateInstance`. 2995db71995Sopenharmony_ciOnce done, the layers that have been enabled will be active for all Vulkan functions 3005db71995Sopenharmony_ciusing the created `VkInstance`, and any of its child objects. 3015db71995Sopenharmony_ci 3025db71995Sopenharmony_ci**NOTE:** Layer ordering is important in several cases since some layers 3035db71995Sopenharmony_ciinteract with each other. 3045db71995Sopenharmony_ciBe careful when enabling layers as this may be the case. 3055db71995Sopenharmony_ciSee the [Overall Layer Ordering](#overall-layer-ordering) section for more 3065db71995Sopenharmony_ciinformation. 3075db71995Sopenharmony_ci 3085db71995Sopenharmony_ciThe following code section shows how to go about enabling the 3095db71995Sopenharmony_ci`VK_LAYER_KHRONOS_validation` layer. 3105db71995Sopenharmony_ci 3115db71995Sopenharmony_ci``` 3125db71995Sopenharmony_cichar *instance_layers[] = { 3135db71995Sopenharmony_ci "VK_LAYER_KHRONOS_validation" 3145db71995Sopenharmony_ci}; 3155db71995Sopenharmony_ciconst VkApplicationInfo app = { 3165db71995Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, 3175db71995Sopenharmony_ci .pNext = NULL, 3185db71995Sopenharmony_ci .pApplicationName = "TEST_APP", 3195db71995Sopenharmony_ci .applicationVersion = 0, 3205db71995Sopenharmony_ci .pEngineName = "TEST_ENGINE", 3215db71995Sopenharmony_ci .engineVersion = 0, 3225db71995Sopenharmony_ci .apiVersion = VK_API_VERSION_1_0, 3235db71995Sopenharmony_ci}; 3245db71995Sopenharmony_ciVkInstanceCreateInfo inst_info = { 3255db71995Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 3265db71995Sopenharmony_ci .pNext = NULL, 3275db71995Sopenharmony_ci .pApplicationInfo = &app, 3285db71995Sopenharmony_ci .enabledLayerCount = 1, 3295db71995Sopenharmony_ci .ppEnabledLayerNames = (const char *const *)instance_layers, 3305db71995Sopenharmony_ci .enabledExtensionCount = 0, 3315db71995Sopenharmony_ci .ppEnabledExtensionNames = NULL, 3325db71995Sopenharmony_ci}; 3335db71995Sopenharmony_cierr = vkCreateInstance(&inst_info, NULL, &demo->inst); 3345db71995Sopenharmony_ciif (VK_ERROR_LAYER_NOT_PRESENT == err) { 3355db71995Sopenharmony_ci // Couldn't find the validation layer 3365db71995Sopenharmony_ci} 3375db71995Sopenharmony_ci``` 3385db71995Sopenharmony_ci 3395db71995Sopenharmony_ciAt `vkCreateInstance` and `vkCreateDevice`, the loader constructs call chains 3405db71995Sopenharmony_cithat include the application specified (enabled) layers. 3415db71995Sopenharmony_ciOrder is important in the `ppEnabledLayerNames` array; array element 0 is the 3425db71995Sopenharmony_citopmost (closest to the application) layer inserted in the chain and the last 3435db71995Sopenharmony_ciarray element is closest to the driver. 3445db71995Sopenharmony_ciSee the [Overall Layer Ordering](#overall-layer-ordering) section for more 3455db71995Sopenharmony_ciinformation on layer ordering. 3465db71995Sopenharmony_ci 3475db71995Sopenharmony_ci**NOTE:** *Device Layers Are Now Deprecated* 3485db71995Sopenharmony_ci> `vkCreateDevice` originally was able to select layers in a similar manner to 3495db71995Sopenharmony_ci`vkCreateInstance`. 3505db71995Sopenharmony_ci> This led to the concept of "instance layers" and "device layers". 3515db71995Sopenharmony_ci> It was decided by Khronos to deprecate the "device layer" functionality and 3525db71995Sopenharmony_ci> only consider "instance layers". 3535db71995Sopenharmony_ci> Therefore, `vkCreateDevice` will use the layers specified at 3545db71995Sopenharmony_ci`vkCreateInstance`. 3555db71995Sopenharmony_ci> Because of this, the following items have been deprecated: 3565db71995Sopenharmony_ci> * `VkDeviceCreateInfo` fields: 3575db71995Sopenharmony_ci> * `ppEnabledLayerNames` 3585db71995Sopenharmony_ci> * `enabledLayerCount` 3595db71995Sopenharmony_ci> * The `vkEnumerateDeviceLayerProperties` function 3605db71995Sopenharmony_ci 3615db71995Sopenharmony_ci 3625db71995Sopenharmony_ci### Meta-Layers 3635db71995Sopenharmony_ci 3645db71995Sopenharmony_ciMeta-layers are layers which contain an ordered list of other layers to enable. 3655db71995Sopenharmony_ciThis is to allow grouping layers together in a specified order so that they can 3665db71995Sopenharmony_ciinteract properly. 3675db71995Sopenharmony_ciOriginally, this was used to group together the individual Vulkan Validation 3685db71995Sopenharmony_cilayers in the proper order to avoid conflicts. 3695db71995Sopenharmony_ciIt was necessary because instead of a single Validation layer, validation was 3705db71995Sopenharmony_cisplit into multiple component layers. 3715db71995Sopenharmony_ciThe new `VK_LAYER_KHRONOS_validation` layer pulled everything into a single 3725db71995Sopenharmony_cilayer, dropping the need for meta layers. 3735db71995Sopenharmony_ciWhile not necessary for validation anymore, VkConfig does use meta layers to 3745db71995Sopenharmony_cigroup layers together based on user's preferences. 3755db71995Sopenharmony_ciMore can be found out about this functionality through both the 3765db71995Sopenharmony_ci[VkConfig documentation](https://github.com/LunarG/VulkanTools/blob/main/vkconfig/README.md) 3775db71995Sopenharmony_ciand the section later on the [Override Layer](#override-layer). 3785db71995Sopenharmony_ci 3795db71995Sopenharmony_ciMeta-layers are detailed more in the 3805db71995Sopenharmony_ci[Meta-Layers](LoaderLayerInterface.md#meta-layers) section of the 3815db71995Sopenharmony_ci[LoaderLayerInterface.md](LoaderLayerInterface.md) file in this folder. 3825db71995Sopenharmony_ci 3835db71995Sopenharmony_ci 3845db71995Sopenharmony_ci### Implicit vs Explicit Layers 3855db71995Sopenharmony_ci 3865db71995Sopenharmony_ci 3875db71995Sopenharmony_ci 3885db71995Sopenharmony_ciExplicit layers are layers which are enabled by an application (e.g. with the 3895db71995Sopenharmony_civkCreateInstance function as mentioned previously). 3905db71995Sopenharmony_ci 3915db71995Sopenharmony_ciImplicit layers are enabled automatically by their very existence, unless 3925db71995Sopenharmony_cirequiring an additional manual enable step, unlike explicit layers that must be 3935db71995Sopenharmony_cienabled explicitly. 3945db71995Sopenharmony_ciFor example, certain application environments (e.g. Steam or an automotive 3955db71995Sopenharmony_ciinfotainment system) may have layers which they always want enabled for all 3965db71995Sopenharmony_ciapplications that they start. 3975db71995Sopenharmony_ciOther implicit layers may be for all applications started on a given system 3985db71995Sopenharmony_ci(e.g. layers that overlay frames-per-second). 3995db71995Sopenharmony_ci 4005db71995Sopenharmony_ciImplicit layers have an additional requirement over explicit layers in that 4015db71995Sopenharmony_cithey require being able to be disabled by an environmental variable. 4025db71995Sopenharmony_ciThis is due to the fact that they are not visible to the application and could 4035db71995Sopenharmony_cicause issues. 4045db71995Sopenharmony_ciA good principle to keep in mind would be to define both an enable and disable 4055db71995Sopenharmony_cienvironment variable so the users can deterministically enable the 4065db71995Sopenharmony_cifunctionality. 4075db71995Sopenharmony_ciOn Desktop platforms (Windows, Linux, and macOS), these enable/disable settings 4085db71995Sopenharmony_ciare defined in the layer's JSON file. 4095db71995Sopenharmony_ci 4105db71995Sopenharmony_ciDiscovery of system-installed implicit and explicit layers is described later 4115db71995Sopenharmony_ciin the [Layer discovery](LoaderLayerInterface.md#layer-discovery) 4125db71995Sopenharmony_cisection in the 4135db71995Sopenharmony_ci[LoaderLayerInterface.md](LoaderLayerInterface.md) document. 4145db71995Sopenharmony_ci 4155db71995Sopenharmony_ciImplicit and explicit layers may be found in different locations based on the 4165db71995Sopenharmony_ciunderlying operating system. 4175db71995Sopenharmony_ciThe table below details more information: 4185db71995Sopenharmony_ci 4195db71995Sopenharmony_ci<table style="width:100%"> 4205db71995Sopenharmony_ci <tr> 4215db71995Sopenharmony_ci <th>Operating System</th> 4225db71995Sopenharmony_ci <th>Implicit Layer Identification</th> 4235db71995Sopenharmony_ci </tr> 4245db71995Sopenharmony_ci <tr> 4255db71995Sopenharmony_ci <td>Windows</td> 4265db71995Sopenharmony_ci <td>Implicit layers are located in a different Windows registry location 4275db71995Sopenharmony_ci than explicit layers.</td> 4285db71995Sopenharmony_ci </tr> 4295db71995Sopenharmony_ci <tr> 4305db71995Sopenharmony_ci <td>Linux</td> 4315db71995Sopenharmony_ci <td>Implicit layers are located in a different directory location than 4325db71995Sopenharmony_ci explicit layers.</td> 4335db71995Sopenharmony_ci </tr> 4345db71995Sopenharmony_ci <tr> 4355db71995Sopenharmony_ci <td>Android</td> 4365db71995Sopenharmony_ci <td>There is **No Support For Implicit Layers** on Android.</td> 4375db71995Sopenharmony_ci </tr> 4385db71995Sopenharmony_ci <tr> 4395db71995Sopenharmony_ci <td>macOS</td> 4405db71995Sopenharmony_ci <td>Implicit layers are located in a different directory location than 4415db71995Sopenharmony_ci explicit layers.</td> 4425db71995Sopenharmony_ci </tr> 4435db71995Sopenharmony_ci</table> 4445db71995Sopenharmony_ci 4455db71995Sopenharmony_ci 4465db71995Sopenharmony_ci#### Override Layer 4475db71995Sopenharmony_ci 4485db71995Sopenharmony_ciThe "Override Layer" is a special implicit meta-layer created by the 4495db71995Sopenharmony_ci[VkConfig](https://github.com/LunarG/VulkanTools/blob/main/vkconfig/README.md) 4505db71995Sopenharmony_citool and available by default when the tool is running. 4515db71995Sopenharmony_ciOnce VkConfig exits, the override layer is removed, and the system should 4525db71995Sopenharmony_cireturn to standard Vulkan behavior. 4535db71995Sopenharmony_ciWhenever the override layer is present in the layer search path, the loader will 4545db71995Sopenharmony_cipull it into the layer call stack with the standard implicit layers along with 4555db71995Sopenharmony_ciall layers contained in the list of layers to load. 4565db71995Sopenharmony_ciThis allows an end-user or developer to easily force on any number of layers 4575db71995Sopenharmony_ciand settings via VkConfig. 4585db71995Sopenharmony_ci 4595db71995Sopenharmony_ciThe override layer is discussed more in the 4605db71995Sopenharmony_ci[Override Meta-Layer](LoaderLayerInterface.md#override-meta-layer) section of the 4615db71995Sopenharmony_ci[LoaderLayerInterface.md](LoaderLayerInterface.md) file in this folder. 4625db71995Sopenharmony_ci 4635db71995Sopenharmony_ci 4645db71995Sopenharmony_ci### Forcing Layer Source Folders 4655db71995Sopenharmony_ci 4665db71995Sopenharmony_ciDevelopers may need to use special, pre-production layers, without modifying 4675db71995Sopenharmony_cithe system-installed layers. 4685db71995Sopenharmony_ci 4695db71995Sopenharmony_ciThis can be accomplished in one of two ways: 4705db71995Sopenharmony_ci 4715db71995Sopenharmony_ci 1. Selecting specific layer paths using the 4725db71995Sopenharmony_ci[VkConfig](https://github.com/LunarG/VulkanTools/blob/main/vkconfig/README.md) 4735db71995Sopenharmony_citool shipped with the Vulkan SDK. 4745db71995Sopenharmony_ci 2. Directing the loader to look for layers in specific files and/or folders by using the 4755db71995Sopenharmony_ci`VK_LAYER_PATH` environment variable. 4765db71995Sopenharmony_ci 4775db71995Sopenharmony_ciThe `VK_LAYER_PATH` environment variable can contain multiple paths separated by 4785db71995Sopenharmony_cithe operating-system specific path separator. 4795db71995Sopenharmony_ciOn Windows, this is a semicolon (`;`), while on Linux and macOS it is a colon 4805db71995Sopenharmony_ci(`:`). 4815db71995Sopenharmony_ci 4825db71995Sopenharmony_ciIf `VK_LAYER_PATH` exists, the files and/or folders listed will be scanned for explicit 4835db71995Sopenharmony_cilayer manifest files. 4845db71995Sopenharmony_ciImplicit layer discovery is unaffected by this environment variable. 4855db71995Sopenharmony_ciEach directory listed should be the full pathname of a folder containing layer 4865db71995Sopenharmony_cimanifest files. 4875db71995Sopenharmony_ci 4885db71995Sopenharmony_ciSee the 4895db71995Sopenharmony_ci[Table of Debug Environment Variables](LoaderInterfaceArchitecture.md#table-of-debug-environment-variables) 4905db71995Sopenharmony_ciin the [LoaderInterfaceArchitecture.md document](LoaderInterfaceArchitecture.md) 4915db71995Sopenharmony_cifor more details. 4925db71995Sopenharmony_ci 4935db71995Sopenharmony_ci 4945db71995Sopenharmony_ci#### Exception for Elevated Privileges 4955db71995Sopenharmony_ci 4965db71995Sopenharmony_ciFor security reasons, `VK_LAYER_PATH` is ignored if running with elevated 4975db71995Sopenharmony_ciprivileges. 4985db71995Sopenharmony_ciBecause of this, `VK_LAYER_PATH` can only be used for applications that do not 4995db71995Sopenharmony_ciuse elevated privileges. 5005db71995Sopenharmony_ci 5015db71995Sopenharmony_ciFor more information see 5025db71995Sopenharmony_ci[Elevated Privilege Caveats](LoaderInterfaceArchitecture.md#elevated-privilege-caveats) 5035db71995Sopenharmony_ciin the top-level 5045db71995Sopenharmony_ci[LoaderInterfaceArchitecture.md][LoaderInterfaceArchitecture.md] document. 5055db71995Sopenharmony_ci 5065db71995Sopenharmony_ci 5075db71995Sopenharmony_ci### Forcing Layers to be Enabled on Windows, Linux and macOS 5085db71995Sopenharmony_ci 5095db71995Sopenharmony_ciDevelopers may want to enable layers that are not enabled by the given 5105db71995Sopenharmony_ciapplication they are using. 5115db71995Sopenharmony_ci 5125db71995Sopenharmony_ciThis can be also be accomplished in one of two ways: 5135db71995Sopenharmony_ci 5145db71995Sopenharmony_ci 1. Selecting specific layers using the 5155db71995Sopenharmony_ci[VkConfig](https://github.com/LunarG/VulkanTools/blob/main/vkconfig/README.md) 5165db71995Sopenharmony_citool shipped with the Vulkan SDK. 5175db71995Sopenharmony_ci 2. Directing the loader to look for additional layers by name using the 5185db71995Sopenharmony_ci`VK_INSTANCE_LAYERS` environment variable. 5195db71995Sopenharmony_ci 5205db71995Sopenharmony_ciBoth can be used to enable additional layers which are not specified (enabled) 5215db71995Sopenharmony_ciby the application at `vkCreateInstance`. 5225db71995Sopenharmony_ci 5235db71995Sopenharmony_ciThe `VK_INSTANCE_LAYERS` environment variable is a list of layer names to enable 5245db71995Sopenharmony_ciseparated by the operating-system specific path separator. 5255db71995Sopenharmony_ciOn Windows, this is a semicolon (`;`), while on Linux and macOS it is a colon 5265db71995Sopenharmony_ci(`:`). 5275db71995Sopenharmony_ciThe order of the names is relevant with the first layer name in the list being 5285db71995Sopenharmony_cithe top-most layer (closest to the application) and the last layer name in the 5295db71995Sopenharmony_cilist being the bottom-most layer (closest to the driver). 5305db71995Sopenharmony_ciSee the [Overall Layer Ordering](#overall-layer-ordering) section for more 5315db71995Sopenharmony_ciinformation. 5325db71995Sopenharmony_ci 5335db71995Sopenharmony_ciApplication specified layers and user specified layers (via environment 5345db71995Sopenharmony_civariables) are aggregated and duplicates removed by the loader when enabling 5355db71995Sopenharmony_cilayers. 5365db71995Sopenharmony_ciLayers specified via environment variable are top-most (closest to the 5375db71995Sopenharmony_ciapplication) while layers specified by the application are bottom-most. 5385db71995Sopenharmony_ci 5395db71995Sopenharmony_ciAn example of using these environment variables to activate the validation 5405db71995Sopenharmony_cilayer `VK_LAYER_KHRONOS_validation` on Linux or macOS is as follows: 5415db71995Sopenharmony_ci 5425db71995Sopenharmony_ci``` 5435db71995Sopenharmony_ci> $ export VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation 5445db71995Sopenharmony_ci``` 5455db71995Sopenharmony_ci 5465db71995Sopenharmony_ciSee the 5475db71995Sopenharmony_ci[Table of Debug Environment Variables](LoaderInterfaceArchitecture.md#table-of-debug-environment-variables) 5485db71995Sopenharmony_ciin the [LoaderInterfaceArchitecture.md document](LoaderInterfaceArchitecture.md) 5495db71995Sopenharmony_cifor more details. 5505db71995Sopenharmony_ci 5515db71995Sopenharmony_ci 5525db71995Sopenharmony_ci### Overall Layer Ordering 5535db71995Sopenharmony_ci 5545db71995Sopenharmony_ciThe overall ordering of all layers by the loader based on the above looks 5555db71995Sopenharmony_cias follows: 5565db71995Sopenharmony_ci 5575db71995Sopenharmony_ci 5585db71995Sopenharmony_ci 5595db71995Sopenharmony_ciOrdering may also be important internally to the list of explicit layers. 5605db71995Sopenharmony_ciSome layers may be dependent on other behavior being implemented before 5615db71995Sopenharmony_cior after the loader calls it. 5625db71995Sopenharmony_ciFor example: An overlay layer may want to use `VK_LAYER_KHRONOS_validation` 5635db71995Sopenharmony_cito verify that the overlay layer is behaving appropriately. 5645db71995Sopenharmony_ciThis requires putting the overlay layer closer to the application so that the 5655db71995Sopenharmony_civalidation layer can intercept any Vulkan API calls the overlay layer needs to 5665db71995Sopenharmony_cimake to function. 5675db71995Sopenharmony_ci 5685db71995Sopenharmony_ci 5695db71995Sopenharmony_ci### Debugging Possible Layer Issues 5705db71995Sopenharmony_ci 5715db71995Sopenharmony_ciIf it is possible that a layer is causing issues, there are several things that 5725db71995Sopenharmony_cican be tried which are documented in the 5735db71995Sopenharmony_ci[Debugging Possible Layer Issues](LoaderDebugging.md#debugging-possible-layer-issues) 5745db71995Sopenharmony_cisection of the [LoaderDebugging.mg](LoaderDebugging.md) document in the docs 5755db71995Sopenharmony_cifolder. 5765db71995Sopenharmony_ci 5775db71995Sopenharmony_ci 5785db71995Sopenharmony_ci## Application Usage of Extensions 5795db71995Sopenharmony_ci 5805db71995Sopenharmony_ciExtensions are optional functionality provided by a layer, the loader, or a 5815db71995Sopenharmony_cidriver. 5825db71995Sopenharmony_ciExtensions can modify the behavior of the Vulkan API and need to be specified 5835db71995Sopenharmony_ciand registered with Khronos. 5845db71995Sopenharmony_ciThese extensions can be implemented by a Vulkan driver, the loader, or a layer 5855db71995Sopenharmony_cito expose functionality not available in the core API. 5865db71995Sopenharmony_ciInformation about various extensions can be found in the Vulkan Spec, and 5875db71995Sopenharmony_civulkan.h header file. 5885db71995Sopenharmony_ci 5895db71995Sopenharmony_ci 5905db71995Sopenharmony_ci### Instance and Device Extensions 5915db71995Sopenharmony_ci 5925db71995Sopenharmony_ciAs hinted at in the 5935db71995Sopenharmony_ci[Instance Versus Device](LoaderInterfaceArchitecture.md#instance-versus-device) 5945db71995Sopenharmony_cisection of the main 5955db71995Sopenharmony_ci[LoaderInterfaceArchitecture.md](LoaderInterfaceArchitecture.md) document, 5965db71995Sopenharmony_cithere are two types of extensions: 5975db71995Sopenharmony_ci * Instance Extensions 5985db71995Sopenharmony_ci * Device Extensions 5995db71995Sopenharmony_ci 6005db71995Sopenharmony_ciAn instance extension modifies existing behavior or implements new behavior on 6015db71995Sopenharmony_ciinstance-level objects, such as `VkInstance` and `VkPhysicalDevice`. 6025db71995Sopenharmony_ciA device extension does the same for device-level objects, such as `VkDevice`, 6035db71995Sopenharmony_ci`VkQueue`, and `VkCommandBuffer` as well as any children of those objects. 6045db71995Sopenharmony_ci 6055db71995Sopenharmony_ciIt is **very** important to know what the type of an extension is because 6065db71995Sopenharmony_ciinstance extensions must be enabled with `vkCreateInstance` while device 6075db71995Sopenharmony_ciextensions are enabled with `vkCreateDevice`. 6085db71995Sopenharmony_ci 6095db71995Sopenharmony_ciWhen calling `vkEnumerateInstanceExtensionProperties` and 6105db71995Sopenharmony_ci`vkEnumerateDeviceExtensionProperties`, the loader discovers and aggregates all 6115db71995Sopenharmony_ciextensions of their respective type from layers (both explicit and implicit), 6125db71995Sopenharmony_cidrivers, and the loader before reporting them to the application. 6135db71995Sopenharmony_ci 6145db71995Sopenharmony_ciLooking at `vulkan.h`, both functions are very similar, 6155db71995Sopenharmony_cifor example, the `vkEnumerateInstanceExtensionProperties` prototype looks as 6165db71995Sopenharmony_cifollows: 6175db71995Sopenharmony_ci 6185db71995Sopenharmony_ci``` 6195db71995Sopenharmony_ciVkResult 6205db71995Sopenharmony_ci vkEnumerateInstanceExtensionProperties( 6215db71995Sopenharmony_ci const char *pLayerName, 6225db71995Sopenharmony_ci uint32_t *pPropertyCount, 6235db71995Sopenharmony_ci VkExtensionProperties *pProperties); 6245db71995Sopenharmony_ci``` 6255db71995Sopenharmony_ci 6265db71995Sopenharmony_ciWhile the `vkEnumerateDeviceExtensionProperties` prototype looks like: 6275db71995Sopenharmony_ci 6285db71995Sopenharmony_ci``` 6295db71995Sopenharmony_ciVkResult 6305db71995Sopenharmony_ci vkEnumerateDeviceExtensionProperties( 6315db71995Sopenharmony_ci VkPhysicalDevice physicalDevice, 6325db71995Sopenharmony_ci const char *pLayerName, 6335db71995Sopenharmony_ci uint32_t *pPropertyCount, 6345db71995Sopenharmony_ci VkExtensionProperties *pProperties); 6355db71995Sopenharmony_ci``` 6365db71995Sopenharmony_ci 6375db71995Sopenharmony_ciThe "pLayerName" parameter in these functions is used to select either a single 6385db71995Sopenharmony_cilayer or the Vulkan platform implementation. 6395db71995Sopenharmony_ciIf "pLayerName" is NULL, extensions from Vulkan implementation components 6405db71995Sopenharmony_ci(including loader, implicit layers, and drivers) are enumerated. 6415db71995Sopenharmony_ciIf "pLayerName" is equal to a discovered layer module name then only extensions 6425db71995Sopenharmony_cifrom that layer (which may be implicit or explicit) are enumerated. 6435db71995Sopenharmony_ci 6445db71995Sopenharmony_ci**Note:** While device layers are deprecated, the instance enabled layers are 6455db71995Sopenharmony_cistill present in the device call-chain. 6465db71995Sopenharmony_ci 6475db71995Sopenharmony_ciDuplicate extensions (e.g. an implicit layer and driver might report support for 6485db71995Sopenharmony_cithe same extension) are eliminated by the loader. 6495db71995Sopenharmony_ciFor duplicates, the driver version is reported and the layer version is culled. 6505db71995Sopenharmony_ci 6515db71995Sopenharmony_ciAlso, extensions **must be enabled** (in `vkCreateInstance` or `vkCreateDevice`) 6525db71995Sopenharmony_cibefore the functions associated with the extensions can be used. 6535db71995Sopenharmony_ciIf an extension function is queried using either `vkGetInstanceProcAddr` or 6545db71995Sopenharmony_ci`vkGetDeviceProcAddr`, but the extension has not been enabled, undefined behavior 6555db71995Sopenharmony_cicould result. 6565db71995Sopenharmony_ciThe Validation layers will catch this invalid API usage. 6575db71995Sopenharmony_ci 6585db71995Sopenharmony_ci 6595db71995Sopenharmony_ci### WSI Extensions 6605db71995Sopenharmony_ci 6615db71995Sopenharmony_ciKhronos-approved WSI extensions are available and provide Windows System 6625db71995Sopenharmony_ciIntegration support for various execution environments. 6635db71995Sopenharmony_ciIt is important to understand that some WSI extensions are valid for all 6645db71995Sopenharmony_citargets, but others are particular to a given execution environment (and 6655db71995Sopenharmony_ciloader). 6665db71995Sopenharmony_ciThis Khronos loader (currently targeting Windows, Linux, macOS, Stadia, and 6675db71995Sopenharmony_ciFuchsia) only enables and directly exports those WSI extensions that are 6685db71995Sopenharmony_ciappropriate to the current environment. 6695db71995Sopenharmony_ciFor the most part, the selection is done in the loader using compile-time 6705db71995Sopenharmony_cipreprocessor flags. 6715db71995Sopenharmony_ciAll versions of the Khronos loader currently expose at least the following WSI 6725db71995Sopenharmony_ciextension support: 6735db71995Sopenharmony_ci- VK_KHR_surface 6745db71995Sopenharmony_ci- VK_KHR_swapchain 6755db71995Sopenharmony_ci- VK_KHR_display 6765db71995Sopenharmony_ci 6775db71995Sopenharmony_ciIn addition, each of the following OS targets for the loader support target- 6785db71995Sopenharmony_cispecific extensions: 6795db71995Sopenharmony_ci 6805db71995Sopenharmony_ci| Windowing System | Extensions available | 6815db71995Sopenharmony_ci| ---------------- | ------------------------------------------ | 6825db71995Sopenharmony_ci| Windows | VK_KHR_win32_surface | 6835db71995Sopenharmony_ci| Linux (Wayland) | VK_KHR_wayland_surface | 6845db71995Sopenharmony_ci| Linux (X11) | VK_KHR_xcb_surface and VK_KHR_xlib_surface | 6855db71995Sopenharmony_ci| macOS (MoltenVK) | VK_MVK_macos_surface | 6865db71995Sopenharmony_ci| QNX (Screen) | VK_QNX_screen_surface | 6875db71995Sopenharmony_ci 6885db71995Sopenharmony_ciIt is important to understand that while the loader may support the various 6895db71995Sopenharmony_cientry-points for these extensions, there is a handshake required to actually 6905db71995Sopenharmony_ciuse them: 6915db71995Sopenharmony_ci* At least one physical device must support the extension(s) 6925db71995Sopenharmony_ci* The application must use such a physical device when creating a logical 6935db71995Sopenharmony_cidevice 6945db71995Sopenharmony_ci* The application must request the extension(s) be enabled while creating the 6955db71995Sopenharmony_ciinstance or logical device (this depends on whether or not the given extension 6965db71995Sopenharmony_ciworks with an instance or a device) 6975db71995Sopenharmony_ci 6985db71995Sopenharmony_ciOnly then can the WSI extension be properly used in a Vulkan program. 6995db71995Sopenharmony_ci 7005db71995Sopenharmony_ci 7015db71995Sopenharmony_ci### Unknown Extensions 7025db71995Sopenharmony_ci 7035db71995Sopenharmony_ciWith the ability to expand Vulkan so easily, extensions will be created that 7045db71995Sopenharmony_cithe loader knows nothing about. 7055db71995Sopenharmony_ciIf the extension is a device extension, the loader will pass the unknown 7065db71995Sopenharmony_cientry-point down the device call chain ending with the appropriate 7075db71995Sopenharmony_cidriver entry-points. 7085db71995Sopenharmony_ciThe same thing will happen if the extension is an instance extension which 7095db71995Sopenharmony_citakes a physical device parameter as its first component. 7105db71995Sopenharmony_ciHowever, for all other instance extensions the loader will fail to load it. 7115db71995Sopenharmony_ci 7125db71995Sopenharmony_ci*But why doesn't the loader support unknown instance extensions?* 7135db71995Sopenharmony_ci<br/> 7145db71995Sopenharmony_ciLet's look again at the instance call chain: 7155db71995Sopenharmony_ci 7165db71995Sopenharmony_ci 7175db71995Sopenharmony_ci 7185db71995Sopenharmony_ciNotice that for a normal instance function call, the loader has to handle 7195db71995Sopenharmony_cipassing along the function call to the available drivers. 7205db71995Sopenharmony_ciIf the loader has no idea of the parameters or return value of the instance 7215db71995Sopenharmony_cicall, it can't properly pass information along to the drivers. 7225db71995Sopenharmony_ciThere may be ways to do this, which will be explored in the future. 7235db71995Sopenharmony_ciHowever, for now, the loader does not support instance extensions which don't 7245db71995Sopenharmony_ciexpose entry points that take a physical device as their first parameter. 7255db71995Sopenharmony_ci 7265db71995Sopenharmony_ciBecause the device call-chain does not normally pass through the loader 7275db71995Sopenharmony_ci*terminator*, this is not a problem for device extensions. 7285db71995Sopenharmony_ciAdditionally, since a physical device is associated with one driver, the loader 7295db71995Sopenharmony_cican use a generic *terminator* pointing to one driver. 7305db71995Sopenharmony_ciThis is because both of these extensions terminate directly in the 7315db71995Sopenharmony_cidriver they are associated with. 7325db71995Sopenharmony_ci 7335db71995Sopenharmony_ci*Is this a big problem?* 7345db71995Sopenharmony_ci<br/> 7355db71995Sopenharmony_ciNo! 7365db71995Sopenharmony_ciMost extension functionality only affects either a physical or logical device 7375db71995Sopenharmony_ciand not an instance. 7385db71995Sopenharmony_ciThus, the overwhelming majority of extensions should be supported with direct 7395db71995Sopenharmony_ciloader support. 7405db71995Sopenharmony_ci 7415db71995Sopenharmony_ci### Filtering Out Unknown Instance Extension Names 7425db71995Sopenharmony_ci 7435db71995Sopenharmony_ciIn some cases, a driver may support instance extensions that are not supported 7445db71995Sopenharmony_ciby the loader. 7455db71995Sopenharmony_ciFor the above reasons, the loader will filter out the names of these unknown 7465db71995Sopenharmony_ciinstance extensions when an application calls 7475db71995Sopenharmony_ci`vkEnumerateInstanceExtensionProperties`. 7485db71995Sopenharmony_ciAdditionally, this behavior will cause the loader to emit an error during 7495db71995Sopenharmony_ci`vkCreateInstance` if the application still attempts to use one of these 7505db71995Sopenharmony_ciextensions. 7515db71995Sopenharmony_ciThe intent is to protect applications so that they don't inadvertently use 7525db71995Sopenharmony_cifunctionality which could lead to a crash. 7535db71995Sopenharmony_ci 7545db71995Sopenharmony_ciOn the other hand, if the extension must be forced on, the filtering may be 7555db71995Sopenharmony_cidisabled by defining the `VK_LOADER_DISABLE_INST_EXT_FILTER` environment 7565db71995Sopenharmony_civariable to a non-zero number. 7575db71995Sopenharmony_ciThis will effectively disable the loader's filtering of instance extension 7585db71995Sopenharmony_cinames. 7595db71995Sopenharmony_ci 7605db71995Sopenharmony_ci## Physical Device Ordering 7615db71995Sopenharmony_ci 7625db71995Sopenharmony_ciPrior to the 1.3.204 loader, physical devices on Linux could be returned in an 7635db71995Sopenharmony_ciinconsistent order. 7645db71995Sopenharmony_ciTo remedy this, the Vulkan loader will now sort devices once they have been 7655db71995Sopenharmony_cireceived from the drivers (before returning the information to any enabled 7665db71995Sopenharmony_cilayers) in the following fashion: 7675db71995Sopenharmony_ci * Sort based on device type (Discrete, Integrated, Virtual, all others) 7685db71995Sopenharmony_ci * Sort internal to the types based on PCI information (Domain, Bus, Device, and 7695db71995Sopenharmony_ci Function). 7705db71995Sopenharmony_ci 7715db71995Sopenharmony_ciThis allows for a consistent physical device order from run to run on the same 7725db71995Sopenharmony_cisystem, unless the actual underlying hardware changes. 7735db71995Sopenharmony_ci 7745db71995Sopenharmony_ciA new environment variable is defined to give users the ability to force a 7755db71995Sopenharmony_cispecific device, `VK_LOADER_DEVICE_SELECT`. 7765db71995Sopenharmony_ciThis environment variable should be set to the desired devices hex value for 7775db71995Sopenharmony_ciVendor Id and Device Id (as returned from `vkGetPhysicalDeviceProperties` in 7785db71995Sopenharmony_cithe `VkPhysicalDeviceProperties` structure). 7795db71995Sopenharmony_ciIt should look like the following: 7805db71995Sopenharmony_ci 7815db71995Sopenharmony_ci``` 7825db71995Sopenharmony_ciset VK_LOADER_DEVICE_SELECT=0x10de:0x1f91 7835db71995Sopenharmony_ci``` 7845db71995Sopenharmony_ci 7855db71995Sopenharmony_ciThis will force on the device with a vendor ID of "0x10de" and a device ID 7865db71995Sopenharmony_ciof "0x1f91". 7875db71995Sopenharmony_ciIf that device is not found, this is simply ignored. 7885db71995Sopenharmony_ci 7895db71995Sopenharmony_ciAll device selection work done in the loader can be disabled by setting the 7905db71995Sopenharmony_cienvironment variable `VK_LOADER_DISABLE_SELECT` to a non-zero value. 7915db71995Sopenharmony_ciThis is intended for debug purposes to narrow down any issues with the loader 7925db71995Sopenharmony_cidevice selection mechanism, but can be used by others. 7935db71995Sopenharmony_ci 7945db71995Sopenharmony_ci[Return to the top-level LoaderInterfaceArchitecture.md file.](LoaderInterfaceArchitecture.md) 795