blob: d2f1e1553f23ef26d6994256cacb944422359508 [file] [log] [blame] [view]
Mark Young39389872017-01-19 21:10:49 -07001# Architecture of the Vulkan Loader Interfaces
Jon Ashburnc2972682016-02-08 15:42:01 -07002
Mark Young39389872017-01-19 21:10:49 -07003## Table of Contents
Lenny Komowde3924a2017-05-04 14:50:01 -06004 * [Overview](#overview)
5 * [Who Should Read This Document](#who-should-read-this-document)
6 * [The Loader](#the-loader)
7 * [Layers](#layers)
8 * [Installable Client Drivers](#installable-client-drivers)
9 * [Instance Versus Device](#instance-versus-device)
10 * [Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains)
Jon Ashburnc2972682016-02-08 15:42:01 -070011
Lenny Komowde3924a2017-05-04 14:50:01 -060012 * [Application Interface to the Loader](#application-interface-to-the-loader)
13 * [Interfacing with Vulkan Functions](#interfacing-with-vulkan-functions)
14 * [Application Layer Usage](#application-layer-usage)
15 * [Application Usage of Extensions](#application-usage-of-extensions)
Jon Ashburnc2972682016-02-08 15:42:01 -070016
Lenny Komowde3924a2017-05-04 14:50:01 -060017 * [Loader and Layer Interface](#loader-and-layer-interface)
18 * [Layer Discovery](#layer-discovery)
19 * [Layer Version Negotiation](#layer-version-negotiation)
20 * [Layer Call Chains and Distributed Dispatch](#layer-call-chains-and-distributed-dispatch)
21 * [Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions)
22 * [Layer Intercept Requirements](#layer-intercept-requirements)
23 * [Distributed Dispatching Requirements](#distributed-dispatching-requirements)
24 * [Layer Conventions and Rules](#layer-conventions-and-rules)
25 * [Layer Dispatch Initialization](#layer-dispatch-initialization)
26 * [Example Code for CreateInstance](#example-code-for-createinstance)
27 * [Example Code for CreateDevice](#example-code-for-createdevice)
Mark Youngc82a0622017-05-05 11:17:17 -060028 * [Meta-layers](#meta-layers)
Lenny Komowde3924a2017-05-04 14:50:01 -060029 * [Special Considerations](#special-considerations)
30 * [Layer Manifest File Format](#layer-manifest-file-format)
31 * [Layer Library Versions](#layer-library-versions)
Jon Ashburnc2972682016-02-08 15:42:01 -070032
Lenny Komowde3924a2017-05-04 14:50:01 -060033 * [Vulkan Installable Client Driver interface with the loader](#vulkan-installable-client-driver-interface-with-the-loader)
34 * [ICD Discovery](#icd-discovery)
35 * [ICD Manifest File Format](#icd-manifest-file-format)
36 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
37 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
38 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
39 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
40 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
Mark Young540d71c2017-05-18 14:52:14 -060041
42 * [Table of Debug Environment Variables](#table-of-debug-environment-variables)
Lenny Komowde3924a2017-05-04 14:50:01 -060043 * [Glossary of Terms](#glossary-of-terms)
Mark Young39389872017-01-19 21:10:49 -070044
45## Overview
Mark Youngcb6e6702016-07-20 11:38:53 -060046
Mark Young39389872017-01-19 21:10:49 -070047Vulkan is a layered architecture, made up of the following elements:
Lenny Komowde3924a2017-05-04 14:50:01 -060048 * The Vulkan Application
49 * [The Vulkan Loader](#the-loader)
50 * [Vulkan Layers](#layers)
51 * [Installable Client Drivers (ICDs)](#installable-client-drivers)
Jon Ashburnc2972682016-02-08 15:42:01 -070052
Mark Young39389872017-01-19 21:10:49 -070053![High Level View of Loader](./images/high_level_loader.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070054
Mark Young39389872017-01-19 21:10:49 -070055The general concepts in this document are applicable to the loaders available
56for Windows, Linux and Android based systems.
Jon Ashburnc2972682016-02-08 15:42:01 -070057
58
Mark Young39389872017-01-19 21:10:49 -070059#### Who Should Read This Document
Jon Ashburnc2972682016-02-08 15:42:01 -070060
Mark Young39389872017-01-19 21:10:49 -070061While this document is primarily targeted at developers of Vulkan applications,
62drivers and layers, the information contained in it could be useful to anyone
63wanting a better understanding of the Vulkan runtime.
Jon Ashburnc2972682016-02-08 15:42:01 -070064
Jon Ashburnc2972682016-02-08 15:42:01 -070065
Mark Young39389872017-01-19 21:10:49 -070066#### The Loader
Jon Ashburnc2972682016-02-08 15:42:01 -070067
Jeff Juliano18e50202017-01-31 16:36:18 -050068The application sits on one end of, and interfaces directly with, the
69loader. On the other end of the loader from the application are the ICDs, which
Mark Young39389872017-01-19 21:10:49 -070070control the Vulkan-capable hardware. An important point to remember is that
Jeff Juliano18e50202017-01-31 16:36:18 -050071Vulkan-capable hardware can be graphics-based, compute-based, or both. Between
72the application and the ICDs the loader can inject a number of optional
73[layers](#layers) that provide special functionality.
Mark Youngcb6e6702016-07-20 11:38:53 -060074
75The loader is responsible for working with the various layers as well as
Mark Young39389872017-01-19 21:10:49 -070076supporting multiple GPUs and their drivers. Any Vulkan function may
Mark Youngcb6e6702016-07-20 11:38:53 -060077wind up calling into a diverse set of modules: loader, layers, and ICDs.
78The loader is critical to managing the proper dispatching of Vulkan
Mark Young39389872017-01-19 21:10:49 -070079functions to the appropriate set of layers and ICDs. The Vulkan object
Mark Youngcb6e6702016-07-20 11:38:53 -060080model allows the loader to insert layers into a call chain so that the layers
Mark Young39389872017-01-19 21:10:49 -070081can process Vulkan functions prior to the ICD being called.
82
83This document is intended to provide an overview of the necessary interfaces
84between each of these.
85
86
87##### Goals of the Loader
88
89The loader was designed with the following goals in mind.
90 1. Support one or more Vulkan-capable ICD on a user's computer system without
91them interfering with one another.
92 2. Support Vulkan Layers which are optional modules that can be enabled by an
93application, developer, or standard system settings.
94 3. Impact the overall performance of a Vulkan application in the lowest
95possible fashion.
96
97
98#### Layers
99
100Layers are optional components that augment the Vulkan system. They can
101intercept, evaluate, and modify existing Vulkan functions on their way from the
102application down to the hardware. Layers are implemented as libraries that can
103be enabled in different ways (including by application request) and are loaded
104during CreateInstance. Each layer can choose to hook (intercept) any Vulkan
105functions which in turn can be ignored or augmented. A layer does not need to
106intercept all Vulkan functions. It may choose to intercept all known functions,
107or, it may choose to intercept only one function.
108
109Some examples of features that layers may expose include:
110 * Validating API usage
111 * Adding the ability to perform Vulkan API tracing and debugging
112 * Overlay additional content on the applications surfaces
113
114Because layers are optionally, you may choose to enable layers for debugging
115your application, but then disable any layer usage when you release your
116product.
117
118
119#### Installable Client Drivers
120
121Vulkan allows multiple Installable Client Drivers (ICDs) each supporting one
122or more devices (represented by a Vulkan `VkPhysicalDevice` object) to be used
123collectively. The loader is responsible for discovering available Vulkan ICDs on
124the system. Given a list of available ICDs, the loader can enumerate all the
125physical devices available for an application and return this information to
126the application.
127
128
129#### Instance Versus Device
130
131There is an important concept which you will see brought up repeatedly
132throughout this document. Many functions, extensions, and other things in
133Vulkan are separated into two main groups:
134 * Instance-related Objects
135 * Device-related Objects
136
137
138##### Instance-related Objects
139
140A Vulkan Instance is a high-level construct used to provide Vulkan system-level
141information, or functionality. Vulkan objects associated directly with an
142instance are:
143 * `VkInstance`
144 * `VkPhysicalDevice`
145
146An Instance function is any Vulkan function which takes as its first parameter
147either an object from the Instance list, or nothing at all. Some Vulkan
148Instance functions are:
149 * `vkEnumerateInstanceExtensionProperties`
150 * `vkEnumeratePhysicalDevices`
151 * `vkCreateInstance`
152 * `vkDestroyInstance`
153
154You query Vulkan Instance functions using `vkGetInstanceProcAddr`.
155`vkGetInstanceProcAddr` can be used to query either device or instance entry-
156points in addition to all core entry-points. The returned function pointer is
157valid for this Instance and any object created under this Instance (including
158all `VkDevice` objects).
159
160Similarly, an Instance extension is a set of Vulkan Instance functions extending
161the Vulkan language. These will be discussed in more detail later.
162
163
164##### Device-related Objects
165
166A Vulkan Device, on the other-hand, is a logical identifier used to associate
167functions with a particular physical device on a user's system. Vulkan
168constructs associated directly with a device include:
169 * `VkDevice`
170 * `VkQueue`
171 * `VkCommandBuffer`
172 * Any dispatchable object that is a child of a one of the above.
173
174A Device function is any Vulkan function which takes any Device Object as its
175first parameter. Some Vulkan Device functions are:
176 * `vkQueueSubmit`
177 * `vkBeginCommandBuffer`
178 * `vkCreateEvent`
179
180You can query Vulkan Device functions using either `vkGetInstanceProcAddr` or
181`vkGetDeviceProcAddr`. If you choose to use `vkGetInstanceProcAddr`, it will
182have an additional level built into the call chain, which will reduce
183performance slightly. However, the function pointer returned can be used for
184any device created later, as long as it is associated with the same Vulkan
185Instance. If, instead you use `vkGetDeviceProcAddr`, the call chain will be more
186optimized to the specific device, but it will **only** work for the device used
187to query the function function pointer. Also, unlike `vkGetInstanceProcAddr`,
188`vkGetDeviceProcAddr` can only be used on core Vulkan Device functions, or
189Device extension functions.
190
191The best solution is to query Instance extension functions using
192`vkGetInstanceProcAddr`, and to query Device extension functions using
193`vkGetDeviceProcAddr`. See
194[Best Application Performance Setup](#best-application-performance-setup) for
195more information on this.
196
197As with Instance extensions, a Device extension is a set of Vulkan Device
198functions extending the Vulkan language. You can read more about these later in
199the document.
200
201
202#### Dispatch Tables and Call Chains
Jon Ashburnc2972682016-02-08 15:42:01 -0700203
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700204Vulkan uses an object model to control the scope of a particular action /
205operation. The object to be acted on is always the first parameter of a Vulkan
Mark Young6d026a72016-06-01 17:49:30 -0600206call and is a dispatchable object (see Vulkan specification section 2.3 Object
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700207Model). Under the covers, the dispatchable object handle is a pointer to a
Mark Youngcb6e6702016-07-20 11:38:53 -0600208structure, which in turn, contains a pointer to a dispatch table maintained by
Mark Young39389872017-01-19 21:10:49 -0700209the loader. This dispatch table contains pointers to the Vulkan functions
210appropriate to that object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700211
Mark Youngcb6e6702016-07-20 11:38:53 -0600212There are two types of dispatch tables the loader maintains:
Mark Young39389872017-01-19 21:10:49 -0700213 - Instance Dispatch Table
214 - Created in the loader during the call to `vkCreateInstance`
215 - Device Dispatch Table
216 - Created in the loader during the call to `vkCreateDevice`
Jon Ashburnc2972682016-02-08 15:42:01 -0700217
Mark Young39389872017-01-19 21:10:49 -0700218At that time the application and/or system can specify optional layers to be
219included. The loader will initialize the specified layers to create a call
220chain for each Vulkan function and each entry of the dispatch table will point
221to the first element of that chain. Thus, the loader builds an instance call
222chain for each `VkInstance` that is created and a device call chain for each
223`VkDevice` that is created.
224
225When an application calls a Vulkan function, this typically will first hit a
226*trampoline* function in the loader. These *trampoline* functions are small,
227simple functions that jump to the appropriate dispatch table entry for the
228object they are given. Additionally, for functions in the instance call chain,
229the loader has an additional function, called a *terminator*, which is called
230after all enabled layers to marshall the appropriate information to all
231available ICDs.
232
233
234##### Instance Call Chain Example
Jon Ashburnc2972682016-02-08 15:42:01 -0700235
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700236For example, the diagram below represents what happens in the call chain for
Mark Young39389872017-01-19 21:10:49 -0700237`vkCreateInstance`. After initializing the chain, the loader will call into the
238first layer's `vkCreateInstance` which will call the next finally terminating in
239the loader again where this function calls every ICD's `vkCreateInstance` and
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700240saves the results. This allows every enabled layer for this chain to set up
Mark Young39389872017-01-19 21:10:49 -0700241what it needs based on the `VkInstanceCreateInfo` structure from the
242application.
243
244![Instance Call Chain](./images/loader_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700245
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700246This also highlights some of the complexity the loader must manage when using
Mark Young39389872017-01-19 21:10:49 -0700247instance call chains. As shown here, the loader's *terminator* must aggregate
248information to and from multiple ICDs when they are present. This implies that
249the loader has to be aware of any instance-level extensions which work on a
250`VkInstance` to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -0700251
Mark Young39389872017-01-19 21:10:49 -0700252
253##### Device Call Chain Example
254
255Device call chains are created at `vkCreateDevice` and are generally simpler
256because they deal with only a single device and the ICD can always be the
257*terminator* of the chain.
258
259![Loader Device Call Chain](./images/loader_device_chain_loader.png)
260
Jon Ashburnc2972682016-02-08 15:42:01 -0700261
Mark Youngcb6e6702016-07-20 11:38:53 -0600262<br/>
Mark Young39389872017-01-19 21:10:49 -0700263<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600264
Mark Young39389872017-01-19 21:10:49 -0700265## Application Interface to the Loader
Jon Ashburnc2972682016-02-08 15:42:01 -0700266
Mark Young39389872017-01-19 21:10:49 -0700267In this section we'll discuss how an application interacts with the loader,
268including:
Lenny Komowde3924a2017-05-04 14:50:01 -0600269 * [Interfacing with Vulkan Functions](#interfacing-with-vulkan-functions)
270 * [Vulkan Direct Exports](#vulkan-direct-exports)
271 * [Directly Linking to the Loader](#directly-linking-to-the-loader)
272 * [Dynamic Linking](#dynamic-linking)
273 * [Static Linking](#static-linking)
274 * [Indirectly Linking to the Loader](#indirectly-linking-to-the-loader)
275 * [Best Application Performance Setup](#best-application-performance-setup)
276 * [ABI Versioning](#abi-versioning)
277 * [Application Layer Usage](#application-layer-usage)
278 * [Implicit vs Explicit Layers](#implicit-vs-explicit-layers)
279 * [Forcing Layer Source Folders](#forcing-layer-source-folders)
280 * [Forcing Layers to be Enabled](#forcing-layers-to-be-enabled)
281 * [Overall Layer Ordering](#overall-layer-ordering)
282 * [Application Usage of Extensions](#application-usage-of-extensions)
283 * [Instance and Device Extensions](#instance-and-device-extensions)
284 * [WSI Extensions](#wsi-extensions)
285 * [Unknown Extensions](#unknown-extensions)
Jon Ashburnc2972682016-02-08 15:42:01 -0700286
Mark Young39389872017-01-19 21:10:49 -0700287
288#### Interfacing with Vulkan Functions
289There are several ways you can interface with Vulkan functions through the
290loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700291
Jon Ashburnc2972682016-02-08 15:42:01 -0700292
Mark Young39389872017-01-19 21:10:49 -0700293##### Vulkan Direct Exports
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700294The loader library on Windows, Linux and Android will export all core Vulkan
295and all appropriate Window System Interface (WSI) extensions. This is done to
296make it simpler to get started with Vulkan development. When an application
297links directly to the loader library in this way, the Vulkan calls are simple
Mark Young39389872017-01-19 21:10:49 -0700298*trampoline* functions that jump to the appropriate dispatch table entry for the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700299object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700300
Mark Young39389872017-01-19 21:10:49 -0700301
Lenny Komowde3924a2017-05-04 14:50:01 -0600302##### Directly Linking to the Loader
303
304###### Dynamic Linking
305The loader is ordinarily distributed as a dynamic library (.dll on Windows or
306.so on Linux) which gets installed to the system path for dynamic libraries.
307Linking to the dynamic library is generally the preferred method of linking to
308the loader, as doing so allows the loader to be updated for bug fixes and
309improvements. Furthermore, the dynamic library is generally installed to Windows
310systems as part of driver installation and is generally provided on Linux
311through the system package manager. This means that applications can usually
312expect a copy of the loader to be present on a system. If applications want to
313be completely sure that a loader is present, they can include a loader or
314runtime installer with their application.
315
316###### Static Linking
317The loader can also be used as a static library (this is shipped in the
318Windows SDK as `VKstatic.1.lib`). Linking to the static loader means that the
319user does not need to have a Vulkan runtime installed, and it also guarantees
320that your application will use a specific version of the loader. However, there
321are several downsides to this approach:
322
323 - The static library can never be updated without re-linking the application
324 - This opens up the possibility that two included libraries could contain
325 different versions of the loader
326 - This could potentially cause conflicts between the different loader versions
327
328As a result, it is recommended that users prefer linking to the .dll and
329.so versions of the loader.
330
331
Mark Young39389872017-01-19 21:10:49 -0700332##### Indirectly Linking to the Loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700333Applications are not required to link directly to the loader library, instead
334they can use the appropriate platform specific dynamic symbol lookup on the
Mark Young6d026a72016-06-01 17:49:30 -0600335loader library to initialize the application's own dispatch table. This allows
Mark Young39389872017-01-19 21:10:49 -0700336an application to fail gracefully if the loader cannot be found. It also
Jeff Julianof1619872016-02-17 17:25:42 -0500337provides the fastest mechanism for the application to call Vulkan functions. An
338application will only need to query (via system calls such as dlsym()) the
Mark Young39389872017-01-19 21:10:49 -0700339address of `vkGetInstanceProcAddr` from the loader library. Using
340`vkGetInstanceProcAddr` the application can then discover the address of all
341functions and extensions available, such as `vkCreateInstance`,
342`vkEnumerateInstanceExtensionProperties` and
343`vkEnumerateInstanceLayerProperties` in a platform-independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700344
Mark Young39389872017-01-19 21:10:49 -0700345
346##### Best Application Performance Setup
347
348If you desire the best performance possible, you should setup your own
349dispatch table so that all your Instance functions are queried using
350`vkGetInstanceProcAddr` and all your Device functions are queried using
351`vkGetDeviceProcAddr`.
352
353*Why should you do this?*
354
355The answer comes in how the call chain of Instance functions are implemented
356versus the call chain of a Device functions. Remember, a [Vulkan Instance is a
357high-level construct used to provide Vulkan system-level information](#instance-
358related-objects). Because of this, Instance functions need to be broadcasted to
359every available ICD on the system. The following diagram shows an approximate
360view of an Instance call chain with 3 enabled layers:
361
362![Instance Call Chain](./images/loader_instance_chain.png)
363
364This is also how a Vulkan Device function call chain looks if you query it
365using `vkGetInstanceProcAddr`. On the otherhand, a Device
366function doesn't need to worry about the broadcast becuase it knows specifically
367which associated ICD and which associated Physical Device the call should
368terminate at. Because of this, the loader doesn't need to get involved between
369any enabled layers and the ICD. Thus, if you used a loader-exported Vulkan
370Device function, the call chain in the same scenario as above would look like:
371
372![Loader Device Call Chain](./images/loader_device_chain_loader.png)
373
374An even better solution would be for an application to perform a
375`vkGetDeviceProcAddr` call on all Device functions. This further optimizes the
376call chain by removing the loader all-together under most scenarios:
377
378![Application Device Call Chain](./images/loader_device_chain_app.png)
379
380Also, notice if no layers are enabled, your application function pointer would
381point **directly to the ICD**. If called enough, those fewer calls can add up
382to performance savings.
383
384**NOTE:** There are some Device functions which still require the loader to
385intercept them with a *trampoline* and *terminator*. There are very few of
386these, but they are typically functions which the loader wraps with its own
387data. In those cases, even the Device call chain will continue to look like the
388Instance call chain. One example of a Device function requiring a *terminator*
389is `vkCreateSwapchainKHR`. For that function, the loader needs to potentially
390convert the KHR_surface object into an ICD-specific KHR_surface object prior to
391passing down the rest of the function's information to the ICD.
392
393Remember:
394 * `vkGetInstanceProcAddr` can be used to query
395either device or instance entry-points in addition to all core entry-points.
396 * `vkGetDeviceProcAddr` can only be used to query for device
397extension or core device entry-points.
398
399
400##### ABI Versioning
Mark Young02df1a82017-04-18 19:52:18 -0600401
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700402The Vulkan loader library will be distributed in various ways including Vulkan
Mark Young39389872017-01-19 21:10:49 -0700403SDKs, OS package distributions and Independent Hardware Vendor (IHV) driver
404packages. These details are beyond the scope of this document. However, the name
405and versioning of the Vulkan loader library is specified so an app can link to
406the correct Vulkan ABI library version. Vulkan versioning is such that ABI
407backwards compatibility is guaranteed for all versions with the same major
408number (e.g. 1.0 and 1.1). On Windows, the loader library encodes the ABI
409version in its name such that multiple ABI incompatible versions of the loader
410can peacefully coexist on a given system. The Vulkan loader library file name is
Jeff Juliano18e50202017-01-31 16:36:18 -0500411`vulkan-<ABI version>.dll`. For example, for Vulkan version 1.X on Windows the
Mark Young39389872017-01-19 21:10:49 -0700412library filename is vulkan-1.dll. And this library file can typically be found
413in the windows/system32 directory (on 64-bit Windows installs, the 32-bit
414version of the loader with the same name can be found in the windows/sysWOW64
415directory).
Jon Ashburnc2972682016-02-08 15:42:01 -0700416
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700417For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
418number is not encoded in the base of the library filename as on Windows. On
419Linux an application wanting to link to the latest Vulkan ABI version would
420just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500421also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700422
Mark Young39389872017-01-19 21:10:49 -0700423
424#### Application Layer Usage
Mark Young6d026a72016-06-01 17:49:30 -0600425
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700426Applications desiring Vulkan functionality beyond what the core API offers may
Mark Young39389872017-01-19 21:10:49 -0700427use various layers or extensions. A layer cannot introduce new Vulkan core API
428entry-points to an application that are not exposed in Vulkan.h. However,
429layers may offer extensions that introduce new Vulkan commands that can be
430queried through the extension interface.
Mark Young02ee5382016-07-22 08:51:05 -0600431
Mark Young39389872017-01-19 21:10:49 -0700432A common use of layers is for API validation which can be enabled by
433loading the layer during application development, but not loading the layer
434for application release. This eliminates the overhead of validating the
435application's usage of the API, something that wasn't available on some previous
436graphics APIs.
437
438To find out what layers are available to your application, use
439`vkEnumerateInstanceLayerProperties`. This will report all layers
440that have been discovered by the loader. The loader looks in various locations
441to find layers on the system. For more information see the
442[Layer discovery](#layer-discovery) section below.
443
444To enable a layer, or layers, simply pass the name of the layers you wish to
445enable in the `ppEnabledLayerNames` field of the `VkInstanceCreateInfo` during
446a call to `vkCreateInstance`. Once done, the layers you have enabled will be
447active for all Vulkan functions using the created `VkInstance`, and any of
448its child objects.
449
450**NOTE:** Layer ordering is important in several cases since some layers
451interact with each other. Be careful when enabling layers as this may be
452the case. See the [Overall Layer Ordering](#overall-layer-ordering) section
453for more information.
454
455The following code section shows how you would go about enabling the
456VK_LAYER_LUNARG_standard_validation layer.
457
458```
459 char *instance_validation_layers[] = {
460 "VK_LAYER_LUNARG_standard_validation"
461 };
462 const VkApplicationInfo app = {
463 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
464 .pNext = NULL,
465 .pApplicationName = "TEST_APP",
466 .applicationVersion = 0,
467 .pEngineName = "TEST_ENGINE",
468 .engineVersion = 0,
469 .apiVersion = VK_API_VERSION_1_0,
470 };
471 VkInstanceCreateInfo inst_info = {
472 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
473 .pNext = NULL,
474 .pApplicationInfo = &app,
475 .enabledLayerCount = 1,
476 .ppEnabledLayerNames = (const char *const *)instance_validation_layers,
477 .enabledExtensionCount = 0,
478 .ppEnabledExtensionNames = NULL,
479 };
480 err = vkCreateInstance(&inst_info, NULL, &demo->inst);
481```
482
483At `vkCreateInstance` and `vkCreateDevice`, the loader constructs call chains
484that include the application specified (enabled) layers. Order is important in
485the `ppEnabledLayerNames` array; array element 0 is the topmost (closest to the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700486application) layer inserted in the chain and the last array element is closest
Mark Young39389872017-01-19 21:10:49 -0700487to the driver. See the [Overall Layer Ordering](#overall-layer-ordering)
488section for more information on layer ordering.
Jon Ashburnc2972682016-02-08 15:42:01 -0700489
Mark Young39389872017-01-19 21:10:49 -0700490**NOTE:** *Device Layers Are Now Deprecated*
491> `vkCreateDevice` originally was able to select layers in a similar manner to
492`vkCreateInstance`. This lead to the concept of "instance
493> layers" and "device layers". It was decided by Khronos to deprecate the
494> "device layer" functionality and only consider "instance layers".
495> Therefore, `vkCreateDevice` will use the layers specified at
496`vkCreateInstance`.
497> Because of this, the following items have been deprecated:
498> * `VkDeviceCreateInfo` fields:
499> * `ppEnabledLayerNames`
500> * `enabledLayerCount`
501> * The `vkEnumerateDeviceLayerProperties` function
Mark Young02ee5382016-07-22 08:51:05 -0600502
Jon Ashburnc2972682016-02-08 15:42:01 -0700503
Mark Young39389872017-01-19 21:10:49 -0700504##### Implicit vs Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700505
Mark Young39389872017-01-19 21:10:49 -0700506Explicit layers are layers which are enabled by an application (e.g. with the
507vkCreateInstance function), or by an environment variable (as mentioned
508previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700509
Mark Young39389872017-01-19 21:10:49 -0700510Implicit layers are those which are enabled by their existence. For example,
511certain application environments (e.g. Steam or an automotive infotainment
512system) may have layers which they always want enabled for all applications
513that they start. Other implicit layers may be for all applications started on a
514given system (e.g. layers that overlay frames-per-second). Implicit layers are
515enabled automatically, whereas explicit layers must be enabled explicitly.
Jon Ashburnc2972682016-02-08 15:42:01 -0700516
Mark Young02ee5382016-07-22 08:51:05 -0600517Implicit layers have an additional requirement over explicit layers in that they
518require being able to be disabled by an environmental variable. This is due
519to the fact that they are not visible to the application and could cause issues.
520A good principle to keep in mind would be to define both an enable and disable
521environment variable so the users can deterministicly enable the functionality.
522On Desktop platforms (Windows and Linux), these enable/disable settings are
523defined in the layer's JSON file.
524
Mark Young39389872017-01-19 21:10:49 -0700525Discovery of system-installed implicit and explicit layers is described later in
526the [Layer Discovery Section](#layer-discovery). For now, simply know that what
527distinguishes a layer as implicit or explicit is dependent on the Operating
528system, as shown in the table below.
529
530| Operating System | Implicit Layer Identification |
531|----------------|--------------------|
532| Windows | Implicit Layers are located in a different Windows registry location than Explicit Layers. |
533| Linux | Implicit Layers are located in a different directory location than Explicit Layers. |
534| Android | There is **No Support For Implicit Layers** on Android. |
535
536
537##### Forcing Layer Source Folders
538
539Developers may need to use special, pre-production layers, without modifying the
540system-installed layers. You can direct the loader to look for layers in a
541specific folder by defining the "VK\_LAYER\_PATH" environment variable. This
542will override the mechanism used for finding system-installed layers. Because
Mark Young18bbaab2017-03-20 08:27:14 -0600543layers of interest may exist in several disinct folders on a system, this
Mark Young39389872017-01-19 21:10:49 -0700544environment variable can containis several paths seperated by the operating
545specific path separator. On Windows, each separate folder should be separated
546in the list using a semi-colon. On Linux, each folder name should be separated
547using a colon.
548
549If "VK\_LAYER\_PATH" exists, **only** the folders listed in it will be scanned
550for layers. Each directory listed should be the full pathname of a folder
551containing layer manifest files.
552
553
554##### Forcing Layers to be Enabled on Windows and Linux
555
556Developers may want to enable layers that are not enabled by the given
557application they are using. On Linux and Windows, the environment variable
558"VK\_INSTANCE\_LAYERS" can be used to enable additional layers which are
559not specified (enabled) by the application at `vkCreateInstance`.
560"VK\_INSTANCE\_LAYERS" is a colon (Linux)/semi-colon (Windows) separated
561list of layer names to enable. Order is relevant with the first layer in the
562list being the top-most layer (closest to the application) and the last
563layer in the list being the bottom-most layer (closest to the driver).
564See the [Overall Layer Ordering](#overall-layer-ordering) section
565for more information.
566
567Application specified layers and user specified layers (via environment
568variables) are aggregated and duplicates removed by the loader when enabling
569layers. Layers specified via environment variable are top-most (closest to the
570application) while layers specified by the application are bottommost.
571
572An example of using these environment variables to activate the validation
573layer `VK_LAYER_LUNARG_parameter_validation` on Windows or Linux is as follows:
574
575```
576> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation
577```
578
579
580##### Overall Layer Ordering
581
582The overall ordering of all layers by the loader based on the above looks
583as follows:
584
585![Loader Layer Ordering](./images/loader_layer_order.png)
586
587Ordering may also be important internal to the list of Explicit Layers.
588Some layers may be dependent on other behavior being implemented before
589or after the loader calls it. For example: the VK_LAYER_LUNARG_core_validation
590layer expects the VK_LAYER_LUNARG_parameter_validation to be called first.
591This is because the VK_LAYER_LUNARG_parameter_validation will filter out any
592invalid `NULL` pointer calls prior to the rest of the validation checking
593done by VK_LAYER_LUNARG_core_validation. If not done properly, you may see
594crashes in the VK_LAYER_LUNARG_core_validation layer that would otherwise be
595avoided.
596
597
598#### Application Usage of Extensions
599
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700600Extensions are optional functionality provided by a layer, the loader or an
601ICD. Extensions can modify the behavior of the Vulkan API and need to be
Mark Young39389872017-01-19 21:10:49 -0700602specified and registered with Khronos. These extensions can be created
603by an Independent Hardware Vendor (IHV) to expose new hardware functionality,
604or by a layer writer to expose some internal feature, or by the loader to
605improve functional behavior. Information about various extensions can be
606found in the Vulkan Spec, and vulkan.h header file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700607
Mark Young6d026a72016-06-01 17:49:30 -0600608
Mark Young39389872017-01-19 21:10:49 -0700609##### Instance and Device Extensions
610
611As hinted at in the [Instance Versus Device](#instance-versus-device) section,
612there are really two types of extensions:
613 * Instance Extensions
614 * Device Extensions
615
616An Instance extension is an extension which modifies existing behavior or
617implements new behavior on instance-level objects, like a `VkInstance` or
618a `VkPhysicalDevice`. A Device extension is an extension which does the same,
619but for any `VkDevice` object, or any dispatchable object that is a child of a
620`VkDevice` (`VkQueue` and `VkCommandBuffer` are examples of these).
621
622It is **very** important to know what type of extension you are desiring to
623enable as you will enable Instance extensions during `vkCreateInstance` and
624Device extensions during `vkCreateDevice`.
625
626The loader discovers and aggregates all
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700627extensions from layers (both explicit and implicit), ICDs and the loader before
Mark Young39389872017-01-19 21:10:49 -0700628reporting them to the application in `vkEnumerateXXXExtensionProperties`
629(where XXX is either "Instance" or "Device").
630 - Instance extensions are discovered via
631`vkEnumerateInstanceExtensionProperties`.
632 - Device extensions are be discovered via
633`vkEnumerateDeviceExtensionProperties`.
634
635Looking at `vulkan.h`, you'll notice that they are both similar. For example,
636`vkEnumerateInstanceExtensionProperties` prototype looks as follows:
637
638```
639 VkResult
640 vkEnumerateInstanceExtensionProperties(const char *pLayerName,
641 uint32_t *pPropertyCount,
642 VkExtensionProperties *pProperties);
643```
644
645The "pLayerName" parameter in these functions is used to select either a single
646layer or the Vulkan platform implementation. If "pLayerName" is NULL, extensions
647from Vulkan implementation components (including loader, implicit layers, and
648ICDs) are enumerated. If "pLayerName" is equal to a discovered layer module name
649then only extensions from that layer (which may be implicit or explicit) are
Jeff Julianof1619872016-02-17 17:25:42 -0500650enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Mark Young39389872017-01-19 21:10:49 -0700651support for the same extension) are eliminated by the loader. For duplicates,
652the ICD version is reported and the layer version is culled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700653
Mark Young39389872017-01-19 21:10:49 -0700654Also, Extensions *must be enabled* (in `vkCreateInstance` or `vkCreateDevice`)
655before the functions associated with the extensions can be used. If you get an
656Extension function using either `vkGetInstanceProcAddr` or
657`vkGetDeviceProcAddr`, but fail to enable it, you could experience undefined
658behavior. This should actually be flagged if you run with Validation layers
659enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700660
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700661
Mark Young78f88c82016-07-19 11:49:45 -0600662##### WSI Extensions
663
Mark Young39389872017-01-19 21:10:49 -0700664Khronos approved WSI extensions are available and provide Windows System
665Integration support for various execution environments. It is important to
666understand that some WSI extensions are valid for all targets, but others are
667particular to a given execution environment (and loader). This desktop loader
668(currently targeting Windows and Linux) only enables and directly exports those
669WSI extensions that are appropriate to the current environment. For the most
670part, the selection is done in the loader using compile-time preprocessor flags.
671All versions of the desktop loader currently expose at least the following WSI
Mark Young78f88c82016-07-19 11:49:45 -0600672extension support:
673- VK_KHR_surface
674- VK_KHR_swapchain
675- VK_KHR_display
676
Mark Young39389872017-01-19 21:10:49 -0700677In addition, each of the following OS targets for the loader support target-
678specific extensions:
Mark Young78f88c82016-07-19 11:49:45 -0600679
Mark Young39389872017-01-19 21:10:49 -0700680| Windowing System | Extensions available |
681|----------------|--------------------|
682| Windows | VK_KHR_win32_surface |
683| Linux (Default) | VK_KHR_xcb_surface and VK_KHR_xlib_surface |
684| Linux (Wayland) | VK_KHR_wayland_surface |
685| Linux (Mir) | VK_KHR_mir_surface |
Mark Young78f88c82016-07-19 11:49:45 -0600686
Mark Young39389872017-01-19 21:10:49 -0700687**NOTE:** Wayland and Mir targets are not fully supported at this time. Wayland
688support is present, but should be considered Beta quality. Mir support is not
689completely implemented at this time.
690
691It is important to understand that while the loader may support the various
692entry-points for these extensions, there is a hand-shake required to actually
693use them:
Mark Young78f88c82016-07-19 11:49:45 -0600694* At least one physical device must support the extension(s)
695* The application must select such a physical device
Mark Young39389872017-01-19 21:10:49 -0700696* The application must request the extension(s) be enabled while creating the
697instance or logical device (This depends on whether or not the given extension
698works with an instance or a device).
Mark Young78f88c82016-07-19 11:49:45 -0600699* The instance and/or logical device creation must succeed.
700
701Only then can you expect to properly use a WSI extension in your Vulkan program.
702
Mark Young78f88c82016-07-19 11:49:45 -0600703
Mark Young39389872017-01-19 21:10:49 -0700704##### Unknown Extensions
705
706With the ability to expand Vulkan so easily, extensions will be created that the
707loader knows nothing about. If the extension is a device extension, the loader
708will pass the unknown entry-point down the device call chain ending with the
709appropriate ICD entry-points. The same thing will happen, if the extension is
710an instance extension which takes a physical device paramater as it's first
711component. However, for all other instance extensions the loader will fail to
712load it.
Mark Young78f88c82016-07-19 11:49:45 -0600713
714*But why doesn't the loader support unknown instance extensions?*
715<br/>
716Let's look again at the Instance call chain:
Mark Young78f88c82016-07-19 11:49:45 -0600717
Mark Young39389872017-01-19 21:10:49 -0700718![Instance call chain](./images/loader_instance_chain.png)
Mark Young78f88c82016-07-19 11:49:45 -0600719
Mark Young39389872017-01-19 21:10:49 -0700720Notice that for a normal instance function call, the loader has to handle
721passing along the function call to the available ICDs. If the loader has no
722idea of the parameters or return value of the instance call, it can't properly
723pass information along to the ICDs. There may be ways to do this, which will be
724explored in the future. However, for now, this loader does not support
725instance extensions which don't take a physical device as their first parameter.
726
727Because the device call-chain does not normally pass through the loader
728*terminator*, this is not a problem for device extensions. Additionally,
729since a physical device is associated with one ICD, we can use a generic
730*terminator* pointing to one ICD. This is because both of these extensions
731terminate directly in the ICD they are associated with.
Mark Young78f88c82016-07-19 11:49:45 -0600732
733*Is this a big problem?*
734<br/>
Mark Young39389872017-01-19 21:10:49 -0700735No! Most extension functionality only affects either a physical or logical
736device and not an instance. Thus, the overwhelming majority of extensions
737should be supported with direct loader support.
Jon Ashburnc2972682016-02-08 15:42:01 -0700738
Mark Young6340bb82017-02-13 15:39:22 -0700739##### Filtering Out Unknown Instance Extension Names
740In some cases, an ICD may support instance extensions that the loader does not.
741For the above reasons, the loader will filter out the names of these unknown instance
742extensions when an application calls `vkEnumerateInstanceExtensionProperties`.
743Additionally, this behavior will cause the loader to throw an error during
744`vkCreateInstance` if you still attempt to use one of these extensions. The intent is
745to protect applications so that they don't inadvertantly use functionality
746which could lead to a crash.
747
748On the other-hand, if you know you can safely use the extension, you may disable
749the filtering by defining the environment variable `VK_LOADER_DISABLE_INST_EXT_FILTER`
750and setting the value to a non-zero number. This will effectively disable the
751loader's filtering out of instance extension names.
Jon Ashburnc2972682016-02-08 15:42:01 -0700752
Mark Youngcb6e6702016-07-20 11:38:53 -0600753<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600754<br/>
755
Mark Young39389872017-01-19 21:10:49 -0700756## Loader and Layer Interface
Jon Ashburnc2972682016-02-08 15:42:01 -0700757
Mark Young39389872017-01-19 21:10:49 -0700758In this section we'll discuss how the loader interacts with layers, including:
Lenny Komowde3924a2017-05-04 14:50:01 -0600759 * [Layer Discovery](#layer-discovery)
760 * [Layer Manifest File Usage](#layer-manifest-file-usage)
761 * [Android Layer Discovery](#android-layer-discovery)
762 * [Windows Layer Discovery](#windows-layer-discovery)
763 * [Linux Layer Discovery](#linux-layer-discovery)
764 * [Layer Version Negotiation](#layer-version-negotiation)
765 * [Layer Call Chains and Distributed Dispatch](#layer-call-chains-and-distributed-dispatch)
766 * [Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions)
767 * [Layer Intercept Requirements](#layer-intercept-requirements)
768 * [Distributed Dispatching Requirements](#distributed-dispatching-requirements)
769 * [Layer Conventions and Rules](#layer-conventions-and-rules)
770 * [Layer Dispatch Initialization](#layer-dispatch-initialization)
771 * [Example Code for CreateInstance](#example-code-for-createinstance)
772 * [Example Code for CreateDevice](#example-code-for-createdevice)
Mark Youngc82a0622017-05-05 11:17:17 -0600773 * [Meta-layers](#meta-layers)
Lenny Komowde3924a2017-05-04 14:50:01 -0600774 * [Special Considerations](#special-considerations)
775 * [Associating Private Data with Vulkan Objects Within a Layer](#associating-private-data-with-vulkan-objects-within-a-layer)
776 * [Wrapping](#wrapping)
777 * [Hash Maps](#hash-maps)
778 * [Creating New Dispatchable Objects](#creating-new-dispatchable-objects)
779 * [Layer Manifest File Format](#layer-manifest-file-format)
780 * [Layer Manifest File Version History](#layer-manifest-file-version-history)
781 * [Layer Library Versions](#layer-library-versions)
782 * [Layer Library API Version 2](#layer-library-api-version-2)
783 * [Layer Library API Version 1](#layer-library-api-version-1)
784 * [Layer Library API Version 0](#layer-library-api-version-0)
Mark Young39389872017-01-19 21:10:49 -0700785
Jon Ashburnc2972682016-02-08 15:42:01 -0700786
Mark Young39389872017-01-19 21:10:49 -0700787
788#### Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700789
Mark Young39389872017-01-19 21:10:49 -0700790As mentioned in the
791[Application Interface section](#implicit-vs-explicit-layers),
792layers can be categorized into two categories:
793 * Implicit Layers
794 * Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700795
Mark Young39389872017-01-19 21:10:49 -0700796The main difference between the two is that Implicit Layers are automatically
797enabled, unless overriden, and Explicit Layers must be enabled. Remember,
798Implicit Layers are not present on all Operating Systems (like Android).
Jon Ashburnc2972682016-02-08 15:42:01 -0700799
Mark Young39389872017-01-19 21:10:49 -0700800On any system, the loader looks in specific areas for information on the
801layers that it can load at a user's request. The process of finding the
802available layers on a system is known as Layer Discovery. During discovery,
803the loader determines what layers are available, the layer name, the layer
804version, and any extensions supported by the layer. This information is
805provided back to an application through `vkEnumerateInstanceLayerProperties`.
806
807The group of layers available to the loader is known as a layer library. This
808section defines an extensible interface to discover what layers are contained in
809the layer library.
810
811This section also specifies the minimal conventions and rules a layer must
812follow, especially with regards to interacting with the loader and other layers.
813
814##### Layer Manifest File Usage
815
Mark Young18bbaab2017-03-20 08:27:14 -0600816On Windows and Linux systems, JSON formatted manifest files are used to store
Mark Young39389872017-01-19 21:10:49 -0700817layer information. In order to find system-installed layers, the Vulkan loader
818will read the JSON files to identify the names and attributes of layers and
819their extensions. The use of manifest files allows the loader to avoid loading
820any shared library files when the application does not query nor request any
821extensions. The format of [Layer Manifest File](#layer-manifest-file-format)
822is detailed below.
823
824The Android loader does not use manifest files. Instead, the loader queries the
825layer properties using special functions known as "introspection" functions.
826The intent of these functions is to determine the same required information
827gathered from reading the manifest files. These introspection functions are
828not used by the desktop loader but should be present in layers to maintain
829consistency. The specific "introspection" functions are called out in
830the [Layer Manifest File Format](#layer-manifest-file-format) table.
831
832
833##### Android Layer Discovery
834
835On Android, the loader looks for layers to enumerate in the
836/data/local/debug/vulkan folder. An application enabled for debug has the
837ability to enumerate and enable any layers in that location.
838
839
840##### Windows Layer Discovery
841
842In order to find system-installed layers, the Vulkan loader will scan the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700843values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700844
Mark Young39389872017-01-19 21:10:49 -0700845```
846 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers
Lenny Komowdfa37352017-03-02 11:29:03 -0700847 HKEY_CURRENT_USER\SOFTWARE\Khronos\Vulkan\ExplicitLayers
Mark Young39389872017-01-19 21:10:49 -0700848 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ImplicitLayers
Lenny Komowdfa37352017-03-02 11:29:03 -0700849 HKEY_CURRENT_USER\SOFTWARE\Khronos\Vulkan\ImplicitLayers
Mark Young39389872017-01-19 21:10:49 -0700850```
Jon Ashburnc2972682016-02-08 15:42:01 -0700851
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700852For each value in these keys which has DWORD data set to 0, the loader opens
853the JSON manifest file specified by the name of the value. Each name must be a
Lenny Komow4c3d3772017-08-31 17:19:17 -0600854full pathname to the manifest file.
855
856Additionally, the loader will scan through registry keys specific to Display
857Adapters and all Software Components associated with these adapters for the
858locations of JSON manifest files. These keys are located in device keys
859created during driver installation and contain configuration information
860for base settings, including Vulkan, OpenGL, and Direct3D ICD location.
861
862The Device Adapter and Software Component key paths should be obtained through the PnP
863Configuration Manager API. The `000X` key will be a numbered key, where each
864device is assigned a different number.
865
866```
867 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanExplicitLayers
868 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanImplicitLayers
869 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanExplicitLayers
870 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanImplicitLayers
871```
872
873In addition, on 64-bit systems there may be another set of registry values, listed
874below. These values record the locations of 32-bit layers on 64-bit operating systems,
875in the same way as the Windows-on-Windows functionality.
876
877```
878 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanExplicitLayersWow
879 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanImplicitLayersWow
880 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanExplicitLayersWow
881 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanImplicitLayersWow
882```
883
884If any of the above values exist and is of type `REG_SZ`, the loader will open the JSON
885manifest file specified by the key value. Each value must be a full absolute
886path to a JSON manifest file. A key value may also be of type `REG_MULTI_SZ`, in
887which case the value will be interpreted as a list of paths to JSON manifest files.
888
889In general, applications should install layers into the `SOFTWARE\Khrosos\Vulkan`
890paths. The PnP registry locations are intended specifically for layers that are
891distrubuted as part of a driver installation. An application installer should not
892modify the device-specific registries, while a device driver should not modify
893the system wide registries.
894
895The Vulkan loader will open each manifest file that is given
Mark Young39389872017-01-19 21:10:49 -0700896to obtain information about the layer, including the name or pathname of a
897shared library (".dll") file. However, if VK\_LAYER\_PATH is defined, then the
898loader will instead look at the paths defined by that variable instead of using
899the information provided by these registry keys. See
900[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
901information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700902
Jon Ashburnc2972682016-02-08 15:42:01 -0700903
Mark Young39389872017-01-19 21:10:49 -0700904##### Linux Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700905
Mark Young39389872017-01-19 21:10:49 -0700906On Linux, the Vulkan loader will scan the files in the following Linux
907directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700908
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600909 /usr/local/etc/vulkan/explicit_layer.d
910 /usr/local/etc/vulkan/implicit_layer.d
911 /usr/local/share/vulkan/explicit_layer.d
912 /usr/local/share/vulkan/implicit_layer.d
913 /etc/vulkan/explicit_layer.d
914 /etc/vulkan/implicit_layer.d
915 /usr/share/vulkan/explicit_layer.d
916 /usr/share/vulkan/implicit_layer.d
917 $HOME/.local/share/vulkan/explicit_layer.d
918 $HOME/.local/share/vulkan/implicit_layer.d
919
Mark Young39389872017-01-19 21:10:49 -0700920Of course, ther are some things you have to know about the above folders:
921 1. The "/usr/local/*" directories can be configured to be other directories at
922build time.
923 2. $HOME is the current home directory of the application's user id; this path
924will be ignored for suid programs.
925 3. The "/usr/local/etc/vulkan/\*\_layer.d" and
926"/usr/local/share/vulkan/\*\_layer.d" directories are for layers that are
927installed from locally-built sources.
928 4. The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600929installed from Linux-distribution-provided packages.
930
Mark Young39389872017-01-19 21:10:49 -0700931As on Windows, if VK\_LAYER\_PATH is defined, then the
932loader will instead look at the paths defined by that variable instead of using
933the information provided by these default paths. However, these
934environment variables are only used for non-suid programs. See
935[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
936information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700937
Mark Young39389872017-01-19 21:10:49 -0700938
939#### Layer Version Negotiation
940
941Now that a layer has been discovered, an application can choose to load it (or
942it is loaded by default if it is an Implicit layer). When the loader attempts
943to load the layer, the first thing it does is attempt to negotiate the version
944of the loader to layer interface. In order to negotiate the loader/layer
945interface version, the layer must implement the
946`vkNegotiateLoaderLayerInterfaceVersion` function. The following information is
947provided for this interface in include/vulkan/vk_layer.h:
948
949```cpp
950 typedef enum VkNegotiateLayerStructType {
951 LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
952 } VkNegotiateLayerStructType;
953
954 typedef struct VkNegotiateLayerInterface {
955 VkNegotiateLayerStructType sType;
956 void *pNext;
957 uint32_t loaderLayerInterfaceVersion;
958 PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
959 PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
960 PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
961 } VkNegotiateLayerInterface;
962
963 VkResult vkNegotiateLoaderLayerInterfaceVersion(
964 VkNegotiateLayerInterface *pVersionStruct);
Jon Ashburncc300a22016-02-11 14:57:30 -0700965```
Jon Ashburnc2972682016-02-08 15:42:01 -0700966
Mark Young39389872017-01-19 21:10:49 -0700967You'll notice the `VkNegotiateLayerInterface` structure is similar to other
968Vulkan structures. The "sType" field, in this case takes a new enum defined
969just for internal loader/layer interfacing use. The valid values for "sType"
970could grow in the future, but right only havs the one value
971"LAYER_NEGOTIATE_INTERFACE_STRUCT".
Jon Ashburnc2972682016-02-08 15:42:01 -0700972
Mark Young39389872017-01-19 21:10:49 -0700973This function (`vkNegotiateLoaderLayerInterfaceVersion`) should be exported by
974the layer so that using "GetProcAddress" on Windows or "dlsym" on Linux, should
975return a valid function pointer to it. Once the loader has grabbed a valid
976address to the layers function, the loader will create a variable of type
977`VkNegotiateLayerInterface` and initialize it in the following ways:
978 1. Set the structure "sType" to "LAYER_NEGOTIATE_INTERFACE_STRUCT"
979 2. Set pNext to NULL.
980 - This is for future growth
981 3. Set "loaderLayerInterfaceVersion" to the current version the loader desires
982to set the interface to.
983 - The minimum value sent by the loader will be 2 since it is the first
984version supporting this function.
Jon Ashburnc2972682016-02-08 15:42:01 -0700985
Mark Young39389872017-01-19 21:10:49 -0700986The loader will then individually call each layer’s
987`vkNegotiateLoaderLayerInterfaceVersion` function with the filled out
988“VkNegotiateLayerInterface”. The layer will either accept the loader's version
989set in "loaderLayerInterfaceVersion", or modify it to the closest value version
990of the interface that the layer can support. The value should not be higher
991than the version requested by the loader. If the layer can't support at a
992minimum the version requested, then the layer should return an error like
993"VK_ERROR_INITIALIZATION_FAILED". If a layer can support some version, then
994the layer should do the following:
995 1. Adjust the version to the layer's desired version.
996 2. The layer should fill in the function pointer values to its internal
997functions:
998 - "pfnGetInstanceProcAddr" should be set to the layer’s internal
999`GetInstanceProcAddr` function.
1000 - "pfnGetDeviceProcAddr" should be set to the layer’s internal
1001`GetDeviceProcAddr` function.
1002 - "pfnGetPhysicalDeviceProcAddr" should be set to the layer’s internal
1003`GetPhysicalDeviceProcAddr` function.
1004 - If the layer supports no physical device extensions, it may set the
1005value to NULL.
1006 - More on this function later
1007 3. The layer should return "VK_SUCCESS"
Jon Ashburnc2972682016-02-08 15:42:01 -07001008
Mark Young39389872017-01-19 21:10:49 -07001009This function **SHOULD NOT CALL DOWN** the layer chain to the next layer.
1010The loader will work with each layer individually.
Jon Ashburnc2972682016-02-08 15:42:01 -07001011
Mark Young39389872017-01-19 21:10:49 -07001012If the layer supports the new interface and reports version 2 or greater, then
1013the loader will use the “fpGetInstanceProcAddr” and “fpGetDeviceProcAddr”
1014functions from the “VkNegotiateLayerInterface” structure. Prior to these
1015changes, the loader would query each of those functions using "GetProcAddress"
1016on Windows or "dlsym" on Linux.
Jon Ashburnc2972682016-02-08 15:42:01 -07001017
Jon Ashburnc2972682016-02-08 15:42:01 -07001018
Mark Young39389872017-01-19 21:10:49 -07001019#### Layer Call Chains and Distributed Dispatch
Jon Ashburnc2972682016-02-08 15:42:01 -07001020
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001021There are two key architectural features that drive the loader to layer library
Mark Young39389872017-01-19 21:10:49 -07001022interface:
1023 1. Separate and distinct instance and device call chains
1024 2. Distributed dispatch.
Jon Ashburnc2972682016-02-08 15:42:01 -07001025
Mark Young39389872017-01-19 21:10:49 -07001026You can read an overview of dispatch tables and call chains above in the
1027[Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) section.
Jon Ashburnc2972682016-02-08 15:42:01 -07001028
Mark Young39389872017-01-19 21:10:49 -07001029What's important to note here is that a layer can intercept Vulkan
1030instance functions, device functions or both. For a layer to intercept instance
1031functions, it must participate in the instance call chain. For a layer to
1032intercept device functions, it must participate in the device call chain.
1033
1034Remember, a layer does not need to intercept all instance or device functions,
1035instead, it can choose to intercept only a subset of those functions.
1036
1037Normally, when a layer intercepts a given Vulkan function, it will call down the
1038instance or device call chain as needed. The loader and all layer libraries that
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001039participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001040from one entity to the next. This group effort for call chain sequencing is
Mark Young39389872017-01-19 21:10:49 -07001041hereinafter referred to as **distributed dispatch**.
Jon Ashburnc2972682016-02-08 15:42:01 -07001042
Mark Young39389872017-01-19 21:10:49 -07001043In distributed dispatch each layer is responsible for properly calling the next
1044entity in the call chain. This means that a dispatch mechanism is required for
1045all Vulkan functions that a layer intercepts. If a Vulkan function is not
1046intercepted by a layer, or if a layer chooses to terminate the function by not
1047calling down the chain, then no dispatch is needed for that particular function.
Jeff Julianof1619872016-02-17 17:25:42 -05001048
Mark Young39389872017-01-19 21:10:49 -07001049For example, if the enabled layers intercepted only certain instance functions,
1050the call chain would look as follows:
1051![Instance Function Chain](./images/function_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -07001052
Mark Young39389872017-01-19 21:10:49 -07001053Likewise, if the enabled layers intercepted only a few of the device functions,
1054the call chain could look this way:
1055![Device Function Chain](./images/function_device_chain.png)
Jeff Julianof1619872016-02-17 17:25:42 -05001056
Mark Young39389872017-01-19 21:10:49 -07001057The loader is responsible for dispatching all core and instance extension Vulkan
1058functions to the first entity in the call chain.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001059
Chia-I Wucb24fec2016-04-20 06:23:24 +08001060
Mark Young39389872017-01-19 21:10:49 -07001061#### Layer Unknown Physical Device Extensions
1062
1063Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
1064result in the following behavior:
1065 1. The loader would check if core function:
1066 - If it was, it would return the function pointer
1067 2. The loader would check if known extension function:
1068 - If it was, it would return the function pointer
1069 3. If the loader knew nothing about it, it would call down using
1070`GetInstanceProcAddr`
1071 - If it returned non-NULL, treat it as an unknown logical device command.
1072 - This meant setting up a generic trampoline function that takes in a
1073VkDevice as the first parameter and adjusting the dispatch table to call the
1074ICD/Layers function after getting the dispatch table from the VkDevice.
1075 4. If all the above failed, the loader would return NULL to the application.
1076
1077This caused problems when a layer attempted to expose new physical device
1078extensions the loader knew nothing about, but an application did. Because the
1079loader knew nothing about it, the loader would get to step 3 in the above
1080process and would treat the function as an unknown logical device command. The
1081problem is, this would create a generic VkDevice trampoline function which, on
1082the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
1083This would lead to a crash or corruption.
1084
1085In order to identify the extension entry-points specific to physical device
1086extensions, the following function can be added to a layer:
1087
1088```cpp
1089PFN_vkVoidFunction vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
1090 const char* pName);
1091```
1092
1093This function behaves similar to `vkGetInstanceProcAddr` and
1094`vkGetDeviceProcAddr` except it should only return values for physical device
1095extension entry-points. In this way, it compares "pName" to every physical
1096device function supported in the layer.
1097
1098The following rules apply:
Lenny Komowde3924a2017-05-04 14:50:01 -06001099 * If it is the name of a physical device function supported by the layer, the
Mark Young39389872017-01-19 21:10:49 -07001100pointer to the layer's corresponding function should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06001101 * If it is the name of a valid function which is **not** a physical device
Mark Young39389872017-01-19 21:10:49 -07001102function (i.e. an Instance, Device, or other function implemented by the layer),
1103then the value of NULL should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06001104 * We don’t call down since we know the command is not a physical device
Mark Young39389872017-01-19 21:10:49 -07001105extension).
Lenny Komowde3924a2017-05-04 14:50:01 -06001106 * If the layer has no idea what this function is, it should call down the layer
Mark Young39389872017-01-19 21:10:49 -07001107chain to the next `vk_layerGetPhysicalDeviceProcAddr` call.
Lenny Komowde3924a2017-05-04 14:50:01 -06001108 * This can be retrieved in one of two ways:
1109 * During `vkCreateInstance`, it is passed to a layer in the
Mark Young39389872017-01-19 21:10:49 -07001110chain information passed to a layer in the `VkLayerInstanceCreateInfo`
1111structure.
1112 * Use `get_chain_info()` to get the pointer to the
1113`VkLayerInstanceCreateInfo` structure. Let's call it chain_info.
1114 * The address is then under
1115chain_info->u.pLayerInfo->pfnNextGetPhysicalDeviceProcAddr
1116 * See
1117[Example Code for CreateInstance](#example-code-for-createinstance)
Lenny Komowde3924a2017-05-04 14:50:01 -06001118 * Using the next layer’s `GetInstanceProcAddr` function to query for
Mark Young39389872017-01-19 21:10:49 -07001119`vk_layerGetPhysicalDeviceProcAddr`.
1120
1121This support is optional and should not be considered a requirement. This is
1122only required if a layer intends to support some functionality not directly
Mark Young18bbaab2017-03-20 08:27:14 -06001123supported by loaders released in the public. If a layer does implement this
Mark Young39389872017-01-19 21:10:49 -07001124support, it should return the address of its `vk_layerGetPhysicalDeviceProcAddr`
1125function in the "pfnGetPhysicalDeviceProcAddr" member of the
1126`VkNegotiateLayerInterface` structure during
1127[Layer Version Negotiation](#layer-version-negotiation). Additionally, the
1128layer should also make sure `vkGetInstanceProcAddr` returns a valid function
1129pointer to a query of `vk_layerGetPhysicalDeviceProcAddr`.
1130
1131The new behavior of the loader's `vkGetInstanceProcAddr` with support for the
1132`vk_layerGetPhysicalDeviceProcAddr` function is as follows:
1133 1. Check if core function:
1134 - If it is, return the function pointer
1135 2. Check if known instance or device extension function:
1136 - If it is, return the function pointer
1137 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
1138 - If it returns non-NULL, return a trampoline to a generic physical device
1139function, and setup a generic terminator which will pass it to the proper ICD.
1140 4. Call down using `GetInstanceProcAddr`
1141 - If it returns non-NULL, treat it as an unknown logical device command.
1142This means setting up a generic trampoline function that takes in a VkDevice as
1143the first parameter and adjusting the dispatch table to call the ICD/Layers
1144function after getting the dispatch table from the VkDevice. Then, return the
1145pointer to corresponding trampoline function.
1146 5. Return NULL
1147
1148You can see now, that, if the command gets promoted to core later, it will no
1149longer be setup using `vk_layerGetPhysicalDeviceProcAddr`. Additionally, if the
1150loader adds direct support for the extension, it will no longer get to step 3,
1151because step 2 will return a valid function pointer. However, the layer should
1152continue to support the command query via `vk_layerGetPhysicalDeviceProcAddr`,
1153until at least a Vulkan version bump, because an older loader may still be
1154attempting to use the commands.
1155
1156
1157#### Layer Intercept Requirements
1158
Lenny Komowde3924a2017-05-04 14:50:01 -06001159 * Layers intercept a Vulkan function by defining a C/C++ function with
Mark Young39389872017-01-19 21:10:49 -07001160signature **identical** to the Vulkan API for that function.
Lenny Komowde3924a2017-05-04 14:50:01 -06001161 * A layer **must intercept at least** `vkGetInstanceProcAddr` and
Mark Young39389872017-01-19 21:10:49 -07001162`vkCreateInstance` to participate in the instance call chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001163 * A layer **may also intercept** `vkGetDeviceProcAddr` and `vkCreateDevice`
Mark Young39389872017-01-19 21:10:49 -07001164to participate in the device call chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001165 * For any Vulkan function a layer intercepts which has a non-void return value,
Mark Young39389872017-01-19 21:10:49 -07001166**an appropriate value must be returned** by the layer intercept function.
Lenny Komowde3924a2017-05-04 14:50:01 -06001167 * Most functions a layer intercepts **should call down the chain** to the
Mark Young39389872017-01-19 21:10:49 -07001168corresponding Vulkan function in the next entity.
Lenny Komowde3924a2017-05-04 14:50:01 -06001169 * The common behavior for a layer is to intercept a call, perform some
Mark Young39389872017-01-19 21:10:49 -07001170behavior, then pass it down to the next entity.
Lenny Komowde3924a2017-05-04 14:50:01 -06001171 * If you don't pass the information down, undefined behavior may occur.
1172 * This is because the function will not be received by layers further down
Mark Young39389872017-01-19 21:10:49 -07001173the chain, or any ICDs.
Lenny Komowde3924a2017-05-04 14:50:01 -06001174 * One function that **must never call down the chain** is:
1175 * `vkNegotiateLoaderLayerInterfaceVersion`
1176 * Three common functions that **may not call down the chain** are:
1177 * `vkGetInstanceProcAddr`
1178 * `vkGetDeviceProcAddr`
1179 * `vk_layerGetPhysicalDeviceProcAddr`
1180 * These functions only call down the chain for Vulkan functions that they
Mark Young39389872017-01-19 21:10:49 -07001181do not intercept.
Lenny Komowde3924a2017-05-04 14:50:01 -06001182 * Layer intercept functions **may insert extra calls** to Vulkan functions in
Mark Young39389872017-01-19 21:10:49 -07001183addition to the intercept.
Lenny Komowde3924a2017-05-04 14:50:01 -06001184 * For example, a layer intercepting `vkQueueSubmit` may want to add a call to
Mark Young39389872017-01-19 21:10:49 -07001185`vkQueueWaitIdle` after calling down the chain for `vkQueueSubmit`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001186 * This would result in two calls down the chain: First a call down the
Mark Young39389872017-01-19 21:10:49 -07001187`vkQueueSubmit` chain, followed by a call down the `vkQueueWaitIdle` chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001188 * Any additional calls inserted by a layer must be on the same chain
1189 * If the function is a device function, only other device functions should
Mark Young39389872017-01-19 21:10:49 -07001190be added.
Lenny Komowde3924a2017-05-04 14:50:01 -06001191 * Likewise, if the function is an instance function, only other instance
Mark Young39389872017-01-19 21:10:49 -07001192functions should be added.
1193
1194
1195#### Distributed Dispatching Requirements
1196
1197- For each entry-point a layer intercepts, it must keep track of the entry
1198point residing in the next entity in the chain it will call down into.
Lenny Komowde3924a2017-05-04 14:50:01 -06001199 * In other words, the layer must have a list of pointers to functions of the
Mark Young39389872017-01-19 21:10:49 -07001200appropriate type to call into the next entity.
Lenny Komowde3924a2017-05-04 14:50:01 -06001201 * This can be implemented in various ways but
Mark Young39389872017-01-19 21:10:49 -07001202for clarity, will be referred to as a dispatch table.
1203- A layer can use the `VkLayerDispatchTable` structure as a device dispatch
1204table (see include/vulkan/vk_layer.h).
1205- A layer can use the `VkLayerInstanceDispatchTable` structure as a instance
1206dispatch table (see include/vulkan/vk_layer.h).
1207- A Layer's `vkGetInstanceProcAddr` function uses the next entity's
1208`vkGetInstanceProcAddr` to call down the chain for unknown (i.e.
1209non-intercepted) functions.
1210- A Layer's `vkGetDeviceProcAddr` function uses the next entity's
1211`vkGetDeviceProcAddr` to call down the chain for unknown (i.e. non-intercepted)
1212functions.
1213- A Layer's `vk_layerGetPhysicalDeviceProcAddr` function uses the next entity's
1214`vk_layerGetPhysicalDeviceProcAddr` to call down the chain for unknown (i.e.
1215non-intercepted) functions.
1216
1217
1218#### Layer Conventions and Rules
Chia-I Wucb24fec2016-04-20 06:23:24 +08001219
1220A layer, when inserted into an otherwise compliant Vulkan implementation, must
Mark Young39389872017-01-19 21:10:49 -07001221still result in a compliant Vulkan implementation. The intention is for layers
1222to have a well-defined baseline behavior. Therefore, it must follow some
1223conventions and rules defined below.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001224
1225A layer is always chained with other layers. It must not make invalid calls
Mark Young39389872017-01-19 21:10:49 -07001226to, or rely on undefined behaviors of, its lower layers. When it changes the
1227behavior of a function, it must make sure its upper layers do not make invalid
Chia-I Wucb24fec2016-04-20 06:23:24 +08001228calls to or rely on undefined behaviors of its lower layers because of the
1229changed behavior. For example, when a layer intercepts an object creation
Mark Young39389872017-01-19 21:10:49 -07001230function to wrap the objects created by its lower layers, it must make sure its
Chia-I Wucb24fec2016-04-20 06:23:24 +08001231lower layers never see the wrapping objects, directly from itself or
1232indirectly from its upper layers.
1233
Chia-I Wub5e850e2016-05-06 08:41:52 +08001234When a layer requires host memory, it may ignore the provided allocators. It
1235should use memory allocators if the layer is intended to run in a production
Mark Young39389872017-01-19 21:10:49 -07001236environment. For example, this usually applies to implicit layers that are
1237always enabled. That will allow applications to include the layer's memory
1238usage.
Chia-I Wub5e850e2016-05-06 08:41:52 +08001239
Mark Young39389872017-01-19 21:10:49 -07001240Additional rules include:
Lenny Komowde3924a2017-05-04 14:50:01 -06001241 - `vkEnumerateInstanceLayerProperties` **must** enumerate and **only**
Mark Young39389872017-01-19 21:10:49 -07001242enumerate the layer itself.
Lenny Komowde3924a2017-05-04 14:50:01 -06001243 - `vkEnumerateInstanceExtensionProperties` **must** handle the case where
Mark Young39389872017-01-19 21:10:49 -07001244`pLayerName` is itself.
Lenny Komowde3924a2017-05-04 14:50:01 -06001245 - It **must** return `VK_ERROR_LAYER_NOT_PRESENT` otherwise, including when
Mark Young39389872017-01-19 21:10:49 -07001246`pLayerName` is `NULL`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001247 - `vkEnumerateDeviceLayerProperties` **is deprecated and may be omitted**.
1248 - Using this will result in undefined behavior.
1249 - `vkEnumerateDeviceExtensionProperties` **must** handle the case where
Mark Young39389872017-01-19 21:10:49 -07001250`pLayerName` is itself.
Lenny Komowde3924a2017-05-04 14:50:01 -06001251 - In other cases, it should normally chain to other layers.
1252 - `vkCreateInstance` **must not** generate an error for unrecognized layer
Mark Young39389872017-01-19 21:10:49 -07001253names and extension names.
Lenny Komowde3924a2017-05-04 14:50:01 -06001254 - It may assume the layer names and extension names have been validated.
1255 - `vkGetInstanceProcAddr` intercepts a Vulkan function by returning a local
Mark Young39389872017-01-19 21:10:49 -07001256entry-point
Lenny Komowde3924a2017-05-04 14:50:01 -06001257 - Otherwise it returns the value obtained by calling down the instance call
Mark Young39389872017-01-19 21:10:49 -07001258chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001259 - `vkGetDeviceProcAddr` intercepts a Vulkan function by returning a local
Mark Young39389872017-01-19 21:10:49 -07001260entry-point
Lenny Komowde3924a2017-05-04 14:50:01 -06001261 - Otherwise it returns the value obtained by calling down the device call
Mark Young39389872017-01-19 21:10:49 -07001262chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001263 - These additional functions must be intercepted if the layer implements
Mark Young39389872017-01-19 21:10:49 -07001264device-level call chaining:
Lenny Komowde3924a2017-05-04 14:50:01 -06001265 - `vkGetDeviceProcAddr`
1266 - `vkCreateDevice`(only required for any device-level chaining)
1267 - **NOTE:** older layer libraries may expect that `vkGetInstanceProcAddr`
Mark Young39389872017-01-19 21:10:49 -07001268ignore `instance` when `pName` is `vkCreateDevice`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001269 - The specification **requires** `NULL` to be returned from
Mark Young39389872017-01-19 21:10:49 -07001270`vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` for disabled functions.
Lenny Komowde3924a2017-05-04 14:50:01 -06001271 - A layer may return `NULL` itself or rely on the following layers to do so.
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001272
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001273
Mark Young39389872017-01-19 21:10:49 -07001274#### Layer Dispatch Initialization
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001275
Mark Young39389872017-01-19 21:10:49 -07001276- A layer initializes its instance dispatch table within its `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001277function.
Mark Young39389872017-01-19 21:10:49 -07001278- A layer initializes its device dispatch table within its `vkCreateDevice`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001279function.
1280- The loader passes a linked list of initialization structures to layers via
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001281the "pNext" field in the `VkInstanceCreateInfo` and `VkDeviceCreateInfo`
Mark Young39389872017-01-19 21:10:49 -07001282structures for `vkCreateInstance` and `VkCreateDevice` respectively.
1283- The head node in this linked list is of type `VkLayerInstanceCreateInfo` for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001284instance and VkLayerDeviceCreateInfo for device. See file
Mark Young39389872017-01-19 21:10:49 -07001285`include/vulkan/vk_layer.h` for details.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001286- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001287"sType" field in `VkLayerInstanceCreateInfo`.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001288- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001289"sType" field in `VkLayerDeviceCreateInfo`.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001290- The "function" field indicates how the union field "u" should be interpreted
Mark Young39389872017-01-19 21:10:49 -07001291within `VkLayer*CreateInfo`. The loader will set the "function" field to
1292VK_LAYER_LINK_INFO. This indicates "u" field should be `VkLayerInstanceLink` or
1293`VkLayerDeviceLink`.
1294- The `VkLayerInstanceLink` and `VkLayerDeviceLink` structures are the list
1295nodes.
1296- The `VkLayerInstanceLink` contains the next entity's `vkGetInstanceProcAddr`
1297used by a layer.
1298- The `VkLayerDeviceLink` contains the next entity's `vkGetInstanceProcAddr` and
1299`vkGetDeviceProcAddr` used by a layer.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001300- Given the above structures set up by the loader, layer must initialize their
1301dispatch table as follows:
Mark Young39389872017-01-19 21:10:49 -07001302 - Find the `VkLayerInstanceCreateInfo`/`VkLayerDeviceCreateInfo` structure in
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001303the `VkInstanceCreateInfo`/`VkDeviceCreateInfo` structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001304 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Mark Young39389872017-01-19 21:10:49 -07001305 - For CreateInstance get the next entity's `vkCreateInstance` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001306"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001307 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Mark Young39389872017-01-19 21:10:49 -07001308 - For CreateDevice get the next entity's `vkCreateDevice` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001309"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001310 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001311 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
Mark Young39389872017-01-19 21:10:49 -07001312 - Call down the chain either `vkCreateDevice` or `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001313 - Initialize your layer dispatch table by calling the next entity's
Mark Young39389872017-01-19 21:10:49 -07001314Get*ProcAddr function once for each Vulkan function needed in your dispatch
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001315table
Jon Ashburncc300a22016-02-11 14:57:30 -07001316
Mark Young39389872017-01-19 21:10:49 -07001317#### Example Code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001318
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001319```cpp
1320VkResult vkCreateInstance(
1321 const VkInstanceCreateInfo *pCreateInfo,
1322 const VkAllocationCallbacks *pAllocator,
1323 VkInstance *pInstance)
1324{
1325 VkLayerInstanceCreateInfo *chain_info =
1326 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1327
1328 assert(chain_info->u.pLayerInfo);
1329 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1330 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1331 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001332 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001333 if (fpCreateInstance == NULL) {
1334 return VK_ERROR_INITIALIZATION_FAILED;
1335 }
1336
1337 // Advance the link info for the next element of the chain
1338 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1339
1340 // Continue call down the chain
1341 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1342 if (result != VK_SUCCESS)
1343 return result;
1344
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001345 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001346 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001347 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001348 layer_init_instance_dispatch_table(
1349 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1350
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001351 // Other layer initialization
1352 ...
1353
1354 return VK_SUCCESS;
1355}
1356```
1357
Mark Young39389872017-01-19 21:10:49 -07001358#### Example Code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001359
1360```cpp
1361VkResult
1362vkCreateDevice(
1363 VkPhysicalDevice gpu,
1364 const VkDeviceCreateInfo *pCreateInfo,
1365 const VkAllocationCallbacks *pAllocator,
1366 VkDevice *pDevice)
1367{
1368 VkLayerDeviceCreateInfo *chain_info =
1369 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1370
1371 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1372 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1373 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1374 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1375 PFN_vkCreateDevice fpCreateDevice =
1376 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1377 if (fpCreateDevice == NULL) {
1378 return VK_ERROR_INITIALIZATION_FAILED;
1379 }
1380
1381 // Advance the link info for the next element on the chain
1382 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1383
1384 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1385 if (result != VK_SUCCESS) {
1386 return result;
1387 }
1388
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001389 // initialize layer's dispatch table
1390 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001391 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001392 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001393
1394 // Other layer initialization
1395 ...
1396
1397 return VK_SUCCESS;
1398}
1399```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001400
Mark Young39389872017-01-19 21:10:49 -07001401
Mark Youngc82a0622017-05-05 11:17:17 -06001402#### Meta-layers
1403
1404Meta-layers are a special kind of layer which is only available through the
1405desktop loader. While normal layers are associated with one particular library,
1406a meta-layer is actually a collection layer which contains an ordered list of
1407other layers (called component layers).
1408
1409The most common example of a meta-layer is the
1410`VK_LAYER_LUNARG_standard_validation` layer which groups all the most common
1411individual validation layers into a single layer for ease-of-use.
1412
1413The benefits of a meta-layer are:
1414 1. You can activate more than one layer using a single layer name by simply
1415grouping multiple layers in a meta-layer.
1416 2. You can define the order the loader will activate individual layers within
1417the meta-layer.
1418 3. You can easily share your special layer configuration with others.
1419 4. The loader will automatically collate all instance and device extensions in
1420a meta-layer's component layers, and report them as the meta-layer's properties
1421to the application when queried.
1422
1423Restrictions to defining and using a meta-layer are:
1424 1. A Meta-layer Manifest file **must** be a properly formated that contains one
1425or more component layers.
1426 3. All component layers **must be** present on a system for the meta-layer to
1427be used.
1428 4. All component layers **must be** at the same Vulkan API major and minor
1429version for the meta-layer to be used.
1430
1431The ordering of a meta-layer's component layers in the instance or device
1432call-chain is simple:
1433 * The first layer listed will be the layer closest to the application.
1434 * The last layer listed will be the layer closest to the drivers.
1435
1436Inside the meta-layer Manifest file, each component layer is listed by its
1437layer name. This is the "name" tag's value associated with each component layer's
1438Manifest file under the "layer" or "layers" tag. This is also the name that
1439would normally be used when activating a layer during `vkCreateInstance`.
1440
1441Any duplicate layer names in either the component layer list, or globally among
1442all enabled layers, will simply be ignored. Only the first instance of any
1443layer name will be used.
1444
1445For example, if you have a layer enabled using the environment variable
1446`VK_INSTANCE_LAYERS` and have that same layer listed in a meta-layer, then the
1447environment variable enabled layer will be used and the component layer will
1448be dropped. Likewise, if a person were to enable a meta-layer and then
1449separately enable one of the component layers afterwards, the second
1450instantiation of the layer name would be ignored.
1451
1452The
1453Manifest file formatting necessary to define a meta-layer can be found in the
1454[Layer Manifest File Format](#layer-manifest-file-format) section.
1455
Jon Ashburncc300a22016-02-11 14:57:30 -07001456#### Special Considerations
Mark Young39389872017-01-19 21:10:49 -07001457
1458
1459##### Associating Private Data with Vulkan Objects Within a Layer
1460
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001461A layer may want to associate it's own private data with one or more Vulkan
Mark Youngf7914cf2016-08-31 11:53:26 -06001462objects. Two common methods to do this are hash maps and object wrapping.
1463
Mark Youngf7914cf2016-08-31 11:53:26 -06001464
Mark Young39389872017-01-19 21:10:49 -07001465###### Wrapping
Ian Elliott0b082e42016-08-31 14:08:44 -06001466
Mark Young39389872017-01-19 21:10:49 -07001467The loader supports layers wrapping any Vulkan object, including dispatchable
1468objects. For functions that return object handles, each layer does not touch
1469the value passed down the call chain. This is because lower items may need to
1470use the original value. However, when the value is returned from a
1471lower-level layer (possibly the ICD), the layer saves the handle and returns
1472its own handle to the layer above it (possibly the application). When a layer
1473receives a Vulkan function using something that it previously returned a handle
1474for, the layer is required to unwrap the handle and pass along the saved handle
1475to the layer below it. This means that the layer **must intercept every Vulkan
1476function which uses the object in question**, and wrap or unwrap the object, as
1477appropriate. This includes adding support for all extensions with functions
Ian Elliott0b082e42016-08-31 14:08:44 -06001478using any object the layer wraps.
Mark Youngf7914cf2016-08-31 11:53:26 -06001479
1480Layers above the object wrapping layer will see the wrapped object. Layers
1481which wrap dispatchable objects must ensure that the first field in the wrapping
Mark Young39389872017-01-19 21:10:49 -07001482structure is a pointer to a dispatch table as defined in `vk_layer.h`.
1483Specifically, an instance wrapped dispatchable object could be as follows:
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001484```
1485struct my_wrapped_instance_obj_ {
1486 VkLayerInstanceDispatchTable *disp;
1487 // whatever data layer wants to add to this object
1488};
1489```
1490A device wrapped dispatchable object could be as follows:
1491```
1492struct my_wrapped_instance_obj_ {
1493 VkLayerDispatchTable *disp;
1494 // whatever data layer wants to add to this object
1495};
1496```
Jeff Julianof1619872016-02-17 17:25:42 -05001497
Ian Elliott0b082e42016-08-31 14:08:44 -06001498Layers that wrap dispatchable objects must follow the guidelines for creating
1499new dispatchable objects (below).
1500
Mark Young39389872017-01-19 21:10:49 -07001501<u>Cautions About Wrapping</u>
Ian Elliott0b082e42016-08-31 14:08:44 -06001502
1503Layers are generally discouraged from wrapping objects, because of the
1504potential for incompatibilities with new extensions. For example, let's say
Mark Young39389872017-01-19 21:10:49 -07001505that a layer wraps `VkImage` objects, and properly wraps and unwraps `VkImage`
1506object handles for all core functions. If a new extension is created which has
1507functions that take `VkImage` objects as parameters, and if the layer does not
1508support those new functions, an application that uses both the layer and the new
1509extension will have undefined behavior when those new functions are called (e.g.
Mark Young18bbaab2017-03-20 08:27:14 -06001510the application may crash). This is because the lower-level layers and ICD
Ian Elliott0b082e42016-08-31 14:08:44 -06001511won't receive the handle that they generated. Instead, they will receive a
1512handle that is only known by the layer that is wrapping the object.
1513
1514Because of the potential for incompatibilities with unsupported extensions,
1515layers that wrap objects must check which extensions are being used by the
1516application, and take appropriate action if the layer is used with unsupported
1517extensions (e.g. disable layer functionality, stop wrapping objects, issue a
1518message to the user).
1519
1520The reason that the validation layers wrap objects, is to track the proper use
1521and destruction of each object. They issue a validation error if used with
1522unsupported extensions, alerting the user to the potential for undefined
1523behavior.
1524
Mark Young39389872017-01-19 21:10:49 -07001525
1526###### Hash Maps
1527
Jeff Julianof1619872016-02-17 17:25:42 -05001528Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001529given object. The key to the map could be the object. Alternatively, for
1530dispatchable objects at a given level (eg device or instance) the layer may
Mark Young39389872017-01-19 21:10:49 -07001531want data associated with the `VkDevice` or `VkInstance` objects. Since
1532there are multiple dispatchable objects for a given `VkInstance` or `VkDevice`,
1533the `VkDevice` or `VkInstance` object is not a great map key. Instead the layer
1534should use the dispatch table pointer within the `VkDevice` or `VkInstance`
1535since that will be unique for a given `VkInstance` or `VkDevice`.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001536
Mark Young39389872017-01-19 21:10:49 -07001537
1538##### Creating New Dispatchable Objects
1539
1540Layers which create dispatchable objects must take special care. Remember that
1541loader *trampoline* code normally fills in the dispatch table pointer in the
1542newly created object. Thus, the layer must fill in the dispatch table pointer if
1543the loader *trampoline* will not do so. Common cases where a layer (or ICD) may
1544create a dispatchable object without loader *trampoline* code is as follows:
1545- layers that wrap dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001546- layers which add extensions that create dispatchable objects
Mark Young18bbaab2017-03-20 08:27:14 -06001547- layers which insert extra Vulkan functions in the stream of functions they
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001548intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001549- ICDs which add extensions that create dispatchable objects
1550
Mark Young39389872017-01-19 21:10:49 -07001551The desktop loader provides a callback that can be used for initializing
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001552a dispatchable object. The callback is passed as an extension structure via the
Mark Young39389872017-01-19 21:10:49 -07001553pNext field in the create info structure when creating an instance
1554(`VkInstanceCreateInfo`) or device (`VkDeviceCreateInfo`). The callback
1555prototype is defined as follows for instance and device callbacks respectively
1556(see `vk_layer.h`):
1557
1558```cpp
1559VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance,
1560 void *object);
1561VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData(VkDevice device,
1562 void *object);
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001563```
Mark Young39389872017-01-19 21:10:49 -07001564
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001565To obtain these callbacks the layer must search through the list of structures
Mark Young39389872017-01-19 21:10:49 -07001566pointed to by the "pNext" field in the `VkInstanceCreateInfo` and
1567`VkDeviceCreateInfo` parameters to find any callback structures inserted by the
1568loader. The salient details are as follows:
1569- For `VkInstanceCreateInfo` the callback structure pointed to by "pNext" is
1570`VkLayerInstanceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1571- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within
1572`VkInstanceCreateInfo` parameter indicates a loader structure.
1573- Within `VkLayerInstanceCreateInfo`, the "function" field indicates how the
1574union field "u" should be interpreted.
1575- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1576contain the callback in "pfnSetInstanceLoaderData".
1577- For `VkDeviceCreateInfo` the callback structure pointed to by "pNext" is
1578`VkLayerDeviceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1579- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within
1580`VkDeviceCreateInfo` parameter indicates a loader structure.
1581- Within `VkLayerDeviceCreateInfo`, the "function" field indicates how the union
1582field "u" should be interpreted.
1583- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1584contain the callback in "pfnSetDeviceLoaderData".
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001585
Mark Young39389872017-01-19 21:10:49 -07001586Alternatively, if an older loader is being used that doesn't provide these
1587callbacks, the layer may manually initialize the newly created dispatchable
1588object. To fill in the dispatch table pointer in newly created dispatchable
1589object, the layer should copy the dispatch pointer, which is always the first
1590entry in the structure, from an existing parent object of the same level
1591(instance versus device).
Jon Ashburnc2972682016-02-08 15:42:01 -07001592
Mark Young39389872017-01-19 21:10:49 -07001593For example, if there is a newly created `VkCommandBuffer` object, then the
1594dispatch pointer from the `VkDevice` object, which is the parent of the
1595`VkCommandBuffer` object, should be copied into the newly created object.
1596
1597
1598#### Layer Manifest File Format
1599
1600On Windows and Linux (desktop), the loader uses manifest files to discover
1601layer libraries and layers. The desktop loader doesn't directly query the
1602layer library except during chaining. This is to reduce the likelihood of
1603loading a malicious layer into memory. Instead, details are read from the
1604Manifest file, which are then provided for applications to determine what
1605layers should actually be loaded.
1606
1607The following section discusses the details of the Layer Manifest JSON file
1608format. The JSON file itself does not have any requirements for naming. The
1609only requirement is that the extension suffix of the file ends with ".json".
1610
1611Here is an example layer JSON Manifest file with a single layer:
1612
1613```
1614{
1615 "file_format_version" : "1.0.0",
1616 "layer": {
1617 "name": "VK_LAYER_LUNARG_overlay",
1618 "type": "INSTANCE",
1619 "library_path": "vkOverlayLayer.dll"
1620 "api_version" : "1.0.5",
1621 "implementation_version" : "2",
1622 "description" : "LunarG HUD layer",
1623 "functions": {
1624 "vkNegotiateLoaderLayerInterfaceVersion":
1625 "OverlayLayer_NegotiateLoaderLayerInterfaceVersion"
1626 },
1627 "instance_extensions": [
1628 {
1629 "name": "VK_EXT_debug_report",
1630 "spec_version": "1"
1631 },
1632 {
1633 "name": "VK_VENDOR_ext_x",
1634 "spec_version": "3"
1635 }
1636 ],
1637 "device_extensions": [
1638 {
1639 "name": "VK_EXT_debug_marker",
1640 "spec_version": "1",
1641 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1642 }
1643 ],
1644 "enable_environment": {
1645 "ENABLE_LAYER_OVERLAY_1": "1"
1646 }
1647 "disable_environment": {
1648 "DISABLE_LAYER_OVERLAY_1": ""
1649 }
1650 }
1651}
1652```
1653
1654Here's a snippet with the changes required to support multiple layers per
1655manifest file:
1656```
1657{
1658 "file_format_version" : "1.0.1",
1659 "layers": [
1660 {
1661 "name": "VK_LAYER_layer_name1",
1662 "type": "INSTANCE",
1663 ...
1664 },
1665 {
1666 "name": "VK_LAYER_layer_name2",
1667 "type": "INSTANCE",
1668 ...
1669 }
1670 ]
1671}
1672```
1673
Mark Youngc82a0622017-05-05 11:17:17 -06001674Here's an example of a meta-layer manifest file:
1675```
1676{
1677 "file_format_version" : "1.1.1",
1678 "layer": {
1679 "name": "VK_LAYER_LUNARG_standard_validation",
1680 "type": "GLOBAL",
1681 "api_version" : "1.0.40",
1682 "implementation_version" : "1",
1683 "description" : "LunarG Standard Validation Meta-layer",
1684 "component_layers": [
1685 "VK_LAYER_GOOGLE_threading",
1686 "VK_LAYER_LUNARG_parameter_validation",
1687 "VK_LAYER_LUNARG_object_tracker",
1688 "VK_LAYER_LUNARG_core_validation",
Mark Youngc82a0622017-05-05 11:17:17 -06001689 "VK_LAYER_GOOGLE_unique_objects"
1690 ]
1691 }
1692}
1693```
Mark Young39389872017-01-19 21:10:49 -07001694| JSON Node | Description and Notes | Introspection Query |
1695|:----------------:|--------------------|:----------------:
1696| "file\_format\_version" | Manifest format major.minor.patch version number. | N/A |
1697| | Supported versions are: 1.0.0, 1.0.1, and 1.1.0. | |
1698| "layer" | The identifier used to group a single layer's information together. | vkEnumerateInstanceLayerProperties |
1699| "layers" | The identifier used to group multiple layers' information together. This requires a minimum Manifest file format version of 1.0.1.| vkEnumerateInstanceLayerProperties |
1700| "name" | The string used to uniquely identify this layer to applications. | vkEnumerateInstanceLayerProperties |
1701| "type" | This field indicates the type of layer. The values can be: GLOBAL, or INSTANCE | vkEnumerate*LayerProperties |
1702| | **NOTES:** Prior to deprecation, the "type" node was used to indicate which layer chain(s) to activate the layer upon: instance, device, or both. Distinct instance and device layers are deprecated; there are now just layers. Allowable values for type (both before and after deprecation) are "INSTANCE", "GLOBAL" and, "DEVICE." "DEVICE" layers are skipped over by the loader as if they were not found. | |
Mark Youngc82a0622017-05-05 11:17:17 -06001703| "library\_path" | The "library\_path" specifies either a filename, a relative pathname, or a full pathname to a layer shared library file. If "library\_path" specifies a relative pathname, it is relative to the path of the JSON manifest file (e.g. for cases when an application provides a layer that is in the same folder hierarchy as the rest of the application files). If "library\_path" specifies a filename, the library must live in the system's shared object search path. There are no rules about the name of the layer shared library files other than it should end with the appropriate suffix (".DLL" on Windows, and ".so" on Linux). **This field must not be present if "component_layers" is defined** | N/A |
Mark Young39389872017-01-19 21:10:49 -07001704| "api\_version" | The major.minor.patch version number of the Vulkan API that the shared library file for the library was built against. For example: 1.0.33. | vkEnumerateInstanceLayerProperties |
1705| "implementation_version" | The version of the layer implemented. If the layer itself has any major changes, this number should change so the loader and/or application can identify it properly. | vkEnumerateInstanceLayerProperties |
1706| "description" | A high-level description of the layer and it's intended use. | vkEnumerateInstanceLayerProperties |
1707| "functions" | **OPTIONAL:** This section can be used to identify a different function name for the loader to use in place of standard layer interface functions. The "functions" node is required if the layer is using an alternative name for `vkNegotiateLoaderLayerInterfaceVersion`. | vkGet*ProcAddr |
1708| "instance\_extensions" | **OPTIONAL:** Contains the list of instance extension names supported by this layer. One "instance\_extensions" node with an array of one or more elements is required if any instance extensions are supported by a layer, otherwise the node is optional. Each element of the array must have the nodes "name" and "spec_version" which correspond to `VkExtensionProperties` "extensionName" and "specVersion" respectively. | vkEnumerateInstanceExtensionProperties |
1709| "device\_extensions" | **OPTIONAL:** Contains the list of device extension names supported by this layer. One "device_\extensions" node with an array of one or more elements is required if any device extensions are supported by a layer, otherwise the node is optional. Each element of the array must have the nodes "name" and "spec_version" which correspond to `VkExtensionProperties` "extensionName" and "specVersion" respectively. Additionally, each element of the array of device extensions must have the node "entrypoints" if the device extension adds Vulkan API functions, otherwise this node is not required. The "entrypoint" node is an array of the names of all entrypoints added by the supported extension. | vkEnumerateDeviceExtensionProperties |
1710| "enable\_environment" | **Implicit Layers Only** - **OPTIONAL:** Indicates an environment variable used to enable the Implicit Layer (w/ value of 1). This environment variable (which should vary with each "version" of the layer) must be set to the given value or else the implicit layer is not loaded. This is for application environments (e.g. Steam) which want to enable a layer(s) only for applications that they launch, and allows for applications run outside of an application environment to not get that implicit layer(s).| N/A |
1711| "disable\_environment" | **Implicit Layers Only** - **REQUIRED:**Indicates an environment variable used to disable the Implicit Layer (w/ value of 1). In rare cases of an application not working with an implicit layer, the application can set this environment variable (before calling Vulkan functions) in order to "blacklist" the layer. This environment variable (which should vary with each "version" of the layer) must be set (not particularly to any value). If both the "enable_environment" and "disable_environment" variables are set, the implicit layer is disabled. | N/A |
Mark Youngc82a0622017-05-05 11:17:17 -06001712| "component_layers" | **Meta-layers Only** - Indicates the component layer names that are part of a meta-layer. The names listed must be the "name" identified in each of the component layer's Mainfest file "name" tag (this is the same as the name of the layer that is passed to the `vkCreateInstance` command). All component layers must be present on the system and found by the loader in order for this meta-layer to be available and activated. **This field must not be present if "library\_path" is defined** | N/A |
Mark Young39389872017-01-19 21:10:49 -07001713
1714##### Layer Manifest File Version History
1715
1716The current highest supported Layer Manifest file format supported is 1.1.0.
1717Information about each version is detailed in the following sub-sections:
1718
1719###### Layer Manifest File Version 1.1.0
1720
1721Layer Manifest File Version 1.1.0 is tied to changes exposed by the Loader/Layer
1722interface version 2.
1723 1. Renaming "vkGetInstanceProcAddr" in the "functions" section is
1724 deprecated since the loader no longer needs to query the layer about
1725 "vkGetInstanceProcAddr" directly. It is now returned during the layer
1726 negotiation, so this field will be ignored.
1727 2. Renaming "vkGetDeviceProcAddr" in the "functions" section is
1728 deprecated since the loader no longer needs to query the layer about
1729 "vkGetDeviceProcAddr" directly. It too is now returned during the layer
1730 negotiation, so this field will be ignored.
1731 3. Renaming the "vkNegotiateLoaderLayerInterfaceVersion" function is
1732 being added to the "functions" section, since this is now the only
1733 function the loader needs to query using OS-specific calls.
1734 - NOTE: This is an optional field and, as the two previous fields, only
1735needed if the layer requires changing the name of the function for some reason.
1736
1737You do not need to update your layer manifest file if you don't change the
1738names of any of the listed functions.
1739
1740###### Layer Manifest File Version 1.0.1
1741
1742The ability to define multiple layers using the "layers" array was added. This
1743JSON array field can be used when defining a single layer or multiple layers.
1744The "layer" field is still present and valid for a single layer definition.
1745
1746###### Layer Manifest File Version 1.0.0
1747
1748The initial version of the layer manifest file specified the basic format and
1749fields of a layer JSON file. The fields of the 1.0.0 file format include:
1750 * "file\_format\_version"
1751 * "layer"
1752 * "name"
1753 * "type"
1754 * "library\_path"
1755 * "api\_version"
1756 * "implementation\_version"
1757 * "description"
1758 * "functions"
1759 * "instance\_extensions"
1760 * "device\_extensions"
1761 * "enable\_environment"
1762 * "disable\_environment"
1763
1764It was also during this time that the value of "DEVICE" was deprecated from
1765the "type" field.
1766
1767
1768#### Layer Library Versions
1769
1770The current Layer Library interface is at version 2. The following sections
1771detail the differences between the various versions.
1772
1773##### Layer Library API Version 2
1774
1775Introduced the concept of
1776[loader and layer interface](#layer-version-negotiation) using the new
1777`vkNegotiateLoaderLayerInterfaceVersion` function. Additionally, it introduced
1778the concept of
1779[Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-
1780extensions)
1781and the associated `vk_layerGetPhysicalDeviceProcAddr` function. Finally, it
1782changed the manifest file defition to 1.1.0.
1783
1784##### Layer Library API Version 1
1785
1786A layer library supporting interface version 1 had the following behavior:
1787 1. `GetInstanceProcAddr` and `GetDeviceProcAddr` were directly exported
1788 2. The layer manifest file was able to override the names of the
1789`GetInstanceProcAddr` and `GetDeviceProcAddr`functions.
1790
1791##### Layer Library API Version 0
1792
1793A layer library supporting interface version 0 must define and export these
1794introspection functions, unrelated to any Vulkan function despite the names,
1795signatures, and other similarities:
1796
Lenny Komowde3924a2017-05-04 14:50:01 -06001797- `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
Mark Young39389872017-01-19 21:10:49 -07001798library.
1799 - This function never fails.
1800 - When a layer library contains only one layer, this function may be an alias
1801 to the layer's `vkEnumerateInstanceLayerProperties`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001802- `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
Mark Young39389872017-01-19 21:10:49 -07001803 layers in a layer library.
1804 - "pLayerName" is always a valid layer name.
1805 - This function never fails.
1806 - When a layer library contains only one layer, this function may be an alias
1807 to the layer's `vkEnumerateInstanceExtensionProperties`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001808- `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
Mark Young39389872017-01-19 21:10:49 -07001809 proper, or empty subset) of layers in a layer library.
1810 - "physicalDevice" is always `VK_NULL_HANDLE`.
1811 - This function never fails.
1812 - If a layer is not enumerated by this function, it will not participate in
1813 device function interception.
Lenny Komowde3924a2017-05-04 14:50:01 -06001814- `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
Mark Young39389872017-01-19 21:10:49 -07001815 layers in a layer library.
1816 - "physicalDevice" is always `VK_NULL_HANDLE`.
1817 - "pLayerName" is always a valid layer name.
1818 - This function never fails.
1819
1820It must also define and export these functions once for each layer in the
1821library:
1822
Lenny Komowde3924a2017-05-04 14:50:01 -06001823- `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a
Mark Young39389872017-01-19 21:10:49 -07001824layer's vkGetInstanceProcAddr except it is exported.
1825
1826 When a layer library contains only one layer, this function may
1827 alternatively be named `vkGetInstanceProcAddr`.
1828
Lenny Komowde3924a2017-05-04 14:50:01 -06001829- `<layerName>GetDeviceProcAddr` behaves identically to a layer's
Mark Young39389872017-01-19 21:10:49 -07001830vkGetDeviceProcAddr except it is exported.
1831
1832 When a layer library contains only one layer, this function may
1833 alternatively be named `vkGetDeviceProcAddr`.
1834
1835All layers contained within a library must support `vk_layer.h`. They do not
1836need to implement functions that they do not intercept. They are recommended
1837not to export any functions.
1838
1839
1840<br/>
1841<br/>
1842
1843## Vulkan Installable Client Driver Interface With the Loader
1844
1845This section discusses the various requirements for the loader and a Vulkan
1846ICD to properly hand-shake.
1847
Lenny Komowde3924a2017-05-04 14:50:01 -06001848 * [ICD Discovery](#icd-discovery)
Mark Young540d71c2017-05-18 14:52:14 -06001849 * [Overriding the Default ICD Usage](#overriding-the-default-icd-usage)
Lenny Komowde3924a2017-05-04 14:50:01 -06001850 * [ICD Manifest File Usage](#icd-manifest-file-usage)
1851 * [ICD Discovery on Windows](#icd-discovery-on-windows)
1852 * [ICD Discovery on Linux](#icd-discovery-on-linux)
1853 * [Using Pre-Production ICDs on Windows and Linux](#using-pre-production-icds-on-windows-and-linux)
1854 * [ICD Discovery on Android](#icd-discovery-on-android)
1855 * [ICD Manifest File Format](#icd-manifest-file-format)
1856 * [ICD Manifest File Versions](#icd-manifest-file-versions)
1857 * [ICD Manifest File Version 1.0.0](#icd-manifest-file-version-1.0.0)
1858 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
1859 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
1860 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
1861 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
1862 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
1863 * [Windows and Linux ICD Negotiation](#windows-and-linux-icd-negotiation)
1864 * [Version Negotiation Between Loader and ICDs](#version-negotiation-between-loader-and-icds)
1865 * [Interfacing With Legacy ICDs or Loader](#interfacing-with-legacy-icds-or-loader)
Mark Young02df1a82017-04-18 19:52:18 -06001866 * [Loader Version 5 Interface Requirements](#loader-version-5-interface-requirements)
Lenny Komowde3924a2017-05-04 14:50:01 -06001867 * [Loader Version 4 Interface Requirements](#loader-version-4-interface-requirements)
1868 * [Loader Version 3 Interface Requirements](#loader-version-3-interface-requirements)
1869 * [Loader Version 2 Interface Requirements](#loader-version-2-interface-requirements)
1870 * [Loader Versions 0 and 1 Interface Requirements](#loader-versions-0-and-1-interface-requirements)
1871 * [Android ICD Negotiation](#android-icd-negotiation)
Mark Young39389872017-01-19 21:10:49 -07001872
1873
1874### ICD Discovery
1875
1876Vulkan allows multiple drivers each with one or more devices (represented by a
1877Vulkan `VkPhysicalDevice` object) to be used collectively. The loader is
1878responsible for discovering available Vulkan ICDs on the system. Given a list
1879of available ICDs, the loader can enumerate all the physical devices available
1880for an application and return this information to the application. The process
1881in which the loader discovers the available Installable Client Drivers (ICDs)
1882on a system is platform dependent. Windows, Linux and Android ICD discovery
1883details are listed below.
1884
Mark Young540d71c2017-05-18 14:52:14 -06001885#### Overriding the Default ICD Usage
1886
1887There may be times that a developer wishes to force the loader to use a specific ICD.
1888This could be for many reasons including : using a beta driver, or forcing the loader
1889to skip a problematic ICD. In order to support this, the loader can be forced to
1890look at specific ICDs with the `VK_ICD_FILENAMES` environment variable. In order
1891to use the setting, simply set it to a properly delimited list of ICD Manifest
1892files that you wish to use. In this case, please provide the global path to these
1893files to reduce issues.
1894
1895For example:
1896
1897##### On Windows
1898
1899```
1900set VK_ICD_FILENAMES=/windows/system32/nv-vk64.json
1901```
1902
1903This is an example which is using the `VK_ICD_FILENAMES` override on Windows to point
1904to the Nvidia Vulkan driver's ICD Manifest file.
1905
1906##### On Linux
1907
1908```
1909export VK_ICD_FILENAMES=/home/user/dev/mesa/share/vulkan/icd.d/intel_icd.x86_64.json
1910```
1911
1912This is an example which is using the `VK_ICD_FILENAMES` override on Linux to point
1913to the Intel Mesa driver's ICD Manifest file.
1914
1915
Mark Young39389872017-01-19 21:10:49 -07001916#### ICD Manifest File Usage
1917
Mark Young18bbaab2017-03-20 08:27:14 -06001918As with layers, on Windows and Linux systems, JSON formatted manifest files are
Mark Young39389872017-01-19 21:10:49 -07001919used to store ICD information. In order to find system-installed drivers, the
1920Vulkan loader will read the JSON files to identify the names and attributes of
1921each driver. One thing you will notice is that ICD Manifest files are much
1922simpler than the corresponding layer Manifest files.
1923
1924See the [Current ICD Manifest File Format](#icd-manifest-file-format) section
1925for more details.
1926
1927
1928#### ICD Discovery on Windows
1929
Lenny Komow4c3d3772017-08-31 17:19:17 -06001930In order to find installed ICDs, the loader scans through registry keys specific to Display
1931Adapters and all Software Components associated with these adapters for the
1932locations of JSON manifest files. These keys are located in device keys
1933created during driver installation and contain configuration information
1934for base settings, including OpenGL and Direct3D ICD location.
1935
1936The Device Adapter and Software Component key paths should be obtained through the PnP
1937Configuration Manager API. The `000X` key will be a numbered key, where each
1938device is assigned a different number.
1939
1940```
1941 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanDriverName
1942 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{SoftwareComponent GUID}\000X\VulkanDriverName
1943```
1944
1945In addition, on 64-bit systems there may be another set of registry values, listed
1946below. These values record the locations of 32-bit layers on 64-bit operating systems,
1947in the same way as the Windows-on-Windows functionality.
1948
1949```
1950 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanDriverNameWow
1951 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{SoftwareComponent GUID}\000X\VulkanDriverNameWow
1952```
1953
1954If any of the above values exist and is of type `REG_SZ`, the loader will open the JSON
1955manifest file specified by the key value. Each value must be a full absolute
1956path to a JSON manifest file. The values may also be of type `REG_MULTI_SZ`, in
1957which case the value will be interpreted as a list of paths to JSON manifest files.
1958
1959Additionally, the Vulkan loader will scan the values in the following Windows registry key:
Mark Young39389872017-01-19 21:10:49 -07001960
1961```
1962 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers
1963```
1964
1965For 32-bit applications on 64-bit Windows, the loader scan's the 32-bit
1966registry location:
1967
1968```
1969 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\Drivers
1970```
1971
Lenny Komow4c3d3772017-08-31 17:19:17 -06001972Every ICD in these locations should be given as a DWORD, with value 0, where
1973the name of the value is the full path to a JSON manifest file. The Vulkan loader
1974will attempt to open each manifest file to obtain the information about an ICD's
1975shared library (".dll") file.
Mark Young39389872017-01-19 21:10:49 -07001976
1977For example, let us assume the registry contains the following data:
1978
1979```
1980[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
1981
1982"C:\vendor a\vk_vendora.json"=dword:00000000
1983"C:\windows\system32\vendorb_vk.json"=dword:00000001
1984"C:\windows\system32\vendorc_icd.json"=dword:00000000
1985```
1986
1987In this case, the loader will step through each entry, and check the value. If
1988the value is 0, then the loader will attempt to load the file. In this case,
Mark Young18bbaab2017-03-20 08:27:14 -06001989the loader will open the first and last listings, but not the middle. This
Mark Young39389872017-01-19 21:10:49 -07001990is because the value of 1 for vendorb_vk.json disables the driver.
1991
1992The Vulkan loader will open each enabled manifest file found to obtain the name
1993or pathname of an ICD shared library (".DLL") file.
1994
Lenny Komow4c3d3772017-08-31 17:19:17 -06001995ICDs should use the registry locations from the PnP Configuration Manager wherever
1996practical. That location clearly ties the ICD to a given device. The
1997`SOFTWARE\Khronos\Vulkan\Drivers` location is the older method for locating ICDs,
1998and is retained for backwards compatibility.
1999
Mark Young39389872017-01-19 21:10:49 -07002000See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
2001details.
2002
2003
2004#### ICD Discovery on Linux
2005
2006In order to find installed ICDs, the Vulkan loader will scan the files
2007in the following Linux directories:
2008
2009```
2010 /usr/local/etc/vulkan/icd.d
2011 /usr/local/share/vulkan/icd.d
2012 /etc/vulkan/icd.d
2013 /usr/share/vulkan/icd.d
2014 $HOME/.local/share/vulkan/icd.d
2015```
2016
2017The "/usr/local/*" directories can be configured to be other directories at
2018build time.
2019
2020The typical usage of the directories is indicated in the table below.
2021
2022| Location | Details |
2023|-------------------|------------------------|
2024| $HOME/.local/share/vulkan/icd.d | $HOME is the current home directory of the application's user id; this path will be ignored for suid programs |
2025| "/usr/local/etc/vulkan/icd.d" | Directory for locally built ICDs |
2026| "/usr/local/share/vulkan/icd.d" | Directory for locally built ICDs |
2027| "/etc/vulkan/icd.d" | Location of ICDs installed from non-Linux-distribution-provided packages |
2028| "/usr/share/vulkan/icd.d" | Location of ICDs installed from Linux-distribution-provided packages |
2029
2030The Vulkan loader will open each manifest file found to obtain the name or
2031pathname of an ICD shared library (".so") file.
2032
2033See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
2034details.
2035
Mark Young540d71c2017-05-18 14:52:14 -06002036##### Additional Settings For ICD Debugging
2037
2038If you are seeing issues which may be related to the ICD. A possible option to debug is to enable the
2039`LD_BIND_NOW` environment variable. This forces every dynamic library's symbols to be fully resolved on load. If
2040there is a problem with an ICD missing symbols on your system, this will expose it and cause the Vulkan loader
2041to fail on loading the ICD. It is recommended that you enable `LD_BIND_NOW` along with `VK_LOADER_DEBUG=warn`
2042to expose any issues.
2043
Mark Young39389872017-01-19 21:10:49 -07002044#### Using Pre-Production ICDs on Windows and Linux
2045
2046Independent Hardware Vendor (IHV) pre-production ICDs. In some cases, a
2047pre-production ICD may be in an installable package. In other cases, a
2048pre-production ICD may simply be a shared library in the developer's build tree.
2049In this latter case, we want to allow developers to point to such an ICD without
2050modifying the system-installed ICD(s) on their system.
2051
2052This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
2053which will override the mechanism used for finding system-installed ICDs. In
2054other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
2055
2056The "VK\_ICD\_FILENAMES" environment variable is a list of ICD
2057manifest files, containing the full path to the ICD JSON Manifest file. This
2058list is colon-separated on Linux, and semi-colon separated on Windows.
2059
2060Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
2061file for a developer-built ICD. A separator (colon or semi-colon) is only used
2062if more than one ICD is listed.
2063
2064**NOTE:** On Linux, this environment variable will be ignored for suid programs.
2065
2066
2067#### ICD Discovery on Android
2068
2069The Android loader lives in the system library folder. The location cannot be
2070changed. The loader will load the driver/ICD via hw\_get\_module with the ID
2071of "vulkan". **Due to security policies in Android, none of this can be modified
2072under normal use.**
2073
2074
2075### ICD Manifest File Format
2076
2077The following section discusses the details of the ICD Manifest JSON file
2078format. The JSON file itself does not have any requirements for naming. The
2079only requirement is that the extension suffix of the file ends with ".json".
2080
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06002081Here is an example ICD JSON Manifest file:
Mark Young39389872017-01-19 21:10:49 -07002082
2083```
2084{
2085 "file_format_version": "1.0.0",
2086 "ICD": {
2087 "library_path": "path to ICD library",
2088 "api_version": "1.0.5"
2089 }
2090}
2091```
2092
2093| Field Name | Field Value |
2094|----------------|--------------------|
2095| "file\_format\_version" | The JSON format major.minor.patch version number of this file. Currently supported version is 1.0.0. |
2096| "ICD" | The identifier used to group all ICD information together. |
2097| "library_path" | The "library\_path" specifies either a filename, a relative pathname, or a full pathname to a layer shared library file. If "library\_path" specifies a relative pathname, it is relative to the path of the JSON manifest file. If "library\_path" specifies a filename, the library must live in the system's shared object search path. There are no rules about the name of the ICD shared library files other than it should end with the appropriate suffix (".DLL" on Windows, and ".so" on Linux). | N/A |
2098| "api_version" | The major.minor.patch version number of the Vulkan API that the shared library files for the ICD was built against. For example: 1.0.33. |
2099
2100**NOTE:** If the same ICD shared library supports multiple, incompatible
2101versions of text manifest file format versions, it must have separate
2102JSON files for each (all of which may point to the same shared library).
2103
2104##### ICD Manifest File Versions
2105
2106There has only been one version of the ICD manifest files supported. This is
2107version 1.0.0.
2108
2109###### ICD Manifest File Version 1.0.0
2110
2111The initial version of the ICD Manifest file specified the basic format and
2112fields of a layer JSON file. The fields of the 1.0.0 file format include:
2113 * "file\_format\_version"
2114 * "ICD"
2115 * "library\_path"
2116 * "api\_version"
2117
2118
2119### ICD Vulkan Entry-Point Discovery
2120
2121The Vulkan symbols exported by an ICD must not clash with the loader's exported
2122Vulkan symbols. This could be for several reasons. Because of this, all ICDs
2123must export the following function that is used for discovery of ICD Vulkan
2124entry-points. This entry-point is not a part of the Vulkan API itself, only a
2125private interface between the loader and ICDs for version 1 and higher
2126interfaces.
2127
2128```cpp
2129VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
2130 VkInstance instance,
2131 const char* pName);
2132```
2133
2134This function has very similar semantics to `vkGetInstanceProcAddr`.
2135`vk_icdGetInstanceProcAddr` returns valid function pointers for all the global-
2136level and instance-level Vulkan functions, and also for `vkGetDeviceProcAddr`.
2137Global-level functions are those which contain no dispatchable object as the
2138first parameter, such as `vkCreateInstance` and
2139`vkEnumerateInstanceExtensionProperties`. The ICD must support querying global-
2140level entry-points by calling `vk_icdGetInstanceProcAddr` with a NULL
2141`VkInstance` parameter. Instance-level functions are those that have either
2142`VkInstance`, or `VkPhysicalDevice` as the first parameter dispatchable object.
2143Both core entry-points and any instance extension entry-points the ICD supports
2144should be available via `vk_icdGetInstanceProcAddr`. Future Vulkan instance
2145extensions may define and use new instance-level dispatchable objects other
2146than `VkInstance` and `VkPhysicalDevice`, in which case extension entry-points
2147using these newly defined dispatchable objects must be queryable via
2148`vk_icdGetInstanceProcAddr`.
2149
2150All other Vulkan entry-points must either:
2151 * NOT be exported directly from the ICD library
2152 * or NOT use the official Vulkan function names if they are exported
2153
2154This requirement is for ICD libraries that include other
2155functionality (such as OpenGL) and thus could be loaded by the
2156application prior to when the Vulkan loader library is loaded by the
2157application.
2158
2159Beware of interposing by dynamic OS library loaders if the official Vulkan
2160names are used. On Linux, if official names are used, the ICD library must be
2161linked with -Bsymbolic.
2162
2163
2164### ICD Unknown Physical Device Extensions
2165
2166Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
2167result in the following behavior:
2168 1. The loader would check if core function:
2169 - If it was, it would return the function pointer
2170 2. The loader would check if known extension function:
2171 - If it was, it would return the function pointer
2172 3. If the loader knew nothing about it, it would call down using
2173`GetInstanceProcAddr`
2174 - If it returned non-NULL, treat it as an unknown logical device command.
2175 - This meant setting up a generic trampoline function that takes in a
2176VkDevice as the first parameter and adjusting the dispatch table to call the
2177ICD/Layers function after getting the dispatch table from the VkDevice.
2178 4. If all the above failed, the loader would return NULL to the application.
2179
2180This caused problems when an ICD attempted to expose new physical device
2181extensions the loader knew nothing about, but an application did. Because the
2182loader knew nothing about it, the loader would get to step 3 in the above
2183process and would treat the function as an unknown logical device command. The
2184problem is, this would create a generic VkDevice trampoline function which, on
2185the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
2186This would lead to a crash or corruption.
2187
2188In order to identify the extension entry-points specific to physical device
2189extensions, the following function can be added to an ICD:
2190
2191```cpp
2192PFN_vkVoidFunction vk_icdGetPhysicalDeviceProcAddr(VkInstance instance,
2193 const char* pName);
2194```
2195
2196This function behaves similar to `vkGetInstanceProcAddr` and
2197`vkGetDeviceProcAddr` except it should only return values for physical device
2198extension entry-points. In this way, it compares "pName" to every physical
2199device function supported in the ICD.
2200
2201The following rules apply:
Lenny Komowde3924a2017-05-04 14:50:01 -06002202* If it is the name of a physical device function supported by the ICD, the
Mark Young39389872017-01-19 21:10:49 -07002203pointer to the ICD's corresponding function should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06002204* If it is the name of a valid function which is **not** a physical device
Mark Young39389872017-01-19 21:10:49 -07002205function (i.e. an Instance, Device, or other function implemented by the ICD),
2206then the value of NULL should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06002207* If the ICD has no idea what this function is, it should return NULL.
Mark Young39389872017-01-19 21:10:49 -07002208
2209This support is optional and should not be considered a requirement. This is
2210only required if an ICD intends to support some functionality not directly
2211supported by a significant population of loaders in the public. If an ICD
Mark Young18bbaab2017-03-20 08:27:14 -06002212does implement this support, it should return the address of its
Mark Young39389872017-01-19 21:10:49 -07002213`vk_icdGetPhysicalDeviceProcAddr` function through the `vkGetInstanceProcAddr`
2214function.
2215
2216The new behavior of the loader's vkGetInstanceProcAddr with support for the
2217`vk_icdGetPhysicalDeviceProcAddr` function is as follows:
2218 1. Check if core function:
2219 - If it is, return the function pointer
2220 2. Check if known instance or device extension function:
2221 - If it is, return the function pointer
2222 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
2223 - If it returns non-NULL, return a trampoline to a generic physical device
2224function, and setup a generic terminator which will pass it to the proper ICD.
2225 4. Call down using `GetInstanceProcAddr`
2226 - If it returns non-NULL, treat it as an unknown logical device command.
2227This means setting up a generic trampoline function that takes in a VkDevice as
2228the first parameter and adjusting the dispatch table to call the ICD/Layers
2229function after getting the dispatch table from the VkDevice. Then, return the
2230pointer to corresponding trampoline function.
2231 5. Return NULL
2232
2233You can see now, that, if the command gets promoted to core later, it will no
2234longer be setup using `vk_icdGetPhysicalDeviceProcAddr`. Additionally, if the
2235loader adds direct support for the extension, it will no longer get to step 3,
2236because step 2 will return a valid function pointer. However, the ICD should
2237continue to support the command query via `vk_icdGetPhysicalDeviceProcAddr`,
2238until at least a Vulkan version bump, because an older loader may still be
2239attempting to use the commands.
2240
2241
2242### ICD Dispatchable Object Creation
2243
2244As previously covered, the loader requires dispatch tables to be accessible
2245within Vulkan dispatchable objects, such as: `VkInstance`, `VkPhysicalDevice`,
2246`VkDevice`, `VkQueue`, and `VkCommandBuffer`. The specific requirements on all
2247dispatchable objects created by ICDs are as follows:
2248
2249- All dispatchable objects created by an ICD can be cast to void \*\*
2250- The loader will replace the first entry with a pointer to the dispatch table
2251 which is owned by the loader. This implies three things for ICD drivers
2252 1. The ICD must return a pointer for the opaque dispatchable object handle
2253 2. This pointer points to a regular C structure with the first entry being a
2254 pointer.
2255 * **NOTE:** For any C\++ ICD's that implement VK objects directly as C\++
2256classes.
2257 * The C\++ compiler may put a vtable at offset zero if your class is non-
2258POD due to the use of a virtual function.
2259 * In this case use a regular C structure (see below).
2260 3. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
2261 dispatchable objects, as follows (see `include/vulkan/vk_icd.h`):
2262
2263```cpp
2264#include "vk_icd.h"
2265
2266union _VK_LOADER_DATA {
2267 uintptr loadermagic;
2268 void *loaderData;
2269} VK_LOADER_DATA;
2270
2271vkObj alloc_icd_obj()
2272{
2273 vkObj *newObj = alloc_obj();
2274 ...
2275 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
2276
2277 set_loader_magic_value(newObj);
2278 ...
2279 return newObj;
2280}
2281```
2282
2283
2284### Handling KHR Surface Objects in WSI Extensions
2285
2286Normally, ICDs handle object creation and destruction for various Vulkan
2287objects. The WSI surface extensions for Linux and Windows
2288("VK\_KHR\_win32\_surface", "VK\_KHR\_xcb\_surface", "VK\_KHR\_xlib\_surface",
2289"VK\_KHR\_mir\_surface", "VK\_KHR\_wayland\_surface", and "VK\_KHR\_surface")
2290are handled differently. For these extensions, the `VkSurfaceKHR` object
2291creation and destruction may be handled by either the loader, or an ICD.
2292
2293If the loader handles the management of the `VkSurfaceKHR` objects:
2294 1. The loader will handle the calls to `vkCreateXXXSurfaceKHR` and
2295`vkDestroySurfaceKHR`
2296 functions without involving the ICDs.
2297 * Where XXX stands for the Windowing System name:
2298 * Mir
2299 * Wayland
2300 * Xcb
2301 * Xlib
2302 * Windows
2303 * Android
2304 2. The loader creates a `VkIcdSurfaceXXX` object for the corresponding
2305`vkCreateXXXSurfaceKHR` call.
2306 * The `VkIcdSurfaceXXX` structures are defined in `include/vulkan/vk_icd.h`.
2307 3. ICDs can cast any `VkSurfaceKHR` object to a pointer to the appropriate
2308 `VkIcdSurfaceXXX` structure.
2309 4. The first field of all the `VkIcdSurfaceXXX` structures is a
2310`VkIcdSurfaceBase` enumerant that indicates whether the
2311 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
2312
2313The ICD may choose to handle `VkSurfaceKHR` object creation instead. If an ICD
2314desires to handle creating and destroying it must do the following:
2315 1. Support version 3 or newer of the loader/ICD interface.
2316 2. Export and handle all functions that take in a `VkSurfaceKHR` object,
2317including:
2318 * `vkCreateXXXSurfaceKHR`
2319 * `vkGetPhysicalDeviceSurfaceSupportKHR`
2320 * `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2321 * `vkGetPhysicalDeviceSurfaceFormatsKHR`
2322 * `vkGetPhysicalDeviceSurfacePresentModesKHR`
2323 * `vkCreateSwapchainKHR`
2324 * `vkDestroySurfaceKHR`
2325
2326Because the `VkSurfaceKHR` object is an instance-level object, one object can be
2327associated with multiple ICDs. Therefore, when the loader receives the
2328`vkCreateXXXSurfaceKHR` call, it still creates an internal `VkSurfaceIcdXXX`
2329object. This object acts as a container for each ICD's version of the
2330`VkSurfaceKHR` object. If an ICD does not support the creation of its own
2331`VkSurfaceKHR` object, the loader's container stores a NULL for that ICD. On
2332the otherhand, if the ICD does support `VkSurfaceKHR` creation, the loader will
2333make the appropriate `vkCreateXXXSurfaceKHR` call to the ICD, and store the
2334returned pointer in it's container object. The loader then returns the
2335`VkSurfaceIcdXXX` as a `VkSurfaceKHR` object back up the call chain. Finally,
2336when the loader receives the `vkDestroySurfaceKHR` call, it subsequently calls
2337`vkDestroySurfaceKHR` for each ICD who's internal `VkSurfaceKHR` object is not
2338NULL. Then the loader destroys the container object before returning.
2339
2340
2341### Loader and ICD Interface Negotiation
2342
2343Generally, for functions issued by an application, the loader can be
2344viewed as a pass through. That is, the loader generally doesn't modify the
2345functions or their parameters, but simply calls the ICDs entry-point for that
2346function. There are specific additional interface requirements an ICD needs to
2347comply with that are not part of any requirements from the Vulkan specification.
2348These addtional requirements are versioned to allow flexibility in the future.
2349
2350
2351#### Windows and Linux ICD Negotiation
2352
2353
2354##### Version Negotiation Between Loader and ICDs
2355
2356All ICDs (supporting interface version 2 or higher) must export the following
2357function that is used for determination of the interface version that will be
2358used. This entry-point is not a part of the Vulkan API itself, only a private
2359interface between the loader and ICDs.
2360
2361```cpp
2362 VKAPI_ATTR VkResult VKAPI_CALL
2363 vk_icdNegotiateLoaderICDInterfaceVersion(
2364 uint32_t* pSupportedVersion);
2365```
2366
2367This function allows the loader and ICD to agree on an interface version to use.
2368The "pSupportedVersion" parameter is both an input and output parameter.
2369"pSupportedVersion" is filled in by the loader with the desired latest interface
2370version supported by the loader (typically the latest). The ICD receives this
2371and returns back the version it desires in the same field. Because it is
2372setting up the interface version between the loader and ICD, this should be
2373the first call made by a loader to the ICD (even prior to any calls to
2374`vk_icdGetInstanceProcAddr`).
2375
2376If the ICD receiving the call no longer supports the interface version provided
2377by the loader (due to deprecation), then it should report
2378VK_ERROR_INCOMPATIBLE_DRIVER error. Otherwise it sets the value pointed by
2379"pSupportedVersion" to the latest interface version supported by both the ICD
2380and the loader and returns VK_SUCCESS.
2381
2382The ICD should report VK_SUCCESS in case the loader provided interface version
2383is newer than that supported by the ICD, as it's the loader's responsibility to
2384determine whether it can support the older interface version supported by the
2385ICD. The ICD should also report VK_SUCCESS in the case its interface version
2386is greater than the loader's, but return the loader's version. Thus, upon
2387return of VK_SUCCESS the "pSupportedVersion" will contain the desired interface
2388version to be used by the ICD.
2389
2390If the loader receives an interface version from the ICD that the loader no
2391longer supports (due to deprecation), or it receives a
2392VK_ERROR_INCOMPATIBLE_DRIVER error instead of VK_SUCCESS, then the loader will
2393treat the ICD as incompatible and will not load it for use. In this case, the
2394application will not see the ICDs `vkPhysicalDevice` during enumeration.
2395
2396###### Interfacing With Legacy ICDs or Loader
2397
2398If a loader sees that an ICD does not export the
2399`vk_icdNegotiateLoaderICDInterfaceVersion` function, then the loader assumes the
2400corresponding ICD only supports either interface version 0 or 1.
2401
2402From the other side of the interface, if an ICD sees a call to
2403`vk_icdGetInstanceProcAddr` before a call to
Tobin Ehlisfde57082017-10-23 16:22:42 -06002404`vk_icdNegotiateLoaderICDInterfaceVersion`, then it knows that loader making the calls
Mark Young39389872017-01-19 21:10:49 -07002405is a legacy loader supporting version 0 or 1. If the loader calls
2406`vk_icdGetInstanceProcAddr` first, it supports at least version 1. Otherwise,
2407the loader only supports version 0.
2408
2409
Mark Young02df1a82017-04-18 19:52:18 -06002410##### Loader Version 5 Interface Requirements
2411
2412Version 5 of the loader/ICD interface has no changes to the actual interface.
2413If the loader requests interface version 5 or greater, it is simply
2414an indication to ICDs that the loader is now evaluating if the API Version info
2415passed into vkCreateInstance is a valid version for the loader. If it is not,
2416the loader will catch this during vkCreateInstance and fail with a
2417VK_ERROR_INCOMPATIBLE_DRIVER error.
2418
2419On the other hand, if version 5 or newer is not requested by the loader, then it
2420indicates to the ICD that the loader is ignorant of the API version being
2421requested. Because of this, it falls on the ICD to validate that the API
2422Version is not greater than major = 1 and minor = 0. If it is, then the ICD
2423should automatically fail with a VK_ERROR_INCOMPATIBLE_DRIVER error since the
2424loader is a 1.0 loader, and is unaware of the version.
2425
2426Here is a table of the expected behaviors:
2427
2428| Loader Supports I/f Version | ICD Supports I/f Version | Result |
2429| :---: |:---:|------------------------|
2430| <= 4 | <= 4 | ICD must fail with `VK_ERROR_INCOMPATIBLE_DRIVER` for all vkCreateInstance calls with apiVersion set to > Vulkan 1.0 because both the loader and ICD support interface version <= 4. Otherwise, the ICD should behave as normal. |
2431| <= 4 | >= 5 | ICD must fail with `VK_ERROR_INCOMPATIBLE_DRIVER` for all vkCreateInstance calls with apiVersion set to > Vulkan 1.0 because the loader is still at interface version <= 4. Otherwise, the ICD should behave as normal. |
2432| >= 5 | <= 4 | Loader will fail with `VK_ERROR_INCOMPATIBLE_DRIVER` if it can't handle the apiVersion. ICD may pass for all apiVersions, but since it's interface is <= 4, it is best if it assumes it needs to do the work of rejecting anything > Vulkan 1.0 and fail with `VK_ERROR_INCOMPATIBLE_DRIVER`. Otherwise, the ICD should behave as normal. |
2433| >= 5 | >= 5 | Loader will fail with `VK_ERROR_INCOMPATIBLE_DRIVER` if it can't handle the apiVersion, and ICDs should fail with `VK_ERROR_INCOMPATIBLE_DRIVER` **only if** they can not support the specified apiVersion. Otherwise, the ICD should behave as normal. |
2434
Mark Young39389872017-01-19 21:10:49 -07002435##### Loader Version 4 Interface Requirements
2436
2437The major change to version 4 of the loader/ICD interface is the support of
2438[Unknown Physical Device Extensions](#icd-unknown-physical-device-
2439extensions] using the `vk_icdGetPhysicalDeviceProcAddr` function. This
2440function is purely optional. However, if an ICD supports a Physical Device
2441extension, it must provide a `vk_icdGetPhysicalDeviceProcAddr` function.
2442Otherwise, the loader will continue to treat any unknown functions as VkDevice
2443functions and cause invalid behavior.
2444
2445
2446##### Loader Version 3 Interface Requirements
2447
2448The primary change that occurred in version 3 of the loader/ICD interface was to
2449allow an ICD to handle creation/destruction of their own KHR_surfaces. Up until
2450this point, the loader created a surface object that was used by all ICDs.
2451However, some ICDs may want to provide their own surface handles. If an ICD
2452chooses to enable this support, it must export support for version 3 of the
2453loader/ICD interface, as well as any Vulkan function that uses a KHR_surface
2454handle, such as:
2455- `vkCreateXXXSurfaceKHR` (where XXX is the platform specific identifier [i.e.
2456`vkCreateWin32SurfaceKHR` for Windows])
2457- `vkDestroySurfaceKHR`
2458- `vkCreateSwapchainKHR`
2459- `vkGetPhysicalDeviceSurfaceSupportKHR`
2460- `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2461- `vkGetPhysicalDeviceSurfaceFormatsKHR`
2462- `vkGetPhysicalDeviceSurfacePresentModesKHR`
2463
2464An ICD can still choose to not take advantage of this functionality by simply
2465not exposing the above the `vkCreateXXXSurfaceKHR` and `vkDestroySurfaceKHR`
2466functions.
2467
2468
2469##### Loader Version 2 Interface Requirements
2470
2471Version 2 interface has requirements in three areas:
2472 1. ICD Vulkan entry-point discovery,
2473 2. `KHR_surface` related requirements in the WSI extensions,
2474 3. Vulkan dispatchable object creation requirements.
2475
2476##### Loader Versions 0 and 1 Interface Requirements
2477
2478Version 0 and 1 interfaces do not support version negotiation via
2479`vk_icdNegotiateLoaderICDInterfaceVersion`. ICDs can distinguish version 0 and
2480version 1 interfaces as follows: if the loader calls `vk_icdGetInstanceProcAddr`
2481first it supports version 1; otherwise the loader only supports version 0.
2482
2483Version 0 interface does not support `vk_icdGetInstanceProcAddr`. Version 0
2484interface requirements for obtaining ICD Vulkan entry-points are as follows:
2485
2486- The function `vkGetInstanceProcAddr` **must be exported** in the ICD library
2487and returns valid function pointers for all the Vulkan API entry-points.
2488- `vkCreateInstance` **must be exported** by the ICD library.
2489- `vkEnumerateInstanceExtensionProperties` **must be exported** by the ICD
2490library.
2491
2492Additional Notes:
2493
2494- The loader will filter out extensions requested in `vkCreateInstance` and
2495`vkCreateDevice` before calling into the ICD; Filtering will be of extensions
2496advertised by entities (e.g. layers) different from the ICD in question.
2497- The loader will not call the ICD for `vkEnumerate\*LayerProperties`() as layer
2498properties are obtained from the layer libraries and layer JSON files.
2499- If an ICD library author wants to implement a layer, it can do so by having
2500the appropriate layer JSON manifest file refer to the ICD library file.
2501- The loader will not call the ICD for
2502 `vkEnumerate\*ExtensionProperties` if "pLayerName" is not equal to `NULL`.
2503- ICDs creating new dispatchable objects via device extensions need to
2504initialize the created dispatchable object. The loader has generic *trampoline*
2505code for unknown device extensions. This generic *trampoline* code doesn't
2506initialize the dispatch table within the newly created object. See the
2507[Creating New Dispatchable Objects](#creating-new-dispatchable-objects) section
2508for more information on how to initialize created dispatchable objects for
2509extensions non known by the loader.
2510
2511
2512#### Android ICD Negotiation
2513
2514The Android loader uses the same protocol for initializing the dispatch
2515table as described above. The only difference is that the Android
2516loader queries layer and extension information directly from the
2517respective libraries and does not use the json manifest files used
2518by the Windows and Linux loaders.
2519
Mark Young540d71c2017-05-18 14:52:14 -06002520## Table of Debug Environment Variables
2521
2522The following are all the Debug Environment Variables available for use with the
2523Loader. These are referenced throughout the text, but collected here for ease
2524of discovery.
2525
2526| Environment Variable | Behavior | Example Format |
Mark Young02df1a82017-04-18 19:52:18 -06002527|:---:|---------------------|----------------------|
Mark Young540d71c2017-05-18 14:52:14 -06002528| VK_ICD_FILENAMES | Force the loader to use the specific ICD JSON files. The value should contain a list of delimited full path listings to ICD JSON Manifest files. **NOTE:** If you fail to use the global path to a JSON file, you may encounter issues. | `export VK_ICD_FILENAMES=<folder_a>\intel.json:<folder_b>\amd.json`<br/><br/>`set VK_ICD_FILENAMES=<folder_a>\nvidia.json;<folder_b>\mesa.json` |
2529| VK_INSTANCE_LAYERS | Force the loader to add the given layers to the list of Enabled layers normally passed into `vkCreateInstance`. These layers are added first, and the loader will remove any duplicate layers that appear in both this list as well as that passed into `ppEnabledLayerNames`. | `export VK_INSTANCE_LAYERS=<layer_a>:<layer_b>`<br/><br/>`set VK_INSTANCE_LAYERS=<layer_a>;<layer_b>` |
2530| VK_LAYER_PATH | Override the loader's standard Layer library search folders and use the provided delimited folders to search for layer Manifest files. | `export VK_LAYER_PATH=<path_a>:<path_b>`<br/><br/>`set VK_LAYER_PATH=<path_a>;<pathb>` |
2531| VK_LOADER_DISABLE_INST_EXT_FILTER | Disable the filtering out of instance extensions that the loader doesn't know about. This will allow applications to enable instance extensions exposed by ICDs but that the loader has no support for. **NOTE:** This may cause the loader or applciation to crash. | `export VK_LOADER_DISABLE_INST_EXT_FILTER=1`<br/><br/>`set VK_LOADER_DISABLE_INST_EXT_FILTER=1` |
2532| VK_LOADER_DEBUG | Enable loader debug messages. Options are:<br/>- error (only errors)<br/>- warn (warnings and errors)<br/>- info (info, warning, and errors)<br/> - debug (debug + all before) <br/> -all (report out all messages) | `export VK_LOADER_DEBUG=all`<br/><br/>`set VK_LOADER_DEBUG=warn` |
Mark Young39389872017-01-19 21:10:49 -07002533
2534## Glossary of Terms
2535
2536| Field Name | Field Value |
Mark Young02df1a82017-04-18 19:52:18 -06002537|:---:|--------------------|
Mark Young39389872017-01-19 21:10:49 -07002538| Android Loader | The loader designed to work primarily for the Android OS. This is generated from a different code-base than the desktop loader. But, in all important aspects, should be functionally equivalent. |
2539| Desktop Loader | The loader designed to work on both Windows and Linux. This is generated from a different [code-base](#https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers) than the Android loader. But in all important aspects, should be functionally equivalent. |
2540| Core Function | A function that is already part of the Vulkan core specification and not an extension. For example, vkCreateDevice(). |
2541| Device Call Chain | The call chain of functions followed for device functions. This call chain for a device function is usually as follows: first the application calls into a loader trampoline, then the loader trampoline calls enabled layers, the final layer calls into the ICD specific to the device. See the [Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) section for more information |
2542| Device Function | A Device function is any Vulkan function which takes a `VkDevice`, `VkQueue`, `VkCommandBuffer`, or any child of these, as its first parameter. Some Vulkan Device functions are: `vkQueueSubmit`, `vkBeginCommandBuffer`, `vkCreateEvent`. See the [Instance Versus Device](#instance-versus-device) section for more information. |
2543| Discovery | The process of the loader searching for ICD and Layer files to setup the internal list of Vulkan objects available. On Windows/Linux, the discovery process typically focuses on searching for Manifest files. While on Android, the process focuses on searching for library files. |
2544| Dispatch Table | An array of function pointers (including core and possibly extension functions) used to step to the next entity in a call chain. The entity could be the loader, a layer or an ICD. See [Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) for more information. |
2545| Extension | A concept of Vulkan used to expand the core Vulkan functionality. Extensions may be IHV-specific, platform-specific, or more broadly available. You should always query if an extension exists, and enable it during `vkCreateInstance` (if it is an instance extension) or during `vkCreateDevice` (if it is a device extension). |
2546| ICD | Acronym for Installable Client Driver. These are drivers that are provided by IHVs to interact with the hardware they provide. See [Installable Client Drivers](#installable-client-drivers) section for more information.
2547| IHV | Acronym for an Independent Hardware Vendor. Typically the company that built the underlying hardware technology you are trying to use. A typical examples for a Graphics IHV are: AMD, ARM, Imagination, Intel, Nvidia, Qualcomm, etc. |
2548| Instance Call Chain | The call chain of functions followed for instance functions. This call chain for an instance function is usually as follows: first the application calls into a loader trampoline, then the loader trampoline calls enabled layers, the final layer calls a loader terminator, and the loader terminator calls all available ICDs. See the [Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) section for more information |
2549| Instance Function | An Instance function is any Vulkan function which takes as its first parameter either a `VkInstance` or a `VkPhysicalDevice` or nothing at all. Some Vulkan Instance functions are: `vkEnumerateInstanceExtensionProperties`, `vkEnumeratePhysicalDevices`, `vkCreateInstance`, `vkDestroyInstance`. See the [Instance Versus Device](#instance-versus-device) section for more information. |
2550| Layer | Layers are optional components that augment the Vulkan system. They can intercept, evaluate, and modify existing Vulkan functions on their way from the application down to the hardware. See the [Layers](#layers) section for more information. |
2551| Loader | The middle-ware program which acts as the mediator between Vulkan applications, Vulkan layers and Vulkan drivers. See [The Loader](#the loader) section for more information. |
2552| Manifest Files | Data files in JSON format used by the desktop loader. These files contain specific information for either a [Layer](#layer-manifest-file-format) or an [ICD](#icd-manifest-file-format).
2553| Terminator Function | The last function in the instance call chain above the ICDs and owned by the loader. This function is required in the instance call chain because all instance functionality must be communicated to all ICDs capable of receiving the call. See [Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) for more information. |
2554| Trampoline Function | The first function in an instance or device call chain owned by the loader which handles the setup and proper call chain walk using the appropriate dispatch table. On device functions (in the device call chain) this function can actually be skipped. See [Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) for more information. |
2555| WSI Extension | Acronym for Windowing System Integration. A Vulkan extension targeting a particular Windowing and designed to interface between the Windowing system and Vulkan. See [WSI Extensions](#wsi-extensions) for more information. |