blob: b4c202ce38205b9ac5c301799d6b58f44da2dff8 [file] [log] [blame] [view]
Jon Ashburnc2972682016-02-08 15:42:01 -07001# Vulkan Loader Specification and Architecture Overview
2
3
4Goals of this document
5----------------------
6
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07007Specify necessary functions and expected behavior of interface between the
8loader library and ICDs and layers for Windows, Linux and Android based
9systems. Also describe the application visible behaviors of the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -070010
11Audience
12--------
13
14Application, Vulkan driver and Vulkan layer developers.
15
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070016Any developers interested in understanding more about loader and layer behavior
17and architecture.
Jon Ashburnc2972682016-02-08 15:42:01 -070018
19
20Loader goals
21------------
22
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070023- Support multiple ICDs (Installable Client Drivers) to co-exist on a system
24without interfering with each other.
Jon Ashburnc2972682016-02-08 15:42:01 -070025
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070026- Support optional modules (layers) that can be enabled by an application,
27developer or the system and have no impact when not enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -070028
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070029- Negligible performance cost for an application calling through the loader
30to an ICD entry point.
Jon Ashburnc2972682016-02-08 15:42:01 -070031
32Architectural overview of layers and loader
33-------------------------------------------
34
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070035Vulkan is a layered architecture. Layers can hook (intercept) Vulkan commands to
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070036achieve various functionality that a Vulkan driver (aka ICD) or loader doesn’t
37support. Functionality such as Vulkan API tracing and debugging, API usage
38validation, and other tools such as framebuffer overlays are all natural
39candidates for Vulkan layers. Layers are implemented as libraries that are
40inserted between the application and the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -070041
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070042Not only is Vulkan a layered architecture but it also supports multiple GPUs
43and their drivers. Vulkan commands called by an application may wind up calling
44into a diverse set of modules: loader, layers, and ICDs. The loader is critical
45to managing the proper dispatching of Vulkan commands to the appropriate set of
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070046layers and ICDs. The Vulkan object model allows the loader to insert layers
47into a call chain so the layers can process Vulkan commands prior to the
48ICD being called.
Jon Ashburnc2972682016-02-08 15:42:01 -070049
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070050Vulkan uses an object model to control the scope of a particular action /
51operation. The object to be acted on is always the first parameter of a Vulkan
52call and is a dispatchable object (see Vulkan specification section 2.2 Object
53Model). Under the covers, the dispatchable object handle is a pointer to a
54structure that contains a pointer to a dispatch table maintained by the loader.
55This dispatch table contains pointers to the Vulkan functions appropriate to
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070056that object. There are two types of dispatch tables the loader maintains,
57Instance and Device. I.e. a VkInstance object’s dispatch table will point to Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070058functions such as vkEnumeratePhysicalDevices, vkDestroyInstance,
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070059vkCreateInstance, etc. Instance functions take a VkInstance or VkPhysicalDevice as
60their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070061
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070062Device objects have a separate dispatch table containing the appropriate
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070063function pointers. The device dispatch table is used for all functions that
64take a VkDevice, VkQueue or VkCommandBuffer as their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070065
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070066These instance and device dispatch tables are constructed when the application
67calls vkCreateInstance and vkCreateDevice. At that time the application and/or
68system can specify optional layers to be included. The loader will initialize
69the specified layers to create a call chain for each Vulkan function and each
70entry of the dispatch table will point to the first element of that chain.
71Thus, the loader builds an instance call chain for each VkInstance that is
72created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070073
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070074For example, the diagram below represents what happens in the call chain for
75vkCreateInstance. After initializing the chain, the loader will call into the
76first layer’s vkCreateInstance which will call the next finally terminating in
77the loader again where this function calls every ICD’s vkCreateInstance and
78saves the results. This allows every enabled layer for this chain to set up
79what it needs based on the VkInstanceCreateInfo structure from the application.
Jon Ashburnc2505562016-02-15 10:19:26 -070080![Instance call chain](instance_call_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070081
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070082This also highlights some of the complexity the loader must manage when using
83instance chains. As shown here, the loader must aggregate information from
84multiple devices when they are present. This means that the loader has to know
85about instance level extensions to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -070086
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070087Device chains are created at vkCreateDevice and are generally simpler because
88they deal with only a single device and the ICD can always be the terminator of
89the chain. The below diagram also illustrates how layers (either device or
90instance) can skip intercepting any given Vulkan entry point.
Jon Ashburnc2505562016-02-15 10:19:26 -070091![Chain skipping layers](chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070092
93Application interface to loader
94-------------------------------
95
96In this section we’ll discuss how an application interacts with the loader.
97
98- Linking to loader library for core and WSI extension symbols.
99
100- Dynamic Vulkan command lookup & application dispatch table.
101
102- Loader library filenames for linking to different Vulkan ABI versions.
103
104- Layers
105
106- Extensions
107
108- vkGetInstanceProcAddr, vkGetDeviceProcAddr
109
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700110The loader library on Windows, Linux and Android will export all core Vulkan
111and all appropriate Window System Interface (WSI) extensions. This is done to
112make it simpler to get started with Vulkan development. When an application
113links directly to the loader library in this way, the Vulkan calls are simple
114trampoline functions that jump to the appropriate dispatch table entry for the
115object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700116
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700117Applications are not required to link directly to the loader library, instead
118they can use the appropriate platform specific dynamic symbol lookup on the
119loader library to initialize the application’s own dispatch table. This allows
Jeff Julianof1619872016-02-17 17:25:42 -0500120an application to fail gracefully if the loader cannot be found, and it
121provides the fastest mechanism for the application to call Vulkan functions. An
122application will only need to query (via system calls such as dlsym()) the
123address of vkGetInstanceProcAddr from the loader library. Using
124vkGetInstanceProcAddr the application can then discover the address of all
125instance and global functions and extensions, such as vkCreateInstance,
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700126vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties
127in a platform independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700128
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700129The Vulkan loader library will be distributed in various ways including Vulkan
130SDKs, OS package distributions and IHV driver packages. These details are
131beyond the scope of this document. However, the name and versioning of the
132Vulkan loader library is specified so an app can link to the correct Vulkan ABI
133library version. Vulkan versioning is such that ABI backwards compatibility is
Jeff Julianof1619872016-02-17 17:25:42 -0500134guaranteed for all versions with the same major number (e.g. 1.0 and 1.1). On
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700135Windows, the loader library encodes the ABI version in its name such that
136multiple ABI incompatible versions of the loader can peacefully coexist on a
Jeff Julianof1619872016-02-17 17:25:42 -0500137given system. The Vulkan loader library file name is “vulkan-<ABI
138version>.dll”. For example, for Vulkan version 1.X on Windows the library
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700139filename is vulkan-1.dll. And this library file can typically be found in the
140windows/system32 directory.
Jon Ashburnc2972682016-02-08 15:42:01 -0700141
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700142For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
143number is not encoded in the base of the library filename as on Windows. On
144Linux an application wanting to link to the latest Vulkan ABI version would
145just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500146also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700147
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700148Applications desiring Vulkan functionality beyond what the core API offers may
149use various layers or extensions. A layer cannot add new or modify existing
150Vulkan commands, but may offer extensions that do. A common use of layers is
151for API validation. A developer can use validation layers during application
152development, but during production the layers can be disabled by the
Jeff Julianof1619872016-02-17 17:25:42 -0500153application. Thus, eliminating the overhead of validating the application's
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700154usage of the API. Layers discovered by the loader can be reported to the
155application via vkEnumerateInstanceLayerProperties and
156vkEnumerateDeviceLayerProperties, for instance and device layers respectively.
157Instance layers are enabled at vkCreateInstance; device layers are enabled at
158vkCreateDevice. For example, the ppEnabledLayerNames array in the
159VkDeviceCreateInfo structure is used by the application to list the device
160layer names to be enabled at vkCreateDevice. At vkCreateInstance and
161vkCreateDevice, the loader will construct call chains that include the
162application specified (enabled) layers. Order is important in the
163ppEnabledLayerNames array; array element 0 is the topmost (closest to the
164application) layer inserted in the chain and the last array element is closest
165to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700166
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700167Developers may want to enable layers that are not enabled by the given
168application they are using. On Linux and Windows, the environment variables
169“VK\_INSTANCE\_LAYERS” and “VK\_DEVICE\_LAYERS” can be used to enable
170additional layers which are not specified (enabled) by the application at
171vkCreateInstance/vkCreateDevice. VK\_INSTANCE\_LAYERS is a colon
172(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
173relevant with the first layer in the list being the topmost layer (closest to
174the application) and the last layer in the list being the bottommost layer
175(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700176
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700177Application specified layers and user specified layers (via environment
178variables) are aggregated and duplicates removed by the loader when enabling
179layers. Layers specified via environment variable are topmost (closest to the
180application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700181
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700182An example of using these environment variables to activate the validation
183layer VK\_LAYER\_LUNARG\_param\_checker on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700184
185```
Jon Ashburncc300a22016-02-11 14:57:30 -0700186> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700187
Jon Ashburncc300a22016-02-11 14:57:30 -0700188> $ export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700189```
190
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700191**Note**: Many layers, including all LunarG validation layers are “global”
192(i.e. both instance and device) layers and *must* be enabled on both the
193instance and device chains to function properly. This is required for “global”
194layers regardless of which method is used to enable the layer (application or
195environment variable).
Jon Ashburnc2972682016-02-08 15:42:01 -0700196
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700197Some platforms, including Linux and Windows, support layers which are enabled
198automatically by the loader rather than explicitly by the application (or via
199environment variable). Explicit layers are those layers enabled by the
200application (or environment variable) by providing the layer name. Implicit
201layers are those layers enabled by the loader automatically. Any implicit
202layers the loader discovers on the system in the appropriate location will be
203enabled (subject to environment variable overrides described later). Discovery
204of properly installed implicit and explicit layers is described later.
205Explicitly enabling a layer that is implicitly enabled has no additional
206effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700207
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700208Extensions are optional functionality provided by a layer, the loader or an
209ICD. Extensions can modify the behavior of the Vulkan API and need to be
210specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700211
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700212Instance extensions can be discovered via
213vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
214vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
215extensions from layers (both explicit and implicit), ICDs and the loader before
216reporting them to the application in vkEnumerate\*ExtensionProperties. The
Jeff Julianof1619872016-02-17 17:25:42 -0500217pLayerName parameter in these functions is used to select either a single layer
218or the Vulkan platform implementation. If pLayerName is NULL, extensions from
219Vulkan implementation components (including loader, implicit layers, and ICDs)
220are enumerated. If pLayerName is equal to a discovered layer module name then
221any extensions from that layer (which may be implicit or explicit) are
222enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700223support for the same extension) are eliminated by the loader. Extensions must
224be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700225
Jeff Julianof1619872016-02-17 17:25:42 -0500226[jjuliano] In previous paragraph, which survives, and which is duplicated?
227 E.g., if a layer and an ICD both expose the same extension, is the layer's
228 version culled, or is the ICD's version culled?
229
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700230Extension command entry points should be queried via vkGetInstanceProcAddr or
231vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
232extension or core device entry points. Device entry points include any command
233that uses a VkDevice as the first parameter or a dispatchable object that is a
234child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
235vkGetInstanceProcAddr can be used to query either device or instance extension
236entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700237
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700238VkGetDeviceProcAddr is particularly interesting because it will provide the
239most efficient way to call into the ICD. For example, the diagram below shows
240what could happen if the application were to use vkGetDeviceProcAddr for the
241function “vkGetDeviceQueue” and “vkDestroyDevice” but not “vkAllocateMemory”.
242The resulting function pointer (fpGetDeviceQueue) would be the ICD’s entry
243point if the loader and any enabled layers do not need to see that call. Even
Jeff Julianof1619872016-02-17 17:25:42 -0500244if an enabled layer intercepts the call (e.g. vkDestroyDevice) the loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700245trampoline code is skipped for function pointers obtained via
246vkGetDeviceProcAddr. This also means that function pointers obtained via
247vkGetDeviceProcAddr will only work with the specific VkDevice it was created
248for, using it with another device has undefined results. For extensions,
249Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700250
Jon Ashburnc2505562016-02-15 10:19:26 -0700251![Get*ProcAddr efficiency](get_proc_addr.png)
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700252
Jon Ashburnc2972682016-02-08 15:42:01 -0700253
254Vulkan Installable Client Driver interface with the loader
255----------------------------------------------------------
256
257### ICD discovery
258
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700259Vulkan allows multiple drivers each with one or more devices (represented by a
260Vulkan VkPhysicalDevice object) to be used collectively. The loader is
261responsible for discovering available Vulkan ICDs on the system. Given a list
262of available ICDs, the loader can enumerate all the physical devices available
263for an application and return this information to the application. The process
264in which the loader discovers the available Installable Client Drivers (ICDs)
265on a system is platform dependent. Windows, Linux and Android ICD discovery
266details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700267
268#### Windows
269
270##### Properly-Installed ICDs
271
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700272In order to find properly-installed ICDs, the Vulkan loader will scan the
273values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700274
275HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
276
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700277For each value in this key which has DWORD data set to 0, the loader opens the
278JSON format text information file (a.k.a. "manifest file") specified by the
279name of the value. Each name must be a full pathname to the text manifest file.
280The Vulkan loader will open each manifest file to obtain the name or pathname
281of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700282
Jon Ashburncc300a22016-02-11 14:57:30 -0700283 ```
284 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700285 "file_format_version": "1.0.0",
286 "ICD": {
287 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700288 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700289 }
290 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700291 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700292
293
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700294The "library\_path" specifies either a filename, a relative pathname, or a full
295pathname to an ICD shared library file, which the loader will attempt to load
296using LoadLibrary(). If the ICD is specified via a filename, the shared library
297lives in the system's DLL search path (e.g. in the "C:\\\\Windows\\\\System32"
298folder). If the ICD is specified via a relative pathname, it is relative to the
299path of the manifest file. Relative pathnames are those that do not start with
300a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
301character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700302
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700303The "file\_format\_version" specifies a major.minor.patch version number in
304case the format of the text information file changes in the future. If the same
305ICD shared library supports multiple, incompatible versions of text manifest
306file format versions, it must have multiple text info files (all of which may
307point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700308
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700309The “api\_version” specifies the major.minor.patch version number of the Vulkan
310API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700311
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700312There are no rules about the name of the text information files (except the
313.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700314
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700315There are no rules about the name of the ICD shared library files. For example,
316if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700317
Jon Ashburncc300a22016-02-11 14:57:30 -0700318```
319[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700320
Jon Ashburncc300a22016-02-11 14:57:30 -0700321"C:\vendor a\vk\_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700322
Jon Ashburncc300a22016-02-11 14:57:30 -0700323"C:\windows\system32\vendorb\_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700324
Jon Ashburncc300a22016-02-11 14:57:30 -0700325"C:\windows\system32\vendorc\_icd.json"=dword:00000000
326```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700327then the loader will open the following text information files, with the
328specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700329
Jon Ashburncc300a22016-02-11 14:57:30 -0700330| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700331|----------------|--------------------|
Jon Ashburncc300a22016-02-11 14:57:30 -0700332|vk\_vendora.json | "ICD": { "library\_path": "C:\\\\VENDORA\\\\vk\_vendora.dll", "api_version": "1.0.3" } |
333| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.3" } |
334|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.3" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700335
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700336Then the loader will open the three files mentioned in the "Text File Contents"
337column, and then try to load and use the three shared libraries indicated by
338the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700339
340##### Using Pre-Production ICDs
341
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700342IHV developers (and sometimes other developers) need to use special,
343pre-production ICDs. In some cases, a pre-production ICD may be in an
344installable package. In other cases, a pre-production ICD may simply be a
345shared library in the developer's build tree. In this latter case, we want to
346allow developers to point to such an ICD without modifying the
347properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700348
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700349This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
350which will override the mechanism used for finding properly-installed ICDs. In
351other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
352"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
353text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700354
Jon Ashburncc300a22016-02-11 14:57:30 -0700355- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700356
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700357Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
358file for a developer-built ICD. A semi-colon is only used if more than one ICD
359is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700360
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700361For example, if a developer wants to refer to one ICD that they built, they
362could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700363
Jon Ashburncc300a22016-02-11 14:57:30 -0700364C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700365
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700366If a developer wants to refer to two ICDs, one of which is a properly-installed
367ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700368
Jon Ashburncc300a22016-02-11 14:57:30 -0700369C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700370
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700371Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
372"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700373
374#### Linux
375
376##### Properly-Installed ICDs
377
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700378In order to find properly-installed ICDs, the Vulkan loader will scan the files
379in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700380
381/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700382/etc/vulkan/icd.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700383$HOME/.local/share/vulkan/icd.d
384
385Where $HOME is the current home directory of the application's user id; this
386path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700387
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700388These directories will contain text information files (a.k.a. "manifest
389files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700390
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700391The Vulkan loader will open each manifest file found to obtain the name or
392pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700393
Jon Ashburncc300a22016-02-11 14:57:30 -0700394```
395{
Jon Ashburnc2972682016-02-08 15:42:01 -0700396 "file_format_version": "1.0.0",
397 "ICD": {
398 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700399 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700400 }
401}
Jon Ashburncc300a22016-02-11 14:57:30 -0700402```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700403The "library\_path" specifies either a filename, a relative pathname, or a full
404pathname to an ICD shared library file. If the ICD is specified via a filename,
405the loader will attempt to open that file as a shared object using dlopen(),
406and the file must be in a directory that dlopen is configured to look in (Note:
407various distributions are configured differently). A distribution is free to
408create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
409required to do so. If the ICD is specified via a relative pathname, it is
410relative to the path of the info file. Relative pathnames are those that do not
411start with, but do contain at least one directory separator (i.e. the '/'
412character). For example, "lib/vendora.so" and "./vendora.so" are examples of
413relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700414
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700415The "file\_format\_version" provides a major.minor.patch version number in case
416the format of the manifest file changes in the future. If the same ICD shared
417library supports multiple, incompatible versions of manifest file format
418versions, it must have multiple manifest files (all of which may point to the
419same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700420
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700421The “api\_version” specifies the major.minor.patch version number of the Vulkan
422API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700423
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700424The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
425Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
426ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700427
428There are no rules about the name of the text files (except the .json suffix).
429
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700430There are no rules about the name of the ICD shared library files. For example,
431if the "/usr/share/vulkan/icd.d" directory contain the following files, with
432the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700433
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700434| Text File Name | Text File Contents |
435|-------------------|------------------------|
436| vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.3" } |
Jon Ashburncc300a22016-02-11 14:57:30 -0700437| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.3" } |
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700438| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.3" } |
Jon Ashburnc2972682016-02-08 15:42:01 -0700439
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700440then the loader will open the three files mentioned in the "Text File Contents"
441column, and then try to load and use the three shared libraries indicated by
442the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700443
444##### Using Pre-Production ICDs
445
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700446IHV developers (and sometimes other developers) need to use special,
447pre-production ICDs. In some cases, a pre-production ICD may be in an
448installable package. In other cases, a pre-production ICD may simply be a
449shared library in the developer's build tree. In this latter case, we want to
450allow developers to point to such an ICD without modifying the
451properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700452
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700453This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
454which will override the mechanism used for finding properly-installed ICDs. In
455other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700456
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700457The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
458manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700459
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700460- A filename (e.g. "libvkicd.json") in the "/usr/share/vulkan/icd.d", "/etc/vulkan/icd.d" "$HOME/.local/share/vulkan/icd.d" directories
Jon Ashburnc2972682016-02-08 15:42:01 -0700461
462- A full pathname (e.g. "/my\_build/my\_icd.json")
463
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700464Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
465file for a developer-built ICD. A colon is only used if more than one ICD is
466listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700467
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700468For example, if a developer wants to refer to one ICD that they built, they
469could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700470
471/my\_build/my\_icd.json
472
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700473If a developer wants to refer to two ICDs, one of which is a properly-installed
474ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700475
476vendorc\_vulkan.json:/my\_build/my\_icd.json
477
478Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
479
480NOTE: this environment variable will be ignored for suid programs.
481
482#### Android
483
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700484The Android loader lives in the system library folder. The location cannot be
485changed. The loader will load the driver/ICD via hw_get_module with the ID
486of "vulkan". Due to security policies in Android none of this can be modified
487under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700488
489
Jon Ashburncc300a22016-02-11 14:57:30 -0700490ICD interface requirements
491----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700492
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700493Generally, for all Vulkan commands issued by an application, the loader can be
494viewed as a pass through. That is, the loader generally doesn’t modified the
495commands or their parameters but simply calls the ICDs entry point for that
496command. Thus, the loader to ICD interface requirements will be specified by
497covering two areas: 1) Obtaining ICD Vulkan entry points; 2) Specifying
498requirements for a given Vulkan command(s) over and above the Vulkan
499specification requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700500
501#### Windows and Linux
502
503##### Obtaining ICD entry points
504
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700505Currently, two methods of the loader finding ICD entry points are supported on
506Linux and Windows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700507
5081) Recommended
509
Jeff Julianof1619872016-02-17 17:25:42 -0500510- vk\_icdGetInstanceProcAddr is exported by the ICD library and it returns
511 valid function pointers for all the global level and instance level Vulkan
512 commands, and also for vkGetDeviceProcAddr. Global level commands are those
513 which contain no dispatchable object as the first parameter, such as
514 vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must
515 support querying global level entry points by calling
516 vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level
517 commands are those that have either VkInstance, or VkPhysicalDevice as the
518 first parameter dispatchable object. Both core entry points and any instance
519 extension entry points the ICD supports should be available via
520 vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and
521 use new instance level dispatchable objects other than VkInstance and
522 VkPhysicalDevice, in which case extension entry points using these newly
523 defined dispatchable objects must be queryable via
524 vk\_icdGetInstanceProcAddr.
Jon Ashburnc2972682016-02-08 15:42:01 -0700525
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700526- All other Vulkan entry points must either NOT be exported from the ICD
527 library or else NOT use the official Vulkan function names if they are
528 exported. This requirement is for ICD libraries that include other
529 functionality (such as OpenGL library) and thus could be loaded by the
530 application prior to when the Vulkan loader library is loaded by the
531 application. In other words, the ICD library exported Vulkan symbols must not
532 clash with the loader's exported Vulkan symbols.
Jon Ashburnc2972682016-02-08 15:42:01 -0700533
Jeff Julianof1619872016-02-17 17:25:42 -0500534- Beware of interposing by dynamic OS library loaders if the official Vulkan
535 names are used. On Linux, if official names are used, the ICD library must be
536 linked with -Bsymbolic.
537
Jon Ashburnc2972682016-02-08 15:42:01 -07005382) Deprecated
539
Jeff Julianof1619872016-02-17 17:25:42 -0500540[jjuliano] Is it time to remove the deprecated method?
541
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700542- vkGetInstanceProcAddr exported in the ICD library and returns valid function
Jeff Julianof1619872016-02-17 17:25:42 -0500543 pointers for all the Vulkan API entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700544
545- vkCreateInstance exported in the ICD library;
546
547- vkEnumerateInstanceExtensionProperties exported in the ICD library;
548
549##### Loader specific requirements for Vulkan commands
550
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700551Normally, ICDs handle object creation and destruction for various Vulkan
552objects. The WSI surface extensions for Linux and Windows
553(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
554VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
555handled differently. For these extensions, the VkSurfaceKHR object creation and
556destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700557
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005581. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
559 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700560
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005612. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
562 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700563
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005643. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
565 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700566
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005674. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
Jeff Julianof1619872016-02-17 17:25:42 -0500568 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field
569 in the structure is a VkIcdSurfaceBase enumerant that indicates whether the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700570 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700571
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700572As previously covered, the loader requires dispatch tables to be accessible
573within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
574VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
575dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700576
Jon Ashburncc300a22016-02-11 14:57:30 -0700577- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700578
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700579- The loader will replace the first entry with a pointer to the dispatch table
580 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700581
Jon Ashburncc300a22016-02-11 14:57:30 -07005821. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700583
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005842. This pointer points to a regular C structure with the first entry being a
585 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
586 classes. The C\++ compiler may put a vtable at offset zero if your class is
Jeff Julianof1619872016-02-17 17:25:42 -0500587 non-POD due to the use of a virtual function. In this case use a regular C
588 structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700589
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005903. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
591 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700592
593```
594
Jon Ashburncc300a22016-02-11 14:57:30 -0700595#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700596
Jon Ashburncc300a22016-02-11 14:57:30 -0700597union _VK_LOADER_DATA {
598 uintptr loadermagic;
599 void *loaderData;
600} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700601
Jon Ashburncc300a22016-02-11 14:57:30 -0700602vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700603{
Jon Ashburncc300a22016-02-11 14:57:30 -0700604 vkObj *newObj = alloc_obj();
605 ...
606 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700607
Jon Ashburncc300a22016-02-11 14:57:30 -0700608 set_loader_magic_value(newObj);
609 ...
610 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700611}
Jon Ashburnc2972682016-02-08 15:42:01 -0700612```
613
614Additional Notes:
615
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700616- The loader will filter out extensions requested in vkCreateInstance and
617vkCreateDevice before calling into the ICD; Filtering will be of extensions
Jeff Julianof1619872016-02-17 17:25:42 -0500618advertised by entities (e.g. layers) different from the ICD in question.
619- The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700620properties are obtained from the layer libraries and layer JSON files.
621- If an ICD library wants to implement a layer it can do so by having the
622appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700623- The loader will not call the ICD for
624 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburnc2972682016-02-08 15:42:01 -0700625- The ICD may or may not implement a dispatch table.
626
Jeff Julianof1619872016-02-17 17:25:42 -0500627[jjuliano] what is the value of pointing out the optional presence of a
628 dispatch table?
629
Jon Ashburnc2972682016-02-08 15:42:01 -0700630#### Android
631
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700632The Android loader uses the same protocol for initializing the dispatch
633table as described above. The only difference is that the Android
634loader queries layer and extension information directly from the
635respective libraries and does not use the json manifest files used
636by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700637
638Vulkan layer interface with the loader
639--------------------------------------
640
641### Layer discovery
642
643#### Windows
644
645##### Properly-Installed Layers
646
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700647In order to find properly-installed layers, the Vulkan loader will use a
648similar mechanism as used for ICDs. Text information files (aka manifest
649files), that use a JSON format, are read in order to identify the names and
650attributes of layers and their extensions. The use of manifest files allows the
651loader to avoid loading any shared library files when the application does not
652query nor request any extensions. Layers and extensions have additional
653complexity, and so their manifest files contain more information than ICD info
654files. For example, a layer shared library file may contain multiple
655layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700656
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700657In order to find properly-installed layers, the Vulkan loader will scan the
658values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700659
660HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
661
662HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
663
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700664Explicit layers are those which are enabled by an application (e.g. with the
665vkCreateInstance function), or by an environment variable (as mentioned
666previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700667
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700668Implicit layers are those which are enabled by their existence. For example,
669certain application environments (e.g. Steam or an automotive infotainment
670system) may have layers which they always want enabled for all applications
671that they start. Other implicit layers may be for all applications started on a
672given system (e.g. layers that overlay frames-per-second). Implicit layers are
673enabled automatically, whereas explicit layers must be enabled explicitly. What
674distinguishes a layer as implicit or explicit is by which registry key its
675layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700676
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700677For each value in these keys which has DWORD data set to 0, the loader opens
678the JSON manifest file specified by the name of the value. Each name must be a
679full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700680
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700681The Vulkan loader will open each info file to obtain information about the
682layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700683
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700684This manifest file is in the JSON format and contains the following
685information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700686
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700687- (required) "file\_format\_version" - same as for ICDs, except that the format
688version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700689
690- (required) "name" - layer name
691
692- (required) "type" - which layer chains should the layer be activated on.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700693Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
694both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700695
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700696- (required) "library\_path" - filename / full path / relative path to the
697library file
Jon Ashburnc2972682016-02-08 15:42:01 -0700698
699- (required) "api\_version" - same as for ICDs.
700
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700701- (required) "implementation\_version" - layer version, a single number
702increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700703
704- (required) "description" - informative description of the layer.
705
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700706- (optional) "device\_extensions" or "instance\_extensions" - array of
707extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700708
Jon Ashburncc300a22016-02-11 14:57:30 -0700709 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700710
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700711 - (required) extension "spec\_version" - extension specification version, a
712single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700713
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700714 - (required for device\_extensions with entry points) extension
Jeff Julianof1619872016-02-17 17:25:42 -0500715"entrypoints" - array of device extension entry points; not used for instance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700716extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700717
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700718- (sometimes required) "functions" - mapping list of function entry points. If
719multiple layers exist within the same shared library (or if a layer is in the
720same shared library as an ICD), this must be specified to allow each layer to
Jeff Julianof1619872016-02-17 17:25:42 -0500721have its own vkGet\*ProcAddr entry points that can be found by the loader. At
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700722this time, only the following two functions are required:
Jon Ashburnc2972682016-02-08 15:42:01 -0700723
Jon Ashburncc300a22016-02-11 14:57:30 -0700724 - "vkGetInstanceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700725
Jon Ashburncc300a22016-02-11 14:57:30 -0700726 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700727
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700728- (optional for implicit layers) "enable\_environment" requirement(s) -
729environment variable and value required to enable an implicit layer. This
730environment variable (which should vary with each "version" of the layer, as in
731"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
732layer is not loaded. This is for application environments (e.g. Steam) which
733want to enable a layer(s) only for applications that they launch, and allows
734for applications run outside of an application environment to not get that
735implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700736
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700737- (required for implicit layers) "disable\_environment" requirement(s) -
738environment variable and value required to disable an implicit layer. Note: in
739rare cases of an application not working with an implicit layer, the
740application can set this environment variable (before calling Vulkan functions)
741in order to "blacklist" the layer. This environment variable (which should vary
742with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
743(not particularly to any value). If both the "enable\_environment" and
744"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700745
746For example:
747
Jon Ashburncc300a22016-02-11 14:57:30 -0700748```
Jon Ashburnc2972682016-02-08 15:42:01 -0700749{
Jon Ashburncc300a22016-02-11 14:57:30 -0700750"file_format_version" : "1.0.0",
751"layer": {
752 "name": "VK_LAYER_LUNARG_OverlayLayer",
753 "type": "DEVICE",
754 "library_path": "vkOverlayLayer.dll"
755 "api_version" : "1.0.3",
756 "implementation_version" : "2",
757 "description" : "LunarG HUD layer",
758 "functions": {
759 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
760 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
761 },
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700762 "instance_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700763 {
764 "name": "VK_debug_report_EXT",
765 "spec_version": "1"
766 },
767 {
768 "name": "VK_VENDOR_DEBUG_X",
769 "spec_version": "3"
770 }
771 ],
Courtney Goeltzenleuchter84a75ce2016-02-15 15:07:54 -0700772 "device_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700773 {
774 "name": "VK_LUNARG_DEBUG_MARKER",
775 "spec_version": "1",
776 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
777 }
778 ],
779 "disable_environment": {
780 "DISABLE_LAYER_OVERLAY_1": ""
781 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700782}
Jon Ashburnc2972682016-02-08 15:42:01 -0700783}
Jon Ashburncc300a22016-02-11 14:57:30 -0700784```
Jon Ashburnc2972682016-02-08 15:42:01 -0700785
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700786The "library\_path" specifies either a filename, a relative pathname, or a full
787pathname to a layer shared library (".dll") file, which the loader will attempt
788to load using LoadLibrary(). If the layer is specified via a relative pathname,
789it is relative to the path of the info file (e.g. for cases when an application
790provides a layer that is in the same folder hierarchy as the rest of the
791application files). If the layer is specified via a filename, the shared
792library lives in the system's DLL search path (e.g. in the
793"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700794
795There are no rules about the name of the text files (except the .json suffix).
796
797There are no rules about the name of the layer shared library files.
798
799##### Using Pre-Production Layers
800
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700801As with ICDs, developers may need to use special, pre-production layers,
802without modifying the properly-installed layers. This need is met with the use
803of the "VK\_LAYER\_PATH" environment variable, which will override the
804mechanism using for finding properly-installed layers. Because many layers may
805exist on a system, this environment variable is a semi-colon-separated list of
806folders that contain layer info files. Only the folder listed in
807"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
808entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700809
810- The full pathname of a folder containing layer info files
811
812#### Linux
813
814##### Properly-Installed Layers
815
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700816In order to find properly-installed layers, the Vulkan loader will use a
817similar mechanism as used for ICDs. Text information files, that use a JSON
818format, are read in order to identify the names and attributes of layers and
819their extensions. The use of text info files allows the loader to avoid loading
820any shared library files when the application does not query nor request any
821extensions. Layers and extensions have additional complexity, and so their info
822files contain more information than ICD info files. For example, a layer shared
823library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700824
825The Vulkan loader will scan the files in the following Linux directories:
826
827/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700828/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700829/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700830/etc/vulkan/implicit\_layer.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700831$HOME/.local/share/vulkan/explicit\_layer.d
832$HOME/.local/share/vulkan/implicit\_layer.d
833
834Where $HOME is the current home directory of the application's user id; this
835path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700836
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700837Explicit layers are those which are enabled by an application (e.g. with the
838vkCreateInstance function), or by an environment variable (as mentioned
839previously). Implicit layers are those which are enabled by their existence.
840For example, certain application environments (e.g. Steam or an automotive
841infotainment system) may have layers which they always want enabled for all
842applications that they start. Other implicit layers may be for all applications
843started on a given system (e.g. layers that overlay frames-per-second).
844Implicit layers are enabled automatically, whereas explicit layers must be
845enabled explicitly. What distinguishes a layer as implicit or explicit is by
846which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700847
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700848The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
849installed from Linux-distribution-provided packages. The
850"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
851non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700852
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700853The information file is in the JSON format and contains the following
854information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700855
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700856- (required) "file\_format\_version" – same as for ICDs, except that the format
857version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700858
859- (required) "name" - layer name
860
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700861- (required) "type" - which layer chains should the layer be activated on.
862Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
863both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700864
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700865- (required) "library\_path" - filename / full path / relative path to the text
866file
Jon Ashburnc2972682016-02-08 15:42:01 -0700867
868- (required) "api\_version" – same as for ICDs.
869
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700870- (required) "implementation\_version" – layer version, a single number
871increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700872
Jeff Julianof1619872016-02-17 17:25:42 -0500873- (required) "description" – informative description of the layer.
Jon Ashburnc2972682016-02-08 15:42:01 -0700874
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700875- (optional) "device\_extensions" or "instance\_extensions" - array of
876extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700877
Jon Ashburncc300a22016-02-11 14:57:30 -0700878 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700879
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700880 - (required) extension "spec\_version" - extension specification version, a
881single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700882
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700883 - (required for device extensions with entry points) extension
Jeff Julianof1619872016-02-17 17:25:42 -0500884"entrypoints" - array of device extension entry points; not used for instance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700885extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700886
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700887- (sometimes required) "functions" - mapping list of function entry points. If
888multiple layers exist within the same shared library (or if a layer is in the
889same shared library as an ICD), this must be specified to allow each layer to
Jeff Julianof1619872016-02-17 17:25:42 -0500890have its own vkGet\*ProcAddr entry points that can be found by the loader. At
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700891this time, only the following two functions are required:
Jon Ashburncc300a22016-02-11 14:57:30 -0700892 - "vkGetInstanceProcAddr" name
893 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700894
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700895- (optional for implicit layers) "enable\_environment" requirement(s) -
896environment variable and value required to enable an implicit layer. This
897environment variable (which should vary with each "version" of the layer, as in
898"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
899layer is not loaded. This is for application environments (e.g. Steam) which
900want to enable a layer(s) only for applications that they launch, and allows
901for applications run outside of an application environment to not get that
902implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700903
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700904- (required for implicit layers) "disable\_environment" requirement(s) -
905environment variable and value required to disable an implicit layer. Note: in
906rare cases of an application not working with an implicit layer, the
907application can set this environment variable (before calling Vulkan functions)
908in order to "blacklist" the layer. This environment variable (which should vary
909with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
910(not particularly to any value). If both the "enable\_environment" and
911"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700912
913For example:
Jon Ashburncc300a22016-02-11 14:57:30 -0700914```
Jon Ashburnc2972682016-02-08 15:42:01 -0700915{
Jon Ashburncc300a22016-02-11 14:57:30 -0700916"file_format_version" : "1.0.0",
Jon Ashburnc2972682016-02-08 15:42:01 -0700917"layer": {
Jon Ashburncc300a22016-02-11 14:57:30 -0700918 "name": "VK_LAYER_LUNARG_OverlayLayer",
919 "type": "DEVICE",
920 "library_path": "vkOverlayLayer.dll"
921 "api_version" : "1.0.3",
922 "implementation_version" : "2",
923 "description" : "LunarG HUD layer",
924 "functions": {
925 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
926 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
927 },
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700928 "instance_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700929 {
930 "name": "VK_debug_report_EXT",
931 "spec_version": "1"
932 },
933 {
934 "name": "VK_VENDOR_DEBUG_X",
935 "spec_version": "3"
936 }
937 ],
Courtney Goeltzenleuchter84a75ce2016-02-15 15:07:54 -0700938 "device_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700939 {
940 "name": "VK_LUNARG_DEBUG_MARKER",
941 "spec_version": "1",
942 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
943 }
944 ],
945 "disable_environment": {
946 "DISABLE_LAYER_OVERLAY_1": ""
947 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700948}
Jon Ashburnc2972682016-02-08 15:42:01 -0700949}
Jon Ashburncc300a22016-02-11 14:57:30 -0700950```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700951The "library\_path" specifies either a filename, a relative pathname, or a full
952pathname to a layer shared library (".so") file, which the loader will attempt
953to load using dlopen(). If the layer is specified via a filename, the loader
954will attempt to open that file as a shared object using dlopen(), and the file
955must be in a directory that dlopen is configured to look in (Note: various
956distributions are configured differently). A distribution is free to create
957Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
958required to do so. If the layer is specified via a relative pathname, it is
959relative to the path of the info file (e.g. for cases when an application
960provides a layer that is in the same directory hierarchy as the rest of the
961application files).
Jon Ashburnc2972682016-02-08 15:42:01 -0700962
963There are no rules about the name of the text files (except the .json suffix).
964
965There are no rules about the name of the layer shared library files.
966
967##### Using Pre-Production Layers
968
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700969As with ICDs, developers may need to use special, pre-production layers,
970without modifying the properly-installed layers. This need is met with the use
971of the "VK\_LAYER\_PATH" environment variable, which will override the
972mechanism using for finding properly-installed layers. Because many layers may
973exist on a system, this environment variable is a colon-separated list of
974directories that contain layer info files. Only the directories listed in
975"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
976is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700977
978- The full pathname of a directory containing layer info files
979
980NOTE: these environment variables will be ignored for suid programs.
981
982#### Android
983
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700984The recommended way to enable layers is for applications
985to programatically enable them. The layers are provided by the application
986and must live in the application's library folder. The application
987enables the layers at vkCreateInstance and vkCreateDevice as any Vulkan
988application would.
989An application enabled for debug has more options. It can enumerate and enable
990layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -0700991
Jon Ashburncc300a22016-02-11 14:57:30 -0700992Layer interface requirements
993------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700994
995#### Architectural interface overview
996
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700997There are two key architectural features that drive the loader to layer library
998interface: 1) separate and distinct instance and device call chains, and 2)
999distributed dispatch. First these architectural features will be described and
1000then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -07001001
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001002Call chains are the links of calls for a given Vulkan command from layer module
1003to layer module with the loader and or the ICD being the bottom most command.
1004Call chains are constructed at both the instance level and the device level by
1005the loader with cooperation from the layer libraries. Instance call chains are
1006constructed by the loader when layers are enabled at vkCreateInstance. Device
1007call chains are constructed by the loader when layers are enabled at
1008CreateDevice. A layer can intercept Vulkan instance commands, device commands
1009or both. For a layer to intercept instance commands, it must participate in the
1010instance call chain. For a layer to intercept device commands, it must
1011participate in the device chain. Layers which participate in intercepting calls
Jeff Julianof1619872016-02-17 17:25:42 -05001012in both the instance and device chains are called global layers.
Jon Ashburnc2972682016-02-08 15:42:01 -07001013
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001014Normally, when a layer intercepts a given Vulkan command, it will call down the
1015instance or device chain as needed. The loader and all layer libraries that
1016participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001017from one entity to the next. This group effort for call chain sequencing is
Jeff Julianof1619872016-02-17 17:25:42 -05001018hereinafter referred to as distributed dispatch. In distributed dispatch, since
1019each layer is responsible for properly calling the next entity in the device or
1020instance chain, a dispatch mechanism is required for all Vulkan commands a
1021layer intercepts. For Vulkan commands that are not intercepted by a layer, or
1022if the layer chooses to terminate a given Vulkan command by not calling down
1023the chain, then no dispatch mechanism is needed for that particular Vulkan
1024command. Only for those Vulkan commands, which may be a subset of all Vulkan
1025commands, that a layer intercepts is a dispatching mechanism by the layer
1026needed. The loader is responsible for dispatching all core and instance
1027extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001028
Jeff Julianof1619872016-02-17 17:25:42 -05001029Instance level Vulkan commands are those that have the dispatchable objects
1030VkInstance, or VkPhysicalDevice as the first parameter and also includes
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001031vkCreateInstance.
Jeff Julianof1619872016-02-17 17:25:42 -05001032
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001033Device level Vulkan commands are those that use VkDevice, VkQueue or
1034VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1035extensions may introduce new instance or device level dispatchable objects, so
1036the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001037
Jeff Julianof1619872016-02-17 17:25:42 -05001038#### Discovery of layer entry points
1039
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001040For the layer libraries that have been discovered by the loader, their
1041intercepting entry points that will participate in a device or instance call
1042chain need to be available to the loader or whatever layer is before them in
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001043the chain. Layers have the following requirements in this area.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001044- A layer intercepting instance level Vulkan commands (aka an instance level
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001045layer) must implement a vkGetInstanceProcAddr type of function.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001046- This vkGetInstanceProcAddr type function must be exported by the layer
1047library. The name of this function is specified in various ways: 1) the layer
1048manifest JSON file in the "functions", "vkGetInstanceProcAddr" node
1049(Linux/Windows); 2) it is named "vkGetInstanceProcAddr"; 3) it is
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001050"<layerName>GetInstanceProcAddr" (Android).
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001051- A layer intercepting device level Vulkan commands (aka a device level layer)
1052must implement a vkGetDeviceProcAddr type of function.
1053- This vkGetDeviceProcAddr type function must be exported by the layer library.
1054The name of this function is specified in various ways: 1) the layer manifest
1055JSON file in the "functions", "vkGetDeviceProcAddr" node (Linux/Windows); 2) it
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001056is named "vkGetDeviceProcAddr"; 3) it is "<layerName>GetDeviceProcAddr"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001057(Android).
Jeff Julianof1619872016-02-17 17:25:42 -05001058- A layer's vkGetInstanceProcAddr function (regardless of its name) must return
1059the local entry points for all instance level Vulkan commands it intercepts. At
1060a minimum, this includes vkGetInstanceProcAddr and vkCreateInstance.
1061- A layer's vkGetDeviceProcAddr function (regardless of its name) must return
1062the entry points for all device level Vulkan commands it intercepts. At a
1063minimum, this includes vkGetDeviceProcAddr and vkCreateDevice.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001064- There are no requirements on the names of the intercepting functions a layer
1065implements except those listed above for vkGetInstanceProcAddr and
1066vkGetDeviceProcAddr.
1067- Currently a layer's VkGetInstanceProcAddr must be able to handle a VkInstance
1068parameter equal to NULL for
Jon Ashburnc2972682016-02-08 15:42:01 -07001069instance level commands it intercepts including vkCreateDevice.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001070- Currently a layer's VkGetDeviceProcAddr must be able to handle a VkDevice
1071parameter equal to NULL for device level commands it intercepts.
Jon Ashburnc2972682016-02-08 15:42:01 -07001072
1073#### Layer intercept requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001074
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001075- Layers intercept a Vulkan command by defining a C/C++ function with signature
1076identical to the Vulkan API for that command.
1077- Other than the two vkGet*ProcAddr, all other functions intercepted by a layer
1078need NOT be exported by the layer.
1079- For any Vulkan command a layer intercepts which has a non-void return value,
1080an appropriate value must be returned by the layer intercept function.
1081- The layer intercept function must call down the chain to the corresponding
1082Vulkan command in the next entity. Undefined results will occur if a layer
1083doesn't propagate calls down the chain. The two exceptions to this requirement
1084are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1085chain for Vulkan commands that they do not intercept.
1086- Layer intercept functions may insert extra calls to Vulkan commands in
1087addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1088want to add a call to vkQueueWaitIdle after calling down the chain for
1089vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1090chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001091
1092#### Distributed dispatching requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001093
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001094- For each entry point a layer intercepts, it must keep track of the entry
1095point residing in the next entity in the chain it will call down into. In other
1096words, the layer must have a list of pointers to functions of the appropriate
1097type to call into the next entity. This can be implemented in various ways but
1098for clarity will be referred to as a dispatch table.
1099- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1100(see include/vulkan/vk_layer.h).
1101- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1102dispatch table (see include/vulkan/vk_layer.h).
1103- Layers vkGetInstanceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001104vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001105functions.
1106- Layers vkGetDeviceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001107vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001108functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001109
1110#### Layer dispatch initialization
Jeff Julianof1619872016-02-17 17:25:42 -05001111
1112- A layer initializes its instance dispatch table within its vkCreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001113function.
Jeff Julianof1619872016-02-17 17:25:42 -05001114- A layer initializes its device dispatch table within its vkCreateDevice
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001115function.
1116- The loader passes a linked list of initialization structures to layers via
1117the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1118for vkCreateInstance and VkCreateDevice respectively.
1119- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001120instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001121include/vulkan/vk_layer.h for details.
1122- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1123"sType" field in VkLayerInstanceCreateInfo.
1124- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1125"sType" field in VkLayerDeviceCreateInfo.
1126- The "function" field indicates how the union field "u" should be interpreted
1127within VkLayer*CreateInfo. The loader will set the "function" field to
1128VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1129VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001130- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001131- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1132by a layer.
1133- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1134vkGetDeviceProcAddr used by a layer.
1135- Given the above structures set up by the loader, layer must initialize their
1136dispatch table as follows:
1137 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1138the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001139 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001140 - For CreateInstance get the next entity's vkCreateInstance by calling the
1141"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001142 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001143 - For CreateDevice get the next entity's vkCreateDevice by calling the
1144"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001145 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001146 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1147 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001148 - Initialize your layer dispatch table by calling the next entity's
1149Get*ProcAddr function once for each Vulkan command needed in your dispatch
1150table
Jon Ashburncc300a22016-02-11 14:57:30 -07001151
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001152#### Example code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001153
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001154```cpp
1155VkResult vkCreateInstance(
1156 const VkInstanceCreateInfo *pCreateInfo,
1157 const VkAllocationCallbacks *pAllocator,
1158 VkInstance *pInstance)
1159{
1160 VkLayerInstanceCreateInfo *chain_info =
1161 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1162
1163 assert(chain_info->u.pLayerInfo);
1164 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1165 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1166 PFN_vkCreateInstance fpCreateInstance =
1167 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
1168 if (fpCreateInstance == NULL) {
1169 return VK_ERROR_INITIALIZATION_FAILED;
1170 }
1171
1172 // Advance the link info for the next element of the chain
1173 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1174
1175 // Continue call down the chain
1176 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1177 if (result != VK_SUCCESS)
1178 return result;
1179
1180 // Allocate new structure to store peristent data
1181 layer_data *my_data = new layer_data;
1182
1183 // Associate this instance with the newly allocated data
1184 // layer will store any persistent state it needs for
1185 // this instance in the my_data structure
1186 layer_data_map[get_dispatch_key(*pInstance)] = my_data;
1187
1188 // Create layer's dispatch table using GetInstanceProcAddr of
1189 // next layer in the chain.
1190 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
1191 layer_init_instance_dispatch_table(
1192 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1193
1194 // Keep track of any extensions that were enabled for this
1195 // instance. In this case check for VK_EXT_debug_report
1196 my_data->report_data = debug_report_create_instance(
1197 my_data->instance_dispatch_table, *pInstance,
1198 pCreateInfo->enabledExtensionCount,
1199 pCreateInfo->ppEnabledExtensionNames);
1200
1201 // Other layer initialization
1202 ...
1203
1204 return VK_SUCCESS;
1205}
1206```
1207
1208#### Example code for CreateDevice
1209
1210```cpp
1211VkResult
1212vkCreateDevice(
1213 VkPhysicalDevice gpu,
1214 const VkDeviceCreateInfo *pCreateInfo,
1215 const VkAllocationCallbacks *pAllocator,
1216 VkDevice *pDevice)
1217{
1218 VkLayerDeviceCreateInfo *chain_info =
1219 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1220
1221 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1222 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1223 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1224 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1225 PFN_vkCreateDevice fpCreateDevice =
1226 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1227 if (fpCreateDevice == NULL) {
1228 return VK_ERROR_INITIALIZATION_FAILED;
1229 }
1230
1231 // Advance the link info for the next element on the chain
1232 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1233
1234 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1235 if (result != VK_SUCCESS) {
1236 return result;
1237 }
1238
1239 // Allocate new structure to store peristent data
1240 layer_data *my_data = new layer_data;
1241
1242 // Associate this instance with the newly allocated data
1243 // layer will store any persistent state it needs for
1244 // this instance in the my_data structure
1245 layer_data_map[get_dispatch_key(*pDevice)] = my_data;
1246
1247 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
1248 layer_init_device_dispatch_table(
1249 *pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
1250
1251 // Keep track of any extensions that were enabled for this
1252 // instance. In this case check for VK_EXT_debug_report
1253 my_data->report_data = debug_report_create_instance(
1254 my_instance_data->report_data, *pDevice);
1255
1256 // Other layer initialization
1257 ...
1258
1259 return VK_SUCCESS;
1260}
1261```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001262
Jon Ashburncc300a22016-02-11 14:57:30 -07001263#### Special Considerations
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001264A layer may want to associate it's own private data with one or more Vulkan
1265objects.
1266Two common methods to do this are hash maps and object wrapping. The loader
1267supports layers wrapping any Vulkan object including dispatchable objects.
1268Layers which wrap objects should ensure they always unwrap objects before
1269passing them down the chain. This implies the layer must intercept every Vulkan
1270command which uses the object in question. Layers above the object wrapping
1271layer will see the wrapped object.
Jeff Julianof1619872016-02-17 17:25:42 -05001272
1273Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001274given object. The key to the map could be the object. Alternatively, for
1275dispatchable objects at a given level (eg device or instance) the layer may
1276want data associated with the VkDevice or VkInstance objects. Since
Jeff Julianof1619872016-02-17 17:25:42 -05001277there are multiple dispatchable objects for a given VkInstance or VkDevice, the
1278VkDevice or VkInstance object is not a great map key. Instead the layer should
1279use the dispatch table pointer within the VkDevice or VkInstance since that
1280will be unique for a given VkInstance or VkDevice.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001281
1282Layers which create dispatchable objects take special care. Remember that loader
1283trampoline code normally fills in the dispatch table pointer in the newly
1284created object. Thus, the layer must fill in the dispatch table pointer if the
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001285loader trampoline will not do so. Common cases where a layer may create a
1286dispatchable object without loader trampoline code is as follows:
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001287- object wrapping layers that wrap dispatchable objects
1288- layers which add extensions that create dispatchable objects
1289- layers which insert extra Vulkan commands in the stream of commands they
1290intercept from the application
Jon Ashburnc2972682016-02-08 15:42:01 -07001291