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