blob: 32de7710b6a252e7b6609356406d4b8db62a122e [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
4 * [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
Mark Young39389872017-01-19 21:10:49 -070012 * [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
Mark Young39389872017-01-19 21:10:49 -070017 * [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)
28 * [Special Considerations](#special-considerations)
29 * [Layer Manifest File Format](#layer-manifest-file-format)
30 * [Layer Library Versions](#layer-library-versions)
Jon Ashburnc2972682016-02-08 15:42:01 -070031
Mark Young39389872017-01-19 21:10:49 -070032 * [Vulkan Installable Client Driver interface with the loader](#vulkan-installable-client-driver-interface-with-the-loader)
33 * [ICD Discovery](#icd-discovery)
34 * [ICD Manifest File Format](#icd-manifest-file-format)
35 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
36 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
37 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
38 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
39 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
40 * [Glossary of Terms](#glossary-of-terms)
41
42## Overview
Mark Youngcb6e6702016-07-20 11:38:53 -060043
Mark Young39389872017-01-19 21:10:49 -070044Vulkan is a layered architecture, made up of the following elements:
45 * The Vulkan Application
46 * [The Vulkan Loader](#the-loader)
47 * [Vulkan Layers](#layers)
48 * [Installable Client Drivers (ICDs)](#installable-client-drivers)
Jon Ashburnc2972682016-02-08 15:42:01 -070049
Mark Young39389872017-01-19 21:10:49 -070050![High Level View of Loader](./images/high_level_loader.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070051
Mark Young39389872017-01-19 21:10:49 -070052The general concepts in this document are applicable to the loaders available
53for Windows, Linux and Android based systems.
Jon Ashburnc2972682016-02-08 15:42:01 -070054
55
Mark Young39389872017-01-19 21:10:49 -070056#### Who Should Read This Document
Jon Ashburnc2972682016-02-08 15:42:01 -070057
Mark Young39389872017-01-19 21:10:49 -070058While this document is primarily targeted at developers of Vulkan applications,
59drivers and layers, the information contained in it could be useful to anyone
60wanting a better understanding of the Vulkan runtime.
Jon Ashburnc2972682016-02-08 15:42:01 -070061
Jon Ashburnc2972682016-02-08 15:42:01 -070062
Mark Young39389872017-01-19 21:10:49 -070063#### The Loader
Jon Ashburnc2972682016-02-08 15:42:01 -070064
Jeff Juliano18e50202017-01-31 16:36:18 -050065The application sits on one end of, and interfaces directly with, the
66loader. On the other end of the loader from the application are the ICDs, which
Mark Young39389872017-01-19 21:10:49 -070067control the Vulkan-capable hardware. An important point to remember is that
Jeff Juliano18e50202017-01-31 16:36:18 -050068Vulkan-capable hardware can be graphics-based, compute-based, or both. Between
69the application and the ICDs the loader can inject a number of optional
70[layers](#layers) that provide special functionality.
Mark Youngcb6e6702016-07-20 11:38:53 -060071
72The loader is responsible for working with the various layers as well as
Mark Young39389872017-01-19 21:10:49 -070073supporting multiple GPUs and their drivers. Any Vulkan function may
Mark Youngcb6e6702016-07-20 11:38:53 -060074wind up calling into a diverse set of modules: loader, layers, and ICDs.
75The loader is critical to managing the proper dispatching of Vulkan
Mark Young39389872017-01-19 21:10:49 -070076functions to the appropriate set of layers and ICDs. The Vulkan object
Mark Youngcb6e6702016-07-20 11:38:53 -060077model allows the loader to insert layers into a call chain so that the layers
Mark Young39389872017-01-19 21:10:49 -070078can process Vulkan functions prior to the ICD being called.
79
80This document is intended to provide an overview of the necessary interfaces
81between each of these.
82
83
84##### Goals of the Loader
85
86The loader was designed with the following goals in mind.
87 1. Support one or more Vulkan-capable ICD on a user's computer system without
88them interfering with one another.
89 2. Support Vulkan Layers which are optional modules that can be enabled by an
90application, developer, or standard system settings.
91 3. Impact the overall performance of a Vulkan application in the lowest
92possible fashion.
93
94
95#### Layers
96
97Layers are optional components that augment the Vulkan system. They can
98intercept, evaluate, and modify existing Vulkan functions on their way from the
99application down to the hardware. Layers are implemented as libraries that can
100be enabled in different ways (including by application request) and are loaded
101during CreateInstance. Each layer can choose to hook (intercept) any Vulkan
102functions which in turn can be ignored or augmented. A layer does not need to
103intercept all Vulkan functions. It may choose to intercept all known functions,
104or, it may choose to intercept only one function.
105
106Some examples of features that layers may expose include:
107 * Validating API usage
108 * Adding the ability to perform Vulkan API tracing and debugging
109 * Overlay additional content on the applications surfaces
110
111Because layers are optionally, you may choose to enable layers for debugging
112your application, but then disable any layer usage when you release your
113product.
114
115
116#### Installable Client Drivers
117
118Vulkan allows multiple Installable Client Drivers (ICDs) each supporting one
119or more devices (represented by a Vulkan `VkPhysicalDevice` object) to be used
120collectively. The loader is responsible for discovering available Vulkan ICDs on
121the system. Given a list of available ICDs, the loader can enumerate all the
122physical devices available for an application and return this information to
123the application.
124
125
126#### Instance Versus Device
127
128There is an important concept which you will see brought up repeatedly
129throughout this document. Many functions, extensions, and other things in
130Vulkan are separated into two main groups:
131 * Instance-related Objects
132 * Device-related Objects
133
134
135##### Instance-related Objects
136
137A Vulkan Instance is a high-level construct used to provide Vulkan system-level
138information, or functionality. Vulkan objects associated directly with an
139instance are:
140 * `VkInstance`
141 * `VkPhysicalDevice`
142
143An Instance function is any Vulkan function which takes as its first parameter
144either an object from the Instance list, or nothing at all. Some Vulkan
145Instance functions are:
146 * `vkEnumerateInstanceExtensionProperties`
147 * `vkEnumeratePhysicalDevices`
148 * `vkCreateInstance`
149 * `vkDestroyInstance`
150
151You query Vulkan Instance functions using `vkGetInstanceProcAddr`.
152`vkGetInstanceProcAddr` can be used to query either device or instance entry-
153points in addition to all core entry-points. The returned function pointer is
154valid for this Instance and any object created under this Instance (including
155all `VkDevice` objects).
156
157Similarly, an Instance extension is a set of Vulkan Instance functions extending
158the Vulkan language. These will be discussed in more detail later.
159
160
161##### Device-related Objects
162
163A Vulkan Device, on the other-hand, is a logical identifier used to associate
164functions with a particular physical device on a user's system. Vulkan
165constructs associated directly with a device include:
166 * `VkDevice`
167 * `VkQueue`
168 * `VkCommandBuffer`
169 * Any dispatchable object that is a child of a one of the above.
170
171A Device function is any Vulkan function which takes any Device Object as its
172first parameter. Some Vulkan Device functions are:
173 * `vkQueueSubmit`
174 * `vkBeginCommandBuffer`
175 * `vkCreateEvent`
176
177You can query Vulkan Device functions using either `vkGetInstanceProcAddr` or
178`vkGetDeviceProcAddr`. If you choose to use `vkGetInstanceProcAddr`, it will
179have an additional level built into the call chain, which will reduce
180performance slightly. However, the function pointer returned can be used for
181any device created later, as long as it is associated with the same Vulkan
182Instance. If, instead you use `vkGetDeviceProcAddr`, the call chain will be more
183optimized to the specific device, but it will **only** work for the device used
184to query the function function pointer. Also, unlike `vkGetInstanceProcAddr`,
185`vkGetDeviceProcAddr` can only be used on core Vulkan Device functions, or
186Device extension functions.
187
188The best solution is to query Instance extension functions using
189`vkGetInstanceProcAddr`, and to query Device extension functions using
190`vkGetDeviceProcAddr`. See
191[Best Application Performance Setup](#best-application-performance-setup) for
192more information on this.
193
194As with Instance extensions, a Device extension is a set of Vulkan Device
195functions extending the Vulkan language. You can read more about these later in
196the document.
197
198
199#### Dispatch Tables and Call Chains
Jon Ashburnc2972682016-02-08 15:42:01 -0700200
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700201Vulkan uses an object model to control the scope of a particular action /
202operation. The object to be acted on is always the first parameter of a Vulkan
Mark Young6d026a72016-06-01 17:49:30 -0600203call and is a dispatchable object (see Vulkan specification section 2.3 Object
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700204Model). Under the covers, the dispatchable object handle is a pointer to a
Mark Youngcb6e6702016-07-20 11:38:53 -0600205structure, which in turn, contains a pointer to a dispatch table maintained by
Mark Young39389872017-01-19 21:10:49 -0700206the loader. This dispatch table contains pointers to the Vulkan functions
207appropriate to that object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700208
Mark Youngcb6e6702016-07-20 11:38:53 -0600209There are two types of dispatch tables the loader maintains:
Mark Young39389872017-01-19 21:10:49 -0700210 - Instance Dispatch Table
211 - Created in the loader during the call to `vkCreateInstance`
212 - Device Dispatch Table
213 - Created in the loader during the call to `vkCreateDevice`
Jon Ashburnc2972682016-02-08 15:42:01 -0700214
Mark Young39389872017-01-19 21:10:49 -0700215At that time the application and/or system can specify optional layers to be
216included. The loader will initialize the specified layers to create a call
217chain for each Vulkan function and each entry of the dispatch table will point
218to the first element of that chain. Thus, the loader builds an instance call
219chain for each `VkInstance` that is created and a device call chain for each
220`VkDevice` that is created.
221
222When an application calls a Vulkan function, this typically will first hit a
223*trampoline* function in the loader. These *trampoline* functions are small,
224simple functions that jump to the appropriate dispatch table entry for the
225object they are given. Additionally, for functions in the instance call chain,
226the loader has an additional function, called a *terminator*, which is called
227after all enabled layers to marshall the appropriate information to all
228available ICDs.
229
230
231##### Instance Call Chain Example
Jon Ashburnc2972682016-02-08 15:42:01 -0700232
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700233For example, the diagram below represents what happens in the call chain for
Mark Young39389872017-01-19 21:10:49 -0700234`vkCreateInstance`. After initializing the chain, the loader will call into the
235first layer's `vkCreateInstance` which will call the next finally terminating in
236the loader again where this function calls every ICD's `vkCreateInstance` and
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700237saves the results. This allows every enabled layer for this chain to set up
Mark Young39389872017-01-19 21:10:49 -0700238what it needs based on the `VkInstanceCreateInfo` structure from the
239application.
240
241![Instance Call Chain](./images/loader_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700242
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700243This also highlights some of the complexity the loader must manage when using
Mark Young39389872017-01-19 21:10:49 -0700244instance call chains. As shown here, the loader's *terminator* must aggregate
245information to and from multiple ICDs when they are present. This implies that
246the loader has to be aware of any instance-level extensions which work on a
247`VkInstance` to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -0700248
Mark Young39389872017-01-19 21:10:49 -0700249
250##### Device Call Chain Example
251
252Device call chains are created at `vkCreateDevice` and are generally simpler
253because they deal with only a single device and the ICD can always be the
254*terminator* of the chain.
255
256![Loader Device Call Chain](./images/loader_device_chain_loader.png)
257
Jon Ashburnc2972682016-02-08 15:42:01 -0700258
Mark Youngcb6e6702016-07-20 11:38:53 -0600259<br/>
Mark Young39389872017-01-19 21:10:49 -0700260<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600261
Mark Young39389872017-01-19 21:10:49 -0700262## Application Interface to the Loader
Jon Ashburnc2972682016-02-08 15:42:01 -0700263
Mark Young39389872017-01-19 21:10:49 -0700264In this section we'll discuss how an application interacts with the loader,
265including:
266 * [Interfacing with Vulkan Functions](#interfacing-with-vulkan-functions)
267 * [Vulkan Direct Exports](#vulkan-direct-exports)
268 * [Indirectly Linking to the Loader](#indirectly-linking-to-the-loader)
269 * [Best Application Performance Setup](#best-application-performance-setup)
270 * [ABI Versioning](#abi-versioning)
271 * [Application Layer Usage](#application-layer-usage)
272 * [Implicit vs Explicit Layers](#implicit-vs-explicit-layers)
273 * [Forcing Layer Source Folders](#forcing-layer-source-folders)
274 * [Forcing Layers to be Enabled](#forcing-layers-to-be-enabled)
275 * [Overall Layer Ordering](#overall-layer-ordering)
276 * [Application Usage of Extensions](#application-usage-of-extensions)
277 * [Instance and Device Extensions](#instance-and-device-extensions)
278 * [WSI Extensions](#wsi-extensions)
279 * [Unknown Extensions](#unknown-extensions)
Jon Ashburnc2972682016-02-08 15:42:01 -0700280
Mark Young39389872017-01-19 21:10:49 -0700281
282#### Interfacing with Vulkan Functions
283There are several ways you can interface with Vulkan functions through the
284loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700285
Jon Ashburnc2972682016-02-08 15:42:01 -0700286
Mark Young39389872017-01-19 21:10:49 -0700287##### Vulkan Direct Exports
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700288The loader library on Windows, Linux and Android will export all core Vulkan
289and all appropriate Window System Interface (WSI) extensions. This is done to
290make it simpler to get started with Vulkan development. When an application
291links directly to the loader library in this way, the Vulkan calls are simple
Mark Young39389872017-01-19 21:10:49 -0700292*trampoline* functions that jump to the appropriate dispatch table entry for the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700293object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700294
Mark Young39389872017-01-19 21:10:49 -0700295
296##### Indirectly Linking to the Loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700297Applications are not required to link directly to the loader library, instead
298they can use the appropriate platform specific dynamic symbol lookup on the
Mark Young6d026a72016-06-01 17:49:30 -0600299loader library to initialize the application's own dispatch table. This allows
Mark Young39389872017-01-19 21:10:49 -0700300an application to fail gracefully if the loader cannot be found. It also
Jeff Julianof1619872016-02-17 17:25:42 -0500301provides the fastest mechanism for the application to call Vulkan functions. An
302application will only need to query (via system calls such as dlsym()) the
Mark Young39389872017-01-19 21:10:49 -0700303address of `vkGetInstanceProcAddr` from the loader library. Using
304`vkGetInstanceProcAddr` the application can then discover the address of all
305functions and extensions available, such as `vkCreateInstance`,
306`vkEnumerateInstanceExtensionProperties` and
307`vkEnumerateInstanceLayerProperties` in a platform-independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700308
Mark Young39389872017-01-19 21:10:49 -0700309
310##### Best Application Performance Setup
311
312If you desire the best performance possible, you should setup your own
313dispatch table so that all your Instance functions are queried using
314`vkGetInstanceProcAddr` and all your Device functions are queried using
315`vkGetDeviceProcAddr`.
316
317*Why should you do this?*
318
319The answer comes in how the call chain of Instance functions are implemented
320versus the call chain of a Device functions. Remember, a [Vulkan Instance is a
321high-level construct used to provide Vulkan system-level information](#instance-
322related-objects). Because of this, Instance functions need to be broadcasted to
323every available ICD on the system. The following diagram shows an approximate
324view of an Instance call chain with 3 enabled layers:
325
326![Instance Call Chain](./images/loader_instance_chain.png)
327
328This is also how a Vulkan Device function call chain looks if you query it
329using `vkGetInstanceProcAddr`. On the otherhand, a Device
330function doesn't need to worry about the broadcast becuase it knows specifically
331which associated ICD and which associated Physical Device the call should
332terminate at. Because of this, the loader doesn't need to get involved between
333any enabled layers and the ICD. Thus, if you used a loader-exported Vulkan
334Device function, the call chain in the same scenario as above would look like:
335
336![Loader Device Call Chain](./images/loader_device_chain_loader.png)
337
338An even better solution would be for an application to perform a
339`vkGetDeviceProcAddr` call on all Device functions. This further optimizes the
340call chain by removing the loader all-together under most scenarios:
341
342![Application Device Call Chain](./images/loader_device_chain_app.png)
343
344Also, notice if no layers are enabled, your application function pointer would
345point **directly to the ICD**. If called enough, those fewer calls can add up
346to performance savings.
347
348**NOTE:** There are some Device functions which still require the loader to
349intercept them with a *trampoline* and *terminator*. There are very few of
350these, but they are typically functions which the loader wraps with its own
351data. In those cases, even the Device call chain will continue to look like the
352Instance call chain. One example of a Device function requiring a *terminator*
353is `vkCreateSwapchainKHR`. For that function, the loader needs to potentially
354convert the KHR_surface object into an ICD-specific KHR_surface object prior to
355passing down the rest of the function's information to the ICD.
356
357Remember:
358 * `vkGetInstanceProcAddr` can be used to query
359either device or instance entry-points in addition to all core entry-points.
360 * `vkGetDeviceProcAddr` can only be used to query for device
361extension or core device entry-points.
362
363
364##### ABI Versioning
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700365The Vulkan loader library will be distributed in various ways including Vulkan
Mark Young39389872017-01-19 21:10:49 -0700366SDKs, OS package distributions and Independent Hardware Vendor (IHV) driver
367packages. These details are beyond the scope of this document. However, the name
368and versioning of the Vulkan loader library is specified so an app can link to
369the correct Vulkan ABI library version. Vulkan versioning is such that ABI
370backwards compatibility is guaranteed for all versions with the same major
371number (e.g. 1.0 and 1.1). On Windows, the loader library encodes the ABI
372version in its name such that multiple ABI incompatible versions of the loader
373can peacefully coexist on a given system. The Vulkan loader library file name is
Jeff Juliano18e50202017-01-31 16:36:18 -0500374`vulkan-<ABI version>.dll`. For example, for Vulkan version 1.X on Windows the
Mark Young39389872017-01-19 21:10:49 -0700375library filename is vulkan-1.dll. And this library file can typically be found
376in the windows/system32 directory (on 64-bit Windows installs, the 32-bit
377version of the loader with the same name can be found in the windows/sysWOW64
378directory).
Jon Ashburnc2972682016-02-08 15:42:01 -0700379
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700380For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
381number is not encoded in the base of the library filename as on Windows. On
382Linux an application wanting to link to the latest Vulkan ABI version would
383just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500384also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700385
Mark Young39389872017-01-19 21:10:49 -0700386
387#### Application Layer Usage
Mark Young6d026a72016-06-01 17:49:30 -0600388
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700389Applications desiring Vulkan functionality beyond what the core API offers may
Mark Young39389872017-01-19 21:10:49 -0700390use various layers or extensions. A layer cannot introduce new Vulkan core API
391entry-points to an application that are not exposed in Vulkan.h. However,
392layers may offer extensions that introduce new Vulkan commands that can be
393queried through the extension interface.
Mark Young02ee5382016-07-22 08:51:05 -0600394
Mark Young39389872017-01-19 21:10:49 -0700395A common use of layers is for API validation which can be enabled by
396loading the layer during application development, but not loading the layer
397for application release. This eliminates the overhead of validating the
398application's usage of the API, something that wasn't available on some previous
399graphics APIs.
400
401To find out what layers are available to your application, use
402`vkEnumerateInstanceLayerProperties`. This will report all layers
403that have been discovered by the loader. The loader looks in various locations
404to find layers on the system. For more information see the
405[Layer discovery](#layer-discovery) section below.
406
407To enable a layer, or layers, simply pass the name of the layers you wish to
408enable in the `ppEnabledLayerNames` field of the `VkInstanceCreateInfo` during
409a call to `vkCreateInstance`. Once done, the layers you have enabled will be
410active for all Vulkan functions using the created `VkInstance`, and any of
411its child objects.
412
413**NOTE:** Layer ordering is important in several cases since some layers
414interact with each other. Be careful when enabling layers as this may be
415the case. See the [Overall Layer Ordering](#overall-layer-ordering) section
416for more information.
417
418The following code section shows how you would go about enabling the
419VK_LAYER_LUNARG_standard_validation layer.
420
421```
422 char *instance_validation_layers[] = {
423 "VK_LAYER_LUNARG_standard_validation"
424 };
425 const VkApplicationInfo app = {
426 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
427 .pNext = NULL,
428 .pApplicationName = "TEST_APP",
429 .applicationVersion = 0,
430 .pEngineName = "TEST_ENGINE",
431 .engineVersion = 0,
432 .apiVersion = VK_API_VERSION_1_0,
433 };
434 VkInstanceCreateInfo inst_info = {
435 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
436 .pNext = NULL,
437 .pApplicationInfo = &app,
438 .enabledLayerCount = 1,
439 .ppEnabledLayerNames = (const char *const *)instance_validation_layers,
440 .enabledExtensionCount = 0,
441 .ppEnabledExtensionNames = NULL,
442 };
443 err = vkCreateInstance(&inst_info, NULL, &demo->inst);
444```
445
446At `vkCreateInstance` and `vkCreateDevice`, the loader constructs call chains
447that include the application specified (enabled) layers. Order is important in
448the `ppEnabledLayerNames` array; array element 0 is the topmost (closest to the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700449application) layer inserted in the chain and the last array element is closest
Mark Young39389872017-01-19 21:10:49 -0700450to the driver. See the [Overall Layer Ordering](#overall-layer-ordering)
451section for more information on layer ordering.
Jon Ashburnc2972682016-02-08 15:42:01 -0700452
Mark Young39389872017-01-19 21:10:49 -0700453**NOTE:** *Device Layers Are Now Deprecated*
454> `vkCreateDevice` originally was able to select layers in a similar manner to
455`vkCreateInstance`. This lead to the concept of "instance
456> layers" and "device layers". It was decided by Khronos to deprecate the
457> "device layer" functionality and only consider "instance layers".
458> Therefore, `vkCreateDevice` will use the layers specified at
459`vkCreateInstance`.
460> Because of this, the following items have been deprecated:
461> * `VkDeviceCreateInfo` fields:
462> * `ppEnabledLayerNames`
463> * `enabledLayerCount`
464> * The `vkEnumerateDeviceLayerProperties` function
Mark Young02ee5382016-07-22 08:51:05 -0600465
Jon Ashburnc2972682016-02-08 15:42:01 -0700466
Mark Young39389872017-01-19 21:10:49 -0700467##### Implicit vs Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700468
Mark Young39389872017-01-19 21:10:49 -0700469Explicit layers are layers which are enabled by an application (e.g. with the
470vkCreateInstance function), or by an environment variable (as mentioned
471previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700472
Mark Young39389872017-01-19 21:10:49 -0700473Implicit layers are those which are enabled by their existence. For example,
474certain application environments (e.g. Steam or an automotive infotainment
475system) may have layers which they always want enabled for all applications
476that they start. Other implicit layers may be for all applications started on a
477given system (e.g. layers that overlay frames-per-second). Implicit layers are
478enabled automatically, whereas explicit layers must be enabled explicitly.
Jon Ashburnc2972682016-02-08 15:42:01 -0700479
Mark Young02ee5382016-07-22 08:51:05 -0600480Implicit layers have an additional requirement over explicit layers in that they
481require being able to be disabled by an environmental variable. This is due
482to the fact that they are not visible to the application and could cause issues.
483A good principle to keep in mind would be to define both an enable and disable
484environment variable so the users can deterministicly enable the functionality.
485On Desktop platforms (Windows and Linux), these enable/disable settings are
486defined in the layer's JSON file.
487
Mark Young39389872017-01-19 21:10:49 -0700488Discovery of system-installed implicit and explicit layers is described later in
489the [Layer Discovery Section](#layer-discovery). For now, simply know that what
490distinguishes a layer as implicit or explicit is dependent on the Operating
491system, as shown in the table below.
492
493| Operating System | Implicit Layer Identification |
494|----------------|--------------------|
495| Windows | Implicit Layers are located in a different Windows registry location than Explicit Layers. |
496| Linux | Implicit Layers are located in a different directory location than Explicit Layers. |
497| Android | There is **No Support For Implicit Layers** on Android. |
498
499
500##### Forcing Layer Source Folders
501
502Developers may need to use special, pre-production layers, without modifying the
503system-installed layers. You can direct the loader to look for layers in a
504specific folder by defining the "VK\_LAYER\_PATH" environment variable. This
505will override the mechanism used for finding system-installed layers. Because
506layers of interest may exist in several disinct folders on on a system, this
507environment variable can containis several paths seperated by the operating
508specific path separator. On Windows, each separate folder should be separated
509in the list using a semi-colon. On Linux, each folder name should be separated
510using a colon.
511
512If "VK\_LAYER\_PATH" exists, **only** the folders listed in it will be scanned
513for layers. Each directory listed should be the full pathname of a folder
514containing layer manifest files.
515
516
517##### Forcing Layers to be Enabled on Windows and Linux
518
519Developers may want to enable layers that are not enabled by the given
520application they are using. On Linux and Windows, the environment variable
521"VK\_INSTANCE\_LAYERS" can be used to enable additional layers which are
522not specified (enabled) by the application at `vkCreateInstance`.
523"VK\_INSTANCE\_LAYERS" is a colon (Linux)/semi-colon (Windows) separated
524list of layer names to enable. Order is relevant with the first layer in the
525list being the top-most layer (closest to the application) and the last
526layer in the list being the bottom-most layer (closest to the driver).
527See the [Overall Layer Ordering](#overall-layer-ordering) section
528for more information.
529
530Application specified layers and user specified layers (via environment
531variables) are aggregated and duplicates removed by the loader when enabling
532layers. Layers specified via environment variable are top-most (closest to the
533application) while layers specified by the application are bottommost.
534
535An example of using these environment variables to activate the validation
536layer `VK_LAYER_LUNARG_parameter_validation` on Windows or Linux is as follows:
537
538```
539> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation
540```
541
542
543##### Overall Layer Ordering
544
545The overall ordering of all layers by the loader based on the above looks
546as follows:
547
548![Loader Layer Ordering](./images/loader_layer_order.png)
549
550Ordering may also be important internal to the list of Explicit Layers.
551Some layers may be dependent on other behavior being implemented before
552or after the loader calls it. For example: the VK_LAYER_LUNARG_core_validation
553layer expects the VK_LAYER_LUNARG_parameter_validation to be called first.
554This is because the VK_LAYER_LUNARG_parameter_validation will filter out any
555invalid `NULL` pointer calls prior to the rest of the validation checking
556done by VK_LAYER_LUNARG_core_validation. If not done properly, you may see
557crashes in the VK_LAYER_LUNARG_core_validation layer that would otherwise be
558avoided.
559
560
561#### Application Usage of Extensions
562
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700563Extensions are optional functionality provided by a layer, the loader or an
564ICD. Extensions can modify the behavior of the Vulkan API and need to be
Mark Young39389872017-01-19 21:10:49 -0700565specified and registered with Khronos. These extensions can be created
566by an Independent Hardware Vendor (IHV) to expose new hardware functionality,
567or by a layer writer to expose some internal feature, or by the loader to
568improve functional behavior. Information about various extensions can be
569found in the Vulkan Spec, and vulkan.h header file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700570
Mark Young6d026a72016-06-01 17:49:30 -0600571
Mark Young39389872017-01-19 21:10:49 -0700572##### Instance and Device Extensions
573
574As hinted at in the [Instance Versus Device](#instance-versus-device) section,
575there are really two types of extensions:
576 * Instance Extensions
577 * Device Extensions
578
579An Instance extension is an extension which modifies existing behavior or
580implements new behavior on instance-level objects, like a `VkInstance` or
581a `VkPhysicalDevice`. A Device extension is an extension which does the same,
582but for any `VkDevice` object, or any dispatchable object that is a child of a
583`VkDevice` (`VkQueue` and `VkCommandBuffer` are examples of these).
584
585It is **very** important to know what type of extension you are desiring to
586enable as you will enable Instance extensions during `vkCreateInstance` and
587Device extensions during `vkCreateDevice`.
588
589The loader discovers and aggregates all
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700590extensions from layers (both explicit and implicit), ICDs and the loader before
Mark Young39389872017-01-19 21:10:49 -0700591reporting them to the application in `vkEnumerateXXXExtensionProperties`
592(where XXX is either "Instance" or "Device").
593 - Instance extensions are discovered via
594`vkEnumerateInstanceExtensionProperties`.
595 - Device extensions are be discovered via
596`vkEnumerateDeviceExtensionProperties`.
597
598Looking at `vulkan.h`, you'll notice that they are both similar. For example,
599`vkEnumerateInstanceExtensionProperties` prototype looks as follows:
600
601```
602 VkResult
603 vkEnumerateInstanceExtensionProperties(const char *pLayerName,
604 uint32_t *pPropertyCount,
605 VkExtensionProperties *pProperties);
606```
607
608The "pLayerName" parameter in these functions is used to select either a single
609layer or the Vulkan platform implementation. If "pLayerName" is NULL, extensions
610from Vulkan implementation components (including loader, implicit layers, and
611ICDs) are enumerated. If "pLayerName" is equal to a discovered layer module name
612then only extensions from that layer (which may be implicit or explicit) are
Jeff Julianof1619872016-02-17 17:25:42 -0500613enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Mark Young39389872017-01-19 21:10:49 -0700614support for the same extension) are eliminated by the loader. For duplicates,
615the ICD version is reported and the layer version is culled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700616
Mark Young39389872017-01-19 21:10:49 -0700617Also, Extensions *must be enabled* (in `vkCreateInstance` or `vkCreateDevice`)
618before the functions associated with the extensions can be used. If you get an
619Extension function using either `vkGetInstanceProcAddr` or
620`vkGetDeviceProcAddr`, but fail to enable it, you could experience undefined
621behavior. This should actually be flagged if you run with Validation layers
622enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700623
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700624
Mark Young78f88c82016-07-19 11:49:45 -0600625##### WSI Extensions
626
Mark Young39389872017-01-19 21:10:49 -0700627Khronos approved WSI extensions are available and provide Windows System
628Integration support for various execution environments. It is important to
629understand that some WSI extensions are valid for all targets, but others are
630particular to a given execution environment (and loader). This desktop loader
631(currently targeting Windows and Linux) only enables and directly exports those
632WSI extensions that are appropriate to the current environment. For the most
633part, the selection is done in the loader using compile-time preprocessor flags.
634All versions of the desktop loader currently expose at least the following WSI
Mark Young78f88c82016-07-19 11:49:45 -0600635extension support:
636- VK_KHR_surface
637- VK_KHR_swapchain
638- VK_KHR_display
639
Mark Young39389872017-01-19 21:10:49 -0700640In addition, each of the following OS targets for the loader support target-
641specific extensions:
Mark Young78f88c82016-07-19 11:49:45 -0600642
Mark Young39389872017-01-19 21:10:49 -0700643| Windowing System | Extensions available |
644|----------------|--------------------|
645| Windows | VK_KHR_win32_surface |
646| Linux (Default) | VK_KHR_xcb_surface and VK_KHR_xlib_surface |
647| Linux (Wayland) | VK_KHR_wayland_surface |
648| Linux (Mir) | VK_KHR_mir_surface |
Mark Young78f88c82016-07-19 11:49:45 -0600649
Mark Young39389872017-01-19 21:10:49 -0700650**NOTE:** Wayland and Mir targets are not fully supported at this time. Wayland
651support is present, but should be considered Beta quality. Mir support is not
652completely implemented at this time.
653
654It is important to understand that while the loader may support the various
655entry-points for these extensions, there is a hand-shake required to actually
656use them:
Mark Young78f88c82016-07-19 11:49:45 -0600657* At least one physical device must support the extension(s)
658* The application must select such a physical device
Mark Young39389872017-01-19 21:10:49 -0700659* The application must request the extension(s) be enabled while creating the
660instance or logical device (This depends on whether or not the given extension
661works with an instance or a device).
Mark Young78f88c82016-07-19 11:49:45 -0600662* The instance and/or logical device creation must succeed.
663
664Only then can you expect to properly use a WSI extension in your Vulkan program.
665
Mark Young78f88c82016-07-19 11:49:45 -0600666
Mark Young39389872017-01-19 21:10:49 -0700667##### Unknown Extensions
668
669With the ability to expand Vulkan so easily, extensions will be created that the
670loader knows nothing about. If the extension is a device extension, the loader
671will pass the unknown entry-point down the device call chain ending with the
672appropriate ICD entry-points. The same thing will happen, if the extension is
673an instance extension which takes a physical device paramater as it's first
674component. However, for all other instance extensions the loader will fail to
675load it.
Mark Young78f88c82016-07-19 11:49:45 -0600676
677*But why doesn't the loader support unknown instance extensions?*
678<br/>
679Let's look again at the Instance call chain:
Mark Young78f88c82016-07-19 11:49:45 -0600680
Mark Young39389872017-01-19 21:10:49 -0700681![Instance call chain](./images/loader_instance_chain.png)
Mark Young78f88c82016-07-19 11:49:45 -0600682
Mark Young39389872017-01-19 21:10:49 -0700683Notice that for a normal instance function call, the loader has to handle
684passing along the function call to the available ICDs. If the loader has no
685idea of the parameters or return value of the instance call, it can't properly
686pass information along to the ICDs. There may be ways to do this, which will be
687explored in the future. However, for now, this loader does not support
688instance extensions which don't take a physical device as their first parameter.
689
690Because the device call-chain does not normally pass through the loader
691*terminator*, this is not a problem for device extensions. Additionally,
692since a physical device is associated with one ICD, we can use a generic
693*terminator* pointing to one ICD. This is because both of these extensions
694terminate directly in the ICD they are associated with.
Mark Young78f88c82016-07-19 11:49:45 -0600695
696*Is this a big problem?*
697<br/>
Mark Young39389872017-01-19 21:10:49 -0700698No! Most extension functionality only affects either a physical or logical
699device and not an instance. Thus, the overwhelming majority of extensions
700should be supported with direct loader support.
Jon Ashburnc2972682016-02-08 15:42:01 -0700701
Jon Ashburnc2972682016-02-08 15:42:01 -0700702
Mark Youngcb6e6702016-07-20 11:38:53 -0600703<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600704<br/>
705
Mark Young39389872017-01-19 21:10:49 -0700706## Loader and Layer Interface
Jon Ashburnc2972682016-02-08 15:42:01 -0700707
Mark Young39389872017-01-19 21:10:49 -0700708In this section we'll discuss how the loader interacts with layers, including:
709 * [Layer Discovery](#layer-discovery)
710 * [Layer Manifest File Usage](#layer-manifest-file-usage)
711 * [Android Layer Discovery](#android-layer-discovery)
712 * [Windows Layer Discovery](#windows-layer-discovery)
713 * [Linux Layer Discovery](#linux-layer-discovery)
714 * [Layer Version Negotiation](#layer-version-negotiation)
715 * [Layer Call Chains and Distributed Dispatch](#layer-call-chains-and-distributed-dispatch)
716 * [Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions)
717 * [Layer Intercept Requirements](#layer-intercept-requirements)
718 * [Distributed Dispatching Requirements](#distributed-dispatching-requirements)
719 * [Layer Conventions and Rules](#layer-conventions-and-rules)
720 * [Layer Dispatch Initialization](#layer-dispatch-initialization)
721 * [Example Code for CreateInstance](#example-code-for-createinstance)
722 * [Example Code for CreateDevice](#example-code-for-createdevice)
723 * [Special Considerations](#special-considerations)
724 * [Associating Private Data with Vulkan Objects Within a Layer](#associating-private-data-with-vulkan-objects-within-a-layer)
725 * [Wrapping](#wrapping)
726 * [Hash Maps](#hash-maps)
727 * [Creating New Dispatchable Objects](#creating-new-dispatchable-objects)
728 * [Layer Manifest File Format](#layer-manifest-file-format)
729 * [Layer Manifest File Version History](#layer-manifest-file-version-history)
730 * [Layer Library Versions](#layer-library-versions)
731 * [Layer Library API Version 2](#layer-library-api-version-2)
732 * [Layer Library API Version 1](#layer-library-api-version-1)
733 * [Layer Library API Version 0](#layer-library-api-version-0)
734
Jon Ashburnc2972682016-02-08 15:42:01 -0700735
Mark Young39389872017-01-19 21:10:49 -0700736
737#### Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700738
Mark Young39389872017-01-19 21:10:49 -0700739As mentioned in the
740[Application Interface section](#implicit-vs-explicit-layers),
741layers can be categorized into two categories:
742 * Implicit Layers
743 * Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700744
Mark Young39389872017-01-19 21:10:49 -0700745The main difference between the two is that Implicit Layers are automatically
746enabled, unless overriden, and Explicit Layers must be enabled. Remember,
747Implicit Layers are not present on all Operating Systems (like Android).
Jon Ashburnc2972682016-02-08 15:42:01 -0700748
Mark Young39389872017-01-19 21:10:49 -0700749On any system, the loader looks in specific areas for information on the
750layers that it can load at a user's request. The process of finding the
751available layers on a system is known as Layer Discovery. During discovery,
752the loader determines what layers are available, the layer name, the layer
753version, and any extensions supported by the layer. This information is
754provided back to an application through `vkEnumerateInstanceLayerProperties`.
755
756The group of layers available to the loader is known as a layer library. This
757section defines an extensible interface to discover what layers are contained in
758the layer library.
759
760This section also specifies the minimal conventions and rules a layer must
761follow, especially with regards to interacting with the loader and other layers.
762
763##### Layer Manifest File Usage
764
765On Windows and Linux systems, JSON formated manifest files are used to store
766layer information. In order to find system-installed layers, the Vulkan loader
767will read the JSON files to identify the names and attributes of layers and
768their extensions. The use of manifest files allows the loader to avoid loading
769any shared library files when the application does not query nor request any
770extensions. The format of [Layer Manifest File](#layer-manifest-file-format)
771is detailed below.
772
773The Android loader does not use manifest files. Instead, the loader queries the
774layer properties using special functions known as "introspection" functions.
775The intent of these functions is to determine the same required information
776gathered from reading the manifest files. These introspection functions are
777not used by the desktop loader but should be present in layers to maintain
778consistency. The specific "introspection" functions are called out in
779the [Layer Manifest File Format](#layer-manifest-file-format) table.
780
781
782##### Android Layer Discovery
783
784On Android, the loader looks for layers to enumerate in the
785/data/local/debug/vulkan folder. An application enabled for debug has the
786ability to enumerate and enable any layers in that location.
787
788
789##### Windows Layer Discovery
790
791In order to find system-installed layers, the Vulkan loader will scan the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700792values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700793
Mark Young39389872017-01-19 21:10:49 -0700794```
795 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers
796 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ImplicitLayers
797```
Jon Ashburnc2972682016-02-08 15:42:01 -0700798
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700799For each value in these keys which has DWORD data set to 0, the loader opens
800the JSON manifest file specified by the name of the value. Each name must be a
Mark Young39389872017-01-19 21:10:49 -0700801full pathname to the manifest file. The Vulkan loader will open each info file
802to obtain information about the layer, including the name or pathname of a
803shared library (".dll") file. However, if VK\_LAYER\_PATH is defined, then the
804loader will instead look at the paths defined by that variable instead of using
805the information provided by these registry keys. See
806[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
807information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700808
Jon Ashburnc2972682016-02-08 15:42:01 -0700809
Mark Young39389872017-01-19 21:10:49 -0700810##### Linux Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700811
Mark Young39389872017-01-19 21:10:49 -0700812On Linux, the Vulkan loader will scan the files in the following Linux
813directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700814
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600815 /usr/local/etc/vulkan/explicit_layer.d
816 /usr/local/etc/vulkan/implicit_layer.d
817 /usr/local/share/vulkan/explicit_layer.d
818 /usr/local/share/vulkan/implicit_layer.d
819 /etc/vulkan/explicit_layer.d
820 /etc/vulkan/implicit_layer.d
821 /usr/share/vulkan/explicit_layer.d
822 /usr/share/vulkan/implicit_layer.d
823 $HOME/.local/share/vulkan/explicit_layer.d
824 $HOME/.local/share/vulkan/implicit_layer.d
825
Mark Young39389872017-01-19 21:10:49 -0700826Of course, ther are some things you have to know about the above folders:
827 1. The "/usr/local/*" directories can be configured to be other directories at
828build time.
829 2. $HOME is the current home directory of the application's user id; this path
830will be ignored for suid programs.
831 3. The "/usr/local/etc/vulkan/\*\_layer.d" and
832"/usr/local/share/vulkan/\*\_layer.d" directories are for layers that are
833installed from locally-built sources.
834 4. The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600835installed from Linux-distribution-provided packages.
836
Mark Young39389872017-01-19 21:10:49 -0700837As on Windows, if VK\_LAYER\_PATH is defined, then the
838loader will instead look at the paths defined by that variable instead of using
839the information provided by these default paths. However, these
840environment variables are only used for non-suid programs. See
841[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
842information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700843
Mark Young39389872017-01-19 21:10:49 -0700844
845#### Layer Version Negotiation
846
847Now that a layer has been discovered, an application can choose to load it (or
848it is loaded by default if it is an Implicit layer). When the loader attempts
849to load the layer, the first thing it does is attempt to negotiate the version
850of the loader to layer interface. In order to negotiate the loader/layer
851interface version, the layer must implement the
852`vkNegotiateLoaderLayerInterfaceVersion` function. The following information is
853provided for this interface in include/vulkan/vk_layer.h:
854
855```cpp
856 typedef enum VkNegotiateLayerStructType {
857 LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
858 } VkNegotiateLayerStructType;
859
860 typedef struct VkNegotiateLayerInterface {
861 VkNegotiateLayerStructType sType;
862 void *pNext;
863 uint32_t loaderLayerInterfaceVersion;
864 PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
865 PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
866 PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
867 } VkNegotiateLayerInterface;
868
869 VkResult vkNegotiateLoaderLayerInterfaceVersion(
870 VkNegotiateLayerInterface *pVersionStruct);
Jon Ashburncc300a22016-02-11 14:57:30 -0700871```
Jon Ashburnc2972682016-02-08 15:42:01 -0700872
Mark Young39389872017-01-19 21:10:49 -0700873You'll notice the `VkNegotiateLayerInterface` structure is similar to other
874Vulkan structures. The "sType" field, in this case takes a new enum defined
875just for internal loader/layer interfacing use. The valid values for "sType"
876could grow in the future, but right only havs the one value
877"LAYER_NEGOTIATE_INTERFACE_STRUCT".
Jon Ashburnc2972682016-02-08 15:42:01 -0700878
Mark Young39389872017-01-19 21:10:49 -0700879This function (`vkNegotiateLoaderLayerInterfaceVersion`) should be exported by
880the layer so that using "GetProcAddress" on Windows or "dlsym" on Linux, should
881return a valid function pointer to it. Once the loader has grabbed a valid
882address to the layers function, the loader will create a variable of type
883`VkNegotiateLayerInterface` and initialize it in the following ways:
884 1. Set the structure "sType" to "LAYER_NEGOTIATE_INTERFACE_STRUCT"
885 2. Set pNext to NULL.
886 - This is for future growth
887 3. Set "loaderLayerInterfaceVersion" to the current version the loader desires
888to set the interface to.
889 - The minimum value sent by the loader will be 2 since it is the first
890version supporting this function.
Jon Ashburnc2972682016-02-08 15:42:01 -0700891
Mark Young39389872017-01-19 21:10:49 -0700892The loader will then individually call each layer’s
893`vkNegotiateLoaderLayerInterfaceVersion` function with the filled out
894“VkNegotiateLayerInterface”. The layer will either accept the loader's version
895set in "loaderLayerInterfaceVersion", or modify it to the closest value version
896of the interface that the layer can support. The value should not be higher
897than the version requested by the loader. If the layer can't support at a
898minimum the version requested, then the layer should return an error like
899"VK_ERROR_INITIALIZATION_FAILED". If a layer can support some version, then
900the layer should do the following:
901 1. Adjust the version to the layer's desired version.
902 2. The layer should fill in the function pointer values to its internal
903functions:
904 - "pfnGetInstanceProcAddr" should be set to the layer’s internal
905`GetInstanceProcAddr` function.
906 - "pfnGetDeviceProcAddr" should be set to the layer’s internal
907`GetDeviceProcAddr` function.
908 - "pfnGetPhysicalDeviceProcAddr" should be set to the layer’s internal
909`GetPhysicalDeviceProcAddr` function.
910 - If the layer supports no physical device extensions, it may set the
911value to NULL.
912 - More on this function later
913 3. The layer should return "VK_SUCCESS"
Jon Ashburnc2972682016-02-08 15:42:01 -0700914
Mark Young39389872017-01-19 21:10:49 -0700915This function **SHOULD NOT CALL DOWN** the layer chain to the next layer.
916The loader will work with each layer individually.
Jon Ashburnc2972682016-02-08 15:42:01 -0700917
Mark Young39389872017-01-19 21:10:49 -0700918If the layer supports the new interface and reports version 2 or greater, then
919the loader will use the “fpGetInstanceProcAddr” and “fpGetDeviceProcAddr”
920functions from the “VkNegotiateLayerInterface” structure. Prior to these
921changes, the loader would query each of those functions using "GetProcAddress"
922on Windows or "dlsym" on Linux.
Jon Ashburnc2972682016-02-08 15:42:01 -0700923
Jon Ashburnc2972682016-02-08 15:42:01 -0700924
Mark Young39389872017-01-19 21:10:49 -0700925#### Layer Call Chains and Distributed Dispatch
Jon Ashburnc2972682016-02-08 15:42:01 -0700926
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700927There are two key architectural features that drive the loader to layer library
Mark Young39389872017-01-19 21:10:49 -0700928interface:
929 1. Separate and distinct instance and device call chains
930 2. Distributed dispatch.
Jon Ashburnc2972682016-02-08 15:42:01 -0700931
Mark Young39389872017-01-19 21:10:49 -0700932You can read an overview of dispatch tables and call chains above in the
933[Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) section.
Jon Ashburnc2972682016-02-08 15:42:01 -0700934
Mark Young39389872017-01-19 21:10:49 -0700935What's important to note here is that a layer can intercept Vulkan
936instance functions, device functions or both. For a layer to intercept instance
937functions, it must participate in the instance call chain. For a layer to
938intercept device functions, it must participate in the device call chain.
939
940Remember, a layer does not need to intercept all instance or device functions,
941instead, it can choose to intercept only a subset of those functions.
942
943Normally, when a layer intercepts a given Vulkan function, it will call down the
944instance or device call chain as needed. The loader and all layer libraries that
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700945participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700946from one entity to the next. This group effort for call chain sequencing is
Mark Young39389872017-01-19 21:10:49 -0700947hereinafter referred to as **distributed dispatch**.
Jon Ashburnc2972682016-02-08 15:42:01 -0700948
Mark Young39389872017-01-19 21:10:49 -0700949In distributed dispatch each layer is responsible for properly calling the next
950entity in the call chain. This means that a dispatch mechanism is required for
951all Vulkan functions that a layer intercepts. If a Vulkan function is not
952intercepted by a layer, or if a layer chooses to terminate the function by not
953calling down the chain, then no dispatch is needed for that particular function.
Jeff Julianof1619872016-02-17 17:25:42 -0500954
Mark Young39389872017-01-19 21:10:49 -0700955For example, if the enabled layers intercepted only certain instance functions,
956the call chain would look as follows:
957![Instance Function Chain](./images/function_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700958
Mark Young39389872017-01-19 21:10:49 -0700959Likewise, if the enabled layers intercepted only a few of the device functions,
960the call chain could look this way:
961![Device Function Chain](./images/function_device_chain.png)
Jeff Julianof1619872016-02-17 17:25:42 -0500962
Mark Young39389872017-01-19 21:10:49 -0700963The loader is responsible for dispatching all core and instance extension Vulkan
964functions to the first entity in the call chain.
Chia-I Wucb24fec2016-04-20 06:23:24 +0800965
Chia-I Wucb24fec2016-04-20 06:23:24 +0800966
Mark Young39389872017-01-19 21:10:49 -0700967#### Layer Unknown Physical Device Extensions
968
969Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
970result in the following behavior:
971 1. The loader would check if core function:
972 - If it was, it would return the function pointer
973 2. The loader would check if known extension function:
974 - If it was, it would return the function pointer
975 3. If the loader knew nothing about it, it would call down using
976`GetInstanceProcAddr`
977 - If it returned non-NULL, treat it as an unknown logical device command.
978 - This meant setting up a generic trampoline function that takes in a
979VkDevice as the first parameter and adjusting the dispatch table to call the
980ICD/Layers function after getting the dispatch table from the VkDevice.
981 4. If all the above failed, the loader would return NULL to the application.
982
983This caused problems when a layer attempted to expose new physical device
984extensions the loader knew nothing about, but an application did. Because the
985loader knew nothing about it, the loader would get to step 3 in the above
986process and would treat the function as an unknown logical device command. The
987problem is, this would create a generic VkDevice trampoline function which, on
988the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
989This would lead to a crash or corruption.
990
991In order to identify the extension entry-points specific to physical device
992extensions, the following function can be added to a layer:
993
994```cpp
995PFN_vkVoidFunction vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
996 const char* pName);
997```
998
999This function behaves similar to `vkGetInstanceProcAddr` and
1000`vkGetDeviceProcAddr` except it should only return values for physical device
1001extension entry-points. In this way, it compares "pName" to every physical
1002device function supported in the layer.
1003
1004The following rules apply:
1005 * If it is the name of a physical device function supported by the layer, the
1006pointer to the layer's corresponding function should be returned.
1007 * If it is the name of a valid function which is **not** a physical device
1008function (i.e. an Instance, Device, or other function implemented by the layer),
1009then the value of NULL should be returned.
1010 * We don’t call down since we know the command is not a physical device
1011extension).
1012 * If the layer has no idea what this function is, it should call down the layer
1013chain to the next `vk_layerGetPhysicalDeviceProcAddr` call.
1014 * This can be retrieved in one of two ways:
1015 * During `vkCreateInstance`, it is passed to a layer in the
1016chain information passed to a layer in the `VkLayerInstanceCreateInfo`
1017structure.
1018 * Use `get_chain_info()` to get the pointer to the
1019`VkLayerInstanceCreateInfo` structure. Let's call it chain_info.
1020 * The address is then under
1021chain_info->u.pLayerInfo->pfnNextGetPhysicalDeviceProcAddr
1022 * See
1023[Example Code for CreateInstance](#example-code-for-createinstance)
1024 * Using the next layer’s `GetInstanceProcAddr` function to query for
1025`vk_layerGetPhysicalDeviceProcAddr`.
1026
1027This support is optional and should not be considered a requirement. This is
1028only required if a layer intends to support some functionality not directly
1029supported by loaders released in the public. If a layer does implent this
1030support, it should return the address of its `vk_layerGetPhysicalDeviceProcAddr`
1031function in the "pfnGetPhysicalDeviceProcAddr" member of the
1032`VkNegotiateLayerInterface` structure during
1033[Layer Version Negotiation](#layer-version-negotiation). Additionally, the
1034layer should also make sure `vkGetInstanceProcAddr` returns a valid function
1035pointer to a query of `vk_layerGetPhysicalDeviceProcAddr`.
1036
1037The new behavior of the loader's `vkGetInstanceProcAddr` with support for the
1038`vk_layerGetPhysicalDeviceProcAddr` function is as follows:
1039 1. Check if core function:
1040 - If it is, return the function pointer
1041 2. Check if known instance or device extension function:
1042 - If it is, return the function pointer
1043 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
1044 - If it returns non-NULL, return a trampoline to a generic physical device
1045function, and setup a generic terminator which will pass it to the proper ICD.
1046 4. Call down using `GetInstanceProcAddr`
1047 - If it returns non-NULL, treat it as an unknown logical device command.
1048This means setting up a generic trampoline function that takes in a VkDevice as
1049the first parameter and adjusting the dispatch table to call the ICD/Layers
1050function after getting the dispatch table from the VkDevice. Then, return the
1051pointer to corresponding trampoline function.
1052 5. Return NULL
1053
1054You can see now, that, if the command gets promoted to core later, it will no
1055longer be setup using `vk_layerGetPhysicalDeviceProcAddr`. Additionally, if the
1056loader adds direct support for the extension, it will no longer get to step 3,
1057because step 2 will return a valid function pointer. However, the layer should
1058continue to support the command query via `vk_layerGetPhysicalDeviceProcAddr`,
1059until at least a Vulkan version bump, because an older loader may still be
1060attempting to use the commands.
1061
1062
1063#### Layer Intercept Requirements
1064
1065 * Layers intercept a Vulkan function by defining a C/C++ function with
1066signature **identical** to the Vulkan API for that function.
1067 * A layer **must intercept at least** `vkGetInstanceProcAddr` and
1068`vkCreateInstance` to participate in the instance call chain.
1069 * A layer **may also intercept** `vkGetDeviceProcAddr` and `vkCreateDevice`
1070to participate in the device call chain.
1071 * For any Vulkan function a layer intercepts which has a non-void return value,
1072**an appropriate value must be returned** by the layer intercept function.
1073 * Most functions a layer intercepts **should call down the chain** to the
1074corresponding Vulkan function in the next entity.
1075 * The common behavior for a layer is to intercept a call, perform some
1076behavior, then pass it down to the next entity.
1077 * If you don't pass the information down, undefined behavior may occur.
1078 * This is because the function will not be received by layers further down
1079the chain, or any ICDs.
1080 * One function that **must never call down the chain** is:
1081 * `vkNegotiateLoaderLayerInterfaceVersion`
1082 * Three common functions that **may not call down the chain** are:
1083 * `vkGetInstanceProcAddr`
1084 * `vkGetDeviceProcAddr`
1085 * `vk_layerGetPhysicalDeviceProcAddr`
1086 * These functions only call down the chain for Vulkan functions that they
1087do not intercept.
1088 * Layer intercept functions **may insert extra calls** to Vulkan functions in
1089addition to the intercept.
1090 * For example, a layer intercepting `vkQueueSubmit` may want to add a call to
1091`vkQueueWaitIdle` after calling down the chain for `vkQueueSubmit`.
1092 * This would result in two calls down the chain: First a call down the
1093`vkQueueSubmit` chain, followed by a call down the `vkQueueWaitIdle` chain.
1094 * Any additional calls inserted by a layer must be on the same chain
1095 * If the function is a device function, only other device functions should
1096be added.
1097 * Likewise, if the function is an instance function, only other instance
1098functions should be added.
1099
1100
1101#### Distributed Dispatching Requirements
1102
1103- For each entry-point a layer intercepts, it must keep track of the entry
1104point residing in the next entity in the chain it will call down into.
1105 * In other words, the layer must have a list of pointers to functions of the
1106appropriate type to call into the next entity.
1107 * This can be implemented in various ways but
1108for clarity, will be referred to as a dispatch table.
1109- A layer can use the `VkLayerDispatchTable` structure as a device dispatch
1110table (see include/vulkan/vk_layer.h).
1111- A layer can use the `VkLayerInstanceDispatchTable` structure as a instance
1112dispatch table (see include/vulkan/vk_layer.h).
1113- A Layer's `vkGetInstanceProcAddr` function uses the next entity's
1114`vkGetInstanceProcAddr` to call down the chain for unknown (i.e.
1115non-intercepted) functions.
1116- A Layer's `vkGetDeviceProcAddr` function uses the next entity's
1117`vkGetDeviceProcAddr` to call down the chain for unknown (i.e. non-intercepted)
1118functions.
1119- A Layer's `vk_layerGetPhysicalDeviceProcAddr` function uses the next entity's
1120`vk_layerGetPhysicalDeviceProcAddr` to call down the chain for unknown (i.e.
1121non-intercepted) functions.
1122
1123
1124#### Layer Conventions and Rules
Chia-I Wucb24fec2016-04-20 06:23:24 +08001125
1126A layer, when inserted into an otherwise compliant Vulkan implementation, must
Mark Young39389872017-01-19 21:10:49 -07001127still result in a compliant Vulkan implementation. The intention is for layers
1128to have a well-defined baseline behavior. Therefore, it must follow some
1129conventions and rules defined below.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001130
1131A layer is always chained with other layers. It must not make invalid calls
Mark Young39389872017-01-19 21:10:49 -07001132to, or rely on undefined behaviors of, its lower layers. When it changes the
1133behavior of a function, it must make sure its upper layers do not make invalid
Chia-I Wucb24fec2016-04-20 06:23:24 +08001134calls to or rely on undefined behaviors of its lower layers because of the
1135changed behavior. For example, when a layer intercepts an object creation
Mark Young39389872017-01-19 21:10:49 -07001136function to wrap the objects created by its lower layers, it must make sure its
Chia-I Wucb24fec2016-04-20 06:23:24 +08001137lower layers never see the wrapping objects, directly from itself or
1138indirectly from its upper layers.
1139
Chia-I Wub5e850e2016-05-06 08:41:52 +08001140When a layer requires host memory, it may ignore the provided allocators. It
1141should use memory allocators if the layer is intended to run in a production
Mark Young39389872017-01-19 21:10:49 -07001142environment. For example, this usually applies to implicit layers that are
1143always enabled. That will allow applications to include the layer's memory
1144usage.
Chia-I Wub5e850e2016-05-06 08:41:52 +08001145
Mark Young39389872017-01-19 21:10:49 -07001146Additional rules include:
1147 - `vkEnumerateInstanceLayerProperties` **must** enumerate and **only**
1148enumerate the layer itself.
1149 - `vkEnumerateInstanceExtensionProperties` **must** handle the case where
1150`pLayerName` is itself.
1151 - It **must** return `VK_ERROR_LAYER_NOT_PRESENT` otherwise, including when
1152`pLayerName` is `NULL`.
1153 - `vkEnumerateDeviceLayerProperties` **is deprecated and may be omitted**.
1154 - Using this will result in undefined behavior.
1155 - `vkEnumerateDeviceExtensionProperties` **must** handle the case where
1156`pLayerName` is itself.
1157 - In other cases, it should normally chain to other layers.
1158 - `vkCreateInstance` **must not** generate an error for unrecognized layer
1159names and extension names.
1160 - It may assume the layer names and extension names have been validated.
1161 - `vkGetInstanceProcAddr` intercepts a Vulkan function by returning a local
1162entry-point
1163 - Otherwise it returns the value obtained by calling down the instance call
1164chain.
1165 - `vkGetDeviceProcAddr` intercepts a Vulkan function by returning a local
1166entry-point
1167 - Otherwise it returns the value obtained by calling down the device call
1168chain.
1169 - These additional functions must be intercepted if the layer implements
1170device-level call chaining:
1171 - `vkGetDeviceProcAddr`
1172 - `vkCreateDevice`(only required for any device-level chaining)
1173 - **NOTE:** older layer libraries may expect that `vkGetInstanceProcAddr`
1174ignore `instance` when `pName` is `vkCreateDevice`.
1175 - The specification **requires** `NULL` to be returned from
1176`vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` for disabled functions.
1177 - A layer may return `NULL` itself or rely on the following layers to do so.
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001178
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001179
Mark Young39389872017-01-19 21:10:49 -07001180#### Layer Dispatch Initialization
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001181
Mark Young39389872017-01-19 21:10:49 -07001182- A layer initializes its instance dispatch table within its `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001183function.
Mark Young39389872017-01-19 21:10:49 -07001184- A layer initializes its device dispatch table within its `vkCreateDevice`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001185function.
1186- The loader passes a linked list of initialization structures to layers via
Mark Young39389872017-01-19 21:10:49 -07001187the "pNext" field in the VkInstanceCreateInfo and `VkDeviceCreateInfo`
1188structures for `vkCreateInstance` and `VkCreateDevice` respectively.
1189- The head node in this linked list is of type `VkLayerInstanceCreateInfo` for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001190instance and VkLayerDeviceCreateInfo for device. See file
Mark Young39389872017-01-19 21:10:49 -07001191`include/vulkan/vk_layer.h` for details.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001192- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1193"sType" field in VkLayerInstanceCreateInfo.
1194- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1195"sType" field in VkLayerDeviceCreateInfo.
1196- The "function" field indicates how the union field "u" should be interpreted
Mark Young39389872017-01-19 21:10:49 -07001197within `VkLayer*CreateInfo`. The loader will set the "function" field to
1198VK_LAYER_LINK_INFO. This indicates "u" field should be `VkLayerInstanceLink` or
1199`VkLayerDeviceLink`.
1200- The `VkLayerInstanceLink` and `VkLayerDeviceLink` structures are the list
1201nodes.
1202- The `VkLayerInstanceLink` contains the next entity's `vkGetInstanceProcAddr`
1203used by a layer.
1204- The `VkLayerDeviceLink` contains the next entity's `vkGetInstanceProcAddr` and
1205`vkGetDeviceProcAddr` used by a layer.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001206- Given the above structures set up by the loader, layer must initialize their
1207dispatch table as follows:
Mark Young39389872017-01-19 21:10:49 -07001208 - Find the `VkLayerInstanceCreateInfo`/`VkLayerDeviceCreateInfo` structure in
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001209the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001210 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Mark Young39389872017-01-19 21:10:49 -07001211 - For CreateInstance get the next entity's `vkCreateInstance` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001212"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001213 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Mark Young39389872017-01-19 21:10:49 -07001214 - For CreateDevice get the next entity's `vkCreateDevice` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001215"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001216 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001217 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
Mark Young39389872017-01-19 21:10:49 -07001218 - Call down the chain either `vkCreateDevice` or `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001219 - Initialize your layer dispatch table by calling the next entity's
Mark Young39389872017-01-19 21:10:49 -07001220Get*ProcAddr function once for each Vulkan function needed in your dispatch
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001221table
Jon Ashburncc300a22016-02-11 14:57:30 -07001222
Mark Young39389872017-01-19 21:10:49 -07001223#### Example Code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001224
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001225```cpp
1226VkResult vkCreateInstance(
1227 const VkInstanceCreateInfo *pCreateInfo,
1228 const VkAllocationCallbacks *pAllocator,
1229 VkInstance *pInstance)
1230{
1231 VkLayerInstanceCreateInfo *chain_info =
1232 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1233
1234 assert(chain_info->u.pLayerInfo);
1235 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1236 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1237 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001238 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001239 if (fpCreateInstance == NULL) {
1240 return VK_ERROR_INITIALIZATION_FAILED;
1241 }
1242
1243 // Advance the link info for the next element of the chain
1244 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1245
1246 // Continue call down the chain
1247 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1248 if (result != VK_SUCCESS)
1249 return result;
1250
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001251 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001252 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001253 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001254 layer_init_instance_dispatch_table(
1255 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1256
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001257 // Other layer initialization
1258 ...
1259
1260 return VK_SUCCESS;
1261}
1262```
1263
Mark Young39389872017-01-19 21:10:49 -07001264#### Example Code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001265
1266```cpp
1267VkResult
1268vkCreateDevice(
1269 VkPhysicalDevice gpu,
1270 const VkDeviceCreateInfo *pCreateInfo,
1271 const VkAllocationCallbacks *pAllocator,
1272 VkDevice *pDevice)
1273{
1274 VkLayerDeviceCreateInfo *chain_info =
1275 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1276
1277 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1278 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1279 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1280 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1281 PFN_vkCreateDevice fpCreateDevice =
1282 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1283 if (fpCreateDevice == NULL) {
1284 return VK_ERROR_INITIALIZATION_FAILED;
1285 }
1286
1287 // Advance the link info for the next element on the chain
1288 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1289
1290 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1291 if (result != VK_SUCCESS) {
1292 return result;
1293 }
1294
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001295 // initialize layer's dispatch table
1296 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001297 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001298 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001299
1300 // Other layer initialization
1301 ...
1302
1303 return VK_SUCCESS;
1304}
1305```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001306
Mark Young39389872017-01-19 21:10:49 -07001307
Jon Ashburncc300a22016-02-11 14:57:30 -07001308#### Special Considerations
Mark Young39389872017-01-19 21:10:49 -07001309
1310
1311##### Associating Private Data with Vulkan Objects Within a Layer
1312
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001313A layer may want to associate it's own private data with one or more Vulkan
Mark Youngf7914cf2016-08-31 11:53:26 -06001314objects. Two common methods to do this are hash maps and object wrapping.
1315
Mark Youngf7914cf2016-08-31 11:53:26 -06001316
Mark Young39389872017-01-19 21:10:49 -07001317###### Wrapping
Ian Elliott0b082e42016-08-31 14:08:44 -06001318
Mark Young39389872017-01-19 21:10:49 -07001319The loader supports layers wrapping any Vulkan object, including dispatchable
1320objects. For functions that return object handles, each layer does not touch
1321the value passed down the call chain. This is because lower items may need to
1322use the original value. However, when the value is returned from a
1323lower-level layer (possibly the ICD), the layer saves the handle and returns
1324its own handle to the layer above it (possibly the application). When a layer
1325receives a Vulkan function using something that it previously returned a handle
1326for, the layer is required to unwrap the handle and pass along the saved handle
1327to the layer below it. This means that the layer **must intercept every Vulkan
1328function which uses the object in question**, and wrap or unwrap the object, as
1329appropriate. This includes adding support for all extensions with functions
Ian Elliott0b082e42016-08-31 14:08:44 -06001330using any object the layer wraps.
Mark Youngf7914cf2016-08-31 11:53:26 -06001331
1332Layers above the object wrapping layer will see the wrapped object. Layers
1333which wrap dispatchable objects must ensure that the first field in the wrapping
Mark Young39389872017-01-19 21:10:49 -07001334structure is a pointer to a dispatch table as defined in `vk_layer.h`.
1335Specifically, an instance wrapped dispatchable object could be as follows:
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001336```
1337struct my_wrapped_instance_obj_ {
1338 VkLayerInstanceDispatchTable *disp;
1339 // whatever data layer wants to add to this object
1340};
1341```
1342A device wrapped dispatchable object could be as follows:
1343```
1344struct my_wrapped_instance_obj_ {
1345 VkLayerDispatchTable *disp;
1346 // whatever data layer wants to add to this object
1347};
1348```
Jeff Julianof1619872016-02-17 17:25:42 -05001349
Ian Elliott0b082e42016-08-31 14:08:44 -06001350Layers that wrap dispatchable objects must follow the guidelines for creating
1351new dispatchable objects (below).
1352
Mark Young39389872017-01-19 21:10:49 -07001353<u>Cautions About Wrapping</u>
Ian Elliott0b082e42016-08-31 14:08:44 -06001354
1355Layers are generally discouraged from wrapping objects, because of the
1356potential for incompatibilities with new extensions. For example, let's say
Mark Young39389872017-01-19 21:10:49 -07001357that a layer wraps `VkImage` objects, and properly wraps and unwraps `VkImage`
1358object handles for all core functions. If a new extension is created which has
1359functions that take `VkImage` objects as parameters, and if the layer does not
1360support those new functions, an application that uses both the layer and the new
1361extension will have undefined behavior when those new functions are called (e.g.
Ian Elliott0b082e42016-08-31 14:08:44 -06001362the application may crash). This is becaues the lower-level layers and ICD
1363won't receive the handle that they generated. Instead, they will receive a
1364handle that is only known by the layer that is wrapping the object.
1365
1366Because of the potential for incompatibilities with unsupported extensions,
1367layers that wrap objects must check which extensions are being used by the
1368application, and take appropriate action if the layer is used with unsupported
1369extensions (e.g. disable layer functionality, stop wrapping objects, issue a
1370message to the user).
1371
1372The reason that the validation layers wrap objects, is to track the proper use
1373and destruction of each object. They issue a validation error if used with
1374unsupported extensions, alerting the user to the potential for undefined
1375behavior.
1376
Mark Young39389872017-01-19 21:10:49 -07001377
1378###### Hash Maps
1379
Jeff Julianof1619872016-02-17 17:25:42 -05001380Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001381given object. The key to the map could be the object. Alternatively, for
1382dispatchable objects at a given level (eg device or instance) the layer may
Mark Young39389872017-01-19 21:10:49 -07001383want data associated with the `VkDevice` or `VkInstance` objects. Since
1384there are multiple dispatchable objects for a given `VkInstance` or `VkDevice`,
1385the `VkDevice` or `VkInstance` object is not a great map key. Instead the layer
1386should use the dispatch table pointer within the `VkDevice` or `VkInstance`
1387since that will be unique for a given `VkInstance` or `VkDevice`.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001388
Mark Young39389872017-01-19 21:10:49 -07001389
1390##### Creating New Dispatchable Objects
1391
1392Layers which create dispatchable objects must take special care. Remember that
1393loader *trampoline* code normally fills in the dispatch table pointer in the
1394newly created object. Thus, the layer must fill in the dispatch table pointer if
1395the loader *trampoline* will not do so. Common cases where a layer (or ICD) may
1396create a dispatchable object without loader *trampoline* code is as follows:
1397- layers that wrap dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001398- layers which add extensions that create dispatchable objects
Mark Young39389872017-01-19 21:10:49 -07001399- layers which insert extra Vulkan funnctions in the stream of functions they
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001400intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001401- ICDs which add extensions that create dispatchable objects
1402
Mark Young39389872017-01-19 21:10:49 -07001403The desktop loader provides a callback that can be used for initializing
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001404a dispatchable object. The callback is passed as an extension structure via the
Mark Young39389872017-01-19 21:10:49 -07001405pNext field in the create info structure when creating an instance
1406(`VkInstanceCreateInfo`) or device (`VkDeviceCreateInfo`). The callback
1407prototype is defined as follows for instance and device callbacks respectively
1408(see `vk_layer.h`):
1409
1410```cpp
1411VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance,
1412 void *object);
1413VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData(VkDevice device,
1414 void *object);
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001415```
Mark Young39389872017-01-19 21:10:49 -07001416
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001417To obtain these callbacks the layer must search through the list of structures
Mark Young39389872017-01-19 21:10:49 -07001418pointed to by the "pNext" field in the `VkInstanceCreateInfo` and
1419`VkDeviceCreateInfo` parameters to find any callback structures inserted by the
1420loader. The salient details are as follows:
1421- For `VkInstanceCreateInfo` the callback structure pointed to by "pNext" is
1422`VkLayerInstanceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1423- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within
1424`VkInstanceCreateInfo` parameter indicates a loader structure.
1425- Within `VkLayerInstanceCreateInfo`, the "function" field indicates how the
1426union field "u" should be interpreted.
1427- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1428contain the callback in "pfnSetInstanceLoaderData".
1429- For `VkDeviceCreateInfo` the callback structure pointed to by "pNext" is
1430`VkLayerDeviceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1431- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within
1432`VkDeviceCreateInfo` parameter indicates a loader structure.
1433- Within `VkLayerDeviceCreateInfo`, the "function" field indicates how the union
1434field "u" should be interpreted.
1435- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1436contain the callback in "pfnSetDeviceLoaderData".
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001437
Mark Young39389872017-01-19 21:10:49 -07001438Alternatively, if an older loader is being used that doesn't provide these
1439callbacks, the layer may manually initialize the newly created dispatchable
1440object. To fill in the dispatch table pointer in newly created dispatchable
1441object, the layer should copy the dispatch pointer, which is always the first
1442entry in the structure, from an existing parent object of the same level
1443(instance versus device).
Jon Ashburnc2972682016-02-08 15:42:01 -07001444
Mark Young39389872017-01-19 21:10:49 -07001445For example, if there is a newly created `VkCommandBuffer` object, then the
1446dispatch pointer from the `VkDevice` object, which is the parent of the
1447`VkCommandBuffer` object, should be copied into the newly created object.
1448
1449
1450#### Layer Manifest File Format
1451
1452On Windows and Linux (desktop), the loader uses manifest files to discover
1453layer libraries and layers. The desktop loader doesn't directly query the
1454layer library except during chaining. This is to reduce the likelihood of
1455loading a malicious layer into memory. Instead, details are read from the
1456Manifest file, which are then provided for applications to determine what
1457layers should actually be loaded.
1458
1459The following section discusses the details of the Layer Manifest JSON file
1460format. The JSON file itself does not have any requirements for naming. The
1461only requirement is that the extension suffix of the file ends with ".json".
1462
1463Here is an example layer JSON Manifest file with a single layer:
1464
1465```
1466{
1467 "file_format_version" : "1.0.0",
1468 "layer": {
1469 "name": "VK_LAYER_LUNARG_overlay",
1470 "type": "INSTANCE",
1471 "library_path": "vkOverlayLayer.dll"
1472 "api_version" : "1.0.5",
1473 "implementation_version" : "2",
1474 "description" : "LunarG HUD layer",
1475 "functions": {
1476 "vkNegotiateLoaderLayerInterfaceVersion":
1477 "OverlayLayer_NegotiateLoaderLayerInterfaceVersion"
1478 },
1479 "instance_extensions": [
1480 {
1481 "name": "VK_EXT_debug_report",
1482 "spec_version": "1"
1483 },
1484 {
1485 "name": "VK_VENDOR_ext_x",
1486 "spec_version": "3"
1487 }
1488 ],
1489 "device_extensions": [
1490 {
1491 "name": "VK_EXT_debug_marker",
1492 "spec_version": "1",
1493 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1494 }
1495 ],
1496 "enable_environment": {
1497 "ENABLE_LAYER_OVERLAY_1": "1"
1498 }
1499 "disable_environment": {
1500 "DISABLE_LAYER_OVERLAY_1": ""
1501 }
1502 }
1503}
1504```
1505
1506Here's a snippet with the changes required to support multiple layers per
1507manifest file:
1508```
1509{
1510 "file_format_version" : "1.0.1",
1511 "layers": [
1512 {
1513 "name": "VK_LAYER_layer_name1",
1514 "type": "INSTANCE",
1515 ...
1516 },
1517 {
1518 "name": "VK_LAYER_layer_name2",
1519 "type": "INSTANCE",
1520 ...
1521 }
1522 ]
1523}
1524```
1525
1526| JSON Node | Description and Notes | Introspection Query |
1527|:----------------:|--------------------|:----------------:
1528| "file\_format\_version" | Manifest format major.minor.patch version number. | N/A |
1529| | Supported versions are: 1.0.0, 1.0.1, and 1.1.0. | |
1530| "layer" | The identifier used to group a single layer's information together. | vkEnumerateInstanceLayerProperties |
1531| "layers" | The identifier used to group multiple layers' information together. This requires a minimum Manifest file format version of 1.0.1.| vkEnumerateInstanceLayerProperties |
1532| "name" | The string used to uniquely identify this layer to applications. | vkEnumerateInstanceLayerProperties |
1533| "type" | This field indicates the type of layer. The values can be: GLOBAL, or INSTANCE | vkEnumerate*LayerProperties |
1534| | **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. | |
1535| "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). | N/A |
1536| "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 |
1537| "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 |
1538| "description" | A high-level description of the layer and it's intended use. | vkEnumerateInstanceLayerProperties |
1539| "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 |
1540| "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 |
1541| "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 |
1542| "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 |
1543| "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 |
1544
1545
1546##### Layer Manifest File Version History
1547
1548The current highest supported Layer Manifest file format supported is 1.1.0.
1549Information about each version is detailed in the following sub-sections:
1550
1551###### Layer Manifest File Version 1.1.0
1552
1553Layer Manifest File Version 1.1.0 is tied to changes exposed by the Loader/Layer
1554interface version 2.
1555 1. Renaming "vkGetInstanceProcAddr" in the "functions" section is
1556 deprecated since the loader no longer needs to query the layer about
1557 "vkGetInstanceProcAddr" directly. It is now returned during the layer
1558 negotiation, so this field will be ignored.
1559 2. Renaming "vkGetDeviceProcAddr" in the "functions" section is
1560 deprecated since the loader no longer needs to query the layer about
1561 "vkGetDeviceProcAddr" directly. It too is now returned during the layer
1562 negotiation, so this field will be ignored.
1563 3. Renaming the "vkNegotiateLoaderLayerInterfaceVersion" function is
1564 being added to the "functions" section, since this is now the only
1565 function the loader needs to query using OS-specific calls.
1566 - NOTE: This is an optional field and, as the two previous fields, only
1567needed if the layer requires changing the name of the function for some reason.
1568
1569You do not need to update your layer manifest file if you don't change the
1570names of any of the listed functions.
1571
1572###### Layer Manifest File Version 1.0.1
1573
1574The ability to define multiple layers using the "layers" array was added. This
1575JSON array field can be used when defining a single layer or multiple layers.
1576The "layer" field is still present and valid for a single layer definition.
1577
1578###### Layer Manifest File Version 1.0.0
1579
1580The initial version of the layer manifest file specified the basic format and
1581fields of a layer JSON file. The fields of the 1.0.0 file format include:
1582 * "file\_format\_version"
1583 * "layer"
1584 * "name"
1585 * "type"
1586 * "library\_path"
1587 * "api\_version"
1588 * "implementation\_version"
1589 * "description"
1590 * "functions"
1591 * "instance\_extensions"
1592 * "device\_extensions"
1593 * "enable\_environment"
1594 * "disable\_environment"
1595
1596It was also during this time that the value of "DEVICE" was deprecated from
1597the "type" field.
1598
1599
1600#### Layer Library Versions
1601
1602The current Layer Library interface is at version 2. The following sections
1603detail the differences between the various versions.
1604
1605##### Layer Library API Version 2
1606
1607Introduced the concept of
1608[loader and layer interface](#layer-version-negotiation) using the new
1609`vkNegotiateLoaderLayerInterfaceVersion` function. Additionally, it introduced
1610the concept of
1611[Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-
1612extensions)
1613and the associated `vk_layerGetPhysicalDeviceProcAddr` function. Finally, it
1614changed the manifest file defition to 1.1.0.
1615
1616##### Layer Library API Version 1
1617
1618A layer library supporting interface version 1 had the following behavior:
1619 1. `GetInstanceProcAddr` and `GetDeviceProcAddr` were directly exported
1620 2. The layer manifest file was able to override the names of the
1621`GetInstanceProcAddr` and `GetDeviceProcAddr`functions.
1622
1623##### Layer Library API Version 0
1624
1625A layer library supporting interface version 0 must define and export these
1626introspection functions, unrelated to any Vulkan function despite the names,
1627signatures, and other similarities:
1628
1629 - `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
1630library.
1631 - This function never fails.
1632 - When a layer library contains only one layer, this function may be an alias
1633 to the layer's `vkEnumerateInstanceLayerProperties`.
1634 - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
1635 layers in a layer library.
1636 - "pLayerName" is always a valid layer name.
1637 - This function never fails.
1638 - When a layer library contains only one layer, this function may be an alias
1639 to the layer's `vkEnumerateInstanceExtensionProperties`.
1640 - `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
1641 proper, or empty subset) of layers in a layer library.
1642 - "physicalDevice" is always `VK_NULL_HANDLE`.
1643 - This function never fails.
1644 - If a layer is not enumerated by this function, it will not participate in
1645 device function interception.
1646 - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
1647 layers in a layer library.
1648 - "physicalDevice" is always `VK_NULL_HANDLE`.
1649 - "pLayerName" is always a valid layer name.
1650 - This function never fails.
1651
1652It must also define and export these functions once for each layer in the
1653library:
1654
1655 - `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a
1656layer's vkGetInstanceProcAddr except it is exported.
1657
1658 When a layer library contains only one layer, this function may
1659 alternatively be named `vkGetInstanceProcAddr`.
1660
1661 - `<layerName>GetDeviceProcAddr` behaves identically to a layer's
1662vkGetDeviceProcAddr except it is exported.
1663
1664 When a layer library contains only one layer, this function may
1665 alternatively be named `vkGetDeviceProcAddr`.
1666
1667All layers contained within a library must support `vk_layer.h`. They do not
1668need to implement functions that they do not intercept. They are recommended
1669not to export any functions.
1670
1671
1672<br/>
1673<br/>
1674
1675## Vulkan Installable Client Driver Interface With the Loader
1676
1677This section discusses the various requirements for the loader and a Vulkan
1678ICD to properly hand-shake.
1679
1680 * [ICD Discovery](#icd-discovery)
1681 * [ICD Manifest File Usage](#icd-manifest-file-usage)
1682 * [ICD Discovery on Windows](#icd-discovery-on-windows)
1683 * [ICD Discovery on Linux](#icd-discovery-on-linux)
1684 * [Using Pre-Production ICDs on Windows and Linux](#using-pre-production-icds-on-windows-and-linux)
1685 * [ICD Discovery on Android](#icd-discovery-on-android)
1686 * [ICD Manifest File Format](#icd-manifest-file-format)
1687 * [ICD Manifest File Versions](#icd-manifest-file-versions)
1688 * [ICD Manifest File Version 1.0.0](#icd-manifest-file-version-1.0.0)
1689 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
1690 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
1691 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
1692 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
1693 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
1694 * [Windows and Linux ICD Negotiation](#windows-and-linux-icd-negotiation)
1695 * [Version Negotiation Between Loader and ICDs](#version-negotiation-between-loader-and-icds)
1696 * [Interfacing With Legacy ICDs or Loader](#interfacing-with-legacy-icds-or-loader]
1697 * [Loader Version 4 Interface Requirements](#loader-version-4-interface-requirements)
1698 * [Loader Version 3 Interface Requirements](#loader-version-3-interface-requirements)
1699 * [Loader Version 2 Interface Requirements](#loader-version-2-interface-requirements)
1700 * [Loader Versions 0 and 1 Interface Requirements](#loader-versions-0-and-1-interface-requirements)
1701 * [Android ICD Negotiation](#android-icd-negotiation)
1702
1703
1704### ICD Discovery
1705
1706Vulkan allows multiple drivers each with one or more devices (represented by a
1707Vulkan `VkPhysicalDevice` object) to be used collectively. The loader is
1708responsible for discovering available Vulkan ICDs on the system. Given a list
1709of available ICDs, the loader can enumerate all the physical devices available
1710for an application and return this information to the application. The process
1711in which the loader discovers the available Installable Client Drivers (ICDs)
1712on a system is platform dependent. Windows, Linux and Android ICD discovery
1713details are listed below.
1714
1715#### ICD Manifest File Usage
1716
1717As with layers, on Windows and Linux systems, JSON formated manifest files are
1718used to store ICD information. In order to find system-installed drivers, the
1719Vulkan loader will read the JSON files to identify the names and attributes of
1720each driver. One thing you will notice is that ICD Manifest files are much
1721simpler than the corresponding layer Manifest files.
1722
1723See the [Current ICD Manifest File Format](#icd-manifest-file-format) section
1724for more details.
1725
1726
1727#### ICD Discovery on Windows
1728
1729In order to find installed ICDs, the Vulkan loader will scan the
1730values in the following Windows registry key:
1731
1732```
1733 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers
1734```
1735
1736For 32-bit applications on 64-bit Windows, the loader scan's the 32-bit
1737registry location:
1738
1739```
1740 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\Drivers
1741```
1742
1743The loader will look at the appropriate registry location and check each value
1744listed. If the key is of type DWORD, and it has a value of 0, the loader will
1745open the JSON manifest file specified by the name. Each name must be a full
1746pathname to a text manifest file. The Vulkan loader will attempt to open each
1747manifest file to obtain the information about an ICD's shared library (".dll")
1748file.
1749
1750For example, let us assume the registry contains the following data:
1751
1752```
1753[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
1754
1755"C:\vendor a\vk_vendora.json"=dword:00000000
1756"C:\windows\system32\vendorb_vk.json"=dword:00000001
1757"C:\windows\system32\vendorc_icd.json"=dword:00000000
1758```
1759
1760In this case, the loader will step through each entry, and check the value. If
1761the value is 0, then the loader will attempt to load the file. In this case,
1762the loader will will open the first and last listings, but not the middle. This
1763is because the value of 1 for vendorb_vk.json disables the driver.
1764
1765The Vulkan loader will open each enabled manifest file found to obtain the name
1766or pathname of an ICD shared library (".DLL") file.
1767
1768See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
1769details.
1770
1771
1772#### ICD Discovery on Linux
1773
1774In order to find installed ICDs, the Vulkan loader will scan the files
1775in the following Linux directories:
1776
1777```
1778 /usr/local/etc/vulkan/icd.d
1779 /usr/local/share/vulkan/icd.d
1780 /etc/vulkan/icd.d
1781 /usr/share/vulkan/icd.d
1782 $HOME/.local/share/vulkan/icd.d
1783```
1784
1785The "/usr/local/*" directories can be configured to be other directories at
1786build time.
1787
1788The typical usage of the directories is indicated in the table below.
1789
1790| Location | Details |
1791|-------------------|------------------------|
1792| $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 |
1793| "/usr/local/etc/vulkan/icd.d" | Directory for locally built ICDs |
1794| "/usr/local/share/vulkan/icd.d" | Directory for locally built ICDs |
1795| "/etc/vulkan/icd.d" | Location of ICDs installed from non-Linux-distribution-provided packages |
1796| "/usr/share/vulkan/icd.d" | Location of ICDs installed from Linux-distribution-provided packages |
1797
1798The Vulkan loader will open each manifest file found to obtain the name or
1799pathname of an ICD shared library (".so") file.
1800
1801See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
1802details.
1803
1804#### Using Pre-Production ICDs on Windows and Linux
1805
1806Independent Hardware Vendor (IHV) pre-production ICDs. In some cases, a
1807pre-production ICD may be in an installable package. In other cases, a
1808pre-production ICD may simply be a shared library in the developer's build tree.
1809In this latter case, we want to allow developers to point to such an ICD without
1810modifying the system-installed ICD(s) on their system.
1811
1812This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
1813which will override the mechanism used for finding system-installed ICDs. In
1814other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
1815
1816The "VK\_ICD\_FILENAMES" environment variable is a list of ICD
1817manifest files, containing the full path to the ICD JSON Manifest file. This
1818list is colon-separated on Linux, and semi-colon separated on Windows.
1819
1820Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
1821file for a developer-built ICD. A separator (colon or semi-colon) is only used
1822if more than one ICD is listed.
1823
1824**NOTE:** On Linux, this environment variable will be ignored for suid programs.
1825
1826
1827#### ICD Discovery on Android
1828
1829The Android loader lives in the system library folder. The location cannot be
1830changed. The loader will load the driver/ICD via hw\_get\_module with the ID
1831of "vulkan". **Due to security policies in Android, none of this can be modified
1832under normal use.**
1833
1834
1835### ICD Manifest File Format
1836
1837The following section discusses the details of the ICD Manifest JSON file
1838format. The JSON file itself does not have any requirements for naming. The
1839only requirement is that the extension suffix of the file ends with ".json".
1840
1841Here is an example layer JSON Manifest file:
1842
1843```
1844{
1845 "file_format_version": "1.0.0",
1846 "ICD": {
1847 "library_path": "path to ICD library",
1848 "api_version": "1.0.5"
1849 }
1850}
1851```
1852
1853| Field Name | Field Value |
1854|----------------|--------------------|
1855| "file\_format\_version" | The JSON format major.minor.patch version number of this file. Currently supported version is 1.0.0. |
1856| "ICD" | The identifier used to group all ICD information together. |
1857| "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 |
1858| "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. |
1859
1860**NOTE:** If the same ICD shared library supports multiple, incompatible
1861versions of text manifest file format versions, it must have separate
1862JSON files for each (all of which may point to the same shared library).
1863
1864##### ICD Manifest File Versions
1865
1866There has only been one version of the ICD manifest files supported. This is
1867version 1.0.0.
1868
1869###### ICD Manifest File Version 1.0.0
1870
1871The initial version of the ICD Manifest file specified the basic format and
1872fields of a layer JSON file. The fields of the 1.0.0 file format include:
1873 * "file\_format\_version"
1874 * "ICD"
1875 * "library\_path"
1876 * "api\_version"
1877
1878
1879### ICD Vulkan Entry-Point Discovery
1880
1881The Vulkan symbols exported by an ICD must not clash with the loader's exported
1882Vulkan symbols. This could be for several reasons. Because of this, all ICDs
1883must export the following function that is used for discovery of ICD Vulkan
1884entry-points. This entry-point is not a part of the Vulkan API itself, only a
1885private interface between the loader and ICDs for version 1 and higher
1886interfaces.
1887
1888```cpp
1889VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
1890 VkInstance instance,
1891 const char* pName);
1892```
1893
1894This function has very similar semantics to `vkGetInstanceProcAddr`.
1895`vk_icdGetInstanceProcAddr` returns valid function pointers for all the global-
1896level and instance-level Vulkan functions, and also for `vkGetDeviceProcAddr`.
1897Global-level functions are those which contain no dispatchable object as the
1898first parameter, such as `vkCreateInstance` and
1899`vkEnumerateInstanceExtensionProperties`. The ICD must support querying global-
1900level entry-points by calling `vk_icdGetInstanceProcAddr` with a NULL
1901`VkInstance` parameter. Instance-level functions are those that have either
1902`VkInstance`, or `VkPhysicalDevice` as the first parameter dispatchable object.
1903Both core entry-points and any instance extension entry-points the ICD supports
1904should be available via `vk_icdGetInstanceProcAddr`. Future Vulkan instance
1905extensions may define and use new instance-level dispatchable objects other
1906than `VkInstance` and `VkPhysicalDevice`, in which case extension entry-points
1907using these newly defined dispatchable objects must be queryable via
1908`vk_icdGetInstanceProcAddr`.
1909
1910All other Vulkan entry-points must either:
1911 * NOT be exported directly from the ICD library
1912 * or NOT use the official Vulkan function names if they are exported
1913
1914This requirement is for ICD libraries that include other
1915functionality (such as OpenGL) and thus could be loaded by the
1916application prior to when the Vulkan loader library is loaded by the
1917application.
1918
1919Beware of interposing by dynamic OS library loaders if the official Vulkan
1920names are used. On Linux, if official names are used, the ICD library must be
1921linked with -Bsymbolic.
1922
1923
1924### ICD Unknown Physical Device Extensions
1925
1926Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
1927result in the following behavior:
1928 1. The loader would check if core function:
1929 - If it was, it would return the function pointer
1930 2. The loader would check if known extension function:
1931 - If it was, it would return the function pointer
1932 3. If the loader knew nothing about it, it would call down using
1933`GetInstanceProcAddr`
1934 - If it returned non-NULL, treat it as an unknown logical device command.
1935 - This meant setting up a generic trampoline function that takes in a
1936VkDevice as the first parameter and adjusting the dispatch table to call the
1937ICD/Layers function after getting the dispatch table from the VkDevice.
1938 4. If all the above failed, the loader would return NULL to the application.
1939
1940This caused problems when an ICD attempted to expose new physical device
1941extensions the loader knew nothing about, but an application did. Because the
1942loader knew nothing about it, the loader would get to step 3 in the above
1943process and would treat the function as an unknown logical device command. The
1944problem is, this would create a generic VkDevice trampoline function which, on
1945the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
1946This would lead to a crash or corruption.
1947
1948In order to identify the extension entry-points specific to physical device
1949extensions, the following function can be added to an ICD:
1950
1951```cpp
1952PFN_vkVoidFunction vk_icdGetPhysicalDeviceProcAddr(VkInstance instance,
1953 const char* pName);
1954```
1955
1956This function behaves similar to `vkGetInstanceProcAddr` and
1957`vkGetDeviceProcAddr` except it should only return values for physical device
1958extension entry-points. In this way, it compares "pName" to every physical
1959device function supported in the ICD.
1960
1961The following rules apply:
1962 * If it is the name of a physical device function supported by the ICD, the
1963pointer to the ICD's corresponding function should be returned.
1964 * If it is the name of a valid function which is **not** a physical device
1965function (i.e. an Instance, Device, or other function implemented by the ICD),
1966then the value of NULL should be returned.
1967 * If the ICD has no idea what this function is, it should return NULL.
1968
1969This support is optional and should not be considered a requirement. This is
1970only required if an ICD intends to support some functionality not directly
1971supported by a significant population of loaders in the public. If an ICD
1972does implent this support, it should return the address of its
1973`vk_icdGetPhysicalDeviceProcAddr` function through the `vkGetInstanceProcAddr`
1974function.
1975
1976The new behavior of the loader's vkGetInstanceProcAddr with support for the
1977`vk_icdGetPhysicalDeviceProcAddr` function is as follows:
1978 1. Check if core function:
1979 - If it is, return the function pointer
1980 2. Check if known instance or device extension function:
1981 - If it is, return the function pointer
1982 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
1983 - If it returns non-NULL, return a trampoline to a generic physical device
1984function, and setup a generic terminator which will pass it to the proper ICD.
1985 4. Call down using `GetInstanceProcAddr`
1986 - If it returns non-NULL, treat it as an unknown logical device command.
1987This means setting up a generic trampoline function that takes in a VkDevice as
1988the first parameter and adjusting the dispatch table to call the ICD/Layers
1989function after getting the dispatch table from the VkDevice. Then, return the
1990pointer to corresponding trampoline function.
1991 5. Return NULL
1992
1993You can see now, that, if the command gets promoted to core later, it will no
1994longer be setup using `vk_icdGetPhysicalDeviceProcAddr`. Additionally, if the
1995loader adds direct support for the extension, it will no longer get to step 3,
1996because step 2 will return a valid function pointer. However, the ICD should
1997continue to support the command query via `vk_icdGetPhysicalDeviceProcAddr`,
1998until at least a Vulkan version bump, because an older loader may still be
1999attempting to use the commands.
2000
2001
2002### ICD Dispatchable Object Creation
2003
2004As previously covered, the loader requires dispatch tables to be accessible
2005within Vulkan dispatchable objects, such as: `VkInstance`, `VkPhysicalDevice`,
2006`VkDevice`, `VkQueue`, and `VkCommandBuffer`. The specific requirements on all
2007dispatchable objects created by ICDs are as follows:
2008
2009- All dispatchable objects created by an ICD can be cast to void \*\*
2010- The loader will replace the first entry with a pointer to the dispatch table
2011 which is owned by the loader. This implies three things for ICD drivers
2012 1. The ICD must return a pointer for the opaque dispatchable object handle
2013 2. This pointer points to a regular C structure with the first entry being a
2014 pointer.
2015 * **NOTE:** For any C\++ ICD's that implement VK objects directly as C\++
2016classes.
2017 * The C\++ compiler may put a vtable at offset zero if your class is non-
2018POD due to the use of a virtual function.
2019 * In this case use a regular C structure (see below).
2020 3. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
2021 dispatchable objects, as follows (see `include/vulkan/vk_icd.h`):
2022
2023```cpp
2024#include "vk_icd.h"
2025
2026union _VK_LOADER_DATA {
2027 uintptr loadermagic;
2028 void *loaderData;
2029} VK_LOADER_DATA;
2030
2031vkObj alloc_icd_obj()
2032{
2033 vkObj *newObj = alloc_obj();
2034 ...
2035 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
2036
2037 set_loader_magic_value(newObj);
2038 ...
2039 return newObj;
2040}
2041```
2042
2043
2044### Handling KHR Surface Objects in WSI Extensions
2045
2046Normally, ICDs handle object creation and destruction for various Vulkan
2047objects. The WSI surface extensions for Linux and Windows
2048("VK\_KHR\_win32\_surface", "VK\_KHR\_xcb\_surface", "VK\_KHR\_xlib\_surface",
2049"VK\_KHR\_mir\_surface", "VK\_KHR\_wayland\_surface", and "VK\_KHR\_surface")
2050are handled differently. For these extensions, the `VkSurfaceKHR` object
2051creation and destruction may be handled by either the loader, or an ICD.
2052
2053If the loader handles the management of the `VkSurfaceKHR` objects:
2054 1. The loader will handle the calls to `vkCreateXXXSurfaceKHR` and
2055`vkDestroySurfaceKHR`
2056 functions without involving the ICDs.
2057 * Where XXX stands for the Windowing System name:
2058 * Mir
2059 * Wayland
2060 * Xcb
2061 * Xlib
2062 * Windows
2063 * Android
2064 2. The loader creates a `VkIcdSurfaceXXX` object for the corresponding
2065`vkCreateXXXSurfaceKHR` call.
2066 * The `VkIcdSurfaceXXX` structures are defined in `include/vulkan/vk_icd.h`.
2067 3. ICDs can cast any `VkSurfaceKHR` object to a pointer to the appropriate
2068 `VkIcdSurfaceXXX` structure.
2069 4. The first field of all the `VkIcdSurfaceXXX` structures is a
2070`VkIcdSurfaceBase` enumerant that indicates whether the
2071 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
2072
2073The ICD may choose to handle `VkSurfaceKHR` object creation instead. If an ICD
2074desires to handle creating and destroying it must do the following:
2075 1. Support version 3 or newer of the loader/ICD interface.
2076 2. Export and handle all functions that take in a `VkSurfaceKHR` object,
2077including:
2078 * `vkCreateXXXSurfaceKHR`
2079 * `vkGetPhysicalDeviceSurfaceSupportKHR`
2080 * `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2081 * `vkGetPhysicalDeviceSurfaceFormatsKHR`
2082 * `vkGetPhysicalDeviceSurfacePresentModesKHR`
2083 * `vkCreateSwapchainKHR`
2084 * `vkDestroySurfaceKHR`
2085
2086Because the `VkSurfaceKHR` object is an instance-level object, one object can be
2087associated with multiple ICDs. Therefore, when the loader receives the
2088`vkCreateXXXSurfaceKHR` call, it still creates an internal `VkSurfaceIcdXXX`
2089object. This object acts as a container for each ICD's version of the
2090`VkSurfaceKHR` object. If an ICD does not support the creation of its own
2091`VkSurfaceKHR` object, the loader's container stores a NULL for that ICD. On
2092the otherhand, if the ICD does support `VkSurfaceKHR` creation, the loader will
2093make the appropriate `vkCreateXXXSurfaceKHR` call to the ICD, and store the
2094returned pointer in it's container object. The loader then returns the
2095`VkSurfaceIcdXXX` as a `VkSurfaceKHR` object back up the call chain. Finally,
2096when the loader receives the `vkDestroySurfaceKHR` call, it subsequently calls
2097`vkDestroySurfaceKHR` for each ICD who's internal `VkSurfaceKHR` object is not
2098NULL. Then the loader destroys the container object before returning.
2099
2100
2101### Loader and ICD Interface Negotiation
2102
2103Generally, for functions issued by an application, the loader can be
2104viewed as a pass through. That is, the loader generally doesn't modify the
2105functions or their parameters, but simply calls the ICDs entry-point for that
2106function. There are specific additional interface requirements an ICD needs to
2107comply with that are not part of any requirements from the Vulkan specification.
2108These addtional requirements are versioned to allow flexibility in the future.
2109
2110
2111#### Windows and Linux ICD Negotiation
2112
2113
2114##### Version Negotiation Between Loader and ICDs
2115
2116All ICDs (supporting interface version 2 or higher) must export the following
2117function that is used for determination of the interface version that will be
2118used. This entry-point is not a part of the Vulkan API itself, only a private
2119interface between the loader and ICDs.
2120
2121```cpp
2122 VKAPI_ATTR VkResult VKAPI_CALL
2123 vk_icdNegotiateLoaderICDInterfaceVersion(
2124 uint32_t* pSupportedVersion);
2125```
2126
2127This function allows the loader and ICD to agree on an interface version to use.
2128The "pSupportedVersion" parameter is both an input and output parameter.
2129"pSupportedVersion" is filled in by the loader with the desired latest interface
2130version supported by the loader (typically the latest). The ICD receives this
2131and returns back the version it desires in the same field. Because it is
2132setting up the interface version between the loader and ICD, this should be
2133the first call made by a loader to the ICD (even prior to any calls to
2134`vk_icdGetInstanceProcAddr`).
2135
2136If the ICD receiving the call no longer supports the interface version provided
2137by the loader (due to deprecation), then it should report
2138VK_ERROR_INCOMPATIBLE_DRIVER error. Otherwise it sets the value pointed by
2139"pSupportedVersion" to the latest interface version supported by both the ICD
2140and the loader and returns VK_SUCCESS.
2141
2142The ICD should report VK_SUCCESS in case the loader provided interface version
2143is newer than that supported by the ICD, as it's the loader's responsibility to
2144determine whether it can support the older interface version supported by the
2145ICD. The ICD should also report VK_SUCCESS in the case its interface version
2146is greater than the loader's, but return the loader's version. Thus, upon
2147return of VK_SUCCESS the "pSupportedVersion" will contain the desired interface
2148version to be used by the ICD.
2149
2150If the loader receives an interface version from the ICD that the loader no
2151longer supports (due to deprecation), or it receives a
2152VK_ERROR_INCOMPATIBLE_DRIVER error instead of VK_SUCCESS, then the loader will
2153treat the ICD as incompatible and will not load it for use. In this case, the
2154application will not see the ICDs `vkPhysicalDevice` during enumeration.
2155
2156###### Interfacing With Legacy ICDs or Loader
2157
2158If a loader sees that an ICD does not export the
2159`vk_icdNegotiateLoaderICDInterfaceVersion` function, then the loader assumes the
2160corresponding ICD only supports either interface version 0 or 1.
2161
2162From the other side of the interface, if an ICD sees a call to
2163`vk_icdGetInstanceProcAddr` before a call to
2164`vk_icdGetLoaderICDInterfaceVersion`, then it knows that loader making the calls
2165is a legacy loader supporting version 0 or 1. If the loader calls
2166`vk_icdGetInstanceProcAddr` first, it supports at least version 1. Otherwise,
2167the loader only supports version 0.
2168
2169
2170##### Loader Version 4 Interface Requirements
2171
2172The major change to version 4 of the loader/ICD interface is the support of
2173[Unknown Physical Device Extensions](#icd-unknown-physical-device-
2174extensions] using the `vk_icdGetPhysicalDeviceProcAddr` function. This
2175function is purely optional. However, if an ICD supports a Physical Device
2176extension, it must provide a `vk_icdGetPhysicalDeviceProcAddr` function.
2177Otherwise, the loader will continue to treat any unknown functions as VkDevice
2178functions and cause invalid behavior.
2179
2180
2181##### Loader Version 3 Interface Requirements
2182
2183The primary change that occurred in version 3 of the loader/ICD interface was to
2184allow an ICD to handle creation/destruction of their own KHR_surfaces. Up until
2185this point, the loader created a surface object that was used by all ICDs.
2186However, some ICDs may want to provide their own surface handles. If an ICD
2187chooses to enable this support, it must export support for version 3 of the
2188loader/ICD interface, as well as any Vulkan function that uses a KHR_surface
2189handle, such as:
2190- `vkCreateXXXSurfaceKHR` (where XXX is the platform specific identifier [i.e.
2191`vkCreateWin32SurfaceKHR` for Windows])
2192- `vkDestroySurfaceKHR`
2193- `vkCreateSwapchainKHR`
2194- `vkGetPhysicalDeviceSurfaceSupportKHR`
2195- `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2196- `vkGetPhysicalDeviceSurfaceFormatsKHR`
2197- `vkGetPhysicalDeviceSurfacePresentModesKHR`
2198
2199An ICD can still choose to not take advantage of this functionality by simply
2200not exposing the above the `vkCreateXXXSurfaceKHR` and `vkDestroySurfaceKHR`
2201functions.
2202
2203
2204##### Loader Version 2 Interface Requirements
2205
2206Version 2 interface has requirements in three areas:
2207 1. ICD Vulkan entry-point discovery,
2208 2. `KHR_surface` related requirements in the WSI extensions,
2209 3. Vulkan dispatchable object creation requirements.
2210
2211##### Loader Versions 0 and 1 Interface Requirements
2212
2213Version 0 and 1 interfaces do not support version negotiation via
2214`vk_icdNegotiateLoaderICDInterfaceVersion`. ICDs can distinguish version 0 and
2215version 1 interfaces as follows: if the loader calls `vk_icdGetInstanceProcAddr`
2216first it supports version 1; otherwise the loader only supports version 0.
2217
2218Version 0 interface does not support `vk_icdGetInstanceProcAddr`. Version 0
2219interface requirements for obtaining ICD Vulkan entry-points are as follows:
2220
2221- The function `vkGetInstanceProcAddr` **must be exported** in the ICD library
2222and returns valid function pointers for all the Vulkan API entry-points.
2223- `vkCreateInstance` **must be exported** by the ICD library.
2224- `vkEnumerateInstanceExtensionProperties` **must be exported** by the ICD
2225library.
2226
2227Additional Notes:
2228
2229- The loader will filter out extensions requested in `vkCreateInstance` and
2230`vkCreateDevice` before calling into the ICD; Filtering will be of extensions
2231advertised by entities (e.g. layers) different from the ICD in question.
2232- The loader will not call the ICD for `vkEnumerate\*LayerProperties`() as layer
2233properties are obtained from the layer libraries and layer JSON files.
2234- If an ICD library author wants to implement a layer, it can do so by having
2235the appropriate layer JSON manifest file refer to the ICD library file.
2236- The loader will not call the ICD for
2237 `vkEnumerate\*ExtensionProperties` if "pLayerName" is not equal to `NULL`.
2238- ICDs creating new dispatchable objects via device extensions need to
2239initialize the created dispatchable object. The loader has generic *trampoline*
2240code for unknown device extensions. This generic *trampoline* code doesn't
2241initialize the dispatch table within the newly created object. See the
2242[Creating New Dispatchable Objects](#creating-new-dispatchable-objects) section
2243for more information on how to initialize created dispatchable objects for
2244extensions non known by the loader.
2245
2246
2247#### Android ICD Negotiation
2248
2249The Android loader uses the same protocol for initializing the dispatch
2250table as described above. The only difference is that the Android
2251loader queries layer and extension information directly from the
2252respective libraries and does not use the json manifest files used
2253by the Windows and Linux loaders.
2254
2255
2256## Glossary of Terms
2257
2258| Field Name | Field Value |
2259|----------------|--------------------|
2260| 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. |
2261| 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. |
2262| Core Function | A function that is already part of the Vulkan core specification and not an extension. For example, vkCreateDevice(). |
2263| 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 |
2264| 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. |
2265| 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. |
2266| 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. |
2267| 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). |
2268| 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.
2269| 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. |
2270| 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 |
2271| 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. |
2272| 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. |
2273| 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. |
2274| 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).
2275| 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. |
2276| 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. |
2277| 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. |