blob: e61619c3244362085d19059dc980e7bfee85b0fd [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 Komow32846e52017-12-27 15:32:44 -070029 * [Pre-Instance Functions](#pre-instance-functions)
Lenny Komowde3924a2017-05-04 14:50:01 -060030 * [Special Considerations](#special-considerations)
31 * [Layer Manifest File Format](#layer-manifest-file-format)
32 * [Layer Library Versions](#layer-library-versions)
Jon Ashburnc2972682016-02-08 15:42:01 -070033
Lenny Komowde3924a2017-05-04 14:50:01 -060034 * [Vulkan Installable Client Driver interface with the loader](#vulkan-installable-client-driver-interface-with-the-loader)
35 * [ICD Discovery](#icd-discovery)
36 * [ICD Manifest File Format](#icd-manifest-file-format)
37 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
38 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
39 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
40 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
41 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
Mark Young540d71c2017-05-18 14:52:14 -060042
43 * [Table of Debug Environment Variables](#table-of-debug-environment-variables)
Lenny Komowde3924a2017-05-04 14:50:01 -060044 * [Glossary of Terms](#glossary-of-terms)
Mark Young39389872017-01-19 21:10:49 -070045
46## Overview
Mark Youngcb6e6702016-07-20 11:38:53 -060047
Mark Young39389872017-01-19 21:10:49 -070048Vulkan is a layered architecture, made up of the following elements:
Lenny Komowde3924a2017-05-04 14:50:01 -060049 * The Vulkan Application
50 * [The Vulkan Loader](#the-loader)
51 * [Vulkan Layers](#layers)
52 * [Installable Client Drivers (ICDs)](#installable-client-drivers)
Jon Ashburnc2972682016-02-08 15:42:01 -070053
Mark Young39389872017-01-19 21:10:49 -070054![High Level View of Loader](./images/high_level_loader.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070055
Mark Young39389872017-01-19 21:10:49 -070056The general concepts in this document are applicable to the loaders available
57for Windows, Linux and Android based systems.
Jon Ashburnc2972682016-02-08 15:42:01 -070058
59
Mark Young39389872017-01-19 21:10:49 -070060#### Who Should Read This Document
Jon Ashburnc2972682016-02-08 15:42:01 -070061
Mark Young39389872017-01-19 21:10:49 -070062While this document is primarily targeted at developers of Vulkan applications,
63drivers and layers, the information contained in it could be useful to anyone
64wanting a better understanding of the Vulkan runtime.
Jon Ashburnc2972682016-02-08 15:42:01 -070065
Jon Ashburnc2972682016-02-08 15:42:01 -070066
Mark Young39389872017-01-19 21:10:49 -070067#### The Loader
Jon Ashburnc2972682016-02-08 15:42:01 -070068
Jeff Juliano18e50202017-01-31 16:36:18 -050069The application sits on one end of, and interfaces directly with, the
70loader. On the other end of the loader from the application are the ICDs, which
Mark Young39389872017-01-19 21:10:49 -070071control the Vulkan-capable hardware. An important point to remember is that
Jeff Juliano18e50202017-01-31 16:36:18 -050072Vulkan-capable hardware can be graphics-based, compute-based, or both. Between
73the application and the ICDs the loader can inject a number of optional
74[layers](#layers) that provide special functionality.
Mark Youngcb6e6702016-07-20 11:38:53 -060075
76The loader is responsible for working with the various layers as well as
Mark Young39389872017-01-19 21:10:49 -070077supporting multiple GPUs and their drivers. Any Vulkan function may
Mark Youngcb6e6702016-07-20 11:38:53 -060078wind up calling into a diverse set of modules: loader, layers, and ICDs.
79The loader is critical to managing the proper dispatching of Vulkan
Mark Young39389872017-01-19 21:10:49 -070080functions to the appropriate set of layers and ICDs. The Vulkan object
Mark Youngcb6e6702016-07-20 11:38:53 -060081model allows the loader to insert layers into a call chain so that the layers
Mark Young39389872017-01-19 21:10:49 -070082can process Vulkan functions prior to the ICD being called.
83
84This document is intended to provide an overview of the necessary interfaces
85between each of these.
86
87
88##### Goals of the Loader
89
90The loader was designed with the following goals in mind.
91 1. Support one or more Vulkan-capable ICD on a user's computer system without
92them interfering with one another.
93 2. Support Vulkan Layers which are optional modules that can be enabled by an
94application, developer, or standard system settings.
95 3. Impact the overall performance of a Vulkan application in the lowest
96possible fashion.
97
98
99#### Layers
100
101Layers are optional components that augment the Vulkan system. They can
102intercept, evaluate, and modify existing Vulkan functions on their way from the
103application down to the hardware. Layers are implemented as libraries that can
104be enabled in different ways (including by application request) and are loaded
105during CreateInstance. Each layer can choose to hook (intercept) any Vulkan
106functions which in turn can be ignored or augmented. A layer does not need to
107intercept all Vulkan functions. It may choose to intercept all known functions,
108or, it may choose to intercept only one function.
109
110Some examples of features that layers may expose include:
111 * Validating API usage
112 * Adding the ability to perform Vulkan API tracing and debugging
113 * Overlay additional content on the applications surfaces
114
115Because layers are optionally, you may choose to enable layers for debugging
116your application, but then disable any layer usage when you release your
117product.
118
119
120#### Installable Client Drivers
121
122Vulkan allows multiple Installable Client Drivers (ICDs) each supporting one
123or more devices (represented by a Vulkan `VkPhysicalDevice` object) to be used
124collectively. The loader is responsible for discovering available Vulkan ICDs on
125the system. Given a list of available ICDs, the loader can enumerate all the
126physical devices available for an application and return this information to
127the application.
128
129
130#### Instance Versus Device
131
132There is an important concept which you will see brought up repeatedly
133throughout this document. Many functions, extensions, and other things in
134Vulkan are separated into two main groups:
135 * Instance-related Objects
136 * Device-related Objects
137
138
139##### Instance-related Objects
140
141A Vulkan Instance is a high-level construct used to provide Vulkan system-level
142information, or functionality. Vulkan objects associated directly with an
143instance are:
144 * `VkInstance`
145 * `VkPhysicalDevice`
146
147An Instance function is any Vulkan function which takes as its first parameter
148either an object from the Instance list, or nothing at all. Some Vulkan
149Instance functions are:
150 * `vkEnumerateInstanceExtensionProperties`
151 * `vkEnumeratePhysicalDevices`
152 * `vkCreateInstance`
153 * `vkDestroyInstance`
154
155You query Vulkan Instance functions using `vkGetInstanceProcAddr`.
156`vkGetInstanceProcAddr` can be used to query either device or instance entry-
157points in addition to all core entry-points. The returned function pointer is
158valid for this Instance and any object created under this Instance (including
159all `VkDevice` objects).
160
161Similarly, an Instance extension is a set of Vulkan Instance functions extending
162the Vulkan language. These will be discussed in more detail later.
163
164
165##### Device-related Objects
166
167A Vulkan Device, on the other-hand, is a logical identifier used to associate
168functions with a particular physical device on a user's system. Vulkan
169constructs associated directly with a device include:
170 * `VkDevice`
171 * `VkQueue`
172 * `VkCommandBuffer`
173 * Any dispatchable object that is a child of a one of the above.
174
175A Device function is any Vulkan function which takes any Device Object as its
176first parameter. Some Vulkan Device functions are:
177 * `vkQueueSubmit`
178 * `vkBeginCommandBuffer`
179 * `vkCreateEvent`
180
181You can query Vulkan Device functions using either `vkGetInstanceProcAddr` or
182`vkGetDeviceProcAddr`. If you choose to use `vkGetInstanceProcAddr`, it will
183have an additional level built into the call chain, which will reduce
184performance slightly. However, the function pointer returned can be used for
185any device created later, as long as it is associated with the same Vulkan
186Instance. If, instead you use `vkGetDeviceProcAddr`, the call chain will be more
187optimized to the specific device, but it will **only** work for the device used
188to query the function function pointer. Also, unlike `vkGetInstanceProcAddr`,
189`vkGetDeviceProcAddr` can only be used on core Vulkan Device functions, or
190Device extension functions.
191
192The best solution is to query Instance extension functions using
193`vkGetInstanceProcAddr`, and to query Device extension functions using
194`vkGetDeviceProcAddr`. See
195[Best Application Performance Setup](#best-application-performance-setup) for
196more information on this.
197
198As with Instance extensions, a Device extension is a set of Vulkan Device
199functions extending the Vulkan language. You can read more about these later in
200the document.
201
202
203#### Dispatch Tables and Call Chains
Jon Ashburnc2972682016-02-08 15:42:01 -0700204
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700205Vulkan uses an object model to control the scope of a particular action /
206operation. The object to be acted on is always the first parameter of a Vulkan
Mark Young6d026a72016-06-01 17:49:30 -0600207call and is a dispatchable object (see Vulkan specification section 2.3 Object
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700208Model). Under the covers, the dispatchable object handle is a pointer to a
Mark Youngcb6e6702016-07-20 11:38:53 -0600209structure, which in turn, contains a pointer to a dispatch table maintained by
Mark Young39389872017-01-19 21:10:49 -0700210the loader. This dispatch table contains pointers to the Vulkan functions
211appropriate to that object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700212
Mark Youngcb6e6702016-07-20 11:38:53 -0600213There are two types of dispatch tables the loader maintains:
Mark Young39389872017-01-19 21:10:49 -0700214 - Instance Dispatch Table
215 - Created in the loader during the call to `vkCreateInstance`
216 - Device Dispatch Table
217 - Created in the loader during the call to `vkCreateDevice`
Jon Ashburnc2972682016-02-08 15:42:01 -0700218
Mark Young39389872017-01-19 21:10:49 -0700219At that time the application and/or system can specify optional layers to be
220included. The loader will initialize the specified layers to create a call
221chain for each Vulkan function and each entry of the dispatch table will point
222to the first element of that chain. Thus, the loader builds an instance call
223chain for each `VkInstance` that is created and a device call chain for each
224`VkDevice` that is created.
225
226When an application calls a Vulkan function, this typically will first hit a
227*trampoline* function in the loader. These *trampoline* functions are small,
228simple functions that jump to the appropriate dispatch table entry for the
229object they are given. Additionally, for functions in the instance call chain,
230the loader has an additional function, called a *terminator*, which is called
231after all enabled layers to marshall the appropriate information to all
232available ICDs.
233
234
235##### Instance Call Chain Example
Jon Ashburnc2972682016-02-08 15:42:01 -0700236
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700237For example, the diagram below represents what happens in the call chain for
Mark Young39389872017-01-19 21:10:49 -0700238`vkCreateInstance`. After initializing the chain, the loader will call into the
239first layer's `vkCreateInstance` which will call the next finally terminating in
240the loader again where this function calls every ICD's `vkCreateInstance` and
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700241saves the results. This allows every enabled layer for this chain to set up
Mark Young39389872017-01-19 21:10:49 -0700242what it needs based on the `VkInstanceCreateInfo` structure from the
243application.
244
245![Instance Call Chain](./images/loader_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700246
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700247This also highlights some of the complexity the loader must manage when using
Mark Young39389872017-01-19 21:10:49 -0700248instance call chains. As shown here, the loader's *terminator* must aggregate
249information to and from multiple ICDs when they are present. This implies that
250the loader has to be aware of any instance-level extensions which work on a
251`VkInstance` to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -0700252
Mark Young39389872017-01-19 21:10:49 -0700253
254##### Device Call Chain Example
255
256Device call chains are created at `vkCreateDevice` and are generally simpler
257because they deal with only a single device and the ICD can always be the
258*terminator* of the chain.
259
260![Loader Device Call Chain](./images/loader_device_chain_loader.png)
261
Jon Ashburnc2972682016-02-08 15:42:01 -0700262
Mark Youngcb6e6702016-07-20 11:38:53 -0600263<br/>
Mark Young39389872017-01-19 21:10:49 -0700264<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600265
Mark Young39389872017-01-19 21:10:49 -0700266## Application Interface to the Loader
Jon Ashburnc2972682016-02-08 15:42:01 -0700267
Mark Young39389872017-01-19 21:10:49 -0700268In this section we'll discuss how an application interacts with the loader,
269including:
Lenny Komowde3924a2017-05-04 14:50:01 -0600270 * [Interfacing with Vulkan Functions](#interfacing-with-vulkan-functions)
271 * [Vulkan Direct Exports](#vulkan-direct-exports)
272 * [Directly Linking to the Loader](#directly-linking-to-the-loader)
273 * [Dynamic Linking](#dynamic-linking)
274 * [Static Linking](#static-linking)
275 * [Indirectly Linking to the Loader](#indirectly-linking-to-the-loader)
276 * [Best Application Performance Setup](#best-application-performance-setup)
277 * [ABI Versioning](#abi-versioning)
278 * [Application Layer Usage](#application-layer-usage)
279 * [Implicit vs Explicit Layers](#implicit-vs-explicit-layers)
280 * [Forcing Layer Source Folders](#forcing-layer-source-folders)
281 * [Forcing Layers to be Enabled](#forcing-layers-to-be-enabled)
282 * [Overall Layer Ordering](#overall-layer-ordering)
283 * [Application Usage of Extensions](#application-usage-of-extensions)
284 * [Instance and Device Extensions](#instance-and-device-extensions)
285 * [WSI Extensions](#wsi-extensions)
286 * [Unknown Extensions](#unknown-extensions)
Jon Ashburnc2972682016-02-08 15:42:01 -0700287
Mark Young39389872017-01-19 21:10:49 -0700288
289#### Interfacing with Vulkan Functions
290There are several ways you can interface with Vulkan functions through the
291loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700292
Jon Ashburnc2972682016-02-08 15:42:01 -0700293
Mark Young39389872017-01-19 21:10:49 -0700294##### Vulkan Direct Exports
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700295The loader library on Windows, Linux and Android will export all core Vulkan
296and all appropriate Window System Interface (WSI) extensions. This is done to
297make it simpler to get started with Vulkan development. When an application
298links directly to the loader library in this way, the Vulkan calls are simple
Mark Young39389872017-01-19 21:10:49 -0700299*trampoline* functions that jump to the appropriate dispatch table entry for the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700300object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700301
Mark Young39389872017-01-19 21:10:49 -0700302
Lenny Komowde3924a2017-05-04 14:50:01 -0600303##### Directly Linking to the Loader
304
305###### Dynamic Linking
306The loader is ordinarily distributed as a dynamic library (.dll on Windows or
307.so on Linux) which gets installed to the system path for dynamic libraries.
308Linking to the dynamic library is generally the preferred method of linking to
309the loader, as doing so allows the loader to be updated for bug fixes and
310improvements. Furthermore, the dynamic library is generally installed to Windows
311systems as part of driver installation and is generally provided on Linux
312through the system package manager. This means that applications can usually
313expect a copy of the loader to be present on a system. If applications want to
314be completely sure that a loader is present, they can include a loader or
315runtime installer with their application.
316
317###### Static Linking
318The loader can also be used as a static library (this is shipped in the
319Windows SDK as `VKstatic.1.lib`). Linking to the static loader means that the
320user does not need to have a Vulkan runtime installed, and it also guarantees
321that your application will use a specific version of the loader. However, there
322are several downsides to this approach:
323
324 - The static library can never be updated without re-linking the application
325 - This opens up the possibility that two included libraries could contain
326 different versions of the loader
327 - This could potentially cause conflicts between the different loader versions
328
329As a result, it is recommended that users prefer linking to the .dll and
330.so versions of the loader.
331
332
Mark Young39389872017-01-19 21:10:49 -0700333##### Indirectly Linking to the Loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700334Applications are not required to link directly to the loader library, instead
335they can use the appropriate platform specific dynamic symbol lookup on the
Mark Young6d026a72016-06-01 17:49:30 -0600336loader library to initialize the application's own dispatch table. This allows
Mark Young39389872017-01-19 21:10:49 -0700337an application to fail gracefully if the loader cannot be found. It also
Jeff Julianof1619872016-02-17 17:25:42 -0500338provides the fastest mechanism for the application to call Vulkan functions. An
339application will only need to query (via system calls such as dlsym()) the
Mark Young39389872017-01-19 21:10:49 -0700340address of `vkGetInstanceProcAddr` from the loader library. Using
341`vkGetInstanceProcAddr` the application can then discover the address of all
342functions and extensions available, such as `vkCreateInstance`,
343`vkEnumerateInstanceExtensionProperties` and
344`vkEnumerateInstanceLayerProperties` in a platform-independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700345
Mark Young39389872017-01-19 21:10:49 -0700346
347##### Best Application Performance Setup
348
349If you desire the best performance possible, you should setup your own
350dispatch table so that all your Instance functions are queried using
351`vkGetInstanceProcAddr` and all your Device functions are queried using
352`vkGetDeviceProcAddr`.
353
354*Why should you do this?*
355
356The answer comes in how the call chain of Instance functions are implemented
357versus the call chain of a Device functions. Remember, a [Vulkan Instance is a
358high-level construct used to provide Vulkan system-level information](#instance-
359related-objects). Because of this, Instance functions need to be broadcasted to
360every available ICD on the system. The following diagram shows an approximate
361view of an Instance call chain with 3 enabled layers:
362
363![Instance Call Chain](./images/loader_instance_chain.png)
364
365This is also how a Vulkan Device function call chain looks if you query it
366using `vkGetInstanceProcAddr`. On the otherhand, a Device
367function doesn't need to worry about the broadcast becuase it knows specifically
368which associated ICD and which associated Physical Device the call should
369terminate at. Because of this, the loader doesn't need to get involved between
370any enabled layers and the ICD. Thus, if you used a loader-exported Vulkan
371Device function, the call chain in the same scenario as above would look like:
372
373![Loader Device Call Chain](./images/loader_device_chain_loader.png)
374
375An even better solution would be for an application to perform a
376`vkGetDeviceProcAddr` call on all Device functions. This further optimizes the
377call chain by removing the loader all-together under most scenarios:
378
379![Application Device Call Chain](./images/loader_device_chain_app.png)
380
381Also, notice if no layers are enabled, your application function pointer would
382point **directly to the ICD**. If called enough, those fewer calls can add up
383to performance savings.
384
385**NOTE:** There are some Device functions which still require the loader to
386intercept them with a *trampoline* and *terminator*. There are very few of
387these, but they are typically functions which the loader wraps with its own
388data. In those cases, even the Device call chain will continue to look like the
389Instance call chain. One example of a Device function requiring a *terminator*
390is `vkCreateSwapchainKHR`. For that function, the loader needs to potentially
391convert the KHR_surface object into an ICD-specific KHR_surface object prior to
392passing down the rest of the function's information to the ICD.
393
394Remember:
395 * `vkGetInstanceProcAddr` can be used to query
396either device or instance entry-points in addition to all core entry-points.
397 * `vkGetDeviceProcAddr` can only be used to query for device
398extension or core device entry-points.
399
400
401##### ABI Versioning
Mark Young02df1a82017-04-18 19:52:18 -0600402
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700403The Vulkan loader library will be distributed in various ways including Vulkan
Mark Young39389872017-01-19 21:10:49 -0700404SDKs, OS package distributions and Independent Hardware Vendor (IHV) driver
405packages. These details are beyond the scope of this document. However, the name
406and versioning of the Vulkan loader library is specified so an app can link to
407the correct Vulkan ABI library version. Vulkan versioning is such that ABI
408backwards compatibility is guaranteed for all versions with the same major
409number (e.g. 1.0 and 1.1). On Windows, the loader library encodes the ABI
410version in its name such that multiple ABI incompatible versions of the loader
411can peacefully coexist on a given system. The Vulkan loader library file name is
Jeff Juliano18e50202017-01-31 16:36:18 -0500412`vulkan-<ABI version>.dll`. For example, for Vulkan version 1.X on Windows the
Mark Young39389872017-01-19 21:10:49 -0700413library filename is vulkan-1.dll. And this library file can typically be found
414in the windows/system32 directory (on 64-bit Windows installs, the 32-bit
415version of the loader with the same name can be found in the windows/sysWOW64
416directory).
Jon Ashburnc2972682016-02-08 15:42:01 -0700417
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700418For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
419number is not encoded in the base of the library filename as on Windows. On
420Linux an application wanting to link to the latest Vulkan ABI version would
421just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500422also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700423
Mark Young39389872017-01-19 21:10:49 -0700424
425#### Application Layer Usage
Mark Young6d026a72016-06-01 17:49:30 -0600426
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700427Applications desiring Vulkan functionality beyond what the core API offers may
Mark Young39389872017-01-19 21:10:49 -0700428use various layers or extensions. A layer cannot introduce new Vulkan core API
429entry-points to an application that are not exposed in Vulkan.h. However,
430layers may offer extensions that introduce new Vulkan commands that can be
431queried through the extension interface.
Mark Young02ee5382016-07-22 08:51:05 -0600432
Mark Young39389872017-01-19 21:10:49 -0700433A common use of layers is for API validation which can be enabled by
434loading the layer during application development, but not loading the layer
435for application release. This eliminates the overhead of validating the
436application's usage of the API, something that wasn't available on some previous
437graphics APIs.
438
439To find out what layers are available to your application, use
440`vkEnumerateInstanceLayerProperties`. This will report all layers
441that have been discovered by the loader. The loader looks in various locations
442to find layers on the system. For more information see the
443[Layer discovery](#layer-discovery) section below.
444
445To enable a layer, or layers, simply pass the name of the layers you wish to
446enable in the `ppEnabledLayerNames` field of the `VkInstanceCreateInfo` during
447a call to `vkCreateInstance`. Once done, the layers you have enabled will be
448active for all Vulkan functions using the created `VkInstance`, and any of
449its child objects.
450
451**NOTE:** Layer ordering is important in several cases since some layers
452interact with each other. Be careful when enabling layers as this may be
453the case. See the [Overall Layer Ordering](#overall-layer-ordering) section
454for more information.
455
456The following code section shows how you would go about enabling the
457VK_LAYER_LUNARG_standard_validation layer.
458
459```
460 char *instance_validation_layers[] = {
461 "VK_LAYER_LUNARG_standard_validation"
462 };
463 const VkApplicationInfo app = {
464 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
465 .pNext = NULL,
466 .pApplicationName = "TEST_APP",
467 .applicationVersion = 0,
468 .pEngineName = "TEST_ENGINE",
469 .engineVersion = 0,
470 .apiVersion = VK_API_VERSION_1_0,
471 };
472 VkInstanceCreateInfo inst_info = {
473 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
474 .pNext = NULL,
475 .pApplicationInfo = &app,
476 .enabledLayerCount = 1,
477 .ppEnabledLayerNames = (const char *const *)instance_validation_layers,
478 .enabledExtensionCount = 0,
479 .ppEnabledExtensionNames = NULL,
480 };
481 err = vkCreateInstance(&inst_info, NULL, &demo->inst);
482```
483
484At `vkCreateInstance` and `vkCreateDevice`, the loader constructs call chains
485that include the application specified (enabled) layers. Order is important in
486the `ppEnabledLayerNames` array; array element 0 is the topmost (closest to the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700487application) layer inserted in the chain and the last array element is closest
Mark Young39389872017-01-19 21:10:49 -0700488to the driver. See the [Overall Layer Ordering](#overall-layer-ordering)
489section for more information on layer ordering.
Jon Ashburnc2972682016-02-08 15:42:01 -0700490
Mark Young39389872017-01-19 21:10:49 -0700491**NOTE:** *Device Layers Are Now Deprecated*
492> `vkCreateDevice` originally was able to select layers in a similar manner to
493`vkCreateInstance`. This lead to the concept of "instance
494> layers" and "device layers". It was decided by Khronos to deprecate the
495> "device layer" functionality and only consider "instance layers".
496> Therefore, `vkCreateDevice` will use the layers specified at
497`vkCreateInstance`.
498> Because of this, the following items have been deprecated:
499> * `VkDeviceCreateInfo` fields:
500> * `ppEnabledLayerNames`
501> * `enabledLayerCount`
502> * The `vkEnumerateDeviceLayerProperties` function
Mark Young02ee5382016-07-22 08:51:05 -0600503
Jon Ashburnc2972682016-02-08 15:42:01 -0700504
Mark Young39389872017-01-19 21:10:49 -0700505##### Implicit vs Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700506
Mark Young39389872017-01-19 21:10:49 -0700507Explicit layers are layers which are enabled by an application (e.g. with the
508vkCreateInstance function), or by an environment variable (as mentioned
509previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700510
Mark Young39389872017-01-19 21:10:49 -0700511Implicit layers are those which are enabled by their existence. For example,
512certain application environments (e.g. Steam or an automotive infotainment
513system) may have layers which they always want enabled for all applications
514that they start. Other implicit layers may be for all applications started on a
515given system (e.g. layers that overlay frames-per-second). Implicit layers are
516enabled automatically, whereas explicit layers must be enabled explicitly.
Jon Ashburnc2972682016-02-08 15:42:01 -0700517
Mark Young02ee5382016-07-22 08:51:05 -0600518Implicit layers have an additional requirement over explicit layers in that they
519require being able to be disabled by an environmental variable. This is due
520to the fact that they are not visible to the application and could cause issues.
521A good principle to keep in mind would be to define both an enable and disable
522environment variable so the users can deterministicly enable the functionality.
523On Desktop platforms (Windows and Linux), these enable/disable settings are
524defined in the layer's JSON file.
525
Mark Young39389872017-01-19 21:10:49 -0700526Discovery of system-installed implicit and explicit layers is described later in
527the [Layer Discovery Section](#layer-discovery). For now, simply know that what
528distinguishes a layer as implicit or explicit is dependent on the Operating
529system, as shown in the table below.
530
531| Operating System | Implicit Layer Identification |
532|----------------|--------------------|
533| Windows | Implicit Layers are located in a different Windows registry location than Explicit Layers. |
534| Linux | Implicit Layers are located in a different directory location than Explicit Layers. |
535| Android | There is **No Support For Implicit Layers** on Android. |
536
537
538##### Forcing Layer Source Folders
539
540Developers may need to use special, pre-production layers, without modifying the
541system-installed layers. You can direct the loader to look for layers in a
542specific folder by defining the "VK\_LAYER\_PATH" environment variable. This
543will override the mechanism used for finding system-installed layers. Because
Mark Young18bbaab2017-03-20 08:27:14 -0600544layers of interest may exist in several disinct folders on a system, this
Mark Young39389872017-01-19 21:10:49 -0700545environment variable can containis several paths seperated by the operating
546specific path separator. On Windows, each separate folder should be separated
547in the list using a semi-colon. On Linux, each folder name should be separated
548using a colon.
549
550If "VK\_LAYER\_PATH" exists, **only** the folders listed in it will be scanned
551for layers. Each directory listed should be the full pathname of a folder
552containing layer manifest files.
553
554
555##### Forcing Layers to be Enabled on Windows and Linux
556
557Developers may want to enable layers that are not enabled by the given
558application they are using. On Linux and Windows, the environment variable
559"VK\_INSTANCE\_LAYERS" can be used to enable additional layers which are
560not specified (enabled) by the application at `vkCreateInstance`.
561"VK\_INSTANCE\_LAYERS" is a colon (Linux)/semi-colon (Windows) separated
562list of layer names to enable. Order is relevant with the first layer in the
563list being the top-most layer (closest to the application) and the last
564layer in the list being the bottom-most layer (closest to the driver).
565See the [Overall Layer Ordering](#overall-layer-ordering) section
566for more information.
567
568Application specified layers and user specified layers (via environment
569variables) are aggregated and duplicates removed by the loader when enabling
570layers. Layers specified via environment variable are top-most (closest to the
571application) while layers specified by the application are bottommost.
572
573An example of using these environment variables to activate the validation
574layer `VK_LAYER_LUNARG_parameter_validation` on Windows or Linux is as follows:
575
576```
577> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation
578```
579
580
581##### Overall Layer Ordering
582
583The overall ordering of all layers by the loader based on the above looks
584as follows:
585
586![Loader Layer Ordering](./images/loader_layer_order.png)
587
588Ordering may also be important internal to the list of Explicit Layers.
589Some layers may be dependent on other behavior being implemented before
590or after the loader calls it. For example: the VK_LAYER_LUNARG_core_validation
591layer expects the VK_LAYER_LUNARG_parameter_validation to be called first.
592This is because the VK_LAYER_LUNARG_parameter_validation will filter out any
593invalid `NULL` pointer calls prior to the rest of the validation checking
594done by VK_LAYER_LUNARG_core_validation. If not done properly, you may see
595crashes in the VK_LAYER_LUNARG_core_validation layer that would otherwise be
596avoided.
597
598
599#### Application Usage of Extensions
600
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700601Extensions are optional functionality provided by a layer, the loader or an
602ICD. Extensions can modify the behavior of the Vulkan API and need to be
Mark Young39389872017-01-19 21:10:49 -0700603specified and registered with Khronos. These extensions can be created
604by an Independent Hardware Vendor (IHV) to expose new hardware functionality,
605or by a layer writer to expose some internal feature, or by the loader to
606improve functional behavior. Information about various extensions can be
607found in the Vulkan Spec, and vulkan.h header file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700608
Mark Young6d026a72016-06-01 17:49:30 -0600609
Mark Young39389872017-01-19 21:10:49 -0700610##### Instance and Device Extensions
611
612As hinted at in the [Instance Versus Device](#instance-versus-device) section,
613there are really two types of extensions:
614 * Instance Extensions
615 * Device Extensions
616
617An Instance extension is an extension which modifies existing behavior or
618implements new behavior on instance-level objects, like a `VkInstance` or
619a `VkPhysicalDevice`. A Device extension is an extension which does the same,
620but for any `VkDevice` object, or any dispatchable object that is a child of a
621`VkDevice` (`VkQueue` and `VkCommandBuffer` are examples of these).
622
623It is **very** important to know what type of extension you are desiring to
624enable as you will enable Instance extensions during `vkCreateInstance` and
625Device extensions during `vkCreateDevice`.
626
627The loader discovers and aggregates all
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700628extensions from layers (both explicit and implicit), ICDs and the loader before
Mark Young39389872017-01-19 21:10:49 -0700629reporting them to the application in `vkEnumerateXXXExtensionProperties`
630(where XXX is either "Instance" or "Device").
631 - Instance extensions are discovered via
632`vkEnumerateInstanceExtensionProperties`.
633 - Device extensions are be discovered via
634`vkEnumerateDeviceExtensionProperties`.
635
636Looking at `vulkan.h`, you'll notice that they are both similar. For example,
637`vkEnumerateInstanceExtensionProperties` prototype looks as follows:
638
639```
640 VkResult
641 vkEnumerateInstanceExtensionProperties(const char *pLayerName,
642 uint32_t *pPropertyCount,
643 VkExtensionProperties *pProperties);
644```
645
646The "pLayerName" parameter in these functions is used to select either a single
647layer or the Vulkan platform implementation. If "pLayerName" is NULL, extensions
648from Vulkan implementation components (including loader, implicit layers, and
649ICDs) are enumerated. If "pLayerName" is equal to a discovered layer module name
650then only extensions from that layer (which may be implicit or explicit) are
Jeff Julianof1619872016-02-17 17:25:42 -0500651enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Mark Young39389872017-01-19 21:10:49 -0700652support for the same extension) are eliminated by the loader. For duplicates,
653the ICD version is reported and the layer version is culled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700654
Mark Young39389872017-01-19 21:10:49 -0700655Also, Extensions *must be enabled* (in `vkCreateInstance` or `vkCreateDevice`)
656before the functions associated with the extensions can be used. If you get an
657Extension function using either `vkGetInstanceProcAddr` or
658`vkGetDeviceProcAddr`, but fail to enable it, you could experience undefined
659behavior. This should actually be flagged if you run with Validation layers
660enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700661
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700662
Mark Young78f88c82016-07-19 11:49:45 -0600663##### WSI Extensions
664
Mark Young39389872017-01-19 21:10:49 -0700665Khronos approved WSI extensions are available and provide Windows System
666Integration support for various execution environments. It is important to
667understand that some WSI extensions are valid for all targets, but others are
668particular to a given execution environment (and loader). This desktop loader
669(currently targeting Windows and Linux) only enables and directly exports those
670WSI extensions that are appropriate to the current environment. For the most
671part, the selection is done in the loader using compile-time preprocessor flags.
672All versions of the desktop loader currently expose at least the following WSI
Mark Young78f88c82016-07-19 11:49:45 -0600673extension support:
674- VK_KHR_surface
675- VK_KHR_swapchain
676- VK_KHR_display
677
Mark Young39389872017-01-19 21:10:49 -0700678In addition, each of the following OS targets for the loader support target-
679specific extensions:
Mark Young78f88c82016-07-19 11:49:45 -0600680
Mark Young39389872017-01-19 21:10:49 -0700681| Windowing System | Extensions available |
682|----------------|--------------------|
683| Windows | VK_KHR_win32_surface |
684| Linux (Default) | VK_KHR_xcb_surface and VK_KHR_xlib_surface |
685| Linux (Wayland) | VK_KHR_wayland_surface |
686| Linux (Mir) | VK_KHR_mir_surface |
Mark Young78f88c82016-07-19 11:49:45 -0600687
Mark Young39389872017-01-19 21:10:49 -0700688**NOTE:** Wayland and Mir targets are not fully supported at this time. Wayland
689support is present, but should be considered Beta quality. Mir support is not
690completely implemented at this time.
691
692It is important to understand that while the loader may support the various
693entry-points for these extensions, there is a hand-shake required to actually
694use them:
Mark Young78f88c82016-07-19 11:49:45 -0600695* At least one physical device must support the extension(s)
696* The application must select such a physical device
Mark Young39389872017-01-19 21:10:49 -0700697* The application must request the extension(s) be enabled while creating the
698instance or logical device (This depends on whether or not the given extension
699works with an instance or a device).
Mark Young78f88c82016-07-19 11:49:45 -0600700* The instance and/or logical device creation must succeed.
701
702Only then can you expect to properly use a WSI extension in your Vulkan program.
703
Mark Young78f88c82016-07-19 11:49:45 -0600704
Mark Young39389872017-01-19 21:10:49 -0700705##### Unknown Extensions
706
707With the ability to expand Vulkan so easily, extensions will be created that the
708loader knows nothing about. If the extension is a device extension, the loader
709will pass the unknown entry-point down the device call chain ending with the
710appropriate ICD entry-points. The same thing will happen, if the extension is
711an instance extension which takes a physical device paramater as it's first
712component. However, for all other instance extensions the loader will fail to
713load it.
Mark Young78f88c82016-07-19 11:49:45 -0600714
715*But why doesn't the loader support unknown instance extensions?*
716<br/>
717Let's look again at the Instance call chain:
Mark Young78f88c82016-07-19 11:49:45 -0600718
Mark Young39389872017-01-19 21:10:49 -0700719![Instance call chain](./images/loader_instance_chain.png)
Mark Young78f88c82016-07-19 11:49:45 -0600720
Mark Young39389872017-01-19 21:10:49 -0700721Notice that for a normal instance function call, the loader has to handle
722passing along the function call to the available ICDs. If the loader has no
723idea of the parameters or return value of the instance call, it can't properly
724pass information along to the ICDs. There may be ways to do this, which will be
725explored in the future. However, for now, this loader does not support
726instance extensions which don't take a physical device as their first parameter.
727
728Because the device call-chain does not normally pass through the loader
729*terminator*, this is not a problem for device extensions. Additionally,
730since a physical device is associated with one ICD, we can use a generic
731*terminator* pointing to one ICD. This is because both of these extensions
732terminate directly in the ICD they are associated with.
Mark Young78f88c82016-07-19 11:49:45 -0600733
734*Is this a big problem?*
735<br/>
Mark Young39389872017-01-19 21:10:49 -0700736No! Most extension functionality only affects either a physical or logical
737device and not an instance. Thus, the overwhelming majority of extensions
738should be supported with direct loader support.
Jon Ashburnc2972682016-02-08 15:42:01 -0700739
Mark Young6340bb82017-02-13 15:39:22 -0700740##### Filtering Out Unknown Instance Extension Names
741In some cases, an ICD may support instance extensions that the loader does not.
742For the above reasons, the loader will filter out the names of these unknown instance
743extensions when an application calls `vkEnumerateInstanceExtensionProperties`.
744Additionally, this behavior will cause the loader to throw an error during
745`vkCreateInstance` if you still attempt to use one of these extensions. The intent is
746to protect applications so that they don't inadvertantly use functionality
747which could lead to a crash.
748
749On the other-hand, if you know you can safely use the extension, you may disable
750the filtering by defining the environment variable `VK_LOADER_DISABLE_INST_EXT_FILTER`
751and setting the value to a non-zero number. This will effectively disable the
752loader's filtering out of instance extension names.
Jon Ashburnc2972682016-02-08 15:42:01 -0700753
Mark Youngcb6e6702016-07-20 11:38:53 -0600754<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600755<br/>
756
Mark Young39389872017-01-19 21:10:49 -0700757## Loader and Layer Interface
Jon Ashburnc2972682016-02-08 15:42:01 -0700758
Mark Young39389872017-01-19 21:10:49 -0700759In this section we'll discuss how the loader interacts with layers, including:
Lenny Komowde3924a2017-05-04 14:50:01 -0600760 * [Layer Discovery](#layer-discovery)
761 * [Layer Manifest File Usage](#layer-manifest-file-usage)
762 * [Android Layer Discovery](#android-layer-discovery)
763 * [Windows Layer Discovery](#windows-layer-discovery)
764 * [Linux Layer Discovery](#linux-layer-discovery)
765 * [Layer Version Negotiation](#layer-version-negotiation)
766 * [Layer Call Chains and Distributed Dispatch](#layer-call-chains-and-distributed-dispatch)
767 * [Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions)
768 * [Layer Intercept Requirements](#layer-intercept-requirements)
769 * [Distributed Dispatching Requirements](#distributed-dispatching-requirements)
770 * [Layer Conventions and Rules](#layer-conventions-and-rules)
771 * [Layer Dispatch Initialization](#layer-dispatch-initialization)
772 * [Example Code for CreateInstance](#example-code-for-createinstance)
773 * [Example Code for CreateDevice](#example-code-for-createdevice)
Mark Youngc82a0622017-05-05 11:17:17 -0600774 * [Meta-layers](#meta-layers)
Lenny Komow32846e52017-12-27 15:32:44 -0700775 * [Pre-Instance Functions](#pre-instance-functions)
Lenny Komowde3924a2017-05-04 14:50:01 -0600776 * [Special Considerations](#special-considerations)
777 * [Associating Private Data with Vulkan Objects Within a Layer](#associating-private-data-with-vulkan-objects-within-a-layer)
778 * [Wrapping](#wrapping)
779 * [Hash Maps](#hash-maps)
780 * [Creating New Dispatchable Objects](#creating-new-dispatchable-objects)
781 * [Layer Manifest File Format](#layer-manifest-file-format)
782 * [Layer Manifest File Version History](#layer-manifest-file-version-history)
783 * [Layer Library Versions](#layer-library-versions)
784 * [Layer Library API Version 2](#layer-library-api-version-2)
785 * [Layer Library API Version 1](#layer-library-api-version-1)
786 * [Layer Library API Version 0](#layer-library-api-version-0)
Mark Young39389872017-01-19 21:10:49 -0700787
Jon Ashburnc2972682016-02-08 15:42:01 -0700788
Mark Young39389872017-01-19 21:10:49 -0700789
790#### Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700791
Mark Young39389872017-01-19 21:10:49 -0700792As mentioned in the
793[Application Interface section](#implicit-vs-explicit-layers),
794layers can be categorized into two categories:
795 * Implicit Layers
796 * Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700797
Mark Young39389872017-01-19 21:10:49 -0700798The main difference between the two is that Implicit Layers are automatically
799enabled, unless overriden, and Explicit Layers must be enabled. Remember,
800Implicit Layers are not present on all Operating Systems (like Android).
Jon Ashburnc2972682016-02-08 15:42:01 -0700801
Mark Young39389872017-01-19 21:10:49 -0700802On any system, the loader looks in specific areas for information on the
803layers that it can load at a user's request. The process of finding the
804available layers on a system is known as Layer Discovery. During discovery,
805the loader determines what layers are available, the layer name, the layer
806version, and any extensions supported by the layer. This information is
807provided back to an application through `vkEnumerateInstanceLayerProperties`.
808
809The group of layers available to the loader is known as a layer library. This
810section defines an extensible interface to discover what layers are contained in
811the layer library.
812
813This section also specifies the minimal conventions and rules a layer must
814follow, especially with regards to interacting with the loader and other layers.
815
816##### Layer Manifest File Usage
817
Mark Young18bbaab2017-03-20 08:27:14 -0600818On Windows and Linux systems, JSON formatted manifest files are used to store
Mark Young39389872017-01-19 21:10:49 -0700819layer information. In order to find system-installed layers, the Vulkan loader
820will read the JSON files to identify the names and attributes of layers and
821their extensions. The use of manifest files allows the loader to avoid loading
822any shared library files when the application does not query nor request any
823extensions. The format of [Layer Manifest File](#layer-manifest-file-format)
824is detailed below.
825
826The Android loader does not use manifest files. Instead, the loader queries the
827layer properties using special functions known as "introspection" functions.
828The intent of these functions is to determine the same required information
829gathered from reading the manifest files. These introspection functions are
830not used by the desktop loader but should be present in layers to maintain
831consistency. The specific "introspection" functions are called out in
832the [Layer Manifest File Format](#layer-manifest-file-format) table.
833
834
835##### Android Layer Discovery
836
837On Android, the loader looks for layers to enumerate in the
838/data/local/debug/vulkan folder. An application enabled for debug has the
839ability to enumerate and enable any layers in that location.
840
841
842##### Windows Layer Discovery
843
844In order to find system-installed layers, the Vulkan loader will scan the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700845values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700846
Mark Young39389872017-01-19 21:10:49 -0700847```
848 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers
Lenny Komowdfa37352017-03-02 11:29:03 -0700849 HKEY_CURRENT_USER\SOFTWARE\Khronos\Vulkan\ExplicitLayers
Mark Young39389872017-01-19 21:10:49 -0700850 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ImplicitLayers
Lenny Komowdfa37352017-03-02 11:29:03 -0700851 HKEY_CURRENT_USER\SOFTWARE\Khronos\Vulkan\ImplicitLayers
Mark Young39389872017-01-19 21:10:49 -0700852```
Jon Ashburnc2972682016-02-08 15:42:01 -0700853
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700854For each value in these keys which has DWORD data set to 0, the loader opens
855the JSON manifest file specified by the name of the value. Each name must be a
Lenny Komow4c3d3772017-08-31 17:19:17 -0600856full pathname to the manifest file.
857
858Additionally, the loader will scan through registry keys specific to Display
859Adapters and all Software Components associated with these adapters for the
860locations of JSON manifest files. These keys are located in device keys
861created during driver installation and contain configuration information
862for base settings, including Vulkan, OpenGL, and Direct3D ICD location.
863
864The Device Adapter and Software Component key paths should be obtained through the PnP
865Configuration Manager API. The `000X` key will be a numbered key, where each
866device is assigned a different number.
867
868```
869 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanExplicitLayers
870 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanImplicitLayers
871 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanExplicitLayers
872 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanImplicitLayers
873```
874
875In addition, on 64-bit systems there may be another set of registry values, listed
876below. These values record the locations of 32-bit layers on 64-bit operating systems,
877in the same way as the Windows-on-Windows functionality.
878
879```
880 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanExplicitLayersWow
881 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanImplicitLayersWow
882 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanExplicitLayersWow
883 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Software Component GUID}\000X\VulkanImplicitLayersWow
884```
885
886If any of the above values exist and is of type `REG_SZ`, the loader will open the JSON
887manifest file specified by the key value. Each value must be a full absolute
888path to a JSON manifest file. A key value may also be of type `REG_MULTI_SZ`, in
889which case the value will be interpreted as a list of paths to JSON manifest files.
890
891In general, applications should install layers into the `SOFTWARE\Khrosos\Vulkan`
892paths. The PnP registry locations are intended specifically for layers that are
893distrubuted as part of a driver installation. An application installer should not
894modify the device-specific registries, while a device driver should not modify
895the system wide registries.
896
897The Vulkan loader will open each manifest file that is given
Mark Young39389872017-01-19 21:10:49 -0700898to obtain information about the layer, including the name or pathname of a
899shared library (".dll") file. However, if VK\_LAYER\_PATH is defined, then the
900loader will instead look at the paths defined by that variable instead of using
901the information provided by these registry keys. See
902[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
903information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700904
Jon Ashburnc2972682016-02-08 15:42:01 -0700905
Mark Young39389872017-01-19 21:10:49 -0700906##### Linux Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700907
Mark Young39389872017-01-19 21:10:49 -0700908On Linux, the Vulkan loader will scan the files in the following Linux
909directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700910
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600911 /usr/local/etc/vulkan/explicit_layer.d
912 /usr/local/etc/vulkan/implicit_layer.d
913 /usr/local/share/vulkan/explicit_layer.d
914 /usr/local/share/vulkan/implicit_layer.d
915 /etc/vulkan/explicit_layer.d
916 /etc/vulkan/implicit_layer.d
917 /usr/share/vulkan/explicit_layer.d
918 /usr/share/vulkan/implicit_layer.d
919 $HOME/.local/share/vulkan/explicit_layer.d
920 $HOME/.local/share/vulkan/implicit_layer.d
921
Mark Young39389872017-01-19 21:10:49 -0700922Of course, ther are some things you have to know about the above folders:
923 1. The "/usr/local/*" directories can be configured to be other directories at
924build time.
925 2. $HOME is the current home directory of the application's user id; this path
926will be ignored for suid programs.
927 3. The "/usr/local/etc/vulkan/\*\_layer.d" and
928"/usr/local/share/vulkan/\*\_layer.d" directories are for layers that are
929installed from locally-built sources.
930 4. The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600931installed from Linux-distribution-provided packages.
932
Mark Young39389872017-01-19 21:10:49 -0700933As on Windows, if VK\_LAYER\_PATH is defined, then the
934loader will instead look at the paths defined by that variable instead of using
935the information provided by these default paths. However, these
936environment variables are only used for non-suid programs. See
937[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
938information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700939
Mark Young39389872017-01-19 21:10:49 -0700940
941#### Layer Version Negotiation
942
943Now that a layer has been discovered, an application can choose to load it (or
944it is loaded by default if it is an Implicit layer). When the loader attempts
945to load the layer, the first thing it does is attempt to negotiate the version
946of the loader to layer interface. In order to negotiate the loader/layer
947interface version, the layer must implement the
948`vkNegotiateLoaderLayerInterfaceVersion` function. The following information is
949provided for this interface in include/vulkan/vk_layer.h:
950
951```cpp
952 typedef enum VkNegotiateLayerStructType {
953 LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
954 } VkNegotiateLayerStructType;
955
956 typedef struct VkNegotiateLayerInterface {
957 VkNegotiateLayerStructType sType;
958 void *pNext;
959 uint32_t loaderLayerInterfaceVersion;
960 PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
961 PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
962 PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
963 } VkNegotiateLayerInterface;
964
965 VkResult vkNegotiateLoaderLayerInterfaceVersion(
966 VkNegotiateLayerInterface *pVersionStruct);
Jon Ashburncc300a22016-02-11 14:57:30 -0700967```
Jon Ashburnc2972682016-02-08 15:42:01 -0700968
Mark Young39389872017-01-19 21:10:49 -0700969You'll notice the `VkNegotiateLayerInterface` structure is similar to other
970Vulkan structures. The "sType" field, in this case takes a new enum defined
971just for internal loader/layer interfacing use. The valid values for "sType"
972could grow in the future, but right only havs the one value
973"LAYER_NEGOTIATE_INTERFACE_STRUCT".
Jon Ashburnc2972682016-02-08 15:42:01 -0700974
Mark Young39389872017-01-19 21:10:49 -0700975This function (`vkNegotiateLoaderLayerInterfaceVersion`) should be exported by
976the layer so that using "GetProcAddress" on Windows or "dlsym" on Linux, should
977return a valid function pointer to it. Once the loader has grabbed a valid
978address to the layers function, the loader will create a variable of type
979`VkNegotiateLayerInterface` and initialize it in the following ways:
980 1. Set the structure "sType" to "LAYER_NEGOTIATE_INTERFACE_STRUCT"
981 2. Set pNext to NULL.
982 - This is for future growth
983 3. Set "loaderLayerInterfaceVersion" to the current version the loader desires
984to set the interface to.
985 - The minimum value sent by the loader will be 2 since it is the first
986version supporting this function.
Jon Ashburnc2972682016-02-08 15:42:01 -0700987
Mark Young39389872017-01-19 21:10:49 -0700988The loader will then individually call each layer’s
989`vkNegotiateLoaderLayerInterfaceVersion` function with the filled out
990“VkNegotiateLayerInterface”. The layer will either accept the loader's version
991set in "loaderLayerInterfaceVersion", or modify it to the closest value version
992of the interface that the layer can support. The value should not be higher
993than the version requested by the loader. If the layer can't support at a
994minimum the version requested, then the layer should return an error like
995"VK_ERROR_INITIALIZATION_FAILED". If a layer can support some version, then
996the layer should do the following:
997 1. Adjust the version to the layer's desired version.
998 2. The layer should fill in the function pointer values to its internal
999functions:
1000 - "pfnGetInstanceProcAddr" should be set to the layer’s internal
1001`GetInstanceProcAddr` function.
1002 - "pfnGetDeviceProcAddr" should be set to the layer’s internal
1003`GetDeviceProcAddr` function.
1004 - "pfnGetPhysicalDeviceProcAddr" should be set to the layer’s internal
1005`GetPhysicalDeviceProcAddr` function.
1006 - If the layer supports no physical device extensions, it may set the
1007value to NULL.
1008 - More on this function later
1009 3. The layer should return "VK_SUCCESS"
Jon Ashburnc2972682016-02-08 15:42:01 -07001010
Mark Young39389872017-01-19 21:10:49 -07001011This function **SHOULD NOT CALL DOWN** the layer chain to the next layer.
1012The loader will work with each layer individually.
Jon Ashburnc2972682016-02-08 15:42:01 -07001013
Mark Young39389872017-01-19 21:10:49 -07001014If the layer supports the new interface and reports version 2 or greater, then
1015the loader will use the “fpGetInstanceProcAddr” and “fpGetDeviceProcAddr”
1016functions from the “VkNegotiateLayerInterface” structure. Prior to these
1017changes, the loader would query each of those functions using "GetProcAddress"
1018on Windows or "dlsym" on Linux.
Jon Ashburnc2972682016-02-08 15:42:01 -07001019
Jon Ashburnc2972682016-02-08 15:42:01 -07001020
Mark Young39389872017-01-19 21:10:49 -07001021#### Layer Call Chains and Distributed Dispatch
Jon Ashburnc2972682016-02-08 15:42:01 -07001022
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001023There are two key architectural features that drive the loader to layer library
Mark Young39389872017-01-19 21:10:49 -07001024interface:
1025 1. Separate and distinct instance and device call chains
1026 2. Distributed dispatch.
Jon Ashburnc2972682016-02-08 15:42:01 -07001027
Mark Young39389872017-01-19 21:10:49 -07001028You can read an overview of dispatch tables and call chains above in the
1029[Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) section.
Jon Ashburnc2972682016-02-08 15:42:01 -07001030
Mark Young39389872017-01-19 21:10:49 -07001031What's important to note here is that a layer can intercept Vulkan
1032instance functions, device functions or both. For a layer to intercept instance
1033functions, it must participate in the instance call chain. For a layer to
1034intercept device functions, it must participate in the device call chain.
1035
1036Remember, a layer does not need to intercept all instance or device functions,
1037instead, it can choose to intercept only a subset of those functions.
1038
1039Normally, when a layer intercepts a given Vulkan function, it will call down the
1040instance or device call chain as needed. The loader and all layer libraries that
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001041participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001042from one entity to the next. This group effort for call chain sequencing is
Mark Young39389872017-01-19 21:10:49 -07001043hereinafter referred to as **distributed dispatch**.
Jon Ashburnc2972682016-02-08 15:42:01 -07001044
Mark Young39389872017-01-19 21:10:49 -07001045In distributed dispatch each layer is responsible for properly calling the next
1046entity in the call chain. This means that a dispatch mechanism is required for
1047all Vulkan functions that a layer intercepts. If a Vulkan function is not
1048intercepted by a layer, or if a layer chooses to terminate the function by not
1049calling down the chain, then no dispatch is needed for that particular function.
Jeff Julianof1619872016-02-17 17:25:42 -05001050
Mark Young39389872017-01-19 21:10:49 -07001051For example, if the enabled layers intercepted only certain instance functions,
1052the call chain would look as follows:
1053![Instance Function Chain](./images/function_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -07001054
Mark Young39389872017-01-19 21:10:49 -07001055Likewise, if the enabled layers intercepted only a few of the device functions,
1056the call chain could look this way:
1057![Device Function Chain](./images/function_device_chain.png)
Jeff Julianof1619872016-02-17 17:25:42 -05001058
Mark Young39389872017-01-19 21:10:49 -07001059The loader is responsible for dispatching all core and instance extension Vulkan
1060functions to the first entity in the call chain.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001061
Chia-I Wucb24fec2016-04-20 06:23:24 +08001062
Mark Young39389872017-01-19 21:10:49 -07001063#### Layer Unknown Physical Device Extensions
1064
1065Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
1066result in the following behavior:
1067 1. The loader would check if core function:
1068 - If it was, it would return the function pointer
1069 2. The loader would check if known extension function:
1070 - If it was, it would return the function pointer
1071 3. If the loader knew nothing about it, it would call down using
1072`GetInstanceProcAddr`
1073 - If it returned non-NULL, treat it as an unknown logical device command.
1074 - This meant setting up a generic trampoline function that takes in a
1075VkDevice as the first parameter and adjusting the dispatch table to call the
1076ICD/Layers function after getting the dispatch table from the VkDevice.
1077 4. If all the above failed, the loader would return NULL to the application.
1078
1079This caused problems when a layer attempted to expose new physical device
1080extensions the loader knew nothing about, but an application did. Because the
1081loader knew nothing about it, the loader would get to step 3 in the above
1082process and would treat the function as an unknown logical device command. The
1083problem is, this would create a generic VkDevice trampoline function which, on
1084the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
1085This would lead to a crash or corruption.
1086
1087In order to identify the extension entry-points specific to physical device
1088extensions, the following function can be added to a layer:
1089
1090```cpp
1091PFN_vkVoidFunction vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
1092 const char* pName);
1093```
1094
1095This function behaves similar to `vkGetInstanceProcAddr` and
1096`vkGetDeviceProcAddr` except it should only return values for physical device
1097extension entry-points. In this way, it compares "pName" to every physical
1098device function supported in the layer.
1099
1100The following rules apply:
Lenny Komowde3924a2017-05-04 14:50:01 -06001101 * If it is the name of a physical device function supported by the layer, the
Mark Young39389872017-01-19 21:10:49 -07001102pointer to the layer's corresponding function should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06001103 * If it is the name of a valid function which is **not** a physical device
Mark Young39389872017-01-19 21:10:49 -07001104function (i.e. an Instance, Device, or other function implemented by the layer),
1105then the value of NULL should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06001106 * We don’t call down since we know the command is not a physical device
Mark Young39389872017-01-19 21:10:49 -07001107extension).
Lenny Komowde3924a2017-05-04 14:50:01 -06001108 * If the layer has no idea what this function is, it should call down the layer
Mark Young39389872017-01-19 21:10:49 -07001109chain to the next `vk_layerGetPhysicalDeviceProcAddr` call.
Lenny Komowde3924a2017-05-04 14:50:01 -06001110 * This can be retrieved in one of two ways:
1111 * During `vkCreateInstance`, it is passed to a layer in the
Mark Young39389872017-01-19 21:10:49 -07001112chain information passed to a layer in the `VkLayerInstanceCreateInfo`
1113structure.
1114 * Use `get_chain_info()` to get the pointer to the
1115`VkLayerInstanceCreateInfo` structure. Let's call it chain_info.
1116 * The address is then under
1117chain_info->u.pLayerInfo->pfnNextGetPhysicalDeviceProcAddr
1118 * See
1119[Example Code for CreateInstance](#example-code-for-createinstance)
Lenny Komowde3924a2017-05-04 14:50:01 -06001120 * Using the next layer’s `GetInstanceProcAddr` function to query for
Mark Young39389872017-01-19 21:10:49 -07001121`vk_layerGetPhysicalDeviceProcAddr`.
1122
1123This support is optional and should not be considered a requirement. This is
1124only required if a layer intends to support some functionality not directly
Mark Young18bbaab2017-03-20 08:27:14 -06001125supported by loaders released in the public. If a layer does implement this
Mark Young39389872017-01-19 21:10:49 -07001126support, it should return the address of its `vk_layerGetPhysicalDeviceProcAddr`
1127function in the "pfnGetPhysicalDeviceProcAddr" member of the
1128`VkNegotiateLayerInterface` structure during
1129[Layer Version Negotiation](#layer-version-negotiation). Additionally, the
1130layer should also make sure `vkGetInstanceProcAddr` returns a valid function
1131pointer to a query of `vk_layerGetPhysicalDeviceProcAddr`.
1132
1133The new behavior of the loader's `vkGetInstanceProcAddr` with support for the
1134`vk_layerGetPhysicalDeviceProcAddr` function is as follows:
1135 1. Check if core function:
1136 - If it is, return the function pointer
1137 2. Check if known instance or device extension function:
1138 - If it is, return the function pointer
1139 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
1140 - If it returns non-NULL, return a trampoline to a generic physical device
1141function, and setup a generic terminator which will pass it to the proper ICD.
1142 4. Call down using `GetInstanceProcAddr`
1143 - If it returns non-NULL, treat it as an unknown logical device command.
1144This means setting up a generic trampoline function that takes in a VkDevice as
1145the first parameter and adjusting the dispatch table to call the ICD/Layers
1146function after getting the dispatch table from the VkDevice. Then, return the
1147pointer to corresponding trampoline function.
1148 5. Return NULL
1149
1150You can see now, that, if the command gets promoted to core later, it will no
1151longer be setup using `vk_layerGetPhysicalDeviceProcAddr`. Additionally, if the
1152loader adds direct support for the extension, it will no longer get to step 3,
1153because step 2 will return a valid function pointer. However, the layer should
1154continue to support the command query via `vk_layerGetPhysicalDeviceProcAddr`,
1155until at least a Vulkan version bump, because an older loader may still be
1156attempting to use the commands.
1157
1158
1159#### Layer Intercept Requirements
1160
Lenny Komowde3924a2017-05-04 14:50:01 -06001161 * Layers intercept a Vulkan function by defining a C/C++ function with
Mark Young39389872017-01-19 21:10:49 -07001162signature **identical** to the Vulkan API for that function.
Lenny Komowde3924a2017-05-04 14:50:01 -06001163 * A layer **must intercept at least** `vkGetInstanceProcAddr` and
Mark Young39389872017-01-19 21:10:49 -07001164`vkCreateInstance` to participate in the instance call chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001165 * A layer **may also intercept** `vkGetDeviceProcAddr` and `vkCreateDevice`
Mark Young39389872017-01-19 21:10:49 -07001166to participate in the device call chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001167 * For any Vulkan function a layer intercepts which has a non-void return value,
Mark Young39389872017-01-19 21:10:49 -07001168**an appropriate value must be returned** by the layer intercept function.
Lenny Komowde3924a2017-05-04 14:50:01 -06001169 * Most functions a layer intercepts **should call down the chain** to the
Mark Young39389872017-01-19 21:10:49 -07001170corresponding Vulkan function in the next entity.
Lenny Komowde3924a2017-05-04 14:50:01 -06001171 * The common behavior for a layer is to intercept a call, perform some
Mark Young39389872017-01-19 21:10:49 -07001172behavior, then pass it down to the next entity.
Lenny Komowde3924a2017-05-04 14:50:01 -06001173 * If you don't pass the information down, undefined behavior may occur.
1174 * This is because the function will not be received by layers further down
Mark Young39389872017-01-19 21:10:49 -07001175the chain, or any ICDs.
Lenny Komowde3924a2017-05-04 14:50:01 -06001176 * One function that **must never call down the chain** is:
1177 * `vkNegotiateLoaderLayerInterfaceVersion`
1178 * Three common functions that **may not call down the chain** are:
1179 * `vkGetInstanceProcAddr`
1180 * `vkGetDeviceProcAddr`
1181 * `vk_layerGetPhysicalDeviceProcAddr`
1182 * These functions only call down the chain for Vulkan functions that they
Mark Young39389872017-01-19 21:10:49 -07001183do not intercept.
Lenny Komowde3924a2017-05-04 14:50:01 -06001184 * Layer intercept functions **may insert extra calls** to Vulkan functions in
Mark Young39389872017-01-19 21:10:49 -07001185addition to the intercept.
Lenny Komowde3924a2017-05-04 14:50:01 -06001186 * For example, a layer intercepting `vkQueueSubmit` may want to add a call to
Mark Young39389872017-01-19 21:10:49 -07001187`vkQueueWaitIdle` after calling down the chain for `vkQueueSubmit`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001188 * This would result in two calls down the chain: First a call down the
Mark Young39389872017-01-19 21:10:49 -07001189`vkQueueSubmit` chain, followed by a call down the `vkQueueWaitIdle` chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001190 * Any additional calls inserted by a layer must be on the same chain
1191 * If the function is a device function, only other device functions should
Mark Young39389872017-01-19 21:10:49 -07001192be added.
Lenny Komowde3924a2017-05-04 14:50:01 -06001193 * Likewise, if the function is an instance function, only other instance
Mark Young39389872017-01-19 21:10:49 -07001194functions should be added.
1195
1196
1197#### Distributed Dispatching Requirements
1198
1199- For each entry-point a layer intercepts, it must keep track of the entry
1200point residing in the next entity in the chain it will call down into.
Lenny Komowde3924a2017-05-04 14:50:01 -06001201 * In other words, the layer must have a list of pointers to functions of the
Mark Young39389872017-01-19 21:10:49 -07001202appropriate type to call into the next entity.
Lenny Komowde3924a2017-05-04 14:50:01 -06001203 * This can be implemented in various ways but
Mark Young39389872017-01-19 21:10:49 -07001204for clarity, will be referred to as a dispatch table.
1205- A layer can use the `VkLayerDispatchTable` structure as a device dispatch
1206table (see include/vulkan/vk_layer.h).
1207- A layer can use the `VkLayerInstanceDispatchTable` structure as a instance
1208dispatch table (see include/vulkan/vk_layer.h).
1209- A Layer's `vkGetInstanceProcAddr` function uses the next entity's
1210`vkGetInstanceProcAddr` to call down the chain for unknown (i.e.
1211non-intercepted) functions.
1212- A Layer's `vkGetDeviceProcAddr` function uses the next entity's
1213`vkGetDeviceProcAddr` to call down the chain for unknown (i.e. non-intercepted)
1214functions.
1215- A Layer's `vk_layerGetPhysicalDeviceProcAddr` function uses the next entity's
1216`vk_layerGetPhysicalDeviceProcAddr` to call down the chain for unknown (i.e.
1217non-intercepted) functions.
1218
1219
1220#### Layer Conventions and Rules
Chia-I Wucb24fec2016-04-20 06:23:24 +08001221
1222A layer, when inserted into an otherwise compliant Vulkan implementation, must
Mark Young39389872017-01-19 21:10:49 -07001223still result in a compliant Vulkan implementation. The intention is for layers
1224to have a well-defined baseline behavior. Therefore, it must follow some
1225conventions and rules defined below.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001226
1227A layer is always chained with other layers. It must not make invalid calls
Mark Young39389872017-01-19 21:10:49 -07001228to, or rely on undefined behaviors of, its lower layers. When it changes the
1229behavior of a function, it must make sure its upper layers do not make invalid
Chia-I Wucb24fec2016-04-20 06:23:24 +08001230calls to or rely on undefined behaviors of its lower layers because of the
1231changed behavior. For example, when a layer intercepts an object creation
Mark Young39389872017-01-19 21:10:49 -07001232function to wrap the objects created by its lower layers, it must make sure its
Chia-I Wucb24fec2016-04-20 06:23:24 +08001233lower layers never see the wrapping objects, directly from itself or
1234indirectly from its upper layers.
1235
Chia-I Wub5e850e2016-05-06 08:41:52 +08001236When a layer requires host memory, it may ignore the provided allocators. It
1237should use memory allocators if the layer is intended to run in a production
Mark Young39389872017-01-19 21:10:49 -07001238environment. For example, this usually applies to implicit layers that are
1239always enabled. That will allow applications to include the layer's memory
1240usage.
Chia-I Wub5e850e2016-05-06 08:41:52 +08001241
Mark Young39389872017-01-19 21:10:49 -07001242Additional rules include:
Lenny Komowde3924a2017-05-04 14:50:01 -06001243 - `vkEnumerateInstanceLayerProperties` **must** enumerate and **only**
Mark Young39389872017-01-19 21:10:49 -07001244enumerate the layer itself.
Lenny Komowde3924a2017-05-04 14:50:01 -06001245 - `vkEnumerateInstanceExtensionProperties` **must** handle the case where
Mark Young39389872017-01-19 21:10:49 -07001246`pLayerName` is itself.
Lenny Komowde3924a2017-05-04 14:50:01 -06001247 - It **must** return `VK_ERROR_LAYER_NOT_PRESENT` otherwise, including when
Mark Young39389872017-01-19 21:10:49 -07001248`pLayerName` is `NULL`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001249 - `vkEnumerateDeviceLayerProperties` **is deprecated and may be omitted**.
1250 - Using this will result in undefined behavior.
1251 - `vkEnumerateDeviceExtensionProperties` **must** handle the case where
Mark Young39389872017-01-19 21:10:49 -07001252`pLayerName` is itself.
Lenny Komowde3924a2017-05-04 14:50:01 -06001253 - In other cases, it should normally chain to other layers.
1254 - `vkCreateInstance` **must not** generate an error for unrecognized layer
Mark Young39389872017-01-19 21:10:49 -07001255names and extension names.
Lenny Komowde3924a2017-05-04 14:50:01 -06001256 - It may assume the layer names and extension names have been validated.
1257 - `vkGetInstanceProcAddr` intercepts a Vulkan function by returning a local
Mark Young39389872017-01-19 21:10:49 -07001258entry-point
Lenny Komowde3924a2017-05-04 14:50:01 -06001259 - Otherwise it returns the value obtained by calling down the instance call
Mark Young39389872017-01-19 21:10:49 -07001260chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001261 - `vkGetDeviceProcAddr` intercepts a Vulkan function by returning a local
Mark Young39389872017-01-19 21:10:49 -07001262entry-point
Lenny Komowde3924a2017-05-04 14:50:01 -06001263 - Otherwise it returns the value obtained by calling down the device call
Mark Young39389872017-01-19 21:10:49 -07001264chain.
Lenny Komowde3924a2017-05-04 14:50:01 -06001265 - These additional functions must be intercepted if the layer implements
Mark Young39389872017-01-19 21:10:49 -07001266device-level call chaining:
Lenny Komowde3924a2017-05-04 14:50:01 -06001267 - `vkGetDeviceProcAddr`
1268 - `vkCreateDevice`(only required for any device-level chaining)
1269 - **NOTE:** older layer libraries may expect that `vkGetInstanceProcAddr`
Mark Young39389872017-01-19 21:10:49 -07001270ignore `instance` when `pName` is `vkCreateDevice`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001271 - The specification **requires** `NULL` to be returned from
Mark Young39389872017-01-19 21:10:49 -07001272`vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` for disabled functions.
Lenny Komowde3924a2017-05-04 14:50:01 -06001273 - A layer may return `NULL` itself or rely on the following layers to do so.
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001274
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001275
Mark Young39389872017-01-19 21:10:49 -07001276#### Layer Dispatch Initialization
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001277
Mark Young39389872017-01-19 21:10:49 -07001278- A layer initializes its instance dispatch table within its `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001279function.
Mark Young39389872017-01-19 21:10:49 -07001280- A layer initializes its device dispatch table within its `vkCreateDevice`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001281function.
1282- The loader passes a linked list of initialization structures to layers via
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001283the "pNext" field in the `VkInstanceCreateInfo` and `VkDeviceCreateInfo`
Mark Young39389872017-01-19 21:10:49 -07001284structures for `vkCreateInstance` and `VkCreateDevice` respectively.
1285- The head node in this linked list is of type `VkLayerInstanceCreateInfo` for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001286instance and VkLayerDeviceCreateInfo for device. See file
Mark Young39389872017-01-19 21:10:49 -07001287`include/vulkan/vk_layer.h` for details.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001288- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001289"sType" field in `VkLayerInstanceCreateInfo`.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001290- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001291"sType" field in `VkLayerDeviceCreateInfo`.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001292- The "function" field indicates how the union field "u" should be interpreted
Mark Young39389872017-01-19 21:10:49 -07001293within `VkLayer*CreateInfo`. The loader will set the "function" field to
1294VK_LAYER_LINK_INFO. This indicates "u" field should be `VkLayerInstanceLink` or
1295`VkLayerDeviceLink`.
1296- The `VkLayerInstanceLink` and `VkLayerDeviceLink` structures are the list
1297nodes.
1298- The `VkLayerInstanceLink` contains the next entity's `vkGetInstanceProcAddr`
1299used by a layer.
1300- The `VkLayerDeviceLink` contains the next entity's `vkGetInstanceProcAddr` and
1301`vkGetDeviceProcAddr` used by a layer.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001302- Given the above structures set up by the loader, layer must initialize their
1303dispatch table as follows:
Mark Young39389872017-01-19 21:10:49 -07001304 - Find the `VkLayerInstanceCreateInfo`/`VkLayerDeviceCreateInfo` structure in
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06001305the `VkInstanceCreateInfo`/`VkDeviceCreateInfo` structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001306 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Mark Young39389872017-01-19 21:10:49 -07001307 - For CreateInstance get the next entity's `vkCreateInstance` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001308"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001309 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Mark Young39389872017-01-19 21:10:49 -07001310 - For CreateDevice get the next entity's `vkCreateDevice` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001311"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001312 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001313 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
Mark Young39389872017-01-19 21:10:49 -07001314 - Call down the chain either `vkCreateDevice` or `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001315 - Initialize your layer dispatch table by calling the next entity's
Mark Young39389872017-01-19 21:10:49 -07001316Get*ProcAddr function once for each Vulkan function needed in your dispatch
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001317table
Jon Ashburncc300a22016-02-11 14:57:30 -07001318
Mark Young39389872017-01-19 21:10:49 -07001319#### Example Code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001320
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001321```cpp
1322VkResult vkCreateInstance(
1323 const VkInstanceCreateInfo *pCreateInfo,
1324 const VkAllocationCallbacks *pAllocator,
1325 VkInstance *pInstance)
1326{
1327 VkLayerInstanceCreateInfo *chain_info =
1328 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1329
1330 assert(chain_info->u.pLayerInfo);
1331 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1332 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1333 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001334 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001335 if (fpCreateInstance == NULL) {
1336 return VK_ERROR_INITIALIZATION_FAILED;
1337 }
1338
1339 // Advance the link info for the next element of the chain
1340 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1341
1342 // Continue call down the chain
1343 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1344 if (result != VK_SUCCESS)
1345 return result;
1346
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001347 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001348 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001349 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001350 layer_init_instance_dispatch_table(
1351 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1352
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001353 // Other layer initialization
1354 ...
1355
1356 return VK_SUCCESS;
1357}
1358```
1359
Mark Young39389872017-01-19 21:10:49 -07001360#### Example Code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001361
1362```cpp
1363VkResult
1364vkCreateDevice(
1365 VkPhysicalDevice gpu,
1366 const VkDeviceCreateInfo *pCreateInfo,
1367 const VkAllocationCallbacks *pAllocator,
1368 VkDevice *pDevice)
1369{
1370 VkLayerDeviceCreateInfo *chain_info =
1371 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1372
1373 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1374 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1375 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1376 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1377 PFN_vkCreateDevice fpCreateDevice =
1378 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1379 if (fpCreateDevice == NULL) {
1380 return VK_ERROR_INITIALIZATION_FAILED;
1381 }
1382
1383 // Advance the link info for the next element on the chain
1384 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1385
1386 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1387 if (result != VK_SUCCESS) {
1388 return result;
1389 }
1390
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001391 // initialize layer's dispatch table
1392 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001393 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001394 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001395
1396 // Other layer initialization
1397 ...
1398
1399 return VK_SUCCESS;
1400}
1401```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001402
Mark Young39389872017-01-19 21:10:49 -07001403
Mark Youngc82a0622017-05-05 11:17:17 -06001404#### Meta-layers
1405
1406Meta-layers are a special kind of layer which is only available through the
1407desktop loader. While normal layers are associated with one particular library,
1408a meta-layer is actually a collection layer which contains an ordered list of
1409other layers (called component layers).
1410
1411The most common example of a meta-layer is the
1412`VK_LAYER_LUNARG_standard_validation` layer which groups all the most common
1413individual validation layers into a single layer for ease-of-use.
1414
1415The benefits of a meta-layer are:
1416 1. You can activate more than one layer using a single layer name by simply
1417grouping multiple layers in a meta-layer.
1418 2. You can define the order the loader will activate individual layers within
1419the meta-layer.
1420 3. You can easily share your special layer configuration with others.
1421 4. The loader will automatically collate all instance and device extensions in
1422a meta-layer's component layers, and report them as the meta-layer's properties
1423to the application when queried.
1424
1425Restrictions to defining and using a meta-layer are:
1426 1. A Meta-layer Manifest file **must** be a properly formated that contains one
1427or more component layers.
1428 3. All component layers **must be** present on a system for the meta-layer to
1429be used.
1430 4. All component layers **must be** at the same Vulkan API major and minor
1431version for the meta-layer to be used.
1432
1433The ordering of a meta-layer's component layers in the instance or device
1434call-chain is simple:
1435 * The first layer listed will be the layer closest to the application.
1436 * The last layer listed will be the layer closest to the drivers.
1437
1438Inside the meta-layer Manifest file, each component layer is listed by its
1439layer name. This is the "name" tag's value associated with each component layer's
1440Manifest file under the "layer" or "layers" tag. This is also the name that
1441would normally be used when activating a layer during `vkCreateInstance`.
1442
1443Any duplicate layer names in either the component layer list, or globally among
1444all enabled layers, will simply be ignored. Only the first instance of any
1445layer name will be used.
1446
1447For example, if you have a layer enabled using the environment variable
1448`VK_INSTANCE_LAYERS` and have that same layer listed in a meta-layer, then the
1449environment variable enabled layer will be used and the component layer will
1450be dropped. Likewise, if a person were to enable a meta-layer and then
1451separately enable one of the component layers afterwards, the second
1452instantiation of the layer name would be ignored.
1453
1454The
1455Manifest file formatting necessary to define a meta-layer can be found in the
1456[Layer Manifest File Format](#layer-manifest-file-format) section.
1457
Lenny Komow32846e52017-12-27 15:32:44 -07001458#### Pre-Instance Functions
1459
1460Vulkan includes a small number of functions which are called without any dispatchable object.
1461Most layers do not intercept these functions, as layers are enabled when an instance is created.
1462However, under certain conditions it is possible for a layer to intercept these functions.
1463
1464In order to intercept the pre-instance functions, several conditions must be met:
1465* The layer must be implicit
1466* The layer manifest version must be 1.1.2 or later
1467* The layer must export the entry point symbols for each intercepted function
1468* The layer manifest must specify the name of each intercepted function in a `pre_instance_functions` JSON object
1469
1470The functions that may be intercepted in this way are:
1471* `vkEnumerateInstanceExtensionProperties`
1472* `vkEnumerateInstanceLayerProperties`
1473
1474Pre-instance functions work differently from all other layer intercept functions.
1475Other intercept functions have a function prototype identical to that of the function they are intercepting.
1476They then rely on data that was passed to the layer at instance or device creation so that layers can call down the chain.
1477Because there is no need to create an instance before calling the pre-instance functions, these functions must use a separate mechanism for constructing the call chain.
1478This mechanism consists of an extra parameter that will be passed to the layer intercept function when it is called.
1479This parameter will be a pointer to a struct, defined as follows:
1480
1481```
1482typedef struct Vk...Chain
1483{
1484 struct {
1485 VkChainType type;
1486 uint32_t version;
1487 uint32_t size;
1488 } header;
1489 PFN_vkVoidFunction pfnNextLayer;
1490 const struct Vk...Chain* pNextLink;
1491} Vk...Chain;
1492```
1493
1494These structs are defined in the `vk_layer.h` file so that it is not necessary to redefine the chain structs in any external code.
1495The name of each struct is be similar to the name of the function it corresponds to, but the leading "V" is capitalized, and the word "Chain" is added to the end.
1496For example, the struct for `vkEnumerateInstanceExtensionProperties` is called `VkEnumerateInstanceExtensionPropertiesChain`.
1497Furthermore, the `pfnNextLayer` struct member is not actually a void function pointer &mdash; its type will be the actual type of each function in the call chain.
1498
1499Each layer intercept function must have a prototype that is the same as the prototype of the function being intercepted, except that the first parameter must be that function's chain struct (passed as a const pointer).
1500For example, a function that wishes to intercept `vkEnumerateInstanceExtensionProperties` would have the prototype:
1501
1502```
1503VkResult InterceptFunctionName(const VkEnumerateInstanceExtensionProperties* pChain,
1504 const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties);
1505```
1506
1507The name of the function is arbitrary; it can be anything provided that it is given in the layer manifest file (see [Layer Manifest File Format](#layer-manifest-file-format)).
1508The implementation of each intercept functions is responsible for calling the next item in the call chain, using the chain parameter.
1509This is done by calling the `pfnNextLayer` member of the chain struct, passing `pNextLink` as the first argument, and passing the remaining function arguments after that.
1510For example, a simple implementation for `vkEnumerateInstanceExtensionProperties` that does nothing but call down the chain would look like:
1511
1512```
1513VkResult InterceptFunctionName(const VkEnumerateInstanceExtensionProperties* pChain,
1514 const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
1515{
1516 return pChain->pfnNextLayer(pChain->pNextLink, pLayerName, pPropertyCount, pProperties);
1517}
1518```
1519
1520When using a C++ compiler, each chain type also defines a function named `CallDown` which can be used to automatically handle the first argument.
1521Implementing the above function using this method would look like:
1522
1523```
1524VkResult InterceptFunctionName(const VkEnumerateInstanceExtensionProperties* pChain,
1525 const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
1526{
1527 return pChain->CallDown(pLayerName, pPropertyCount, pProperties);
1528}
1529```
1530
1531Unlike with other functions in layers, the layer may not save any global data between these function calls.
1532Because Vulkan does not store any state until an instance has been created, all layer libraries are released at the end of each pre-instance call.
1533This means that implicit layers can use pre-instance intercepts to modify data that is returned by the functions, but they cannot be used to record that data.
1534
Jon Ashburncc300a22016-02-11 14:57:30 -07001535#### Special Considerations
Mark Young39389872017-01-19 21:10:49 -07001536
1537
1538##### Associating Private Data with Vulkan Objects Within a Layer
1539
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001540A layer may want to associate it's own private data with one or more Vulkan
Mark Youngf7914cf2016-08-31 11:53:26 -06001541objects. Two common methods to do this are hash maps and object wrapping.
1542
Mark Youngf7914cf2016-08-31 11:53:26 -06001543
Mark Young39389872017-01-19 21:10:49 -07001544###### Wrapping
Ian Elliott0b082e42016-08-31 14:08:44 -06001545
Mark Young39389872017-01-19 21:10:49 -07001546The loader supports layers wrapping any Vulkan object, including dispatchable
1547objects. For functions that return object handles, each layer does not touch
1548the value passed down the call chain. This is because lower items may need to
1549use the original value. However, when the value is returned from a
1550lower-level layer (possibly the ICD), the layer saves the handle and returns
1551its own handle to the layer above it (possibly the application). When a layer
1552receives a Vulkan function using something that it previously returned a handle
1553for, the layer is required to unwrap the handle and pass along the saved handle
1554to the layer below it. This means that the layer **must intercept every Vulkan
1555function which uses the object in question**, and wrap or unwrap the object, as
1556appropriate. This includes adding support for all extensions with functions
Ian Elliott0b082e42016-08-31 14:08:44 -06001557using any object the layer wraps.
Mark Youngf7914cf2016-08-31 11:53:26 -06001558
1559Layers above the object wrapping layer will see the wrapped object. Layers
1560which wrap dispatchable objects must ensure that the first field in the wrapping
Mark Young39389872017-01-19 21:10:49 -07001561structure is a pointer to a dispatch table as defined in `vk_layer.h`.
1562Specifically, an instance wrapped dispatchable object could be as follows:
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001563```
1564struct my_wrapped_instance_obj_ {
1565 VkLayerInstanceDispatchTable *disp;
1566 // whatever data layer wants to add to this object
1567};
1568```
1569A device wrapped dispatchable object could be as follows:
1570```
1571struct my_wrapped_instance_obj_ {
1572 VkLayerDispatchTable *disp;
1573 // whatever data layer wants to add to this object
1574};
1575```
Jeff Julianof1619872016-02-17 17:25:42 -05001576
Ian Elliott0b082e42016-08-31 14:08:44 -06001577Layers that wrap dispatchable objects must follow the guidelines for creating
1578new dispatchable objects (below).
1579
Mark Young39389872017-01-19 21:10:49 -07001580<u>Cautions About Wrapping</u>
Ian Elliott0b082e42016-08-31 14:08:44 -06001581
1582Layers are generally discouraged from wrapping objects, because of the
1583potential for incompatibilities with new extensions. For example, let's say
Mark Young39389872017-01-19 21:10:49 -07001584that a layer wraps `VkImage` objects, and properly wraps and unwraps `VkImage`
1585object handles for all core functions. If a new extension is created which has
1586functions that take `VkImage` objects as parameters, and if the layer does not
1587support those new functions, an application that uses both the layer and the new
1588extension will have undefined behavior when those new functions are called (e.g.
Mark Young18bbaab2017-03-20 08:27:14 -06001589the application may crash). This is because the lower-level layers and ICD
Ian Elliott0b082e42016-08-31 14:08:44 -06001590won't receive the handle that they generated. Instead, they will receive a
1591handle that is only known by the layer that is wrapping the object.
1592
1593Because of the potential for incompatibilities with unsupported extensions,
1594layers that wrap objects must check which extensions are being used by the
1595application, and take appropriate action if the layer is used with unsupported
1596extensions (e.g. disable layer functionality, stop wrapping objects, issue a
1597message to the user).
1598
1599The reason that the validation layers wrap objects, is to track the proper use
1600and destruction of each object. They issue a validation error if used with
1601unsupported extensions, alerting the user to the potential for undefined
1602behavior.
1603
Mark Young39389872017-01-19 21:10:49 -07001604
1605###### Hash Maps
1606
Jeff Julianof1619872016-02-17 17:25:42 -05001607Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001608given object. The key to the map could be the object. Alternatively, for
1609dispatchable objects at a given level (eg device or instance) the layer may
Mark Young39389872017-01-19 21:10:49 -07001610want data associated with the `VkDevice` or `VkInstance` objects. Since
1611there are multiple dispatchable objects for a given `VkInstance` or `VkDevice`,
1612the `VkDevice` or `VkInstance` object is not a great map key. Instead the layer
1613should use the dispatch table pointer within the `VkDevice` or `VkInstance`
1614since that will be unique for a given `VkInstance` or `VkDevice`.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001615
Mark Young39389872017-01-19 21:10:49 -07001616
1617##### Creating New Dispatchable Objects
1618
1619Layers which create dispatchable objects must take special care. Remember that
1620loader *trampoline* code normally fills in the dispatch table pointer in the
1621newly created object. Thus, the layer must fill in the dispatch table pointer if
1622the loader *trampoline* will not do so. Common cases where a layer (or ICD) may
1623create a dispatchable object without loader *trampoline* code is as follows:
1624- layers that wrap dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001625- layers which add extensions that create dispatchable objects
Mark Young18bbaab2017-03-20 08:27:14 -06001626- layers which insert extra Vulkan functions in the stream of functions they
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001627intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001628- ICDs which add extensions that create dispatchable objects
1629
Mark Young39389872017-01-19 21:10:49 -07001630The desktop loader provides a callback that can be used for initializing
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001631a dispatchable object. The callback is passed as an extension structure via the
Mark Young39389872017-01-19 21:10:49 -07001632pNext field in the create info structure when creating an instance
1633(`VkInstanceCreateInfo`) or device (`VkDeviceCreateInfo`). The callback
1634prototype is defined as follows for instance and device callbacks respectively
1635(see `vk_layer.h`):
1636
1637```cpp
1638VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance,
1639 void *object);
1640VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData(VkDevice device,
1641 void *object);
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001642```
Mark Young39389872017-01-19 21:10:49 -07001643
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001644To obtain these callbacks the layer must search through the list of structures
Mark Young39389872017-01-19 21:10:49 -07001645pointed to by the "pNext" field in the `VkInstanceCreateInfo` and
1646`VkDeviceCreateInfo` parameters to find any callback structures inserted by the
1647loader. The salient details are as follows:
1648- For `VkInstanceCreateInfo` the callback structure pointed to by "pNext" is
1649`VkLayerInstanceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1650- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within
1651`VkInstanceCreateInfo` parameter indicates a loader structure.
1652- Within `VkLayerInstanceCreateInfo`, the "function" field indicates how the
1653union field "u" should be interpreted.
1654- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1655contain the callback in "pfnSetInstanceLoaderData".
1656- For `VkDeviceCreateInfo` the callback structure pointed to by "pNext" is
1657`VkLayerDeviceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1658- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within
1659`VkDeviceCreateInfo` parameter indicates a loader structure.
1660- Within `VkLayerDeviceCreateInfo`, the "function" field indicates how the union
1661field "u" should be interpreted.
1662- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1663contain the callback in "pfnSetDeviceLoaderData".
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001664
Mark Young39389872017-01-19 21:10:49 -07001665Alternatively, if an older loader is being used that doesn't provide these
1666callbacks, the layer may manually initialize the newly created dispatchable
1667object. To fill in the dispatch table pointer in newly created dispatchable
1668object, the layer should copy the dispatch pointer, which is always the first
1669entry in the structure, from an existing parent object of the same level
1670(instance versus device).
Jon Ashburnc2972682016-02-08 15:42:01 -07001671
Mark Young39389872017-01-19 21:10:49 -07001672For example, if there is a newly created `VkCommandBuffer` object, then the
1673dispatch pointer from the `VkDevice` object, which is the parent of the
1674`VkCommandBuffer` object, should be copied into the newly created object.
1675
1676
1677#### Layer Manifest File Format
1678
1679On Windows and Linux (desktop), the loader uses manifest files to discover
1680layer libraries and layers. The desktop loader doesn't directly query the
1681layer library except during chaining. This is to reduce the likelihood of
1682loading a malicious layer into memory. Instead, details are read from the
1683Manifest file, which are then provided for applications to determine what
1684layers should actually be loaded.
1685
1686The following section discusses the details of the Layer Manifest JSON file
1687format. The JSON file itself does not have any requirements for naming. The
1688only requirement is that the extension suffix of the file ends with ".json".
1689
1690Here is an example layer JSON Manifest file with a single layer:
1691
1692```
1693{
1694 "file_format_version" : "1.0.0",
1695 "layer": {
1696 "name": "VK_LAYER_LUNARG_overlay",
1697 "type": "INSTANCE",
1698 "library_path": "vkOverlayLayer.dll"
1699 "api_version" : "1.0.5",
1700 "implementation_version" : "2",
1701 "description" : "LunarG HUD layer",
1702 "functions": {
1703 "vkNegotiateLoaderLayerInterfaceVersion":
1704 "OverlayLayer_NegotiateLoaderLayerInterfaceVersion"
1705 },
1706 "instance_extensions": [
1707 {
1708 "name": "VK_EXT_debug_report",
1709 "spec_version": "1"
1710 },
1711 {
1712 "name": "VK_VENDOR_ext_x",
1713 "spec_version": "3"
1714 }
1715 ],
1716 "device_extensions": [
1717 {
1718 "name": "VK_EXT_debug_marker",
1719 "spec_version": "1",
1720 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1721 }
1722 ],
1723 "enable_environment": {
1724 "ENABLE_LAYER_OVERLAY_1": "1"
Lenny Komow32846e52017-12-27 15:32:44 -07001725 },
Mark Young39389872017-01-19 21:10:49 -07001726 "disable_environment": {
1727 "DISABLE_LAYER_OVERLAY_1": ""
1728 }
1729 }
1730}
1731```
1732
1733Here's a snippet with the changes required to support multiple layers per
1734manifest file:
1735```
1736{
1737 "file_format_version" : "1.0.1",
1738 "layers": [
1739 {
1740 "name": "VK_LAYER_layer_name1",
1741 "type": "INSTANCE",
1742 ...
1743 },
1744 {
1745 "name": "VK_LAYER_layer_name2",
1746 "type": "INSTANCE",
1747 ...
1748 }
1749 ]
1750}
1751```
1752
Mark Youngc82a0622017-05-05 11:17:17 -06001753Here's an example of a meta-layer manifest file:
1754```
1755{
1756 "file_format_version" : "1.1.1",
1757 "layer": {
1758 "name": "VK_LAYER_LUNARG_standard_validation",
1759 "type": "GLOBAL",
1760 "api_version" : "1.0.40",
1761 "implementation_version" : "1",
1762 "description" : "LunarG Standard Validation Meta-layer",
1763 "component_layers": [
1764 "VK_LAYER_GOOGLE_threading",
1765 "VK_LAYER_LUNARG_parameter_validation",
1766 "VK_LAYER_LUNARG_object_tracker",
1767 "VK_LAYER_LUNARG_core_validation",
Mark Youngc82a0622017-05-05 11:17:17 -06001768 "VK_LAYER_GOOGLE_unique_objects"
1769 ]
1770 }
1771}
1772```
Mark Young39389872017-01-19 21:10:49 -07001773| JSON Node | Description and Notes | Introspection Query |
1774|:----------------:|--------------------|:----------------:
1775| "file\_format\_version" | Manifest format major.minor.patch version number. | N/A |
Lenny Komow32846e52017-12-27 15:32:44 -07001776| | Supported versions are: 1.0.0, 1.0.1, 1.1.0, 1.1.1, and 1.1.2. | |
Mark Young39389872017-01-19 21:10:49 -07001777| "layer" | The identifier used to group a single layer's information together. | vkEnumerateInstanceLayerProperties |
1778| "layers" | The identifier used to group multiple layers' information together. This requires a minimum Manifest file format version of 1.0.1.| vkEnumerateInstanceLayerProperties |
1779| "name" | The string used to uniquely identify this layer to applications. | vkEnumerateInstanceLayerProperties |
1780| "type" | This field indicates the type of layer. The values can be: GLOBAL, or INSTANCE | vkEnumerate*LayerProperties |
1781| | **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 -06001782| "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 -07001783| "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 |
1784| "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 |
1785| "description" | A high-level description of the layer and it's intended use. | vkEnumerateInstanceLayerProperties |
1786| "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 |
1787| "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 |
1788| "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 |
1789| "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 |
1790| "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 -06001791| "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 |
Lenny Komow32846e52017-12-27 15:32:44 -07001792| "pre_instance_functions" | **Implicit Layers Only** - **OPTIONAL:** Indicates which functions the layer wishes to intercept, that do not require that an instance has been created. This should be an object where each function to be intercepted is defined as a string entry where the key is the Vulkan function name and the value is the name of the intercept function in the layer's dynamic library. Available in layer manifest versions 1.1.2 and up. See [Pre-Instance Functions](#pre-instance-functions) for more information. | vkEnumerateInstance*Properties |
Mark Young39389872017-01-19 21:10:49 -07001793
1794##### Layer Manifest File Version History
1795
Lenny Komow32846e52017-12-27 15:32:44 -07001796The current highest supported Layer Manifest file format supported is 1.1.2.
Mark Young39389872017-01-19 21:10:49 -07001797Information about each version is detailed in the following sub-sections:
1798
Lenny Komow32846e52017-12-27 15:32:44 -07001799###### Layer Manifest File Version 1.1.2
1800
1801Version 1.1.2 introduced the ability of layers to intercept function calls that do not have an instance.
1802
1803###### Layer Manifest File Version 1.1.1
1804
1805The ability to define custom metalayers was added.
1806To support metalayers, the "component_layers" section was added, and the requirement for a "library_path" section to be present was removed when the "component_layers" section is present.
1807
Mark Young39389872017-01-19 21:10:49 -07001808###### Layer Manifest File Version 1.1.0
1809
1810Layer Manifest File Version 1.1.0 is tied to changes exposed by the Loader/Layer
1811interface version 2.
1812 1. Renaming "vkGetInstanceProcAddr" in the "functions" section is
1813 deprecated since the loader no longer needs to query the layer about
1814 "vkGetInstanceProcAddr" directly. It is now returned during the layer
1815 negotiation, so this field will be ignored.
1816 2. Renaming "vkGetDeviceProcAddr" in the "functions" section is
1817 deprecated since the loader no longer needs to query the layer about
1818 "vkGetDeviceProcAddr" directly. It too is now returned during the layer
1819 negotiation, so this field will be ignored.
1820 3. Renaming the "vkNegotiateLoaderLayerInterfaceVersion" function is
1821 being added to the "functions" section, since this is now the only
1822 function the loader needs to query using OS-specific calls.
1823 - NOTE: This is an optional field and, as the two previous fields, only
1824needed if the layer requires changing the name of the function for some reason.
1825
1826You do not need to update your layer manifest file if you don't change the
1827names of any of the listed functions.
1828
1829###### Layer Manifest File Version 1.0.1
1830
1831The ability to define multiple layers using the "layers" array was added. This
1832JSON array field can be used when defining a single layer or multiple layers.
1833The "layer" field is still present and valid for a single layer definition.
1834
1835###### Layer Manifest File Version 1.0.0
1836
1837The initial version of the layer manifest file specified the basic format and
1838fields of a layer JSON file. The fields of the 1.0.0 file format include:
1839 * "file\_format\_version"
1840 * "layer"
1841 * "name"
1842 * "type"
1843 * "library\_path"
1844 * "api\_version"
1845 * "implementation\_version"
1846 * "description"
1847 * "functions"
1848 * "instance\_extensions"
1849 * "device\_extensions"
1850 * "enable\_environment"
1851 * "disable\_environment"
1852
1853It was also during this time that the value of "DEVICE" was deprecated from
1854the "type" field.
1855
1856
1857#### Layer Library Versions
1858
1859The current Layer Library interface is at version 2. The following sections
1860detail the differences between the various versions.
1861
1862##### Layer Library API Version 2
1863
1864Introduced the concept of
1865[loader and layer interface](#layer-version-negotiation) using the new
1866`vkNegotiateLoaderLayerInterfaceVersion` function. Additionally, it introduced
1867the concept of
1868[Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-
1869extensions)
1870and the associated `vk_layerGetPhysicalDeviceProcAddr` function. Finally, it
1871changed the manifest file defition to 1.1.0.
1872
1873##### Layer Library API Version 1
1874
1875A layer library supporting interface version 1 had the following behavior:
1876 1. `GetInstanceProcAddr` and `GetDeviceProcAddr` were directly exported
1877 2. The layer manifest file was able to override the names of the
1878`GetInstanceProcAddr` and `GetDeviceProcAddr`functions.
1879
1880##### Layer Library API Version 0
1881
1882A layer library supporting interface version 0 must define and export these
1883introspection functions, unrelated to any Vulkan function despite the names,
1884signatures, and other similarities:
1885
Lenny Komowde3924a2017-05-04 14:50:01 -06001886- `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
Mark Young39389872017-01-19 21:10:49 -07001887library.
1888 - This function never fails.
1889 - When a layer library contains only one layer, this function may be an alias
1890 to the layer's `vkEnumerateInstanceLayerProperties`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001891- `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
Mark Young39389872017-01-19 21:10:49 -07001892 layers in a layer library.
1893 - "pLayerName" is always a valid layer name.
1894 - This function never fails.
1895 - When a layer library contains only one layer, this function may be an alias
1896 to the layer's `vkEnumerateInstanceExtensionProperties`.
Lenny Komowde3924a2017-05-04 14:50:01 -06001897- `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
Mark Young39389872017-01-19 21:10:49 -07001898 proper, or empty subset) of layers in a layer library.
1899 - "physicalDevice" is always `VK_NULL_HANDLE`.
1900 - This function never fails.
1901 - If a layer is not enumerated by this function, it will not participate in
1902 device function interception.
Lenny Komowde3924a2017-05-04 14:50:01 -06001903- `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
Mark Young39389872017-01-19 21:10:49 -07001904 layers in a layer library.
1905 - "physicalDevice" is always `VK_NULL_HANDLE`.
1906 - "pLayerName" is always a valid layer name.
1907 - This function never fails.
1908
1909It must also define and export these functions once for each layer in the
1910library:
1911
Lenny Komowde3924a2017-05-04 14:50:01 -06001912- `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a
Mark Young39389872017-01-19 21:10:49 -07001913layer's vkGetInstanceProcAddr except it is exported.
1914
1915 When a layer library contains only one layer, this function may
1916 alternatively be named `vkGetInstanceProcAddr`.
1917
Lenny Komowde3924a2017-05-04 14:50:01 -06001918- `<layerName>GetDeviceProcAddr` behaves identically to a layer's
Mark Young39389872017-01-19 21:10:49 -07001919vkGetDeviceProcAddr except it is exported.
1920
1921 When a layer library contains only one layer, this function may
1922 alternatively be named `vkGetDeviceProcAddr`.
1923
1924All layers contained within a library must support `vk_layer.h`. They do not
1925need to implement functions that they do not intercept. They are recommended
1926not to export any functions.
1927
1928
1929<br/>
1930<br/>
1931
1932## Vulkan Installable Client Driver Interface With the Loader
1933
1934This section discusses the various requirements for the loader and a Vulkan
1935ICD to properly hand-shake.
1936
Lenny Komowde3924a2017-05-04 14:50:01 -06001937 * [ICD Discovery](#icd-discovery)
Mark Young540d71c2017-05-18 14:52:14 -06001938 * [Overriding the Default ICD Usage](#overriding-the-default-icd-usage)
Lenny Komowde3924a2017-05-04 14:50:01 -06001939 * [ICD Manifest File Usage](#icd-manifest-file-usage)
1940 * [ICD Discovery on Windows](#icd-discovery-on-windows)
1941 * [ICD Discovery on Linux](#icd-discovery-on-linux)
1942 * [Using Pre-Production ICDs on Windows and Linux](#using-pre-production-icds-on-windows-and-linux)
1943 * [ICD Discovery on Android](#icd-discovery-on-android)
1944 * [ICD Manifest File Format](#icd-manifest-file-format)
1945 * [ICD Manifest File Versions](#icd-manifest-file-versions)
1946 * [ICD Manifest File Version 1.0.0](#icd-manifest-file-version-1.0.0)
1947 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
1948 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
1949 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
1950 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
1951 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
1952 * [Windows and Linux ICD Negotiation](#windows-and-linux-icd-negotiation)
1953 * [Version Negotiation Between Loader and ICDs](#version-negotiation-between-loader-and-icds)
1954 * [Interfacing With Legacy ICDs or Loader](#interfacing-with-legacy-icds-or-loader)
Mark Young02df1a82017-04-18 19:52:18 -06001955 * [Loader Version 5 Interface Requirements](#loader-version-5-interface-requirements)
Lenny Komowde3924a2017-05-04 14:50:01 -06001956 * [Loader Version 4 Interface Requirements](#loader-version-4-interface-requirements)
1957 * [Loader Version 3 Interface Requirements](#loader-version-3-interface-requirements)
1958 * [Loader Version 2 Interface Requirements](#loader-version-2-interface-requirements)
1959 * [Loader Versions 0 and 1 Interface Requirements](#loader-versions-0-and-1-interface-requirements)
1960 * [Android ICD Negotiation](#android-icd-negotiation)
Mark Young39389872017-01-19 21:10:49 -07001961
1962
1963### ICD Discovery
1964
1965Vulkan allows multiple drivers each with one or more devices (represented by a
1966Vulkan `VkPhysicalDevice` object) to be used collectively. The loader is
1967responsible for discovering available Vulkan ICDs on the system. Given a list
1968of available ICDs, the loader can enumerate all the physical devices available
1969for an application and return this information to the application. The process
1970in which the loader discovers the available Installable Client Drivers (ICDs)
1971on a system is platform dependent. Windows, Linux and Android ICD discovery
1972details are listed below.
1973
Mark Young540d71c2017-05-18 14:52:14 -06001974#### Overriding the Default ICD Usage
1975
1976There may be times that a developer wishes to force the loader to use a specific ICD.
1977This could be for many reasons including : using a beta driver, or forcing the loader
1978to skip a problematic ICD. In order to support this, the loader can be forced to
1979look at specific ICDs with the `VK_ICD_FILENAMES` environment variable. In order
1980to use the setting, simply set it to a properly delimited list of ICD Manifest
1981files that you wish to use. In this case, please provide the global path to these
1982files to reduce issues.
1983
1984For example:
1985
1986##### On Windows
1987
1988```
1989set VK_ICD_FILENAMES=/windows/system32/nv-vk64.json
1990```
1991
1992This is an example which is using the `VK_ICD_FILENAMES` override on Windows to point
1993to the Nvidia Vulkan driver's ICD Manifest file.
1994
1995##### On Linux
1996
1997```
1998export VK_ICD_FILENAMES=/home/user/dev/mesa/share/vulkan/icd.d/intel_icd.x86_64.json
1999```
2000
2001This is an example which is using the `VK_ICD_FILENAMES` override on Linux to point
2002to the Intel Mesa driver's ICD Manifest file.
2003
2004
Mark Young39389872017-01-19 21:10:49 -07002005#### ICD Manifest File Usage
2006
Mark Young18bbaab2017-03-20 08:27:14 -06002007As with layers, on Windows and Linux systems, JSON formatted manifest files are
Mark Young39389872017-01-19 21:10:49 -07002008used to store ICD information. In order to find system-installed drivers, the
2009Vulkan loader will read the JSON files to identify the names and attributes of
2010each driver. One thing you will notice is that ICD Manifest files are much
2011simpler than the corresponding layer Manifest files.
2012
2013See the [Current ICD Manifest File Format](#icd-manifest-file-format) section
2014for more details.
2015
2016
2017#### ICD Discovery on Windows
2018
Lenny Komow4c3d3772017-08-31 17:19:17 -06002019In order to find installed ICDs, the loader scans through registry keys specific to Display
2020Adapters and all Software Components associated with these adapters for the
2021locations of JSON manifest files. These keys are located in device keys
2022created during driver installation and contain configuration information
2023for base settings, including OpenGL and Direct3D ICD location.
2024
2025The Device Adapter and Software Component key paths should be obtained through the PnP
2026Configuration Manager API. The `000X` key will be a numbered key, where each
2027device is assigned a different number.
2028
2029```
2030 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanDriverName
2031 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{SoftwareComponent GUID}\000X\VulkanDriverName
2032```
2033
2034In addition, on 64-bit systems there may be another set of registry values, listed
2035below. These values record the locations of 32-bit layers on 64-bit operating systems,
2036in the same way as the Windows-on-Windows functionality.
2037
2038```
2039 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{Adapter GUID}\000X\VulkanDriverNameWow
2040 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Class\{SoftwareComponent GUID}\000X\VulkanDriverNameWow
2041```
2042
2043If any of the above values exist and is of type `REG_SZ`, the loader will open the JSON
2044manifest file specified by the key value. Each value must be a full absolute
2045path to a JSON manifest file. The values may also be of type `REG_MULTI_SZ`, in
2046which case the value will be interpreted as a list of paths to JSON manifest files.
2047
2048Additionally, the Vulkan loader will scan the values in the following Windows registry key:
Mark Young39389872017-01-19 21:10:49 -07002049
2050```
2051 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers
2052```
2053
2054For 32-bit applications on 64-bit Windows, the loader scan's the 32-bit
2055registry location:
2056
2057```
2058 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\Drivers
2059```
2060
Lenny Komow4c3d3772017-08-31 17:19:17 -06002061Every ICD in these locations should be given as a DWORD, with value 0, where
2062the name of the value is the full path to a JSON manifest file. The Vulkan loader
2063will attempt to open each manifest file to obtain the information about an ICD's
2064shared library (".dll") file.
Mark Young39389872017-01-19 21:10:49 -07002065
2066For example, let us assume the registry contains the following data:
2067
2068```
2069[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
2070
2071"C:\vendor a\vk_vendora.json"=dword:00000000
2072"C:\windows\system32\vendorb_vk.json"=dword:00000001
2073"C:\windows\system32\vendorc_icd.json"=dword:00000000
2074```
2075
2076In this case, the loader will step through each entry, and check the value. If
2077the value is 0, then the loader will attempt to load the file. In this case,
Mark Young18bbaab2017-03-20 08:27:14 -06002078the loader will open the first and last listings, but not the middle. This
Mark Young39389872017-01-19 21:10:49 -07002079is because the value of 1 for vendorb_vk.json disables the driver.
2080
2081The Vulkan loader will open each enabled manifest file found to obtain the name
2082or pathname of an ICD shared library (".DLL") file.
2083
Lenny Komow4c3d3772017-08-31 17:19:17 -06002084ICDs should use the registry locations from the PnP Configuration Manager wherever
2085practical. That location clearly ties the ICD to a given device. The
2086`SOFTWARE\Khronos\Vulkan\Drivers` location is the older method for locating ICDs,
2087and is retained for backwards compatibility.
2088
Mark Young39389872017-01-19 21:10:49 -07002089See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
2090details.
2091
2092
2093#### ICD Discovery on Linux
2094
2095In order to find installed ICDs, the Vulkan loader will scan the files
2096in the following Linux directories:
2097
2098```
2099 /usr/local/etc/vulkan/icd.d
2100 /usr/local/share/vulkan/icd.d
2101 /etc/vulkan/icd.d
2102 /usr/share/vulkan/icd.d
2103 $HOME/.local/share/vulkan/icd.d
2104```
2105
2106The "/usr/local/*" directories can be configured to be other directories at
2107build time.
2108
2109The typical usage of the directories is indicated in the table below.
2110
2111| Location | Details |
2112|-------------------|------------------------|
2113| $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 |
2114| "/usr/local/etc/vulkan/icd.d" | Directory for locally built ICDs |
2115| "/usr/local/share/vulkan/icd.d" | Directory for locally built ICDs |
2116| "/etc/vulkan/icd.d" | Location of ICDs installed from non-Linux-distribution-provided packages |
2117| "/usr/share/vulkan/icd.d" | Location of ICDs installed from Linux-distribution-provided packages |
2118
2119The Vulkan loader will open each manifest file found to obtain the name or
2120pathname of an ICD shared library (".so") file.
2121
2122See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
2123details.
2124
Mark Young540d71c2017-05-18 14:52:14 -06002125##### Additional Settings For ICD Debugging
2126
2127If you are seeing issues which may be related to the ICD. A possible option to debug is to enable the
2128`LD_BIND_NOW` environment variable. This forces every dynamic library's symbols to be fully resolved on load. If
2129there is a problem with an ICD missing symbols on your system, this will expose it and cause the Vulkan loader
2130to fail on loading the ICD. It is recommended that you enable `LD_BIND_NOW` along with `VK_LOADER_DEBUG=warn`
2131to expose any issues.
2132
Mark Young39389872017-01-19 21:10:49 -07002133#### Using Pre-Production ICDs on Windows and Linux
2134
2135Independent Hardware Vendor (IHV) pre-production ICDs. In some cases, a
2136pre-production ICD may be in an installable package. In other cases, a
2137pre-production ICD may simply be a shared library in the developer's build tree.
2138In this latter case, we want to allow developers to point to such an ICD without
2139modifying the system-installed ICD(s) on their system.
2140
2141This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
2142which will override the mechanism used for finding system-installed ICDs. In
2143other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
2144
2145The "VK\_ICD\_FILENAMES" environment variable is a list of ICD
2146manifest files, containing the full path to the ICD JSON Manifest file. This
2147list is colon-separated on Linux, and semi-colon separated on Windows.
2148
2149Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
2150file for a developer-built ICD. A separator (colon or semi-colon) is only used
2151if more than one ICD is listed.
2152
2153**NOTE:** On Linux, this environment variable will be ignored for suid programs.
2154
2155
2156#### ICD Discovery on Android
2157
2158The Android loader lives in the system library folder. The location cannot be
2159changed. The loader will load the driver/ICD via hw\_get\_module with the ID
2160of "vulkan". **Due to security policies in Android, none of this can be modified
2161under normal use.**
2162
2163
2164### ICD Manifest File Format
2165
2166The following section discusses the details of the ICD Manifest JSON file
2167format. The JSON file itself does not have any requirements for naming. The
2168only requirement is that the extension suffix of the file ends with ".json".
2169
Tobin Ehlis2dbc2152017-10-19 13:58:23 -06002170Here is an example ICD JSON Manifest file:
Mark Young39389872017-01-19 21:10:49 -07002171
2172```
2173{
2174 "file_format_version": "1.0.0",
2175 "ICD": {
2176 "library_path": "path to ICD library",
2177 "api_version": "1.0.5"
2178 }
2179}
2180```
2181
2182| Field Name | Field Value |
2183|----------------|--------------------|
2184| "file\_format\_version" | The JSON format major.minor.patch version number of this file. Currently supported version is 1.0.0. |
2185| "ICD" | The identifier used to group all ICD information together. |
2186| "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 |
2187| "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. |
2188
2189**NOTE:** If the same ICD shared library supports multiple, incompatible
2190versions of text manifest file format versions, it must have separate
2191JSON files for each (all of which may point to the same shared library).
2192
2193##### ICD Manifest File Versions
2194
2195There has only been one version of the ICD manifest files supported. This is
2196version 1.0.0.
2197
2198###### ICD Manifest File Version 1.0.0
2199
2200The initial version of the ICD Manifest file specified the basic format and
2201fields of a layer JSON file. The fields of the 1.0.0 file format include:
2202 * "file\_format\_version"
2203 * "ICD"
2204 * "library\_path"
2205 * "api\_version"
2206
2207
2208### ICD Vulkan Entry-Point Discovery
2209
2210The Vulkan symbols exported by an ICD must not clash with the loader's exported
2211Vulkan symbols. This could be for several reasons. Because of this, all ICDs
2212must export the following function that is used for discovery of ICD Vulkan
2213entry-points. This entry-point is not a part of the Vulkan API itself, only a
2214private interface between the loader and ICDs for version 1 and higher
2215interfaces.
2216
2217```cpp
2218VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
2219 VkInstance instance,
2220 const char* pName);
2221```
2222
2223This function has very similar semantics to `vkGetInstanceProcAddr`.
2224`vk_icdGetInstanceProcAddr` returns valid function pointers for all the global-
2225level and instance-level Vulkan functions, and also for `vkGetDeviceProcAddr`.
2226Global-level functions are those which contain no dispatchable object as the
2227first parameter, such as `vkCreateInstance` and
2228`vkEnumerateInstanceExtensionProperties`. The ICD must support querying global-
2229level entry-points by calling `vk_icdGetInstanceProcAddr` with a NULL
2230`VkInstance` parameter. Instance-level functions are those that have either
2231`VkInstance`, or `VkPhysicalDevice` as the first parameter dispatchable object.
2232Both core entry-points and any instance extension entry-points the ICD supports
2233should be available via `vk_icdGetInstanceProcAddr`. Future Vulkan instance
2234extensions may define and use new instance-level dispatchable objects other
2235than `VkInstance` and `VkPhysicalDevice`, in which case extension entry-points
2236using these newly defined dispatchable objects must be queryable via
2237`vk_icdGetInstanceProcAddr`.
2238
2239All other Vulkan entry-points must either:
2240 * NOT be exported directly from the ICD library
2241 * or NOT use the official Vulkan function names if they are exported
2242
2243This requirement is for ICD libraries that include other
2244functionality (such as OpenGL) and thus could be loaded by the
2245application prior to when the Vulkan loader library is loaded by the
2246application.
2247
2248Beware of interposing by dynamic OS library loaders if the official Vulkan
2249names are used. On Linux, if official names are used, the ICD library must be
2250linked with -Bsymbolic.
2251
2252
2253### ICD Unknown Physical Device Extensions
2254
2255Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
2256result in the following behavior:
2257 1. The loader would check if core function:
2258 - If it was, it would return the function pointer
2259 2. The loader would check if known extension function:
2260 - If it was, it would return the function pointer
2261 3. If the loader knew nothing about it, it would call down using
2262`GetInstanceProcAddr`
2263 - If it returned non-NULL, treat it as an unknown logical device command.
2264 - This meant setting up a generic trampoline function that takes in a
2265VkDevice as the first parameter and adjusting the dispatch table to call the
2266ICD/Layers function after getting the dispatch table from the VkDevice.
2267 4. If all the above failed, the loader would return NULL to the application.
2268
2269This caused problems when an ICD attempted to expose new physical device
2270extensions the loader knew nothing about, but an application did. Because the
2271loader knew nothing about it, the loader would get to step 3 in the above
2272process and would treat the function as an unknown logical device command. The
2273problem is, this would create a generic VkDevice trampoline function which, on
2274the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
2275This would lead to a crash or corruption.
2276
2277In order to identify the extension entry-points specific to physical device
2278extensions, the following function can be added to an ICD:
2279
2280```cpp
2281PFN_vkVoidFunction vk_icdGetPhysicalDeviceProcAddr(VkInstance instance,
2282 const char* pName);
2283```
2284
2285This function behaves similar to `vkGetInstanceProcAddr` and
2286`vkGetDeviceProcAddr` except it should only return values for physical device
2287extension entry-points. In this way, it compares "pName" to every physical
2288device function supported in the ICD.
2289
2290The following rules apply:
Lenny Komowde3924a2017-05-04 14:50:01 -06002291* If it is the name of a physical device function supported by the ICD, the
Mark Young39389872017-01-19 21:10:49 -07002292pointer to the ICD's corresponding function should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06002293* If it is the name of a valid function which is **not** a physical device
Mark Young39389872017-01-19 21:10:49 -07002294function (i.e. an Instance, Device, or other function implemented by the ICD),
2295then the value of NULL should be returned.
Lenny Komowde3924a2017-05-04 14:50:01 -06002296* If the ICD has no idea what this function is, it should return NULL.
Mark Young39389872017-01-19 21:10:49 -07002297
2298This support is optional and should not be considered a requirement. This is
2299only required if an ICD intends to support some functionality not directly
2300supported by a significant population of loaders in the public. If an ICD
Mark Young18bbaab2017-03-20 08:27:14 -06002301does implement this support, it should return the address of its
Mark Young39389872017-01-19 21:10:49 -07002302`vk_icdGetPhysicalDeviceProcAddr` function through the `vkGetInstanceProcAddr`
2303function.
2304
2305The new behavior of the loader's vkGetInstanceProcAddr with support for the
2306`vk_icdGetPhysicalDeviceProcAddr` function is as follows:
2307 1. Check if core function:
2308 - If it is, return the function pointer
2309 2. Check if known instance or device extension function:
2310 - If it is, return the function pointer
2311 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
2312 - If it returns non-NULL, return a trampoline to a generic physical device
2313function, and setup a generic terminator which will pass it to the proper ICD.
2314 4. Call down using `GetInstanceProcAddr`
2315 - If it returns non-NULL, treat it as an unknown logical device command.
2316This means setting up a generic trampoline function that takes in a VkDevice as
2317the first parameter and adjusting the dispatch table to call the ICD/Layers
2318function after getting the dispatch table from the VkDevice. Then, return the
2319pointer to corresponding trampoline function.
2320 5. Return NULL
2321
2322You can see now, that, if the command gets promoted to core later, it will no
2323longer be setup using `vk_icdGetPhysicalDeviceProcAddr`. Additionally, if the
2324loader adds direct support for the extension, it will no longer get to step 3,
2325because step 2 will return a valid function pointer. However, the ICD should
2326continue to support the command query via `vk_icdGetPhysicalDeviceProcAddr`,
2327until at least a Vulkan version bump, because an older loader may still be
2328attempting to use the commands.
2329
2330
2331### ICD Dispatchable Object Creation
2332
2333As previously covered, the loader requires dispatch tables to be accessible
2334within Vulkan dispatchable objects, such as: `VkInstance`, `VkPhysicalDevice`,
2335`VkDevice`, `VkQueue`, and `VkCommandBuffer`. The specific requirements on all
2336dispatchable objects created by ICDs are as follows:
2337
2338- All dispatchable objects created by an ICD can be cast to void \*\*
2339- The loader will replace the first entry with a pointer to the dispatch table
2340 which is owned by the loader. This implies three things for ICD drivers
2341 1. The ICD must return a pointer for the opaque dispatchable object handle
2342 2. This pointer points to a regular C structure with the first entry being a
2343 pointer.
2344 * **NOTE:** For any C\++ ICD's that implement VK objects directly as C\++
2345classes.
2346 * The C\++ compiler may put a vtable at offset zero if your class is non-
2347POD due to the use of a virtual function.
2348 * In this case use a regular C structure (see below).
2349 3. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
2350 dispatchable objects, as follows (see `include/vulkan/vk_icd.h`):
2351
2352```cpp
2353#include "vk_icd.h"
2354
2355union _VK_LOADER_DATA {
2356 uintptr loadermagic;
2357 void *loaderData;
2358} VK_LOADER_DATA;
2359
2360vkObj alloc_icd_obj()
2361{
2362 vkObj *newObj = alloc_obj();
2363 ...
2364 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
2365
2366 set_loader_magic_value(newObj);
2367 ...
2368 return newObj;
2369}
2370```
2371
2372
2373### Handling KHR Surface Objects in WSI Extensions
2374
2375Normally, ICDs handle object creation and destruction for various Vulkan
2376objects. The WSI surface extensions for Linux and Windows
2377("VK\_KHR\_win32\_surface", "VK\_KHR\_xcb\_surface", "VK\_KHR\_xlib\_surface",
2378"VK\_KHR\_mir\_surface", "VK\_KHR\_wayland\_surface", and "VK\_KHR\_surface")
2379are handled differently. For these extensions, the `VkSurfaceKHR` object
2380creation and destruction may be handled by either the loader, or an ICD.
2381
2382If the loader handles the management of the `VkSurfaceKHR` objects:
2383 1. The loader will handle the calls to `vkCreateXXXSurfaceKHR` and
2384`vkDestroySurfaceKHR`
2385 functions without involving the ICDs.
2386 * Where XXX stands for the Windowing System name:
2387 * Mir
2388 * Wayland
2389 * Xcb
2390 * Xlib
2391 * Windows
2392 * Android
2393 2. The loader creates a `VkIcdSurfaceXXX` object for the corresponding
2394`vkCreateXXXSurfaceKHR` call.
2395 * The `VkIcdSurfaceXXX` structures are defined in `include/vulkan/vk_icd.h`.
2396 3. ICDs can cast any `VkSurfaceKHR` object to a pointer to the appropriate
2397 `VkIcdSurfaceXXX` structure.
2398 4. The first field of all the `VkIcdSurfaceXXX` structures is a
2399`VkIcdSurfaceBase` enumerant that indicates whether the
2400 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
2401
2402The ICD may choose to handle `VkSurfaceKHR` object creation instead. If an ICD
2403desires to handle creating and destroying it must do the following:
2404 1. Support version 3 or newer of the loader/ICD interface.
2405 2. Export and handle all functions that take in a `VkSurfaceKHR` object,
2406including:
2407 * `vkCreateXXXSurfaceKHR`
2408 * `vkGetPhysicalDeviceSurfaceSupportKHR`
2409 * `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2410 * `vkGetPhysicalDeviceSurfaceFormatsKHR`
2411 * `vkGetPhysicalDeviceSurfacePresentModesKHR`
2412 * `vkCreateSwapchainKHR`
2413 * `vkDestroySurfaceKHR`
2414
2415Because the `VkSurfaceKHR` object is an instance-level object, one object can be
2416associated with multiple ICDs. Therefore, when the loader receives the
2417`vkCreateXXXSurfaceKHR` call, it still creates an internal `VkSurfaceIcdXXX`
2418object. This object acts as a container for each ICD's version of the
2419`VkSurfaceKHR` object. If an ICD does not support the creation of its own
2420`VkSurfaceKHR` object, the loader's container stores a NULL for that ICD. On
2421the otherhand, if the ICD does support `VkSurfaceKHR` creation, the loader will
2422make the appropriate `vkCreateXXXSurfaceKHR` call to the ICD, and store the
2423returned pointer in it's container object. The loader then returns the
2424`VkSurfaceIcdXXX` as a `VkSurfaceKHR` object back up the call chain. Finally,
2425when the loader receives the `vkDestroySurfaceKHR` call, it subsequently calls
2426`vkDestroySurfaceKHR` for each ICD who's internal `VkSurfaceKHR` object is not
2427NULL. Then the loader destroys the container object before returning.
2428
2429
2430### Loader and ICD Interface Negotiation
2431
2432Generally, for functions issued by an application, the loader can be
2433viewed as a pass through. That is, the loader generally doesn't modify the
2434functions or their parameters, but simply calls the ICDs entry-point for that
2435function. There are specific additional interface requirements an ICD needs to
2436comply with that are not part of any requirements from the Vulkan specification.
2437These addtional requirements are versioned to allow flexibility in the future.
2438
2439
2440#### Windows and Linux ICD Negotiation
2441
2442
2443##### Version Negotiation Between Loader and ICDs
2444
2445All ICDs (supporting interface version 2 or higher) must export the following
2446function that is used for determination of the interface version that will be
2447used. This entry-point is not a part of the Vulkan API itself, only a private
2448interface between the loader and ICDs.
2449
2450```cpp
2451 VKAPI_ATTR VkResult VKAPI_CALL
2452 vk_icdNegotiateLoaderICDInterfaceVersion(
2453 uint32_t* pSupportedVersion);
2454```
2455
2456This function allows the loader and ICD to agree on an interface version to use.
2457The "pSupportedVersion" parameter is both an input and output parameter.
2458"pSupportedVersion" is filled in by the loader with the desired latest interface
2459version supported by the loader (typically the latest). The ICD receives this
2460and returns back the version it desires in the same field. Because it is
2461setting up the interface version between the loader and ICD, this should be
2462the first call made by a loader to the ICD (even prior to any calls to
2463`vk_icdGetInstanceProcAddr`).
2464
2465If the ICD receiving the call no longer supports the interface version provided
2466by the loader (due to deprecation), then it should report
2467VK_ERROR_INCOMPATIBLE_DRIVER error. Otherwise it sets the value pointed by
2468"pSupportedVersion" to the latest interface version supported by both the ICD
2469and the loader and returns VK_SUCCESS.
2470
2471The ICD should report VK_SUCCESS in case the loader provided interface version
2472is newer than that supported by the ICD, as it's the loader's responsibility to
2473determine whether it can support the older interface version supported by the
2474ICD. The ICD should also report VK_SUCCESS in the case its interface version
2475is greater than the loader's, but return the loader's version. Thus, upon
2476return of VK_SUCCESS the "pSupportedVersion" will contain the desired interface
2477version to be used by the ICD.
2478
2479If the loader receives an interface version from the ICD that the loader no
2480longer supports (due to deprecation), or it receives a
2481VK_ERROR_INCOMPATIBLE_DRIVER error instead of VK_SUCCESS, then the loader will
2482treat the ICD as incompatible and will not load it for use. In this case, the
2483application will not see the ICDs `vkPhysicalDevice` during enumeration.
2484
2485###### Interfacing With Legacy ICDs or Loader
2486
2487If a loader sees that an ICD does not export the
2488`vk_icdNegotiateLoaderICDInterfaceVersion` function, then the loader assumes the
2489corresponding ICD only supports either interface version 0 or 1.
2490
2491From the other side of the interface, if an ICD sees a call to
2492`vk_icdGetInstanceProcAddr` before a call to
Tobin Ehlisfde57082017-10-23 16:22:42 -06002493`vk_icdNegotiateLoaderICDInterfaceVersion`, then it knows that loader making the calls
Mark Young39389872017-01-19 21:10:49 -07002494is a legacy loader supporting version 0 or 1. If the loader calls
2495`vk_icdGetInstanceProcAddr` first, it supports at least version 1. Otherwise,
2496the loader only supports version 0.
2497
2498
Mark Young02df1a82017-04-18 19:52:18 -06002499##### Loader Version 5 Interface Requirements
2500
2501Version 5 of the loader/ICD interface has no changes to the actual interface.
2502If the loader requests interface version 5 or greater, it is simply
2503an indication to ICDs that the loader is now evaluating if the API Version info
2504passed into vkCreateInstance is a valid version for the loader. If it is not,
2505the loader will catch this during vkCreateInstance and fail with a
2506VK_ERROR_INCOMPATIBLE_DRIVER error.
2507
2508On the other hand, if version 5 or newer is not requested by the loader, then it
2509indicates to the ICD that the loader is ignorant of the API version being
2510requested. Because of this, it falls on the ICD to validate that the API
2511Version is not greater than major = 1 and minor = 0. If it is, then the ICD
2512should automatically fail with a VK_ERROR_INCOMPATIBLE_DRIVER error since the
2513loader is a 1.0 loader, and is unaware of the version.
2514
2515Here is a table of the expected behaviors:
2516
2517| Loader Supports I/f Version | ICD Supports I/f Version | Result |
2518| :---: |:---:|------------------------|
2519| <= 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. |
2520| <= 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. |
2521| >= 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. |
2522| >= 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. |
2523
Mark Young39389872017-01-19 21:10:49 -07002524##### Loader Version 4 Interface Requirements
2525
2526The major change to version 4 of the loader/ICD interface is the support of
2527[Unknown Physical Device Extensions](#icd-unknown-physical-device-
2528extensions] using the `vk_icdGetPhysicalDeviceProcAddr` function. This
2529function is purely optional. However, if an ICD supports a Physical Device
2530extension, it must provide a `vk_icdGetPhysicalDeviceProcAddr` function.
2531Otherwise, the loader will continue to treat any unknown functions as VkDevice
2532functions and cause invalid behavior.
2533
2534
2535##### Loader Version 3 Interface Requirements
2536
2537The primary change that occurred in version 3 of the loader/ICD interface was to
2538allow an ICD to handle creation/destruction of their own KHR_surfaces. Up until
2539this point, the loader created a surface object that was used by all ICDs.
2540However, some ICDs may want to provide their own surface handles. If an ICD
2541chooses to enable this support, it must export support for version 3 of the
2542loader/ICD interface, as well as any Vulkan function that uses a KHR_surface
2543handle, such as:
2544- `vkCreateXXXSurfaceKHR` (where XXX is the platform specific identifier [i.e.
2545`vkCreateWin32SurfaceKHR` for Windows])
2546- `vkDestroySurfaceKHR`
2547- `vkCreateSwapchainKHR`
2548- `vkGetPhysicalDeviceSurfaceSupportKHR`
2549- `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2550- `vkGetPhysicalDeviceSurfaceFormatsKHR`
2551- `vkGetPhysicalDeviceSurfacePresentModesKHR`
2552
2553An ICD can still choose to not take advantage of this functionality by simply
2554not exposing the above the `vkCreateXXXSurfaceKHR` and `vkDestroySurfaceKHR`
2555functions.
2556
2557
2558##### Loader Version 2 Interface Requirements
2559
2560Version 2 interface has requirements in three areas:
2561 1. ICD Vulkan entry-point discovery,
2562 2. `KHR_surface` related requirements in the WSI extensions,
2563 3. Vulkan dispatchable object creation requirements.
2564
2565##### Loader Versions 0 and 1 Interface Requirements
2566
2567Version 0 and 1 interfaces do not support version negotiation via
2568`vk_icdNegotiateLoaderICDInterfaceVersion`. ICDs can distinguish version 0 and
2569version 1 interfaces as follows: if the loader calls `vk_icdGetInstanceProcAddr`
2570first it supports version 1; otherwise the loader only supports version 0.
2571
2572Version 0 interface does not support `vk_icdGetInstanceProcAddr`. Version 0
2573interface requirements for obtaining ICD Vulkan entry-points are as follows:
2574
2575- The function `vkGetInstanceProcAddr` **must be exported** in the ICD library
2576and returns valid function pointers for all the Vulkan API entry-points.
2577- `vkCreateInstance` **must be exported** by the ICD library.
2578- `vkEnumerateInstanceExtensionProperties` **must be exported** by the ICD
2579library.
2580
2581Additional Notes:
2582
2583- The loader will filter out extensions requested in `vkCreateInstance` and
2584`vkCreateDevice` before calling into the ICD; Filtering will be of extensions
2585advertised by entities (e.g. layers) different from the ICD in question.
2586- The loader will not call the ICD for `vkEnumerate\*LayerProperties`() as layer
2587properties are obtained from the layer libraries and layer JSON files.
2588- If an ICD library author wants to implement a layer, it can do so by having
2589the appropriate layer JSON manifest file refer to the ICD library file.
2590- The loader will not call the ICD for
2591 `vkEnumerate\*ExtensionProperties` if "pLayerName" is not equal to `NULL`.
2592- ICDs creating new dispatchable objects via device extensions need to
2593initialize the created dispatchable object. The loader has generic *trampoline*
2594code for unknown device extensions. This generic *trampoline* code doesn't
2595initialize the dispatch table within the newly created object. See the
2596[Creating New Dispatchable Objects](#creating-new-dispatchable-objects) section
2597for more information on how to initialize created dispatchable objects for
2598extensions non known by the loader.
2599
2600
2601#### Android ICD Negotiation
2602
2603The Android loader uses the same protocol for initializing the dispatch
2604table as described above. The only difference is that the Android
2605loader queries layer and extension information directly from the
2606respective libraries and does not use the json manifest files used
2607by the Windows and Linux loaders.
2608
Mark Young540d71c2017-05-18 14:52:14 -06002609## Table of Debug Environment Variables
2610
2611The following are all the Debug Environment Variables available for use with the
2612Loader. These are referenced throughout the text, but collected here for ease
2613of discovery.
2614
2615| Environment Variable | Behavior | Example Format |
Mark Young02df1a82017-04-18 19:52:18 -06002616|:---:|---------------------|----------------------|
Mark Young540d71c2017-05-18 14:52:14 -06002617| 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` |
2618| 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>` |
2619| 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>` |
2620| 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` |
2621| 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 -07002622
2623## Glossary of Terms
2624
2625| Field Name | Field Value |
Mark Young02df1a82017-04-18 19:52:18 -06002626|:---:|--------------------|
Mark Young39389872017-01-19 21:10:49 -07002627| 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. |
2628| 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. |
2629| Core Function | A function that is already part of the Vulkan core specification and not an extension. For example, vkCreateDevice(). |
2630| 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 |
2631| 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. |
2632| 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. |
2633| 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. |
2634| 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). |
2635| 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.
2636| 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. |
2637| 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 |
2638| 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. |
2639| 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. |
2640| 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. |
2641| 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).
2642| 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. |
2643| 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. |
2644| 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. |