blob: 6b71d600fcdf5438bc2a10ef511e21b3a26ac999 [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
Mark Young6340bb82017-02-13 15:39:22 -0700702##### Filtering Out Unknown Instance Extension Names
703In some cases, an ICD may support instance extensions that the loader does not.
704For the above reasons, the loader will filter out the names of these unknown instance
705extensions when an application calls `vkEnumerateInstanceExtensionProperties`.
706Additionally, this behavior will cause the loader to throw an error during
707`vkCreateInstance` if you still attempt to use one of these extensions. The intent is
708to protect applications so that they don't inadvertantly use functionality
709which could lead to a crash.
710
711On the other-hand, if you know you can safely use the extension, you may disable
712the filtering by defining the environment variable `VK_LOADER_DISABLE_INST_EXT_FILTER`
713and setting the value to a non-zero number. This will effectively disable the
714loader's filtering out of instance extension names.
Jon Ashburnc2972682016-02-08 15:42:01 -0700715
Mark Youngcb6e6702016-07-20 11:38:53 -0600716<br/>
Mark Youngcb6e6702016-07-20 11:38:53 -0600717<br/>
718
Mark Young39389872017-01-19 21:10:49 -0700719## Loader and Layer Interface
Jon Ashburnc2972682016-02-08 15:42:01 -0700720
Mark Young39389872017-01-19 21:10:49 -0700721In this section we'll discuss how the loader interacts with layers, including:
722 * [Layer Discovery](#layer-discovery)
723 * [Layer Manifest File Usage](#layer-manifest-file-usage)
724 * [Android Layer Discovery](#android-layer-discovery)
725 * [Windows Layer Discovery](#windows-layer-discovery)
726 * [Linux Layer Discovery](#linux-layer-discovery)
727 * [Layer Version Negotiation](#layer-version-negotiation)
728 * [Layer Call Chains and Distributed Dispatch](#layer-call-chains-and-distributed-dispatch)
729 * [Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-extensions)
730 * [Layer Intercept Requirements](#layer-intercept-requirements)
731 * [Distributed Dispatching Requirements](#distributed-dispatching-requirements)
732 * [Layer Conventions and Rules](#layer-conventions-and-rules)
733 * [Layer Dispatch Initialization](#layer-dispatch-initialization)
734 * [Example Code for CreateInstance](#example-code-for-createinstance)
735 * [Example Code for CreateDevice](#example-code-for-createdevice)
736 * [Special Considerations](#special-considerations)
737 * [Associating Private Data with Vulkan Objects Within a Layer](#associating-private-data-with-vulkan-objects-within-a-layer)
738 * [Wrapping](#wrapping)
739 * [Hash Maps](#hash-maps)
740 * [Creating New Dispatchable Objects](#creating-new-dispatchable-objects)
741 * [Layer Manifest File Format](#layer-manifest-file-format)
742 * [Layer Manifest File Version History](#layer-manifest-file-version-history)
743 * [Layer Library Versions](#layer-library-versions)
744 * [Layer Library API Version 2](#layer-library-api-version-2)
745 * [Layer Library API Version 1](#layer-library-api-version-1)
746 * [Layer Library API Version 0](#layer-library-api-version-0)
747
Jon Ashburnc2972682016-02-08 15:42:01 -0700748
Mark Young39389872017-01-19 21:10:49 -0700749
750#### Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700751
Mark Young39389872017-01-19 21:10:49 -0700752As mentioned in the
753[Application Interface section](#implicit-vs-explicit-layers),
754layers can be categorized into two categories:
755 * Implicit Layers
756 * Explicit Layers
Jon Ashburnc2972682016-02-08 15:42:01 -0700757
Mark Young39389872017-01-19 21:10:49 -0700758The main difference between the two is that Implicit Layers are automatically
759enabled, unless overriden, and Explicit Layers must be enabled. Remember,
760Implicit Layers are not present on all Operating Systems (like Android).
Jon Ashburnc2972682016-02-08 15:42:01 -0700761
Mark Young39389872017-01-19 21:10:49 -0700762On any system, the loader looks in specific areas for information on the
763layers that it can load at a user's request. The process of finding the
764available layers on a system is known as Layer Discovery. During discovery,
765the loader determines what layers are available, the layer name, the layer
766version, and any extensions supported by the layer. This information is
767provided back to an application through `vkEnumerateInstanceLayerProperties`.
768
769The group of layers available to the loader is known as a layer library. This
770section defines an extensible interface to discover what layers are contained in
771the layer library.
772
773This section also specifies the minimal conventions and rules a layer must
774follow, especially with regards to interacting with the loader and other layers.
775
776##### Layer Manifest File Usage
777
778On Windows and Linux systems, JSON formated manifest files are used to store
779layer information. In order to find system-installed layers, the Vulkan loader
780will read the JSON files to identify the names and attributes of layers and
781their extensions. The use of manifest files allows the loader to avoid loading
782any shared library files when the application does not query nor request any
783extensions. The format of [Layer Manifest File](#layer-manifest-file-format)
784is detailed below.
785
786The Android loader does not use manifest files. Instead, the loader queries the
787layer properties using special functions known as "introspection" functions.
788The intent of these functions is to determine the same required information
789gathered from reading the manifest files. These introspection functions are
790not used by the desktop loader but should be present in layers to maintain
791consistency. The specific "introspection" functions are called out in
792the [Layer Manifest File Format](#layer-manifest-file-format) table.
793
794
795##### Android Layer Discovery
796
797On Android, the loader looks for layers to enumerate in the
798/data/local/debug/vulkan folder. An application enabled for debug has the
799ability to enumerate and enable any layers in that location.
800
801
802##### Windows Layer Discovery
803
804In order to find system-installed layers, the Vulkan loader will scan the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700805values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700806
Mark Young39389872017-01-19 21:10:49 -0700807```
808 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers
809 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ImplicitLayers
810```
Jon Ashburnc2972682016-02-08 15:42:01 -0700811
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700812For each value in these keys which has DWORD data set to 0, the loader opens
813the JSON manifest file specified by the name of the value. Each name must be a
Mark Young39389872017-01-19 21:10:49 -0700814full pathname to the manifest file. The Vulkan loader will open each info file
815to obtain information about the layer, including the name or pathname of a
816shared library (".dll") file. However, if VK\_LAYER\_PATH is defined, then the
817loader will instead look at the paths defined by that variable instead of using
818the information provided by these registry keys. See
819[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
820information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700821
Jon Ashburnc2972682016-02-08 15:42:01 -0700822
Mark Young39389872017-01-19 21:10:49 -0700823##### Linux Layer Discovery
Jon Ashburnc2972682016-02-08 15:42:01 -0700824
Mark Young39389872017-01-19 21:10:49 -0700825On Linux, the Vulkan loader will scan the files in the following Linux
826directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700827
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600828 /usr/local/etc/vulkan/explicit_layer.d
829 /usr/local/etc/vulkan/implicit_layer.d
830 /usr/local/share/vulkan/explicit_layer.d
831 /usr/local/share/vulkan/implicit_layer.d
832 /etc/vulkan/explicit_layer.d
833 /etc/vulkan/implicit_layer.d
834 /usr/share/vulkan/explicit_layer.d
835 /usr/share/vulkan/implicit_layer.d
836 $HOME/.local/share/vulkan/explicit_layer.d
837 $HOME/.local/share/vulkan/implicit_layer.d
838
Mark Young39389872017-01-19 21:10:49 -0700839Of course, ther are some things you have to know about the above folders:
840 1. The "/usr/local/*" directories can be configured to be other directories at
841build time.
842 2. $HOME is the current home directory of the application's user id; this path
843will be ignored for suid programs.
844 3. The "/usr/local/etc/vulkan/\*\_layer.d" and
845"/usr/local/share/vulkan/\*\_layer.d" directories are for layers that are
846installed from locally-built sources.
847 4. The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
Karl Schultz1f58d7e2016-10-31 15:58:21 -0600848installed from Linux-distribution-provided packages.
849
Mark Young39389872017-01-19 21:10:49 -0700850As on Windows, if VK\_LAYER\_PATH is defined, then the
851loader will instead look at the paths defined by that variable instead of using
852the information provided by these default paths. However, these
853environment variables are only used for non-suid programs. See
854[Forcing Layer Source Folders](#forcing-layer-source-folders) for more
855information on this.
Jon Ashburnc2972682016-02-08 15:42:01 -0700856
Mark Young39389872017-01-19 21:10:49 -0700857
858#### Layer Version Negotiation
859
860Now that a layer has been discovered, an application can choose to load it (or
861it is loaded by default if it is an Implicit layer). When the loader attempts
862to load the layer, the first thing it does is attempt to negotiate the version
863of the loader to layer interface. In order to negotiate the loader/layer
864interface version, the layer must implement the
865`vkNegotiateLoaderLayerInterfaceVersion` function. The following information is
866provided for this interface in include/vulkan/vk_layer.h:
867
868```cpp
869 typedef enum VkNegotiateLayerStructType {
870 LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
871 } VkNegotiateLayerStructType;
872
873 typedef struct VkNegotiateLayerInterface {
874 VkNegotiateLayerStructType sType;
875 void *pNext;
876 uint32_t loaderLayerInterfaceVersion;
877 PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
878 PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
879 PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
880 } VkNegotiateLayerInterface;
881
882 VkResult vkNegotiateLoaderLayerInterfaceVersion(
883 VkNegotiateLayerInterface *pVersionStruct);
Jon Ashburncc300a22016-02-11 14:57:30 -0700884```
Jon Ashburnc2972682016-02-08 15:42:01 -0700885
Mark Young39389872017-01-19 21:10:49 -0700886You'll notice the `VkNegotiateLayerInterface` structure is similar to other
887Vulkan structures. The "sType" field, in this case takes a new enum defined
888just for internal loader/layer interfacing use. The valid values for "sType"
889could grow in the future, but right only havs the one value
890"LAYER_NEGOTIATE_INTERFACE_STRUCT".
Jon Ashburnc2972682016-02-08 15:42:01 -0700891
Mark Young39389872017-01-19 21:10:49 -0700892This function (`vkNegotiateLoaderLayerInterfaceVersion`) should be exported by
893the layer so that using "GetProcAddress" on Windows or "dlsym" on Linux, should
894return a valid function pointer to it. Once the loader has grabbed a valid
895address to the layers function, the loader will create a variable of type
896`VkNegotiateLayerInterface` and initialize it in the following ways:
897 1. Set the structure "sType" to "LAYER_NEGOTIATE_INTERFACE_STRUCT"
898 2. Set pNext to NULL.
899 - This is for future growth
900 3. Set "loaderLayerInterfaceVersion" to the current version the loader desires
901to set the interface to.
902 - The minimum value sent by the loader will be 2 since it is the first
903version supporting this function.
Jon Ashburnc2972682016-02-08 15:42:01 -0700904
Mark Young39389872017-01-19 21:10:49 -0700905The loader will then individually call each layer’s
906`vkNegotiateLoaderLayerInterfaceVersion` function with the filled out
907“VkNegotiateLayerInterface”. The layer will either accept the loader's version
908set in "loaderLayerInterfaceVersion", or modify it to the closest value version
909of the interface that the layer can support. The value should not be higher
910than the version requested by the loader. If the layer can't support at a
911minimum the version requested, then the layer should return an error like
912"VK_ERROR_INITIALIZATION_FAILED". If a layer can support some version, then
913the layer should do the following:
914 1. Adjust the version to the layer's desired version.
915 2. The layer should fill in the function pointer values to its internal
916functions:
917 - "pfnGetInstanceProcAddr" should be set to the layer’s internal
918`GetInstanceProcAddr` function.
919 - "pfnGetDeviceProcAddr" should be set to the layer’s internal
920`GetDeviceProcAddr` function.
921 - "pfnGetPhysicalDeviceProcAddr" should be set to the layer’s internal
922`GetPhysicalDeviceProcAddr` function.
923 - If the layer supports no physical device extensions, it may set the
924value to NULL.
925 - More on this function later
926 3. The layer should return "VK_SUCCESS"
Jon Ashburnc2972682016-02-08 15:42:01 -0700927
Mark Young39389872017-01-19 21:10:49 -0700928This function **SHOULD NOT CALL DOWN** the layer chain to the next layer.
929The loader will work with each layer individually.
Jon Ashburnc2972682016-02-08 15:42:01 -0700930
Mark Young39389872017-01-19 21:10:49 -0700931If the layer supports the new interface and reports version 2 or greater, then
932the loader will use the “fpGetInstanceProcAddr” and “fpGetDeviceProcAddr”
933functions from the “VkNegotiateLayerInterface” structure. Prior to these
934changes, the loader would query each of those functions using "GetProcAddress"
935on Windows or "dlsym" on Linux.
Jon Ashburnc2972682016-02-08 15:42:01 -0700936
Jon Ashburnc2972682016-02-08 15:42:01 -0700937
Mark Young39389872017-01-19 21:10:49 -0700938#### Layer Call Chains and Distributed Dispatch
Jon Ashburnc2972682016-02-08 15:42:01 -0700939
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700940There are two key architectural features that drive the loader to layer library
Mark Young39389872017-01-19 21:10:49 -0700941interface:
942 1. Separate and distinct instance and device call chains
943 2. Distributed dispatch.
Jon Ashburnc2972682016-02-08 15:42:01 -0700944
Mark Young39389872017-01-19 21:10:49 -0700945You can read an overview of dispatch tables and call chains above in the
946[Dispatch Tables and Call Chains](#dispatch-tables-and-call-chains) section.
Jon Ashburnc2972682016-02-08 15:42:01 -0700947
Mark Young39389872017-01-19 21:10:49 -0700948What's important to note here is that a layer can intercept Vulkan
949instance functions, device functions or both. For a layer to intercept instance
950functions, it must participate in the instance call chain. For a layer to
951intercept device functions, it must participate in the device call chain.
952
953Remember, a layer does not need to intercept all instance or device functions,
954instead, it can choose to intercept only a subset of those functions.
955
956Normally, when a layer intercepts a given Vulkan function, it will call down the
957instance or device call chain as needed. The loader and all layer libraries that
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700958participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700959from one entity to the next. This group effort for call chain sequencing is
Mark Young39389872017-01-19 21:10:49 -0700960hereinafter referred to as **distributed dispatch**.
Jon Ashburnc2972682016-02-08 15:42:01 -0700961
Mark Young39389872017-01-19 21:10:49 -0700962In distributed dispatch each layer is responsible for properly calling the next
963entity in the call chain. This means that a dispatch mechanism is required for
964all Vulkan functions that a layer intercepts. If a Vulkan function is not
965intercepted by a layer, or if a layer chooses to terminate the function by not
966calling down the chain, then no dispatch is needed for that particular function.
Jeff Julianof1619872016-02-17 17:25:42 -0500967
Mark Young39389872017-01-19 21:10:49 -0700968For example, if the enabled layers intercepted only certain instance functions,
969the call chain would look as follows:
970![Instance Function Chain](./images/function_instance_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700971
Mark Young39389872017-01-19 21:10:49 -0700972Likewise, if the enabled layers intercepted only a few of the device functions,
973the call chain could look this way:
974![Device Function Chain](./images/function_device_chain.png)
Jeff Julianof1619872016-02-17 17:25:42 -0500975
Mark Young39389872017-01-19 21:10:49 -0700976The loader is responsible for dispatching all core and instance extension Vulkan
977functions to the first entity in the call chain.
Chia-I Wucb24fec2016-04-20 06:23:24 +0800978
Chia-I Wucb24fec2016-04-20 06:23:24 +0800979
Mark Young39389872017-01-19 21:10:49 -0700980#### Layer Unknown Physical Device Extensions
981
982Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
983result in the following behavior:
984 1. The loader would check if core function:
985 - If it was, it would return the function pointer
986 2. The loader would check if known extension function:
987 - If it was, it would return the function pointer
988 3. If the loader knew nothing about it, it would call down using
989`GetInstanceProcAddr`
990 - If it returned non-NULL, treat it as an unknown logical device command.
991 - This meant setting up a generic trampoline function that takes in a
992VkDevice as the first parameter and adjusting the dispatch table to call the
993ICD/Layers function after getting the dispatch table from the VkDevice.
994 4. If all the above failed, the loader would return NULL to the application.
995
996This caused problems when a layer attempted to expose new physical device
997extensions the loader knew nothing about, but an application did. Because the
998loader knew nothing about it, the loader would get to step 3 in the above
999process and would treat the function as an unknown logical device command. The
1000problem is, this would create a generic VkDevice trampoline function which, on
1001the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
1002This would lead to a crash or corruption.
1003
1004In order to identify the extension entry-points specific to physical device
1005extensions, the following function can be added to a layer:
1006
1007```cpp
1008PFN_vkVoidFunction vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
1009 const char* pName);
1010```
1011
1012This function behaves similar to `vkGetInstanceProcAddr` and
1013`vkGetDeviceProcAddr` except it should only return values for physical device
1014extension entry-points. In this way, it compares "pName" to every physical
1015device function supported in the layer.
1016
1017The following rules apply:
1018 * If it is the name of a physical device function supported by the layer, the
1019pointer to the layer's corresponding function should be returned.
1020 * If it is the name of a valid function which is **not** a physical device
1021function (i.e. an Instance, Device, or other function implemented by the layer),
1022then the value of NULL should be returned.
1023 * We don’t call down since we know the command is not a physical device
1024extension).
1025 * If the layer has no idea what this function is, it should call down the layer
1026chain to the next `vk_layerGetPhysicalDeviceProcAddr` call.
1027 * This can be retrieved in one of two ways:
1028 * During `vkCreateInstance`, it is passed to a layer in the
1029chain information passed to a layer in the `VkLayerInstanceCreateInfo`
1030structure.
1031 * Use `get_chain_info()` to get the pointer to the
1032`VkLayerInstanceCreateInfo` structure. Let's call it chain_info.
1033 * The address is then under
1034chain_info->u.pLayerInfo->pfnNextGetPhysicalDeviceProcAddr
1035 * See
1036[Example Code for CreateInstance](#example-code-for-createinstance)
1037 * Using the next layer’s `GetInstanceProcAddr` function to query for
1038`vk_layerGetPhysicalDeviceProcAddr`.
1039
1040This support is optional and should not be considered a requirement. This is
1041only required if a layer intends to support some functionality not directly
1042supported by loaders released in the public. If a layer does implent this
1043support, it should return the address of its `vk_layerGetPhysicalDeviceProcAddr`
1044function in the "pfnGetPhysicalDeviceProcAddr" member of the
1045`VkNegotiateLayerInterface` structure during
1046[Layer Version Negotiation](#layer-version-negotiation). Additionally, the
1047layer should also make sure `vkGetInstanceProcAddr` returns a valid function
1048pointer to a query of `vk_layerGetPhysicalDeviceProcAddr`.
1049
1050The new behavior of the loader's `vkGetInstanceProcAddr` with support for the
1051`vk_layerGetPhysicalDeviceProcAddr` function is as follows:
1052 1. Check if core function:
1053 - If it is, return the function pointer
1054 2. Check if known instance or device extension function:
1055 - If it is, return the function pointer
1056 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
1057 - If it returns non-NULL, return a trampoline to a generic physical device
1058function, and setup a generic terminator which will pass it to the proper ICD.
1059 4. Call down using `GetInstanceProcAddr`
1060 - If it returns non-NULL, treat it as an unknown logical device command.
1061This means setting up a generic trampoline function that takes in a VkDevice as
1062the first parameter and adjusting the dispatch table to call the ICD/Layers
1063function after getting the dispatch table from the VkDevice. Then, return the
1064pointer to corresponding trampoline function.
1065 5. Return NULL
1066
1067You can see now, that, if the command gets promoted to core later, it will no
1068longer be setup using `vk_layerGetPhysicalDeviceProcAddr`. Additionally, if the
1069loader adds direct support for the extension, it will no longer get to step 3,
1070because step 2 will return a valid function pointer. However, the layer should
1071continue to support the command query via `vk_layerGetPhysicalDeviceProcAddr`,
1072until at least a Vulkan version bump, because an older loader may still be
1073attempting to use the commands.
1074
1075
1076#### Layer Intercept Requirements
1077
1078 * Layers intercept a Vulkan function by defining a C/C++ function with
1079signature **identical** to the Vulkan API for that function.
1080 * A layer **must intercept at least** `vkGetInstanceProcAddr` and
1081`vkCreateInstance` to participate in the instance call chain.
1082 * A layer **may also intercept** `vkGetDeviceProcAddr` and `vkCreateDevice`
1083to participate in the device call chain.
1084 * For any Vulkan function a layer intercepts which has a non-void return value,
1085**an appropriate value must be returned** by the layer intercept function.
1086 * Most functions a layer intercepts **should call down the chain** to the
1087corresponding Vulkan function in the next entity.
1088 * The common behavior for a layer is to intercept a call, perform some
1089behavior, then pass it down to the next entity.
1090 * If you don't pass the information down, undefined behavior may occur.
1091 * This is because the function will not be received by layers further down
1092the chain, or any ICDs.
1093 * One function that **must never call down the chain** is:
1094 * `vkNegotiateLoaderLayerInterfaceVersion`
1095 * Three common functions that **may not call down the chain** are:
1096 * `vkGetInstanceProcAddr`
1097 * `vkGetDeviceProcAddr`
1098 * `vk_layerGetPhysicalDeviceProcAddr`
1099 * These functions only call down the chain for Vulkan functions that they
1100do not intercept.
1101 * Layer intercept functions **may insert extra calls** to Vulkan functions in
1102addition to the intercept.
1103 * For example, a layer intercepting `vkQueueSubmit` may want to add a call to
1104`vkQueueWaitIdle` after calling down the chain for `vkQueueSubmit`.
1105 * This would result in two calls down the chain: First a call down the
1106`vkQueueSubmit` chain, followed by a call down the `vkQueueWaitIdle` chain.
1107 * Any additional calls inserted by a layer must be on the same chain
1108 * If the function is a device function, only other device functions should
1109be added.
1110 * Likewise, if the function is an instance function, only other instance
1111functions should be added.
1112
1113
1114#### Distributed Dispatching Requirements
1115
1116- For each entry-point a layer intercepts, it must keep track of the entry
1117point residing in the next entity in the chain it will call down into.
1118 * In other words, the layer must have a list of pointers to functions of the
1119appropriate type to call into the next entity.
1120 * This can be implemented in various ways but
1121for clarity, will be referred to as a dispatch table.
1122- A layer can use the `VkLayerDispatchTable` structure as a device dispatch
1123table (see include/vulkan/vk_layer.h).
1124- A layer can use the `VkLayerInstanceDispatchTable` structure as a instance
1125dispatch table (see include/vulkan/vk_layer.h).
1126- A Layer's `vkGetInstanceProcAddr` function uses the next entity's
1127`vkGetInstanceProcAddr` to call down the chain for unknown (i.e.
1128non-intercepted) functions.
1129- A Layer's `vkGetDeviceProcAddr` function uses the next entity's
1130`vkGetDeviceProcAddr` to call down the chain for unknown (i.e. non-intercepted)
1131functions.
1132- A Layer's `vk_layerGetPhysicalDeviceProcAddr` function uses the next entity's
1133`vk_layerGetPhysicalDeviceProcAddr` to call down the chain for unknown (i.e.
1134non-intercepted) functions.
1135
1136
1137#### Layer Conventions and Rules
Chia-I Wucb24fec2016-04-20 06:23:24 +08001138
1139A layer, when inserted into an otherwise compliant Vulkan implementation, must
Mark Young39389872017-01-19 21:10:49 -07001140still result in a compliant Vulkan implementation. The intention is for layers
1141to have a well-defined baseline behavior. Therefore, it must follow some
1142conventions and rules defined below.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001143
1144A layer is always chained with other layers. It must not make invalid calls
Mark Young39389872017-01-19 21:10:49 -07001145to, or rely on undefined behaviors of, its lower layers. When it changes the
1146behavior of a function, it must make sure its upper layers do not make invalid
Chia-I Wucb24fec2016-04-20 06:23:24 +08001147calls to or rely on undefined behaviors of its lower layers because of the
1148changed behavior. For example, when a layer intercepts an object creation
Mark Young39389872017-01-19 21:10:49 -07001149function to wrap the objects created by its lower layers, it must make sure its
Chia-I Wucb24fec2016-04-20 06:23:24 +08001150lower layers never see the wrapping objects, directly from itself or
1151indirectly from its upper layers.
1152
Chia-I Wub5e850e2016-05-06 08:41:52 +08001153When a layer requires host memory, it may ignore the provided allocators. It
1154should use memory allocators if the layer is intended to run in a production
Mark Young39389872017-01-19 21:10:49 -07001155environment. For example, this usually applies to implicit layers that are
1156always enabled. That will allow applications to include the layer's memory
1157usage.
Chia-I Wub5e850e2016-05-06 08:41:52 +08001158
Mark Young39389872017-01-19 21:10:49 -07001159Additional rules include:
1160 - `vkEnumerateInstanceLayerProperties` **must** enumerate and **only**
1161enumerate the layer itself.
1162 - `vkEnumerateInstanceExtensionProperties` **must** handle the case where
1163`pLayerName` is itself.
1164 - It **must** return `VK_ERROR_LAYER_NOT_PRESENT` otherwise, including when
1165`pLayerName` is `NULL`.
1166 - `vkEnumerateDeviceLayerProperties` **is deprecated and may be omitted**.
1167 - Using this will result in undefined behavior.
1168 - `vkEnumerateDeviceExtensionProperties` **must** handle the case where
1169`pLayerName` is itself.
1170 - In other cases, it should normally chain to other layers.
1171 - `vkCreateInstance` **must not** generate an error for unrecognized layer
1172names and extension names.
1173 - It may assume the layer names and extension names have been validated.
1174 - `vkGetInstanceProcAddr` intercepts a Vulkan function by returning a local
1175entry-point
1176 - Otherwise it returns the value obtained by calling down the instance call
1177chain.
1178 - `vkGetDeviceProcAddr` intercepts a Vulkan function by returning a local
1179entry-point
1180 - Otherwise it returns the value obtained by calling down the device call
1181chain.
1182 - These additional functions must be intercepted if the layer implements
1183device-level call chaining:
1184 - `vkGetDeviceProcAddr`
1185 - `vkCreateDevice`(only required for any device-level chaining)
1186 - **NOTE:** older layer libraries may expect that `vkGetInstanceProcAddr`
1187ignore `instance` when `pName` is `vkCreateDevice`.
1188 - The specification **requires** `NULL` to be returned from
1189`vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` for disabled functions.
1190 - A layer may return `NULL` itself or rely on the following layers to do so.
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001191
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001192
Mark Young39389872017-01-19 21:10:49 -07001193#### Layer Dispatch Initialization
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001194
Mark Young39389872017-01-19 21:10:49 -07001195- A layer initializes its instance dispatch table within its `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001196function.
Mark Young39389872017-01-19 21:10:49 -07001197- A layer initializes its device dispatch table within its `vkCreateDevice`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001198function.
1199- The loader passes a linked list of initialization structures to layers via
Mark Young39389872017-01-19 21:10:49 -07001200the "pNext" field in the VkInstanceCreateInfo and `VkDeviceCreateInfo`
1201structures for `vkCreateInstance` and `VkCreateDevice` respectively.
1202- The head node in this linked list is of type `VkLayerInstanceCreateInfo` for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001203instance and VkLayerDeviceCreateInfo for device. See file
Mark Young39389872017-01-19 21:10:49 -07001204`include/vulkan/vk_layer.h` for details.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001205- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1206"sType" field in VkLayerInstanceCreateInfo.
1207- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1208"sType" field in VkLayerDeviceCreateInfo.
1209- The "function" field indicates how the union field "u" should be interpreted
Mark Young39389872017-01-19 21:10:49 -07001210within `VkLayer*CreateInfo`. The loader will set the "function" field to
1211VK_LAYER_LINK_INFO. This indicates "u" field should be `VkLayerInstanceLink` or
1212`VkLayerDeviceLink`.
1213- The `VkLayerInstanceLink` and `VkLayerDeviceLink` structures are the list
1214nodes.
1215- The `VkLayerInstanceLink` contains the next entity's `vkGetInstanceProcAddr`
1216used by a layer.
1217- The `VkLayerDeviceLink` contains the next entity's `vkGetInstanceProcAddr` and
1218`vkGetDeviceProcAddr` used by a layer.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001219- Given the above structures set up by the loader, layer must initialize their
1220dispatch table as follows:
Mark Young39389872017-01-19 21:10:49 -07001221 - Find the `VkLayerInstanceCreateInfo`/`VkLayerDeviceCreateInfo` structure in
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001222the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001223 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Mark Young39389872017-01-19 21:10:49 -07001224 - For CreateInstance get the next entity's `vkCreateInstance` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001225"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001226 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Mark Young39389872017-01-19 21:10:49 -07001227 - For CreateDevice get the next entity's `vkCreateDevice` by calling the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001228"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001229 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001230 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
Mark Young39389872017-01-19 21:10:49 -07001231 - Call down the chain either `vkCreateDevice` or `vkCreateInstance`
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001232 - Initialize your layer dispatch table by calling the next entity's
Mark Young39389872017-01-19 21:10:49 -07001233Get*ProcAddr function once for each Vulkan function needed in your dispatch
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001234table
Jon Ashburncc300a22016-02-11 14:57:30 -07001235
Mark Young39389872017-01-19 21:10:49 -07001236#### Example Code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001237
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001238```cpp
1239VkResult vkCreateInstance(
1240 const VkInstanceCreateInfo *pCreateInfo,
1241 const VkAllocationCallbacks *pAllocator,
1242 VkInstance *pInstance)
1243{
1244 VkLayerInstanceCreateInfo *chain_info =
1245 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1246
1247 assert(chain_info->u.pLayerInfo);
1248 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1249 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1250 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001251 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001252 if (fpCreateInstance == NULL) {
1253 return VK_ERROR_INITIALIZATION_FAILED;
1254 }
1255
1256 // Advance the link info for the next element of the chain
1257 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1258
1259 // Continue call down the chain
1260 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1261 if (result != VK_SUCCESS)
1262 return result;
1263
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001264 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001265 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001266 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001267 layer_init_instance_dispatch_table(
1268 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1269
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001270 // Other layer initialization
1271 ...
1272
1273 return VK_SUCCESS;
1274}
1275```
1276
Mark Young39389872017-01-19 21:10:49 -07001277#### Example Code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001278
1279```cpp
1280VkResult
1281vkCreateDevice(
1282 VkPhysicalDevice gpu,
1283 const VkDeviceCreateInfo *pCreateInfo,
1284 const VkAllocationCallbacks *pAllocator,
1285 VkDevice *pDevice)
1286{
1287 VkLayerDeviceCreateInfo *chain_info =
1288 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1289
1290 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1291 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1292 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1293 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1294 PFN_vkCreateDevice fpCreateDevice =
1295 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1296 if (fpCreateDevice == NULL) {
1297 return VK_ERROR_INITIALIZATION_FAILED;
1298 }
1299
1300 // Advance the link info for the next element on the chain
1301 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1302
1303 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1304 if (result != VK_SUCCESS) {
1305 return result;
1306 }
1307
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001308 // initialize layer's dispatch table
1309 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001310 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001311 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001312
1313 // Other layer initialization
1314 ...
1315
1316 return VK_SUCCESS;
1317}
1318```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001319
Mark Young39389872017-01-19 21:10:49 -07001320
Jon Ashburncc300a22016-02-11 14:57:30 -07001321#### Special Considerations
Mark Young39389872017-01-19 21:10:49 -07001322
1323
1324##### Associating Private Data with Vulkan Objects Within a Layer
1325
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001326A layer may want to associate it's own private data with one or more Vulkan
Mark Youngf7914cf2016-08-31 11:53:26 -06001327objects. Two common methods to do this are hash maps and object wrapping.
1328
Mark Youngf7914cf2016-08-31 11:53:26 -06001329
Mark Young39389872017-01-19 21:10:49 -07001330###### Wrapping
Ian Elliott0b082e42016-08-31 14:08:44 -06001331
Mark Young39389872017-01-19 21:10:49 -07001332The loader supports layers wrapping any Vulkan object, including dispatchable
1333objects. For functions that return object handles, each layer does not touch
1334the value passed down the call chain. This is because lower items may need to
1335use the original value. However, when the value is returned from a
1336lower-level layer (possibly the ICD), the layer saves the handle and returns
1337its own handle to the layer above it (possibly the application). When a layer
1338receives a Vulkan function using something that it previously returned a handle
1339for, the layer is required to unwrap the handle and pass along the saved handle
1340to the layer below it. This means that the layer **must intercept every Vulkan
1341function which uses the object in question**, and wrap or unwrap the object, as
1342appropriate. This includes adding support for all extensions with functions
Ian Elliott0b082e42016-08-31 14:08:44 -06001343using any object the layer wraps.
Mark Youngf7914cf2016-08-31 11:53:26 -06001344
1345Layers above the object wrapping layer will see the wrapped object. Layers
1346which wrap dispatchable objects must ensure that the first field in the wrapping
Mark Young39389872017-01-19 21:10:49 -07001347structure is a pointer to a dispatch table as defined in `vk_layer.h`.
1348Specifically, an instance wrapped dispatchable object could be as follows:
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001349```
1350struct my_wrapped_instance_obj_ {
1351 VkLayerInstanceDispatchTable *disp;
1352 // whatever data layer wants to add to this object
1353};
1354```
1355A device wrapped dispatchable object could be as follows:
1356```
1357struct my_wrapped_instance_obj_ {
1358 VkLayerDispatchTable *disp;
1359 // whatever data layer wants to add to this object
1360};
1361```
Jeff Julianof1619872016-02-17 17:25:42 -05001362
Ian Elliott0b082e42016-08-31 14:08:44 -06001363Layers that wrap dispatchable objects must follow the guidelines for creating
1364new dispatchable objects (below).
1365
Mark Young39389872017-01-19 21:10:49 -07001366<u>Cautions About Wrapping</u>
Ian Elliott0b082e42016-08-31 14:08:44 -06001367
1368Layers are generally discouraged from wrapping objects, because of the
1369potential for incompatibilities with new extensions. For example, let's say
Mark Young39389872017-01-19 21:10:49 -07001370that a layer wraps `VkImage` objects, and properly wraps and unwraps `VkImage`
1371object handles for all core functions. If a new extension is created which has
1372functions that take `VkImage` objects as parameters, and if the layer does not
1373support those new functions, an application that uses both the layer and the new
1374extension will have undefined behavior when those new functions are called (e.g.
Ian Elliott0b082e42016-08-31 14:08:44 -06001375the application may crash). This is becaues the lower-level layers and ICD
1376won't receive the handle that they generated. Instead, they will receive a
1377handle that is only known by the layer that is wrapping the object.
1378
1379Because of the potential for incompatibilities with unsupported extensions,
1380layers that wrap objects must check which extensions are being used by the
1381application, and take appropriate action if the layer is used with unsupported
1382extensions (e.g. disable layer functionality, stop wrapping objects, issue a
1383message to the user).
1384
1385The reason that the validation layers wrap objects, is to track the proper use
1386and destruction of each object. They issue a validation error if used with
1387unsupported extensions, alerting the user to the potential for undefined
1388behavior.
1389
Mark Young39389872017-01-19 21:10:49 -07001390
1391###### Hash Maps
1392
Jeff Julianof1619872016-02-17 17:25:42 -05001393Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001394given object. The key to the map could be the object. Alternatively, for
1395dispatchable objects at a given level (eg device or instance) the layer may
Mark Young39389872017-01-19 21:10:49 -07001396want data associated with the `VkDevice` or `VkInstance` objects. Since
1397there are multiple dispatchable objects for a given `VkInstance` or `VkDevice`,
1398the `VkDevice` or `VkInstance` object is not a great map key. Instead the layer
1399should use the dispatch table pointer within the `VkDevice` or `VkInstance`
1400since that will be unique for a given `VkInstance` or `VkDevice`.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001401
Mark Young39389872017-01-19 21:10:49 -07001402
1403##### Creating New Dispatchable Objects
1404
1405Layers which create dispatchable objects must take special care. Remember that
1406loader *trampoline* code normally fills in the dispatch table pointer in the
1407newly created object. Thus, the layer must fill in the dispatch table pointer if
1408the loader *trampoline* will not do so. Common cases where a layer (or ICD) may
1409create a dispatchable object without loader *trampoline* code is as follows:
1410- layers that wrap dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001411- layers which add extensions that create dispatchable objects
Mark Young39389872017-01-19 21:10:49 -07001412- layers which insert extra Vulkan funnctions in the stream of functions they
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001413intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001414- ICDs which add extensions that create dispatchable objects
1415
Mark Young39389872017-01-19 21:10:49 -07001416The desktop loader provides a callback that can be used for initializing
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001417a dispatchable object. The callback is passed as an extension structure via the
Mark Young39389872017-01-19 21:10:49 -07001418pNext field in the create info structure when creating an instance
1419(`VkInstanceCreateInfo`) or device (`VkDeviceCreateInfo`). The callback
1420prototype is defined as follows for instance and device callbacks respectively
1421(see `vk_layer.h`):
1422
1423```cpp
1424VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance,
1425 void *object);
1426VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData(VkDevice device,
1427 void *object);
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001428```
Mark Young39389872017-01-19 21:10:49 -07001429
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001430To obtain these callbacks the layer must search through the list of structures
Mark Young39389872017-01-19 21:10:49 -07001431pointed to by the "pNext" field in the `VkInstanceCreateInfo` and
1432`VkDeviceCreateInfo` parameters to find any callback structures inserted by the
1433loader. The salient details are as follows:
1434- For `VkInstanceCreateInfo` the callback structure pointed to by "pNext" is
1435`VkLayerInstanceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1436- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within
1437`VkInstanceCreateInfo` parameter indicates a loader structure.
1438- Within `VkLayerInstanceCreateInfo`, the "function" field indicates how the
1439union field "u" should be interpreted.
1440- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1441contain the callback in "pfnSetInstanceLoaderData".
1442- For `VkDeviceCreateInfo` the callback structure pointed to by "pNext" is
1443`VkLayerDeviceCreateInfo` as defined in `include/vulkan/vk_layer.h`.
1444- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within
1445`VkDeviceCreateInfo` parameter indicates a loader structure.
1446- Within `VkLayerDeviceCreateInfo`, the "function" field indicates how the union
1447field "u" should be interpreted.
1448- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will
1449contain the callback in "pfnSetDeviceLoaderData".
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001450
Mark Young39389872017-01-19 21:10:49 -07001451Alternatively, if an older loader is being used that doesn't provide these
1452callbacks, the layer may manually initialize the newly created dispatchable
1453object. To fill in the dispatch table pointer in newly created dispatchable
1454object, the layer should copy the dispatch pointer, which is always the first
1455entry in the structure, from an existing parent object of the same level
1456(instance versus device).
Jon Ashburnc2972682016-02-08 15:42:01 -07001457
Mark Young39389872017-01-19 21:10:49 -07001458For example, if there is a newly created `VkCommandBuffer` object, then the
1459dispatch pointer from the `VkDevice` object, which is the parent of the
1460`VkCommandBuffer` object, should be copied into the newly created object.
1461
1462
1463#### Layer Manifest File Format
1464
1465On Windows and Linux (desktop), the loader uses manifest files to discover
1466layer libraries and layers. The desktop loader doesn't directly query the
1467layer library except during chaining. This is to reduce the likelihood of
1468loading a malicious layer into memory. Instead, details are read from the
1469Manifest file, which are then provided for applications to determine what
1470layers should actually be loaded.
1471
1472The following section discusses the details of the Layer Manifest JSON file
1473format. The JSON file itself does not have any requirements for naming. The
1474only requirement is that the extension suffix of the file ends with ".json".
1475
1476Here is an example layer JSON Manifest file with a single layer:
1477
1478```
1479{
1480 "file_format_version" : "1.0.0",
1481 "layer": {
1482 "name": "VK_LAYER_LUNARG_overlay",
1483 "type": "INSTANCE",
1484 "library_path": "vkOverlayLayer.dll"
1485 "api_version" : "1.0.5",
1486 "implementation_version" : "2",
1487 "description" : "LunarG HUD layer",
1488 "functions": {
1489 "vkNegotiateLoaderLayerInterfaceVersion":
1490 "OverlayLayer_NegotiateLoaderLayerInterfaceVersion"
1491 },
1492 "instance_extensions": [
1493 {
1494 "name": "VK_EXT_debug_report",
1495 "spec_version": "1"
1496 },
1497 {
1498 "name": "VK_VENDOR_ext_x",
1499 "spec_version": "3"
1500 }
1501 ],
1502 "device_extensions": [
1503 {
1504 "name": "VK_EXT_debug_marker",
1505 "spec_version": "1",
1506 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1507 }
1508 ],
1509 "enable_environment": {
1510 "ENABLE_LAYER_OVERLAY_1": "1"
1511 }
1512 "disable_environment": {
1513 "DISABLE_LAYER_OVERLAY_1": ""
1514 }
1515 }
1516}
1517```
1518
1519Here's a snippet with the changes required to support multiple layers per
1520manifest file:
1521```
1522{
1523 "file_format_version" : "1.0.1",
1524 "layers": [
1525 {
1526 "name": "VK_LAYER_layer_name1",
1527 "type": "INSTANCE",
1528 ...
1529 },
1530 {
1531 "name": "VK_LAYER_layer_name2",
1532 "type": "INSTANCE",
1533 ...
1534 }
1535 ]
1536}
1537```
1538
1539| JSON Node | Description and Notes | Introspection Query |
1540|:----------------:|--------------------|:----------------:
1541| "file\_format\_version" | Manifest format major.minor.patch version number. | N/A |
1542| | Supported versions are: 1.0.0, 1.0.1, and 1.1.0. | |
1543| "layer" | The identifier used to group a single layer's information together. | vkEnumerateInstanceLayerProperties |
1544| "layers" | The identifier used to group multiple layers' information together. This requires a minimum Manifest file format version of 1.0.1.| vkEnumerateInstanceLayerProperties |
1545| "name" | The string used to uniquely identify this layer to applications. | vkEnumerateInstanceLayerProperties |
1546| "type" | This field indicates the type of layer. The values can be: GLOBAL, or INSTANCE | vkEnumerate*LayerProperties |
1547| | **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. | |
1548| "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 |
1549| "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 |
1550| "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 |
1551| "description" | A high-level description of the layer and it's intended use. | vkEnumerateInstanceLayerProperties |
1552| "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 |
1553| "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 |
1554| "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 |
1555| "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 |
1556| "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 |
1557
1558
1559##### Layer Manifest File Version History
1560
1561The current highest supported Layer Manifest file format supported is 1.1.0.
1562Information about each version is detailed in the following sub-sections:
1563
1564###### Layer Manifest File Version 1.1.0
1565
1566Layer Manifest File Version 1.1.0 is tied to changes exposed by the Loader/Layer
1567interface version 2.
1568 1. Renaming "vkGetInstanceProcAddr" in the "functions" section is
1569 deprecated since the loader no longer needs to query the layer about
1570 "vkGetInstanceProcAddr" directly. It is now returned during the layer
1571 negotiation, so this field will be ignored.
1572 2. Renaming "vkGetDeviceProcAddr" in the "functions" section is
1573 deprecated since the loader no longer needs to query the layer about
1574 "vkGetDeviceProcAddr" directly. It too is now returned during the layer
1575 negotiation, so this field will be ignored.
1576 3. Renaming the "vkNegotiateLoaderLayerInterfaceVersion" function is
1577 being added to the "functions" section, since this is now the only
1578 function the loader needs to query using OS-specific calls.
1579 - NOTE: This is an optional field and, as the two previous fields, only
1580needed if the layer requires changing the name of the function for some reason.
1581
1582You do not need to update your layer manifest file if you don't change the
1583names of any of the listed functions.
1584
1585###### Layer Manifest File Version 1.0.1
1586
1587The ability to define multiple layers using the "layers" array was added. This
1588JSON array field can be used when defining a single layer or multiple layers.
1589The "layer" field is still present and valid for a single layer definition.
1590
1591###### Layer Manifest File Version 1.0.0
1592
1593The initial version of the layer manifest file specified the basic format and
1594fields of a layer JSON file. The fields of the 1.0.0 file format include:
1595 * "file\_format\_version"
1596 * "layer"
1597 * "name"
1598 * "type"
1599 * "library\_path"
1600 * "api\_version"
1601 * "implementation\_version"
1602 * "description"
1603 * "functions"
1604 * "instance\_extensions"
1605 * "device\_extensions"
1606 * "enable\_environment"
1607 * "disable\_environment"
1608
1609It was also during this time that the value of "DEVICE" was deprecated from
1610the "type" field.
1611
1612
1613#### Layer Library Versions
1614
1615The current Layer Library interface is at version 2. The following sections
1616detail the differences between the various versions.
1617
1618##### Layer Library API Version 2
1619
1620Introduced the concept of
1621[loader and layer interface](#layer-version-negotiation) using the new
1622`vkNegotiateLoaderLayerInterfaceVersion` function. Additionally, it introduced
1623the concept of
1624[Layer Unknown Physical Device Extensions](#layer-unknown-physical-device-
1625extensions)
1626and the associated `vk_layerGetPhysicalDeviceProcAddr` function. Finally, it
1627changed the manifest file defition to 1.1.0.
1628
1629##### Layer Library API Version 1
1630
1631A layer library supporting interface version 1 had the following behavior:
1632 1. `GetInstanceProcAddr` and `GetDeviceProcAddr` were directly exported
1633 2. The layer manifest file was able to override the names of the
1634`GetInstanceProcAddr` and `GetDeviceProcAddr`functions.
1635
1636##### Layer Library API Version 0
1637
1638A layer library supporting interface version 0 must define and export these
1639introspection functions, unrelated to any Vulkan function despite the names,
1640signatures, and other similarities:
1641
1642 - `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
1643library.
1644 - This function never fails.
1645 - When a layer library contains only one layer, this function may be an alias
1646 to the layer's `vkEnumerateInstanceLayerProperties`.
1647 - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
1648 layers in a layer library.
1649 - "pLayerName" is always a valid layer name.
1650 - This function never fails.
1651 - When a layer library contains only one layer, this function may be an alias
1652 to the layer's `vkEnumerateInstanceExtensionProperties`.
1653 - `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
1654 proper, or empty subset) of layers in a layer library.
1655 - "physicalDevice" is always `VK_NULL_HANDLE`.
1656 - This function never fails.
1657 - If a layer is not enumerated by this function, it will not participate in
1658 device function interception.
1659 - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
1660 layers in a layer library.
1661 - "physicalDevice" is always `VK_NULL_HANDLE`.
1662 - "pLayerName" is always a valid layer name.
1663 - This function never fails.
1664
1665It must also define and export these functions once for each layer in the
1666library:
1667
1668 - `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a
1669layer's vkGetInstanceProcAddr except it is exported.
1670
1671 When a layer library contains only one layer, this function may
1672 alternatively be named `vkGetInstanceProcAddr`.
1673
1674 - `<layerName>GetDeviceProcAddr` behaves identically to a layer's
1675vkGetDeviceProcAddr except it is exported.
1676
1677 When a layer library contains only one layer, this function may
1678 alternatively be named `vkGetDeviceProcAddr`.
1679
1680All layers contained within a library must support `vk_layer.h`. They do not
1681need to implement functions that they do not intercept. They are recommended
1682not to export any functions.
1683
1684
1685<br/>
1686<br/>
1687
1688## Vulkan Installable Client Driver Interface With the Loader
1689
1690This section discusses the various requirements for the loader and a Vulkan
1691ICD to properly hand-shake.
1692
1693 * [ICD Discovery](#icd-discovery)
1694 * [ICD Manifest File Usage](#icd-manifest-file-usage)
1695 * [ICD Discovery on Windows](#icd-discovery-on-windows)
1696 * [ICD Discovery on Linux](#icd-discovery-on-linux)
1697 * [Using Pre-Production ICDs on Windows and Linux](#using-pre-production-icds-on-windows-and-linux)
1698 * [ICD Discovery on Android](#icd-discovery-on-android)
1699 * [ICD Manifest File Format](#icd-manifest-file-format)
1700 * [ICD Manifest File Versions](#icd-manifest-file-versions)
1701 * [ICD Manifest File Version 1.0.0](#icd-manifest-file-version-1.0.0)
1702 * [ICD Vulkan Entry-Point Discovery](#icd-vulkan-entry-point-discovery)
1703 * [ICD Unknown Physical Device Extensions](#icd-unknown-physical-device-extensions)
1704 * [ICD Dispatchable Object Creation](#icd-dispatchable-object-creation)
1705 * [Handling KHR Surface Objects in WSI Extensions](#handling-khr-surface-objects-in-wsi-extensions)
1706 * [Loader and ICD Interface Negotiation](#loader-and-icd-interface-negotiation)
1707 * [Windows and Linux ICD Negotiation](#windows-and-linux-icd-negotiation)
1708 * [Version Negotiation Between Loader and ICDs](#version-negotiation-between-loader-and-icds)
1709 * [Interfacing With Legacy ICDs or Loader](#interfacing-with-legacy-icds-or-loader]
1710 * [Loader Version 4 Interface Requirements](#loader-version-4-interface-requirements)
1711 * [Loader Version 3 Interface Requirements](#loader-version-3-interface-requirements)
1712 * [Loader Version 2 Interface Requirements](#loader-version-2-interface-requirements)
1713 * [Loader Versions 0 and 1 Interface Requirements](#loader-versions-0-and-1-interface-requirements)
1714 * [Android ICD Negotiation](#android-icd-negotiation)
1715
1716
1717### ICD Discovery
1718
1719Vulkan allows multiple drivers each with one or more devices (represented by a
1720Vulkan `VkPhysicalDevice` object) to be used collectively. The loader is
1721responsible for discovering available Vulkan ICDs on the system. Given a list
1722of available ICDs, the loader can enumerate all the physical devices available
1723for an application and return this information to the application. The process
1724in which the loader discovers the available Installable Client Drivers (ICDs)
1725on a system is platform dependent. Windows, Linux and Android ICD discovery
1726details are listed below.
1727
1728#### ICD Manifest File Usage
1729
1730As with layers, on Windows and Linux systems, JSON formated manifest files are
1731used to store ICD information. In order to find system-installed drivers, the
1732Vulkan loader will read the JSON files to identify the names and attributes of
1733each driver. One thing you will notice is that ICD Manifest files are much
1734simpler than the corresponding layer Manifest files.
1735
1736See the [Current ICD Manifest File Format](#icd-manifest-file-format) section
1737for more details.
1738
1739
1740#### ICD Discovery on Windows
1741
1742In order to find installed ICDs, the Vulkan loader will scan the
1743values in the following Windows registry key:
1744
1745```
1746 HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers
1747```
1748
1749For 32-bit applications on 64-bit Windows, the loader scan's the 32-bit
1750registry location:
1751
1752```
1753 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\Drivers
1754```
1755
1756The loader will look at the appropriate registry location and check each value
1757listed. If the key is of type DWORD, and it has a value of 0, the loader will
1758open the JSON manifest file specified by the name. Each name must be a full
1759pathname to a text manifest file. The Vulkan loader will attempt to open each
1760manifest file to obtain the information about an ICD's shared library (".dll")
1761file.
1762
1763For example, let us assume the registry contains the following data:
1764
1765```
1766[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
1767
1768"C:\vendor a\vk_vendora.json"=dword:00000000
1769"C:\windows\system32\vendorb_vk.json"=dword:00000001
1770"C:\windows\system32\vendorc_icd.json"=dword:00000000
1771```
1772
1773In this case, the loader will step through each entry, and check the value. If
1774the value is 0, then the loader will attempt to load the file. In this case,
1775the loader will will open the first and last listings, but not the middle. This
1776is because the value of 1 for vendorb_vk.json disables the driver.
1777
1778The Vulkan loader will open each enabled manifest file found to obtain the name
1779or pathname of an ICD shared library (".DLL") file.
1780
1781See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
1782details.
1783
1784
1785#### ICD Discovery on Linux
1786
1787In order to find installed ICDs, the Vulkan loader will scan the files
1788in the following Linux directories:
1789
1790```
1791 /usr/local/etc/vulkan/icd.d
1792 /usr/local/share/vulkan/icd.d
1793 /etc/vulkan/icd.d
1794 /usr/share/vulkan/icd.d
1795 $HOME/.local/share/vulkan/icd.d
1796```
1797
1798The "/usr/local/*" directories can be configured to be other directories at
1799build time.
1800
1801The typical usage of the directories is indicated in the table below.
1802
1803| Location | Details |
1804|-------------------|------------------------|
1805| $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 |
1806| "/usr/local/etc/vulkan/icd.d" | Directory for locally built ICDs |
1807| "/usr/local/share/vulkan/icd.d" | Directory for locally built ICDs |
1808| "/etc/vulkan/icd.d" | Location of ICDs installed from non-Linux-distribution-provided packages |
1809| "/usr/share/vulkan/icd.d" | Location of ICDs installed from Linux-distribution-provided packages |
1810
1811The Vulkan loader will open each manifest file found to obtain the name or
1812pathname of an ICD shared library (".so") file.
1813
1814See the [ICD Manifest File Format](#icd-manifest-file-format) section for more
1815details.
1816
1817#### Using Pre-Production ICDs on Windows and Linux
1818
1819Independent Hardware Vendor (IHV) pre-production ICDs. In some cases, a
1820pre-production ICD may be in an installable package. In other cases, a
1821pre-production ICD may simply be a shared library in the developer's build tree.
1822In this latter case, we want to allow developers to point to such an ICD without
1823modifying the system-installed ICD(s) on their system.
1824
1825This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
1826which will override the mechanism used for finding system-installed ICDs. In
1827other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
1828
1829The "VK\_ICD\_FILENAMES" environment variable is a list of ICD
1830manifest files, containing the full path to the ICD JSON Manifest file. This
1831list is colon-separated on Linux, and semi-colon separated on Windows.
1832
1833Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
1834file for a developer-built ICD. A separator (colon or semi-colon) is only used
1835if more than one ICD is listed.
1836
1837**NOTE:** On Linux, this environment variable will be ignored for suid programs.
1838
1839
1840#### ICD Discovery on Android
1841
1842The Android loader lives in the system library folder. The location cannot be
1843changed. The loader will load the driver/ICD via hw\_get\_module with the ID
1844of "vulkan". **Due to security policies in Android, none of this can be modified
1845under normal use.**
1846
1847
1848### ICD Manifest File Format
1849
1850The following section discusses the details of the ICD Manifest JSON file
1851format. The JSON file itself does not have any requirements for naming. The
1852only requirement is that the extension suffix of the file ends with ".json".
1853
1854Here is an example layer JSON Manifest file:
1855
1856```
1857{
1858 "file_format_version": "1.0.0",
1859 "ICD": {
1860 "library_path": "path to ICD library",
1861 "api_version": "1.0.5"
1862 }
1863}
1864```
1865
1866| Field Name | Field Value |
1867|----------------|--------------------|
1868| "file\_format\_version" | The JSON format major.minor.patch version number of this file. Currently supported version is 1.0.0. |
1869| "ICD" | The identifier used to group all ICD information together. |
1870| "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 |
1871| "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. |
1872
1873**NOTE:** If the same ICD shared library supports multiple, incompatible
1874versions of text manifest file format versions, it must have separate
1875JSON files for each (all of which may point to the same shared library).
1876
1877##### ICD Manifest File Versions
1878
1879There has only been one version of the ICD manifest files supported. This is
1880version 1.0.0.
1881
1882###### ICD Manifest File Version 1.0.0
1883
1884The initial version of the ICD Manifest file specified the basic format and
1885fields of a layer JSON file. The fields of the 1.0.0 file format include:
1886 * "file\_format\_version"
1887 * "ICD"
1888 * "library\_path"
1889 * "api\_version"
1890
1891
1892### ICD Vulkan Entry-Point Discovery
1893
1894The Vulkan symbols exported by an ICD must not clash with the loader's exported
1895Vulkan symbols. This could be for several reasons. Because of this, all ICDs
1896must export the following function that is used for discovery of ICD Vulkan
1897entry-points. This entry-point is not a part of the Vulkan API itself, only a
1898private interface between the loader and ICDs for version 1 and higher
1899interfaces.
1900
1901```cpp
1902VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
1903 VkInstance instance,
1904 const char* pName);
1905```
1906
1907This function has very similar semantics to `vkGetInstanceProcAddr`.
1908`vk_icdGetInstanceProcAddr` returns valid function pointers for all the global-
1909level and instance-level Vulkan functions, and also for `vkGetDeviceProcAddr`.
1910Global-level functions are those which contain no dispatchable object as the
1911first parameter, such as `vkCreateInstance` and
1912`vkEnumerateInstanceExtensionProperties`. The ICD must support querying global-
1913level entry-points by calling `vk_icdGetInstanceProcAddr` with a NULL
1914`VkInstance` parameter. Instance-level functions are those that have either
1915`VkInstance`, or `VkPhysicalDevice` as the first parameter dispatchable object.
1916Both core entry-points and any instance extension entry-points the ICD supports
1917should be available via `vk_icdGetInstanceProcAddr`. Future Vulkan instance
1918extensions may define and use new instance-level dispatchable objects other
1919than `VkInstance` and `VkPhysicalDevice`, in which case extension entry-points
1920using these newly defined dispatchable objects must be queryable via
1921`vk_icdGetInstanceProcAddr`.
1922
1923All other Vulkan entry-points must either:
1924 * NOT be exported directly from the ICD library
1925 * or NOT use the official Vulkan function names if they are exported
1926
1927This requirement is for ICD libraries that include other
1928functionality (such as OpenGL) and thus could be loaded by the
1929application prior to when the Vulkan loader library is loaded by the
1930application.
1931
1932Beware of interposing by dynamic OS library loaders if the official Vulkan
1933names are used. On Linux, if official names are used, the ICD library must be
1934linked with -Bsymbolic.
1935
1936
1937### ICD Unknown Physical Device Extensions
1938
1939Originally, if the loader was called with `vkGetInstanceProcAddr`, it would
1940result in the following behavior:
1941 1. The loader would check if core function:
1942 - If it was, it would return the function pointer
1943 2. The loader would check if known extension function:
1944 - If it was, it would return the function pointer
1945 3. If the loader knew nothing about it, it would call down using
1946`GetInstanceProcAddr`
1947 - If it returned non-NULL, treat it as an unknown logical device command.
1948 - This meant setting up a generic trampoline function that takes in a
1949VkDevice as the first parameter and adjusting the dispatch table to call the
1950ICD/Layers function after getting the dispatch table from the VkDevice.
1951 4. If all the above failed, the loader would return NULL to the application.
1952
1953This caused problems when an ICD attempted to expose new physical device
1954extensions the loader knew nothing about, but an application did. Because the
1955loader knew nothing about it, the loader would get to step 3 in the above
1956process and would treat the function as an unknown logical device command. The
1957problem is, this would create a generic VkDevice trampoline function which, on
1958the first call, would attempt to dereference the VkPhysicalDevice as a VkDevice.
1959This would lead to a crash or corruption.
1960
1961In order to identify the extension entry-points specific to physical device
1962extensions, the following function can be added to an ICD:
1963
1964```cpp
1965PFN_vkVoidFunction vk_icdGetPhysicalDeviceProcAddr(VkInstance instance,
1966 const char* pName);
1967```
1968
1969This function behaves similar to `vkGetInstanceProcAddr` and
1970`vkGetDeviceProcAddr` except it should only return values for physical device
1971extension entry-points. In this way, it compares "pName" to every physical
1972device function supported in the ICD.
1973
1974The following rules apply:
1975 * If it is the name of a physical device function supported by the ICD, the
1976pointer to the ICD's corresponding function should be returned.
1977 * If it is the name of a valid function which is **not** a physical device
1978function (i.e. an Instance, Device, or other function implemented by the ICD),
1979then the value of NULL should be returned.
1980 * If the ICD has no idea what this function is, it should return NULL.
1981
1982This support is optional and should not be considered a requirement. This is
1983only required if an ICD intends to support some functionality not directly
1984supported by a significant population of loaders in the public. If an ICD
1985does implent this support, it should return the address of its
1986`vk_icdGetPhysicalDeviceProcAddr` function through the `vkGetInstanceProcAddr`
1987function.
1988
1989The new behavior of the loader's vkGetInstanceProcAddr with support for the
1990`vk_icdGetPhysicalDeviceProcAddr` function is as follows:
1991 1. Check if core function:
1992 - If it is, return the function pointer
1993 2. Check if known instance or device extension function:
1994 - If it is, return the function pointer
1995 3. Call the layer/ICD `GetPhysicalDeviceProcAddr`
1996 - If it returns non-NULL, return a trampoline to a generic physical device
1997function, and setup a generic terminator which will pass it to the proper ICD.
1998 4. Call down using `GetInstanceProcAddr`
1999 - If it returns non-NULL, treat it as an unknown logical device command.
2000This means setting up a generic trampoline function that takes in a VkDevice as
2001the first parameter and adjusting the dispatch table to call the ICD/Layers
2002function after getting the dispatch table from the VkDevice. Then, return the
2003pointer to corresponding trampoline function.
2004 5. Return NULL
2005
2006You can see now, that, if the command gets promoted to core later, it will no
2007longer be setup using `vk_icdGetPhysicalDeviceProcAddr`. Additionally, if the
2008loader adds direct support for the extension, it will no longer get to step 3,
2009because step 2 will return a valid function pointer. However, the ICD should
2010continue to support the command query via `vk_icdGetPhysicalDeviceProcAddr`,
2011until at least a Vulkan version bump, because an older loader may still be
2012attempting to use the commands.
2013
2014
2015### ICD Dispatchable Object Creation
2016
2017As previously covered, the loader requires dispatch tables to be accessible
2018within Vulkan dispatchable objects, such as: `VkInstance`, `VkPhysicalDevice`,
2019`VkDevice`, `VkQueue`, and `VkCommandBuffer`. The specific requirements on all
2020dispatchable objects created by ICDs are as follows:
2021
2022- All dispatchable objects created by an ICD can be cast to void \*\*
2023- The loader will replace the first entry with a pointer to the dispatch table
2024 which is owned by the loader. This implies three things for ICD drivers
2025 1. The ICD must return a pointer for the opaque dispatchable object handle
2026 2. This pointer points to a regular C structure with the first entry being a
2027 pointer.
2028 * **NOTE:** For any C\++ ICD's that implement VK objects directly as C\++
2029classes.
2030 * The C\++ compiler may put a vtable at offset zero if your class is non-
2031POD due to the use of a virtual function.
2032 * In this case use a regular C structure (see below).
2033 3. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
2034 dispatchable objects, as follows (see `include/vulkan/vk_icd.h`):
2035
2036```cpp
2037#include "vk_icd.h"
2038
2039union _VK_LOADER_DATA {
2040 uintptr loadermagic;
2041 void *loaderData;
2042} VK_LOADER_DATA;
2043
2044vkObj alloc_icd_obj()
2045{
2046 vkObj *newObj = alloc_obj();
2047 ...
2048 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
2049
2050 set_loader_magic_value(newObj);
2051 ...
2052 return newObj;
2053}
2054```
2055
2056
2057### Handling KHR Surface Objects in WSI Extensions
2058
2059Normally, ICDs handle object creation and destruction for various Vulkan
2060objects. The WSI surface extensions for Linux and Windows
2061("VK\_KHR\_win32\_surface", "VK\_KHR\_xcb\_surface", "VK\_KHR\_xlib\_surface",
2062"VK\_KHR\_mir\_surface", "VK\_KHR\_wayland\_surface", and "VK\_KHR\_surface")
2063are handled differently. For these extensions, the `VkSurfaceKHR` object
2064creation and destruction may be handled by either the loader, or an ICD.
2065
2066If the loader handles the management of the `VkSurfaceKHR` objects:
2067 1. The loader will handle the calls to `vkCreateXXXSurfaceKHR` and
2068`vkDestroySurfaceKHR`
2069 functions without involving the ICDs.
2070 * Where XXX stands for the Windowing System name:
2071 * Mir
2072 * Wayland
2073 * Xcb
2074 * Xlib
2075 * Windows
2076 * Android
2077 2. The loader creates a `VkIcdSurfaceXXX` object for the corresponding
2078`vkCreateXXXSurfaceKHR` call.
2079 * The `VkIcdSurfaceXXX` structures are defined in `include/vulkan/vk_icd.h`.
2080 3. ICDs can cast any `VkSurfaceKHR` object to a pointer to the appropriate
2081 `VkIcdSurfaceXXX` structure.
2082 4. The first field of all the `VkIcdSurfaceXXX` structures is a
2083`VkIcdSurfaceBase` enumerant that indicates whether the
2084 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
2085
2086The ICD may choose to handle `VkSurfaceKHR` object creation instead. If an ICD
2087desires to handle creating and destroying it must do the following:
2088 1. Support version 3 or newer of the loader/ICD interface.
2089 2. Export and handle all functions that take in a `VkSurfaceKHR` object,
2090including:
2091 * `vkCreateXXXSurfaceKHR`
2092 * `vkGetPhysicalDeviceSurfaceSupportKHR`
2093 * `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2094 * `vkGetPhysicalDeviceSurfaceFormatsKHR`
2095 * `vkGetPhysicalDeviceSurfacePresentModesKHR`
2096 * `vkCreateSwapchainKHR`
2097 * `vkDestroySurfaceKHR`
2098
2099Because the `VkSurfaceKHR` object is an instance-level object, one object can be
2100associated with multiple ICDs. Therefore, when the loader receives the
2101`vkCreateXXXSurfaceKHR` call, it still creates an internal `VkSurfaceIcdXXX`
2102object. This object acts as a container for each ICD's version of the
2103`VkSurfaceKHR` object. If an ICD does not support the creation of its own
2104`VkSurfaceKHR` object, the loader's container stores a NULL for that ICD. On
2105the otherhand, if the ICD does support `VkSurfaceKHR` creation, the loader will
2106make the appropriate `vkCreateXXXSurfaceKHR` call to the ICD, and store the
2107returned pointer in it's container object. The loader then returns the
2108`VkSurfaceIcdXXX` as a `VkSurfaceKHR` object back up the call chain. Finally,
2109when the loader receives the `vkDestroySurfaceKHR` call, it subsequently calls
2110`vkDestroySurfaceKHR` for each ICD who's internal `VkSurfaceKHR` object is not
2111NULL. Then the loader destroys the container object before returning.
2112
2113
2114### Loader and ICD Interface Negotiation
2115
2116Generally, for functions issued by an application, the loader can be
2117viewed as a pass through. That is, the loader generally doesn't modify the
2118functions or their parameters, but simply calls the ICDs entry-point for that
2119function. There are specific additional interface requirements an ICD needs to
2120comply with that are not part of any requirements from the Vulkan specification.
2121These addtional requirements are versioned to allow flexibility in the future.
2122
2123
2124#### Windows and Linux ICD Negotiation
2125
2126
2127##### Version Negotiation Between Loader and ICDs
2128
2129All ICDs (supporting interface version 2 or higher) must export the following
2130function that is used for determination of the interface version that will be
2131used. This entry-point is not a part of the Vulkan API itself, only a private
2132interface between the loader and ICDs.
2133
2134```cpp
2135 VKAPI_ATTR VkResult VKAPI_CALL
2136 vk_icdNegotiateLoaderICDInterfaceVersion(
2137 uint32_t* pSupportedVersion);
2138```
2139
2140This function allows the loader and ICD to agree on an interface version to use.
2141The "pSupportedVersion" parameter is both an input and output parameter.
2142"pSupportedVersion" is filled in by the loader with the desired latest interface
2143version supported by the loader (typically the latest). The ICD receives this
2144and returns back the version it desires in the same field. Because it is
2145setting up the interface version between the loader and ICD, this should be
2146the first call made by a loader to the ICD (even prior to any calls to
2147`vk_icdGetInstanceProcAddr`).
2148
2149If the ICD receiving the call no longer supports the interface version provided
2150by the loader (due to deprecation), then it should report
2151VK_ERROR_INCOMPATIBLE_DRIVER error. Otherwise it sets the value pointed by
2152"pSupportedVersion" to the latest interface version supported by both the ICD
2153and the loader and returns VK_SUCCESS.
2154
2155The ICD should report VK_SUCCESS in case the loader provided interface version
2156is newer than that supported by the ICD, as it's the loader's responsibility to
2157determine whether it can support the older interface version supported by the
2158ICD. The ICD should also report VK_SUCCESS in the case its interface version
2159is greater than the loader's, but return the loader's version. Thus, upon
2160return of VK_SUCCESS the "pSupportedVersion" will contain the desired interface
2161version to be used by the ICD.
2162
2163If the loader receives an interface version from the ICD that the loader no
2164longer supports (due to deprecation), or it receives a
2165VK_ERROR_INCOMPATIBLE_DRIVER error instead of VK_SUCCESS, then the loader will
2166treat the ICD as incompatible and will not load it for use. In this case, the
2167application will not see the ICDs `vkPhysicalDevice` during enumeration.
2168
2169###### Interfacing With Legacy ICDs or Loader
2170
2171If a loader sees that an ICD does not export the
2172`vk_icdNegotiateLoaderICDInterfaceVersion` function, then the loader assumes the
2173corresponding ICD only supports either interface version 0 or 1.
2174
2175From the other side of the interface, if an ICD sees a call to
2176`vk_icdGetInstanceProcAddr` before a call to
2177`vk_icdGetLoaderICDInterfaceVersion`, then it knows that loader making the calls
2178is a legacy loader supporting version 0 or 1. If the loader calls
2179`vk_icdGetInstanceProcAddr` first, it supports at least version 1. Otherwise,
2180the loader only supports version 0.
2181
2182
2183##### Loader Version 4 Interface Requirements
2184
2185The major change to version 4 of the loader/ICD interface is the support of
2186[Unknown Physical Device Extensions](#icd-unknown-physical-device-
2187extensions] using the `vk_icdGetPhysicalDeviceProcAddr` function. This
2188function is purely optional. However, if an ICD supports a Physical Device
2189extension, it must provide a `vk_icdGetPhysicalDeviceProcAddr` function.
2190Otherwise, the loader will continue to treat any unknown functions as VkDevice
2191functions and cause invalid behavior.
2192
2193
2194##### Loader Version 3 Interface Requirements
2195
2196The primary change that occurred in version 3 of the loader/ICD interface was to
2197allow an ICD to handle creation/destruction of their own KHR_surfaces. Up until
2198this point, the loader created a surface object that was used by all ICDs.
2199However, some ICDs may want to provide their own surface handles. If an ICD
2200chooses to enable this support, it must export support for version 3 of the
2201loader/ICD interface, as well as any Vulkan function that uses a KHR_surface
2202handle, such as:
2203- `vkCreateXXXSurfaceKHR` (where XXX is the platform specific identifier [i.e.
2204`vkCreateWin32SurfaceKHR` for Windows])
2205- `vkDestroySurfaceKHR`
2206- `vkCreateSwapchainKHR`
2207- `vkGetPhysicalDeviceSurfaceSupportKHR`
2208- `vkGetPhysicalDeviceSurfaceCapabilitiesKHR`
2209- `vkGetPhysicalDeviceSurfaceFormatsKHR`
2210- `vkGetPhysicalDeviceSurfacePresentModesKHR`
2211
2212An ICD can still choose to not take advantage of this functionality by simply
2213not exposing the above the `vkCreateXXXSurfaceKHR` and `vkDestroySurfaceKHR`
2214functions.
2215
2216
2217##### Loader Version 2 Interface Requirements
2218
2219Version 2 interface has requirements in three areas:
2220 1. ICD Vulkan entry-point discovery,
2221 2. `KHR_surface` related requirements in the WSI extensions,
2222 3. Vulkan dispatchable object creation requirements.
2223
2224##### Loader Versions 0 and 1 Interface Requirements
2225
2226Version 0 and 1 interfaces do not support version negotiation via
2227`vk_icdNegotiateLoaderICDInterfaceVersion`. ICDs can distinguish version 0 and
2228version 1 interfaces as follows: if the loader calls `vk_icdGetInstanceProcAddr`
2229first it supports version 1; otherwise the loader only supports version 0.
2230
2231Version 0 interface does not support `vk_icdGetInstanceProcAddr`. Version 0
2232interface requirements for obtaining ICD Vulkan entry-points are as follows:
2233
2234- The function `vkGetInstanceProcAddr` **must be exported** in the ICD library
2235and returns valid function pointers for all the Vulkan API entry-points.
2236- `vkCreateInstance` **must be exported** by the ICD library.
2237- `vkEnumerateInstanceExtensionProperties` **must be exported** by the ICD
2238library.
2239
2240Additional Notes:
2241
2242- The loader will filter out extensions requested in `vkCreateInstance` and
2243`vkCreateDevice` before calling into the ICD; Filtering will be of extensions
2244advertised by entities (e.g. layers) different from the ICD in question.
2245- The loader will not call the ICD for `vkEnumerate\*LayerProperties`() as layer
2246properties are obtained from the layer libraries and layer JSON files.
2247- If an ICD library author wants to implement a layer, it can do so by having
2248the appropriate layer JSON manifest file refer to the ICD library file.
2249- The loader will not call the ICD for
2250 `vkEnumerate\*ExtensionProperties` if "pLayerName" is not equal to `NULL`.
2251- ICDs creating new dispatchable objects via device extensions need to
2252initialize the created dispatchable object. The loader has generic *trampoline*
2253code for unknown device extensions. This generic *trampoline* code doesn't
2254initialize the dispatch table within the newly created object. See the
2255[Creating New Dispatchable Objects](#creating-new-dispatchable-objects) section
2256for more information on how to initialize created dispatchable objects for
2257extensions non known by the loader.
2258
2259
2260#### Android ICD Negotiation
2261
2262The Android loader uses the same protocol for initializing the dispatch
2263table as described above. The only difference is that the Android
2264loader queries layer and extension information directly from the
2265respective libraries and does not use the json manifest files used
2266by the Windows and Linux loaders.
2267
2268
2269## Glossary of Terms
2270
2271| Field Name | Field Value |
2272|----------------|--------------------|
2273| 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. |
2274| 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. |
2275| Core Function | A function that is already part of the Vulkan core specification and not an extension. For example, vkCreateDevice(). |
2276| 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 |
2277| 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. |
2278| 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. |
2279| 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. |
2280| 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). |
2281| 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.
2282| 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. |
2283| 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 |
2284| 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. |
2285| 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. |
2286| 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. |
2287| 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).
2288| 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. |
2289| 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. |
2290| 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. |