blob: 139a81cb891555675c2b9fb2f768f420ab70838d [file] [log] [blame] [view]
Jon Ashburnc2972682016-02-08 15:42:01 -07001# Vulkan Loader Specification and Architecture Overview
2
Mark Youngcb6e6702016-07-20 11:38:53 -06003<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -07004
Mark Youngcb6e6702016-07-20 11:38:53 -06005## Goals of this document ##
Jon Ashburnc2972682016-02-08 15:42:01 -07006
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07007Specify necessary functions and expected behavior of interface between the
8loader library and ICDs and layers for Windows, Linux and Android based
9systems. Also describe the application visible behaviors of the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -070010
Mark Youngcb6e6702016-07-20 11:38:53 -060011<br/>
12
13## Audience ##
Jon Ashburnc2972682016-02-08 15:42:01 -070014
Mark Youngcb6e6702016-07-20 11:38:53 -060015This document is primarily targeted at Vulkan application, driver and layer developers.
16However, it can also be used by any developer interested in understanding more about
17how the Vulkan loader and layers interact.
Jon Ashburnc2972682016-02-08 15:42:01 -070018
Mark Youngcb6e6702016-07-20 11:38:53 -060019<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -070020
21
Mark Youngcb6e6702016-07-20 11:38:53 -060022## Loader goals ##
Jon Ashburnc2972682016-02-08 15:42:01 -070023
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070024- Support multiple ICDs (Installable Client Drivers) to co-exist on a system
25without interfering with each other.
Jon Ashburnc2972682016-02-08 15:42:01 -070026
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070027- Support optional modules (layers) that can be enabled by an application,
28developer or the system and have no impact when not enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -070029
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070030- Negligible performance cost for an application calling through the loader
31to an ICD entry point.
Jon Ashburnc2972682016-02-08 15:42:01 -070032
Mark Youngcb6e6702016-07-20 11:38:53 -060033<br/>
34
35## Architectural overview of layers and loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -070036
Mark Youngcb6e6702016-07-20 11:38:53 -060037Vulkan is a layered architecture placing the Application on one end, the
38ICDs on the other, and the loader and some number of layers in between.
Jon Ashburnc2972682016-02-08 15:42:01 -070039
Mark Youngcb6e6702016-07-20 11:38:53 -060040Layers are implemented as libraries that can be enabled in different ways
41(including by application request) and loaded during CreateInstance. Each
42layer can chooses to hook (intercept) any Vulkan commands which in turn
43can be ignored, augmented, or simply passed along. A layer may also
44expose functionality not available in the loader or any ICD. Some examples
45of this include: the ability to perform Vulkan API tracing and debugging,
46validate API usage, or overlay additional content on the applications surfaces.
47
48The loader is responsible for working with the various layers as well as
49supporting multiple GPUs and their drivers. Any Vulkan command may
50wind up calling into a diverse set of modules: loader, layers, and ICDs.
51The loader is critical to managing the proper dispatching of Vulkan
52commands to the appropriate set of layers and ICDs. The Vulkan object
53model allows the loader to insert layers into a call chain so that the layers
54can process Vulkan commands prior to the ICD being called.
Jon Ashburnc2972682016-02-08 15:42:01 -070055
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070056Vulkan uses an object model to control the scope of a particular action /
57operation. The object to be acted on is always the first parameter of a Vulkan
Mark Young6d026a72016-06-01 17:49:30 -060058call and is a dispatchable object (see Vulkan specification section 2.3 Object
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070059Model). Under the covers, the dispatchable object handle is a pointer to a
Mark Youngcb6e6702016-07-20 11:38:53 -060060structure, which in turn, contains a pointer to a dispatch table maintained by
61the loader. This dispatch table contains pointers to the Vulkan functions appropriate to
62that object.
Jon Ashburnc2972682016-02-08 15:42:01 -070063
Mark Youngcb6e6702016-07-20 11:38:53 -060064There are two types of dispatch tables the loader maintains:
65- **Instance Dispatch Table**
66 - Contains any function that takes a VkInstance or VkPhysicalDevice as their first parameter
67 - vkEnumeratePhysicalDevices
68 - vkDestroyInstance
69 - vkCreateInstance
70 - ...
71- **Device Dispatch Table**
72 - Contains any function that takes a VkDevice, VkQueue or VkCommandBuffer as their first parameter
Jon Ashburnc2972682016-02-08 15:42:01 -070073
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070074These instance and device dispatch tables are constructed when the application
75calls vkCreateInstance and vkCreateDevice. At that time the application and/or
76system can specify optional layers to be included. The loader will initialize
77the specified layers to create a call chain for each Vulkan function and each
78entry of the dispatch table will point to the first element of that chain.
79Thus, the loader builds an instance call chain for each VkInstance that is
80created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070081
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070082For example, the diagram below represents what happens in the call chain for
83vkCreateInstance. After initializing the chain, the loader will call into the
Mark Young6d026a72016-06-01 17:49:30 -060084first layer's vkCreateInstance which will call the next finally terminating in
85the loader again where this function calls every ICD's vkCreateInstance and
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070086saves the results. This allows every enabled layer for this chain to set up
87what it needs based on the VkInstanceCreateInfo structure from the application.
Jon Ashburnc2505562016-02-15 10:19:26 -070088![Instance call chain](instance_call_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070089
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070090This also highlights some of the complexity the loader must manage when using
91instance chains. As shown here, the loader must aggregate information from
92multiple devices when they are present. This means that the loader has to know
93about instance level extensions to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -070094
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070095Device chains are created at vkCreateDevice and are generally simpler because
96they deal with only a single device and the ICD can always be the terminator of
97the chain. The below diagram also illustrates how layers (either device or
98instance) can skip intercepting any given Vulkan entry point.
Jon Ashburnc2505562016-02-15 10:19:26 -070099![Chain skipping layers](chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700100
Mark Youngcb6e6702016-07-20 11:38:53 -0600101<br/>
102
103## Application interface to loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700104
Mark Young6d026a72016-06-01 17:49:30 -0600105In this section we'll discuss how an application interacts with the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700106
107- Linking to loader library for core and WSI extension symbols.
108
109- Dynamic Vulkan command lookup & application dispatch table.
110
111- Loader library filenames for linking to different Vulkan ABI versions.
112
113- Layers
114
115- Extensions
116
117- vkGetInstanceProcAddr, vkGetDeviceProcAddr
118
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700119The loader library on Windows, Linux and Android will export all core Vulkan
120and all appropriate Window System Interface (WSI) extensions. This is done to
121make it simpler to get started with Vulkan development. When an application
122links directly to the loader library in this way, the Vulkan calls are simple
123trampoline functions that jump to the appropriate dispatch table entry for the
124object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700125
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700126Applications are not required to link directly to the loader library, instead
127they can use the appropriate platform specific dynamic symbol lookup on the
Mark Young6d026a72016-06-01 17:49:30 -0600128loader library to initialize the application's own dispatch table. This allows
Jeff Julianof1619872016-02-17 17:25:42 -0500129an application to fail gracefully if the loader cannot be found, and it
130provides the fastest mechanism for the application to call Vulkan functions. An
131application will only need to query (via system calls such as dlsym()) the
132address of vkGetInstanceProcAddr from the loader library. Using
133vkGetInstanceProcAddr the application can then discover the address of all
134instance and global functions and extensions, such as vkCreateInstance,
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700135vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties
136in a platform independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700137
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700138The Vulkan loader library will be distributed in various ways including Vulkan
139SDKs, OS package distributions and IHV driver packages. These details are
140beyond the scope of this document. However, the name and versioning of the
141Vulkan loader library is specified so an app can link to the correct Vulkan ABI
142library version. Vulkan versioning is such that ABI backwards compatibility is
Jeff Julianof1619872016-02-17 17:25:42 -0500143guaranteed for all versions with the same major number (e.g. 1.0 and 1.1). On
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700144Windows, the loader library encodes the ABI version in its name such that
145multiple ABI incompatible versions of the loader can peacefully coexist on a
Mark Young6d026a72016-06-01 17:49:30 -0600146given system. The Vulkan loader library file name is "vulkan-<ABI
147version>.dll". For example, for Vulkan version 1.X on Windows the library
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700148filename is vulkan-1.dll. And this library file can typically be found in the
Mark Young6d026a72016-06-01 17:49:30 -0600149windows/system32 directory (on 64-bit Windows installs, the 32-bit version of
150the loader with the same name can be found in the windows/sysWOW64 directory).
Jon Ashburnc2972682016-02-08 15:42:01 -0700151
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700152For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
153number is not encoded in the base of the library filename as on Windows. On
154Linux an application wanting to link to the latest Vulkan ABI version would
155just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500156also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700157
Mark Young6d026a72016-06-01 17:49:30 -0600158####Layer Usage
159
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700160Applications desiring Vulkan functionality beyond what the core API offers may
161use various layers or extensions. A layer cannot add new or modify existing
162Vulkan commands, but may offer extensions that do. A common use of layers is
163for API validation. A developer can use validation layers during application
164development, but during production the layers can be disabled by the
Jeff Julianof1619872016-02-17 17:25:42 -0500165application. Thus, eliminating the overhead of validating the application's
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600166usage of the API. Layers discovered by the loader are reported to the
167application via vkEnumerateInstanceLayerProperties.
168Layers are enabled at vkCreateInstance and are active for all Vulkan commands
Mark Young6d026a72016-06-01 17:49:30 -0600169using the given VkIstance and any of it's child objects. For example, the
170ppEnabledLayerNames array in the VkInstanceCreateInfo structure is used by
171the application to list the layer names to be enabled at vkCreateInstance. At
172vkCreateInstance and vkCreateDevice, the loader will construct call chains that
173include the application specified (enabled) layers. vkCreateDevice will use the
174layers specified at vkCreateInstance. vkEnumerateDeviceLayerProperties and
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600175device layers are deprecated. Order is important in the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700176ppEnabledLayerNames array; array element 0 is the topmost (closest to the
177application) layer inserted in the chain and the last array element is closest
178to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700179
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700180Developers may want to enable layers that are not enabled by the given
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600181application they are using. On Linux and Windows, the environment variable
Mark Young6d026a72016-06-01 17:49:30 -0600182"VK\_INSTANCE\_LAYERS" can be used to enable
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700183additional layers which are not specified (enabled) by the application at
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600184vkCreateInstance. VK\_INSTANCE\_LAYERS is a colon
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700185(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
186relevant with the first layer in the list being the topmost layer (closest to
187the application) and the last layer in the list being the bottommost layer
188(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700189
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700190Application specified layers and user specified layers (via environment
191variables) are aggregated and duplicates removed by the loader when enabling
192layers. Layers specified via environment variable are topmost (closest to the
193application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700194
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700195An example of using these environment variables to activate the validation
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600196layer VK\_LAYER\_LUNARG\_parameter\_validation on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700197
198```
Mark Lobodzinski739391a2016-03-17 15:08:18 -0600199> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation
Jon Ashburnc2972682016-02-08 15:42:01 -0700200
Jon Ashburnc2972682016-02-08 15:42:01 -0700201```
202
Mark Young6d026a72016-06-01 17:49:30 -0600203#### Implicit vs Explicit Layers
204
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700205Some platforms, including Linux and Windows, support layers which are enabled
206automatically by the loader rather than explicitly by the application (or via
207environment variable). Explicit layers are those layers enabled by the
208application (or environment variable) by providing the layer name. Implicit
209layers are those layers enabled by the loader automatically. Any implicit
210layers the loader discovers on the system in the appropriate location will be
211enabled (subject to environment variable overrides described later). Discovery
212of properly installed implicit and explicit layers is described later.
213Explicitly enabling a layer that is implicitly enabled has no additional
214effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700215
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700216Extensions are optional functionality provided by a layer, the loader or an
217ICD. Extensions can modify the behavior of the Vulkan API and need to be
218specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700219
Mark Young6d026a72016-06-01 17:49:30 -0600220#### Instance/Device Extensions
221
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700222Instance extensions can be discovered via
223vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
224vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
225extensions from layers (both explicit and implicit), ICDs and the loader before
226reporting them to the application in vkEnumerate\*ExtensionProperties. The
Jeff Julianof1619872016-02-17 17:25:42 -0500227pLayerName parameter in these functions is used to select either a single layer
228or the Vulkan platform implementation. If pLayerName is NULL, extensions from
229Vulkan implementation components (including loader, implicit layers, and ICDs)
230are enumerated. If pLayerName is equal to a discovered layer module name then
231any extensions from that layer (which may be implicit or explicit) are
232enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Jon Ashburn859c7fb2016-03-02 17:26:31 -0700233support for the same extension) are eliminated by the loader. For duplicates, the
234ICD version is reported and the layer version is culled. Extensions must
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700235be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700236
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700237Extension command entry points should be queried via vkGetInstanceProcAddr or
238vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
239extension or core device entry points. Device entry points include any command
240that uses a VkDevice as the first parameter or a dispatchable object that is a
241child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
242vkGetInstanceProcAddr can be used to query either device or instance extension
243entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700244
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700245VkGetDeviceProcAddr is particularly interesting because it will provide the
246most efficient way to call into the ICD. For example, the diagram below shows
247what could happen if the application were to use vkGetDeviceProcAddr for the
Mark Young6d026a72016-06-01 17:49:30 -0600248function "vkGetDeviceQueue" and "vkDestroyDevice" but not "vkAllocateMemory".
249The resulting function pointer (fpGetDeviceQueue) would be the ICD's entry
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700250point if the loader and any enabled layers do not need to see that call. Even
Jeff Julianof1619872016-02-17 17:25:42 -0500251if an enabled layer intercepts the call (e.g. vkDestroyDevice) the loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700252trampoline code is skipped for function pointers obtained via
253vkGetDeviceProcAddr. This also means that function pointers obtained via
254vkGetDeviceProcAddr will only work with the specific VkDevice it was created
255for, using it with another device has undefined results. For extensions,
256Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700257
Jon Ashburnc2505562016-02-15 10:19:26 -0700258![Get*ProcAddr efficiency](get_proc_addr.png)
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700259
Mark Young78f88c82016-07-19 11:49:45 -0600260##### WSI Extensions
261
262Khronos approved WSI extensions are available and provide Windows System Integration
263support for various execution environments. It is important to understand that some WSI
264extensions are valid for all targets, but others are particular to a given execution
265environment (and loader). This desktop loader (currently targeting Windows and Linux)
266only enables those WSI extensions that are appropriate to the current environment.
267For the most part, the selection is done in the loader using compile-time preprocessor
268flags. All versions of the desktop loader currently expose at least the following WSI
269extension support:
270- VK_KHR_surface
271- VK_KHR_swapchain
272- VK_KHR_display
273
274In addition, each of the following OS targets for the loader support target-specific extensions:
275- **Windows** : VK_KHR_win32_surface
276- **Linux (default)** : VK_KHR_xcb_surface and VK_KHR_xlib_surface
277- **Linux (Wayland build)** : VK_KHR_wayland_surface
278- **Linux (Mir build)** : VK_KHR_mir_surface
279
280**NOTE:** Wayland and Mir targets are not fully supported at this time and should be considered
281alpha quality.
282
283It is important to understand that while the loader may support the various entry-points
284for these extensions, there is a hand-shake required to actually use them:
285* At least one physical device must support the extension(s)
286* The application must select such a physical device
287* The application must request the extension(s) be enabled while creating the instance or logical device (This depends on whether or not the given extension works with an instance or a device).
288* The instance and/or logical device creation must succeed.
289
290Only then can you expect to properly use a WSI extension in your Vulkan program.
291
292##### New Extensions
293
294With the ability to expand Vulkan so easily, extensions will be created that the loader knows
295nothing about. If the extension is a device extension, the loader will pass the unknown
296entry-point down the device call chain ending with the appropriate ICD entry-points.
297However, if the extension is an instance extension, the loader will fail to load it.
298
299*But why doesn't the loader support unknown instance extensions?*
300<br/>
301Let's look again at the Instance call chain:
302![Instance call chain](instance_call_chain.png)
303
304Notice that for a normal instance function call, the loader has to handle passing along the
305function call to the available ICDs. If the loader has no idea of the parameters or return
306value of the instance call, it can't properly pass information along to the ICDs.
307There may be ways to do this, which will be explored in the future. However, for now, this
308loader does not support any unknown instance extensions.
309
310Because the device call-chain does not pass through the loader terminator, this is not
311a problem for device extensions. Instead, device extensions terminate directly in the
312ICD they are associated with.
313
314*Is this a big problem?*
315<br/>
316No! Most extension functionality only affects a device and not an instance or a physical
317device. Thus, the overwhelming majority of extensions will be device extensions rather than
318instance extensions.
319
Mark Youngcb6e6702016-07-20 11:38:53 -0600320<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -0700321
Mark Youngcb6e6702016-07-20 11:38:53 -0600322
323## Vulkan Installable Client Driver interface with the loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700324
325### ICD discovery
326
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700327Vulkan allows multiple drivers each with one or more devices (represented by a
328Vulkan VkPhysicalDevice object) to be used collectively. The loader is
329responsible for discovering available Vulkan ICDs on the system. Given a list
330of available ICDs, the loader can enumerate all the physical devices available
331for an application and return this information to the application. The process
332in which the loader discovers the available Installable Client Drivers (ICDs)
333on a system is platform dependent. Windows, Linux and Android ICD discovery
334details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700335
336#### Windows
337
338##### Properly-Installed ICDs
339
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700340In order to find properly-installed ICDs, the Vulkan loader will scan the
341values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700342
343HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
344
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700345For each value in this key which has DWORD data set to 0, the loader opens the
346JSON format text information file (a.k.a. "manifest file") specified by the
347name of the value. Each name must be a full pathname to the text manifest file.
348The Vulkan loader will open each manifest file to obtain the name or pathname
349of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700350
Jon Ashburncc300a22016-02-11 14:57:30 -0700351 ```
352 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700353 "file_format_version": "1.0.0",
354 "ICD": {
355 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700356 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700357 }
358 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700359 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700360
361
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700362The "library\_path" specifies either a filename, a relative pathname, or a full
363pathname to an ICD shared library file, which the loader will attempt to load
364using LoadLibrary(). If the ICD is specified via a filename, the shared library
David Pinedo3e163ee2016-04-18 16:59:59 -0600365lives in the system's DLL search path (e.g. in the "C:\Windows\System32"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700366folder). If the ICD is specified via a relative pathname, it is relative to the
367path of the manifest file. Relative pathnames are those that do not start with
368a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
369character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700370
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700371The "file\_format\_version" specifies a major.minor.patch version number in
372case the format of the text information file changes in the future. If the same
373ICD shared library supports multiple, incompatible versions of text manifest
374file format versions, it must have multiple text info files (all of which may
375point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700376
Mark Young6d026a72016-06-01 17:49:30 -0600377The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700378API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700379
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700380There are no rules about the name of the text information files (except the
381.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700382
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700383There are no rules about the name of the ICD shared library files. For example,
384if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700385
Jon Ashburncc300a22016-02-11 14:57:30 -0700386```
387[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700388
David Pinedo3e163ee2016-04-18 16:59:59 -0600389"C:\vendor a\vk_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700390
David Pinedo3e163ee2016-04-18 16:59:59 -0600391"C:\windows\system32\vendorb_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700392
David Pinedo3e163ee2016-04-18 16:59:59 -0600393"C:\windows\system32\vendorc_icd.json"=dword:00000000
Jon Ashburncc300a22016-02-11 14:57:30 -0700394```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700395then the loader will open the following text information files, with the
396specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700397
Jon Ashburncc300a22016-02-11 14:57:30 -0700398| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700399|----------------|--------------------|
David Pinedo3e163ee2016-04-18 16:59:59 -0600400|vk\_vendora.json | "ICD": { "library\_path": "C:\VENDOR A\vk_vendora.dll", "api_version": "1.0.5" } |
Tony Barbourd83f06c2016-03-08 14:50:03 -0700401| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.5" } |
402|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.5" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700403
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700404Then the loader will open the three files mentioned in the "Text File Contents"
405column, and then try to load and use the three shared libraries indicated by
406the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700407
408##### Using Pre-Production ICDs
409
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700410IHV developers (and sometimes other developers) need to use special,
411pre-production ICDs. In some cases, a pre-production ICD may be in an
412installable package. In other cases, a pre-production ICD may simply be a
413shared library in the developer's build tree. In this latter case, we want to
414allow developers to point to such an ICD without modifying the
415properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700416
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700417This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
418which will override the mechanism used for finding properly-installed ICDs. In
419other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
420"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
421text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700422
Jon Ashburncc300a22016-02-11 14:57:30 -0700423- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700424
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700425Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
426file for a developer-built ICD. A semi-colon is only used if more than one ICD
427is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700428
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700429For example, if a developer wants to refer to one ICD that they built, they
430could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700431
Jon Ashburncc300a22016-02-11 14:57:30 -0700432C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700433
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700434If a developer wants to refer to two ICDs, one of which is a properly-installed
435ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700436
Jon Ashburncc300a22016-02-11 14:57:30 -0700437C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700438
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700439Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
440"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700441
442#### Linux
443
444##### Properly-Installed ICDs
445
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700446In order to find properly-installed ICDs, the Vulkan loader will scan the files
447in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700448
449/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700450/etc/vulkan/icd.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700451$HOME/.local/share/vulkan/icd.d
452
453Where $HOME is the current home directory of the application's user id; this
454path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700455
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700456These directories will contain text information files (a.k.a. "manifest
457files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700458
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700459The Vulkan loader will open each manifest file found to obtain the name or
460pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700461
Jon Ashburncc300a22016-02-11 14:57:30 -0700462```
463{
Jon Ashburnc2972682016-02-08 15:42:01 -0700464 "file_format_version": "1.0.0",
465 "ICD": {
466 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700467 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700468 }
469}
Jon Ashburncc300a22016-02-11 14:57:30 -0700470```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700471The "library\_path" specifies either a filename, a relative pathname, or a full
472pathname to an ICD shared library file. If the ICD is specified via a filename,
473the loader will attempt to open that file as a shared object using dlopen(),
474and the file must be in a directory that dlopen is configured to look in (Note:
475various distributions are configured differently). A distribution is free to
476create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
477required to do so. If the ICD is specified via a relative pathname, it is
478relative to the path of the info file. Relative pathnames are those that do not
479start with, but do contain at least one directory separator (i.e. the '/'
480character). For example, "lib/vendora.so" and "./vendora.so" are examples of
481relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700482
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700483The "file\_format\_version" provides a major.minor.patch version number in case
484the format of the manifest file changes in the future. If the same ICD shared
485library supports multiple, incompatible versions of manifest file format
486versions, it must have multiple manifest files (all of which may point to the
487same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700488
Mark Young6d026a72016-06-01 17:49:30 -0600489The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700490API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700491
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700492The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
493Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
494ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700495
496There are no rules about the name of the text files (except the .json suffix).
497
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700498There are no rules about the name of the ICD shared library files. For example,
499if the "/usr/share/vulkan/icd.d" directory contain the following files, with
500the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700501
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700502| Text File Name | Text File Contents |
503|-------------------|------------------------|
Tony Barbourd83f06c2016-03-08 14:50:03 -0700504| vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.5" } |
505| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.5" } |
506| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.5" } |
Jon Ashburnc2972682016-02-08 15:42:01 -0700507
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700508then the loader will open the three files mentioned in the "Text File Contents"
509column, and then try to load and use the three shared libraries indicated by
510the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700511
512##### Using Pre-Production ICDs
513
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700514IHV developers (and sometimes other developers) need to use special,
515pre-production ICDs. In some cases, a pre-production ICD may be in an
516installable package. In other cases, a pre-production ICD may simply be a
517shared library in the developer's build tree. In this latter case, we want to
518allow developers to point to such an ICD without modifying the
519properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700520
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700521This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
522which will override the mechanism used for finding properly-installed ICDs. In
523other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700524
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700525The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
526manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700527
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700528- A filename (e.g. "libvkicd.json") in the "/usr/share/vulkan/icd.d", "/etc/vulkan/icd.d" "$HOME/.local/share/vulkan/icd.d" directories
Jon Ashburnc2972682016-02-08 15:42:01 -0700529
530- A full pathname (e.g. "/my\_build/my\_icd.json")
531
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700532Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
533file for a developer-built ICD. A colon is only used if more than one ICD is
534listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700535
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700536For example, if a developer wants to refer to one ICD that they built, they
537could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700538
539/my\_build/my\_icd.json
540
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700541If a developer wants to refer to two ICDs, one of which is a properly-installed
542ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700543
544vendorc\_vulkan.json:/my\_build/my\_icd.json
545
546Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
547
548NOTE: this environment variable will be ignored for suid programs.
549
550#### Android
551
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700552The Android loader lives in the system library folder. The location cannot be
553changed. The loader will load the driver/ICD via hw_get_module with the ID
554of "vulkan". Due to security policies in Android none of this can be modified
555under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700556
Mark Youngcb6e6702016-07-20 11:38:53 -0600557<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -0700558
Mark Youngcb6e6702016-07-20 11:38:53 -0600559## ICD interface requirements ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700560
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700561Generally, for all Vulkan commands issued by an application, the loader can be
Mark Young6d026a72016-06-01 17:49:30 -0600562viewed as a pass through. That is, the loader generally doesn't modify the
Jon Ashburn54791f62016-04-22 14:40:07 -0600563commands or their parameters, but simply calls the ICDs entry point for that
564command. There are specific additional interface requirements an ICD needs to comply with that
565are over and above any requirements from the Vulkan specification including WSI extension specification.
566These addtional requirements are versioned to allow flexibility in the future.
567These interface requirements will be set forth in the following sections: 1) describing
568which "loader-ICD" interface version is available, 2) detailing the most recent interface version;
5693) the supported, older interface requirements will be described as differences
570from the most recent interface version.
Jon Ashburnc2972682016-02-08 15:42:01 -0700571
572#### Windows and Linux
573
Jon Ashburn54791f62016-04-22 14:40:07 -0600574##### Version Negotiation Between Loader and ICDs
Jon Ashburnc2972682016-02-08 15:42:01 -0700575
Jon Ashburn54791f62016-04-22 14:40:07 -0600576All ICDs (supporting interface version 2 or higher) must export the following
577function that is used for determination of the interface version that will be used.
578This entry point is not a part of the Vulkan API itself, only a private interface
579between the loader and ICDs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700580
Jon Ashburn54791f62016-04-22 14:40:07 -0600581VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion);
Jon Ashburnc2972682016-02-08 15:42:01 -0700582
Jon Ashburn54791f62016-04-22 14:40:07 -0600583This entry point reports the "loader-ICD" interface version supported by both the loader and the ICD.
584The loader informs the ICD of it's desired interface version (typically the latest) via the
585pSupportedVersion parameter.
586This call is the first call made by the loader into the ICD (prior to any calls to
587vk\_icdGetInstanceProcAddr).
Jon Ashburnc2972682016-02-08 15:42:01 -0700588
Jon Ashburn54791f62016-04-22 14:40:07 -0600589If a loader sees that an ICD does not export this symbol it knows that it's dealing
590with a legacy ICD supporting either interface version 0 or 1.
591Similarly, if an ICD sees a call to vk\_icdGetInstanceProcAddr before a call to
592vk_icdGetLoaderICDInterfaceVersion then it knows that it's dealing with a legacy loader
593supporting version 0 or 1.
594Note if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
595otherwise the loader only supports version 0.
Jon Ashburnc2972682016-02-08 15:42:01 -0700596
Jon Ashburn54791f62016-04-22 14:40:07 -0600597The pSupportedVersion parameter is both an input and output parameter.
598It is filled in by the loader before the call with the desired latest interface version supported by the loader.
Jeff Julianof1619872016-02-17 17:25:42 -0500599
Jon Ashburn54791f62016-04-22 14:40:07 -0600600If the ICD receiving the call no longer supports the interface version provided
601by the loader (due to deprecation) then it can report VK_ERROR_INCOMPATIBLE_DRIVER error,
602otherwise it sets the value pointed by pSupportedVersion to the latest interface
603version supported by both the ICD and the loader and returns VK_SUCCESS.
604The ICD should report VK_SUCCESS in case the loader provided interface version
605is newer than that supported by the ICD, as it's the loader's responsibility to
606determine whether it can support the older interface version supported by the ICD.
607The ICD should also report VK_SUCCESS in the case it's interface version is greater
608than the loader's, but return the loader's version. Thus, upon return of VK_SUCCESS
609the pSupportedVersion will contain the desired interface version to be used by the ICD.
Jon Ashburnc2972682016-02-08 15:42:01 -0700610
Jon Ashburn54791f62016-04-22 14:40:07 -0600611If the loader receives back an interface version from the ICD that the loader no longer
612supports (due to deprecation) or it receives a VK_ERROR_INCOMPATIBLE_DRIVER error
613instead of VK_SUCCESS then the loader will treat the ICD as incompatible
614and will not load it for use. In this case the application will not see the ICDs vkPhysicalDevice
615during enumeration.
Jon Ashburnc2972682016-02-08 15:42:01 -0700616
Jon Ashburn54791f62016-04-22 14:40:07 -0600617##### Loader Version 2 Interface Requirements
Jon Ashburnc2972682016-02-08 15:42:01 -0700618
Jon Ashburn54791f62016-04-22 14:40:07 -0600619Version 2 interface has requirements in three areas: 1) ICD Vulkan entry point discovery,
6202) KHR_surface related requirements in the WSI extensions, 3) Vulkan dispatchable object
621creation requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700622
Jon Ashburn54791f62016-04-22 14:40:07 -0600623###### ICD Vulkan entry point discovery
624All ICDs must export the following function that is used for discovery of ICD Vulkan entry points.
625This entry point is not a part of the Vulkan API itself, only a private interface between the loader and ICDs for version 1 and higher interfaces.
Jon Ashburnc2972682016-02-08 15:42:01 -0700626
Jon Ashburn54791f62016-04-22 14:40:07 -0600627VKAPI\_ATTR PFN\_vkVoidFunction VKAPI\_CALL vk\_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
628
629This function has very similar semantics to the Vulkan command vkGetInstanceProcAddr.
630vk\_icdGetInstanceProcAddr returns valid function pointers for all the global level
631and instance level Vulkan commands, and also for vkGetDeviceProcAddr.
632Global level commands are those
633which contain no dispatchable object as the first parameter, such as
634vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must
635support querying global level entry points by calling
636vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level
637commands are those that have either VkInstance, or VkPhysicalDevice as the
638first parameter dispatchable object. Both core entry points and any instance
639extension entry points the ICD supports should be available via
640vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and
641use new instance level dispatchable objects other than VkInstance and
642VkPhysicalDevice, in which case extension entry points using these newly
643defined dispatchable objects must be queryable via vk\_icdGetInstanceProcAddr.
644
645All other Vulkan entry points must either NOT be exported from the ICD
646library or else NOT use the official Vulkan function names if they are
647exported. This requirement is for ICD libraries that include other
648functionality (such as OpenGL library) and thus could be loaded by the
649application prior to when the Vulkan loader library is loaded by the
650application. In other words, the ICD library exported Vulkan symbols must not
651clash with the loader's exported Vulkan symbols.
652
653Beware of interposing by dynamic OS library loaders if the official Vulkan
654names are used. On Linux, if official names are used, the ICD library must be
655linked with -Bsymbolic.
656
657###### Handling KHR_surface objects in the WSI extensions
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700658Normally, ICDs handle object creation and destruction for various Vulkan
659objects. The WSI surface extensions for Linux and Windows
660(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
661VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
662handled differently. For these extensions, the VkSurfaceKHR object creation and
663destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700664
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006651. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
666 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700667
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006682. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
669 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700670
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006713. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
672 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700673
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006744. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
Jeff Julianof1619872016-02-17 17:25:42 -0500675 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field
676 in the structure is a VkIcdSurfaceBase enumerant that indicates whether the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700677 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700678
Jon Ashburn54791f62016-04-22 14:40:07 -0600679###### ICD dispatchable object creation
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700680As previously covered, the loader requires dispatch tables to be accessible
681within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
682VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
683dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700684
Jon Ashburncc300a22016-02-11 14:57:30 -0700685- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700686
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700687- The loader will replace the first entry with a pointer to the dispatch table
688 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700689
Jon Ashburncc300a22016-02-11 14:57:30 -07006901. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700691
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006922. This pointer points to a regular C structure with the first entry being a
693 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
694 classes. The C\++ compiler may put a vtable at offset zero if your class is
Jeff Julianof1619872016-02-17 17:25:42 -0500695 non-POD due to the use of a virtual function. In this case use a regular C
696 structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700697
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006983. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
699 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700700
701```
702
Jon Ashburncc300a22016-02-11 14:57:30 -0700703#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700704
Jon Ashburncc300a22016-02-11 14:57:30 -0700705union _VK_LOADER_DATA {
706 uintptr loadermagic;
707 void *loaderData;
708} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700709
Jon Ashburncc300a22016-02-11 14:57:30 -0700710vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700711{
Jon Ashburncc300a22016-02-11 14:57:30 -0700712 vkObj *newObj = alloc_obj();
713 ...
714 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700715
Jon Ashburncc300a22016-02-11 14:57:30 -0700716 set_loader_magic_value(newObj);
717 ...
718 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700719}
Jon Ashburnc2972682016-02-08 15:42:01 -0700720```
721
Jon Ashburn54791f62016-04-22 14:40:07 -0600722##### Loader Version 0 and 1 Interface Differences
723
724Version 0 and 1 interfaces do not support version negotiation via vk\_icdNegotiateLoaderICDInterfaceVersion.
725ICDs can distinguish version 0 and version 1 interfaces as follows:
726if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
727otherwise the loader only supports version 0.
728
729Version 0 interface does not support vk\_icdGetInstanceProcAddr. Version 0 interface requirements for
730obtaining ICD Vulkan entry points are as follows:
731
732- vkGetInstanceProcAddr exported in the ICD library and returns valid function
733 pointers for all the Vulkan API entry points;
734
735- vkCreateInstance exported in the ICD library;
736
737- vkEnumerateInstanceExtensionProperties exported in the ICD library;
738
739
Jon Ashburnc2972682016-02-08 15:42:01 -0700740Additional Notes:
741
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700742- The loader will filter out extensions requested in vkCreateInstance and
743vkCreateDevice before calling into the ICD; Filtering will be of extensions
Jeff Julianof1619872016-02-17 17:25:42 -0500744advertised by entities (e.g. layers) different from the ICD in question.
745- The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700746properties are obtained from the layer libraries and layer JSON files.
747- If an ICD library wants to implement a layer it can do so by having the
748appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700749- The loader will not call the ICD for
750 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600751- ICDs creating new dispatchable objects via device extensions need to initialize
Jon Ashburn54791f62016-04-22 14:40:07 -0600752the created dispatchable object. The loader has generic trampoline code for unknown
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600753device extensions. This generic trampoline code doesn't initialize the dispatch table within
Jon Ashburn54791f62016-04-22 14:40:07 -0600754the newly created object. See the section for more information on how to initialize created
755dispatchable objects for extensions non known by the loader. [layer link](#creating-new-dispatchable-objects)
Jeff Julianof1619872016-02-17 17:25:42 -0500756
Jon Ashburnc2972682016-02-08 15:42:01 -0700757#### Android
758
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700759The Android loader uses the same protocol for initializing the dispatch
760table as described above. The only difference is that the Android
761loader queries layer and extension information directly from the
762respective libraries and does not use the json manifest files used
763by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700764
Mark Youngcb6e6702016-07-20 11:38:53 -0600765<br/>
766
767## Vulkan layer interface with the loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700768
769### Layer discovery
770
771#### Windows
772
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600773<a name="ManifestFileExample"></a>
Jon Ashburnc2972682016-02-08 15:42:01 -0700774##### Properly-Installed Layers
775
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700776In order to find properly-installed layers, the Vulkan loader will use a
777similar mechanism as used for ICDs. Text information files (aka manifest
778files), that use a JSON format, are read in order to identify the names and
779attributes of layers and their extensions. The use of manifest files allows the
780loader to avoid loading any shared library files when the application does not
781query nor request any extensions. Layers and extensions have additional
782complexity, and so their manifest files contain more information than ICD info
783files. For example, a layer shared library file may contain multiple
784layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700785
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700786In order to find properly-installed layers, the Vulkan loader will scan the
787values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700788
789HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
790
791HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
792
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700793Explicit layers are those which are enabled by an application (e.g. with the
794vkCreateInstance function), or by an environment variable (as mentioned
795previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700796
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700797Implicit layers are those which are enabled by their existence. For example,
798certain application environments (e.g. Steam or an automotive infotainment
799system) may have layers which they always want enabled for all applications
800that they start. Other implicit layers may be for all applications started on a
801given system (e.g. layers that overlay frames-per-second). Implicit layers are
802enabled automatically, whereas explicit layers must be enabled explicitly. What
803distinguishes a layer as implicit or explicit is by which registry key its
804layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700805
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700806For each value in these keys which has DWORD data set to 0, the loader opens
807the JSON manifest file specified by the name of the value. Each name must be a
808full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700809
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700810The Vulkan loader will open each info file to obtain information about the
811layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700812
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600813This manifest file is in the JSON format as shown in the following example.
814See the section [Layer Library Manifest File](#LayerLibraryManifestFile) for more information about each of the nodes in the JSON file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700815
Jon Ashburncc300a22016-02-11 14:57:30 -0700816```
Jon Ashburnc2972682016-02-08 15:42:01 -0700817{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600818 "file_format_version" : "1.0.0",
819 "layer": {
820 "name": "VK_LAYER_LUNARG_overlay",
821 "type": "INSTANCE",
822 "library_path": "vkOverlayLayer.dll"
823 "api_version" : "1.0.5",
824 "implementation_version" : "2",
825 "description" : "LunarG HUD layer",
826 "functions": {
827 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
828 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
829 },
830 "instance_extensions": [
831 {
832 "name": "VK_EXT_debug_report",
833 "spec_version": "1"
834 },
835 {
836 "name": "VK_VENDOR_ext_x",
837 "spec_version": "3"
838 }
839 ],
840 "device_extensions": [
841 {
842 "name": "VK_EXT_debug_marker",
843 "spec_version": "1",
844 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
845 }
846 ],
847 "enable_environment": {
848 "ENABLE_LAYER_OVERLAY_1": "1"
849 }
850 "disable_environment": {
851 "DISABLE_LAYER_OVERLAY_1": ""
852 }
853 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700854}
Jon Ashburncc300a22016-02-11 14:57:30 -0700855```
Jon Ashburnc2972682016-02-08 15:42:01 -0700856
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700857The "library\_path" specifies either a filename, a relative pathname, or a full
858pathname to a layer shared library (".dll") file, which the loader will attempt
859to load using LoadLibrary(). If the layer is specified via a relative pathname,
860it is relative to the path of the info file (e.g. for cases when an application
861provides a layer that is in the same folder hierarchy as the rest of the
862application files). If the layer is specified via a filename, the shared
863library lives in the system's DLL search path (e.g. in the
864"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700865
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600866If defining multiple layers in a single JSON file prior to "file\_format\_version"
8671.0.1, you would simply define multiple "layer" objects. However, this is not
868valid JSON syntax. Instead, you should now define "file\_format\_version"
8691.0.1 (or newer) and use the new "layers" array object as seen in the
870following example:
871
872```
873{
874 "file_format_version" : "1.0.1",
875 "layers": [
876 {
877 "name": "VK_LAYER_layer_name1",
878 "type": "INSTANCE",
879 ...
880 },
881 {
882 "name": "VK_LAYER_layer_name2",
883 "type": "INSTANCE",
884 ...
885 }
886 ]
887}
888```
889
890You could use the "layers" array object to define a single layer, as long as
891your "file\_format\_version" is defined to at least 1.0.1. It is functionally the
892same as using a single "layer" object.
893
Jon Ashburnc2972682016-02-08 15:42:01 -0700894There are no rules about the name of the text files (except the .json suffix).
895
896There are no rules about the name of the layer shared library files.
897
898##### Using Pre-Production Layers
899
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700900As with ICDs, developers may need to use special, pre-production layers,
901without modifying the properly-installed layers. This need is met with the use
902of the "VK\_LAYER\_PATH" environment variable, which will override the
903mechanism using for finding properly-installed layers. Because many layers may
904exist on a system, this environment variable is a semi-colon-separated list of
905folders that contain layer info files. Only the folder listed in
906"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
907entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700908
909- The full pathname of a folder containing layer info files
910
911#### Linux
912
913##### Properly-Installed Layers
914
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700915In order to find properly-installed layers, the Vulkan loader will use a
916similar mechanism as used for ICDs. Text information files, that use a JSON
917format, are read in order to identify the names and attributes of layers and
918their extensions. The use of text info files allows the loader to avoid loading
919any shared library files when the application does not query nor request any
920extensions. Layers and extensions have additional complexity, and so their info
921files contain more information than ICD info files. For example, a layer shared
922library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700923
924The Vulkan loader will scan the files in the following Linux directories:
925
926/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700927/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700928/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700929/etc/vulkan/implicit\_layer.d
David Pinedo3e163ee2016-04-18 16:59:59 -0600930\$HOME/.local/share/vulkan/explicit\_layer.d
931\$HOME/.local/share/vulkan/implicit\_layer.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700932
933Where $HOME is the current home directory of the application's user id; this
934path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700935
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700936Explicit layers are those which are enabled by an application (e.g. with the
937vkCreateInstance function), or by an environment variable (as mentioned
938previously). Implicit layers are those which are enabled by their existence.
939For example, certain application environments (e.g. Steam or an automotive
940infotainment system) may have layers which they always want enabled for all
941applications that they start. Other implicit layers may be for all applications
942started on a given system (e.g. layers that overlay frames-per-second).
943Implicit layers are enabled automatically, whereas explicit layers must be
944enabled explicitly. What distinguishes a layer as implicit or explicit is by
945which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700946
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700947The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
948installed from Linux-distribution-provided packages. The
949"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
950non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700951
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600952This manifest file is in the JSON format as shown in the following example.
953See the section [Layer Library Manifest File](#LayerLibraryManifestFile) for more information about each of the nodes in the JSON file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700954
Jon Ashburncc300a22016-02-11 14:57:30 -0700955```
Jon Ashburnc2972682016-02-08 15:42:01 -0700956{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600957 "file_format_version" : "1.0.0",
958 "layer": {
959 "name": "VK_LAYER_LUNARG_overlay",
960 "type": "INSTANCE",
961 "library_path": "libvkOverlayLayer.so"
962 "api_version" : "1.0.5",
963 "implementation_version" : "2",
964 "description" : "LunarG HUD layer",
965 "functions": {
966 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
967 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
968 },
969 "instance_extensions": [
970 {
971 "name": "VK_EXT_debug_report",
972 "spec_version": "1"
973 },
974 {
975 "name": "VK_VENDOR_ext_x",
976 "spec_version": "3"
977 }
978 ],
979 "device_extensions": [
980 {
981 "name": "VK_EXT_debug_marker",
982 "spec_version": "1",
983 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
984 }
985 ],
986 "enable_environment": {
987 "ENABLE_LAYER_OVERLAY_1": "1"
988 },
989 "disable_environment": {
990 "DISABLE_LAYER_OVERLAY_1": ""
991 }
992 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700993}
Jon Ashburncc300a22016-02-11 14:57:30 -0700994```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700995The "library\_path" specifies either a filename, a relative pathname, or a full
996pathname to a layer shared library (".so") file, which the loader will attempt
997to load using dlopen(). If the layer is specified via a filename, the loader
998will attempt to open that file as a shared object using dlopen(), and the file
999must be in a directory that dlopen is configured to look in (Note: various
1000distributions are configured differently). A distribution is free to create
1001Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
1002required to do so. If the layer is specified via a relative pathname, it is
1003relative to the path of the info file (e.g. for cases when an application
1004provides a layer that is in the same directory hierarchy as the rest of the
1005application files).
Jon Ashburnc2972682016-02-08 15:42:01 -07001006
1007There are no rules about the name of the text files (except the .json suffix).
1008
1009There are no rules about the name of the layer shared library files.
1010
1011##### Using Pre-Production Layers
1012
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001013As with ICDs, developers may need to use special, pre-production layers,
1014without modifying the properly-installed layers. This need is met with the use
1015of the "VK\_LAYER\_PATH" environment variable, which will override the
1016mechanism using for finding properly-installed layers. Because many layers may
1017exist on a system, this environment variable is a colon-separated list of
1018directories that contain layer info files. Only the directories listed in
1019"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
1020is:
Jon Ashburnc2972682016-02-08 15:42:01 -07001021
1022- The full pathname of a directory containing layer info files
1023
1024NOTE: these environment variables will be ignored for suid programs.
1025
1026#### Android
1027
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001028The recommended way to enable layers is for applications
1029to programatically enable them. The layers are provided by the application
1030and must live in the application's library folder. The application
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001031enables the layers at vkCreateInstance as any Vulkan
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001032application would.
1033An application enabled for debug has more options. It can enumerate and enable
1034layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -07001035
Mark Youngcb6e6702016-07-20 11:38:53 -06001036<br/>
1037
1038## Layer interface requirements ##
Jon Ashburnc2972682016-02-08 15:42:01 -07001039
1040#### Architectural interface overview
1041
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001042There are two key architectural features that drive the loader to layer library
1043interface: 1) separate and distinct instance and device call chains, and 2)
1044distributed dispatch. First these architectural features will be described and
1045then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -07001046
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001047Call chains are the links of calls for a given Vulkan command from layer module
1048to layer module with the loader and or the ICD being the bottom most command.
1049Call chains are constructed at both the instance level and the device level by
1050the loader with cooperation from the layer libraries. Instance call chains are
1051constructed by the loader when layers are enabled at vkCreateInstance. Device
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001052call chains are constructed by the loader when layers are enabled, by the loader, at
ttyio0811cec2016-04-10 22:09:44 +08001053vkCreateDevice. A layer can intercept Vulkan instance commands, device commands
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001054or both. For a layer to intercept instance commands, it must participate in the
1055instance call chain. For a layer to intercept device commands, it must
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001056participate in the device chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001057
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001058Normally, when a layer intercepts a given Vulkan command, it will call down the
1059instance or device chain as needed. The loader and all layer libraries that
1060participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001061from one entity to the next. This group effort for call chain sequencing is
Jeff Julianof1619872016-02-17 17:25:42 -05001062hereinafter referred to as distributed dispatch. In distributed dispatch, since
1063each layer is responsible for properly calling the next entity in the device or
1064instance chain, a dispatch mechanism is required for all Vulkan commands a
1065layer intercepts. For Vulkan commands that are not intercepted by a layer, or
1066if the layer chooses to terminate a given Vulkan command by not calling down
1067the chain, then no dispatch mechanism is needed for that particular Vulkan
1068command. Only for those Vulkan commands, which may be a subset of all Vulkan
1069commands, that a layer intercepts is a dispatching mechanism by the layer
1070needed. The loader is responsible for dispatching all core and instance
1071extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001072
Jeff Julianof1619872016-02-17 17:25:42 -05001073Instance level Vulkan commands are those that have the dispatchable objects
1074VkInstance, or VkPhysicalDevice as the first parameter and also includes
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001075vkCreateInstance.
Jeff Julianof1619872016-02-17 17:25:42 -05001076
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001077Device level Vulkan commands are those that use VkDevice, VkQueue or
1078VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1079extensions may introduce new instance or device level dispatchable objects, so
1080the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001081
Chia-I Wucb24fec2016-04-20 06:23:24 +08001082#### Layer Library Interface
Jeff Julianof1619872016-02-17 17:25:42 -05001083
Chia-I Wucb24fec2016-04-20 06:23:24 +08001084A layer library is a container of layers. This section defines an extensible
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001085interface to discover layers contained in layer libraries.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001086The extensible programming interface is used on Android only. For Windows and Linux,
1087the layer manifest JSON files are used.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001088
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001089It also specifies the minimal conventions
1090and rules a layer must follow. Other sections might have other guidelines that layers should follow.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001091
1092##### Layer Conventions and Rules
1093
1094A layer, when inserted into an otherwise compliant Vulkan implementation, must
1095still result in a compliant Vulkan implementation[\*]. It must additionally
1096follow some conventions and rules.
1097
1098A layer is always chained with other layers. It must not make invalid calls
1099to or rely on undefined behaviors of its lower layers. When it changes the
1100behavior of a command, it must make sure its upper layers do not make invalid
1101calls to or rely on undefined behaviors of its lower layers because of the
1102changed behavior. For example, when a layer intercepts an object creation
1103command to wrap the objects created by its lower layers, it must make sure its
1104lower layers never see the wrapping objects, directly from itself or
1105indirectly from its upper layers.
1106
Chia-I Wub5e850e2016-05-06 08:41:52 +08001107When a layer requires host memory, it may ignore the provided allocators. It
1108should use memory allocators if the layer is intended to run in a production
1109environment, such as an implicit layer that is always enabled. That will
1110allow applications to include the layer's memory usage.
1111
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001112`vkEnumerateInstanceLayerProperties` must enumerate and only enumerate the
1113layer itself.
1114
1115`vkEnumerateInstanceExtensionProperties` must handle the case where
1116`pLayerName` is itself. It must return `VK_ERROR_LAYER_NOT_PRESENT`
1117otherwise, including when `pLayerName` is `NULL`.
1118
1119`vkEnumerateDeviceLayerProperties` is deprecated and may be omitted. The
1120behavior is undefined.
1121
Chia-I Wuadac8342016-04-22 08:12:19 +08001122`vkEnumerateDeviceExtensionProperties` must handle the case where `pLayerName`
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001123is itself. In other cases, it should normally chain to other layers.
1124
1125`vkCreateInstance` must not generate an error for unrecognized layer names and
1126extension names. It may assume the layer names and extension names have been
1127validated.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001128
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001129`vkGetInstanceProcAddr` intercepts a Vulkan command by returning a local entry point,
1130otherwise it returns the value obtained by calling down the instance chain.
1131 These commands must be intercepted
1132 - vkGetInstanceProcAddr
1133 - vkCreateInstance
1134 - vkCreateDevice (only required for any device-level chaining)
Chia-I Wucb24fec2016-04-20 06:23:24 +08001135
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001136 For compatibility with older layer libraries,
1137 - when `pName` is `vkCreateDevice`, it ignores `instance`.
1138
1139`vkGetDeviceProcAddr` intercepts a Vulkan command by returning a local entry point,
1140otherwise it returns the value obtained by calling down the device chain.
1141
1142The specification requires `NULL` to be returned from `vkGetInstanceProcAddr` and
1143`vkGetDeviceProcAddr` for disabled commands. A layer may return `NULL` itself or
1144rely on the following layers to do so.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001145
Chia-I Wucb24fec2016-04-20 06:23:24 +08001146[\*]: The intention is for layers to have a well-defined baseline behavior.
1147Some of the conventions or rules, for example, may be considered abuses of the
1148specification.
1149
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001150##### Layer Library API Version 0
Chia-I Wucb24fec2016-04-20 06:23:24 +08001151
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001152A layer library supporting interface version 0 must define and export these
1153introspection functions, unrelated to any Vulkan command despite the names,
1154signatures, and other similarities:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001155
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001156 - `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
1157 library. This function never fails.
1158
1159 When a layer library contains only one layer, this function may be an alias
1160 to the layer's `vkEnumerateInstanceLayerProperties`.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001161
1162 - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001163 layers in a layer library. `pLayerName` is always a valid layer name.
1164 This function never fails.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001165
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001166 When a layer library contains only one layer, this function may be an alias
1167 to the layer's `vkEnumerateInstanceExtensionProperties`.
1168
1169 - `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
1170 proper, or empty subset) of layers in a layer library. `physicalDevice` is
1171 always `VK_NULL_HANDLE`. This function never fails.
1172
1173 If a layer is not enumerated by this function, it will not participate in
1174 device command interception.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001175
1176 - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001177 layers in a layer library. `physicalDevice` is always `VK_NULL_HANDLE`.
1178 `pLayerName` is always a valid layer name. This function never fails.
1179
1180The introspection functions are not used by the desktop loader.
1181
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001182It must also define and export these functions one for each layer in the library:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001183
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001184 - `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a layer's vkGetInstanceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001185
1186 When a layer library contains only one layer, this function may
1187 alternatively be named `vkGetInstanceProcAddr`.
1188
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001189 - `<layerName>GetDeviceProcAddr` behaves identically to a layer's vkGetDeviceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001190
1191 When a layer library contains only one layer, this function may
1192 alternatively be named `vkGetDeviceProcAddr`.
1193
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001194All layers contained within a library must support [`vk_layer.h`][]. They do not need to
1195implement commands that they do not intercept. They are recommended not to export
1196any commands.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001197
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001198<a name="LayerLibraryManifestFile"></a>
1199##### Layer Library Manifest File Version 0
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001200On Windows and Linux (desktop), the loader uses manifest files to discover
1201layer libraries and layers. The desktop loader doesn't directly query the
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001202layer library except during chaining.
1203On Android, the loader queries the layer libraries via the introspection functions as outlined above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001204
1205The layer libraries and the manifest files must be kept in sync.
1206
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001207The following table associates the desktop JSON nodes with the layer library introspection queries. It also indicates requirements.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001208
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001209| Property | JSON node | Introspection query | Notes |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001210|----------|-----------|-----------------------|-------|
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001211| file version | file_format_version | N/A | one node required per JSON file |
1212| layers in library | layer | vkEnumerateInstanceLayerProperties | one node required per layer |
1213| layer name | name | vkEnumerateInstanceLayerProperties | one node is required |
1214| layer type | type | vkEnumerate*LayerProperties | see Note 1 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001215| library location | library_path | N/A | one node is required |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001216| vulkan spec version | api_version | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001217| layer implementation version | api_version | vkEnumerateInstanceLayerProperties | see Note 2 |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001218| layer description | description | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001219| chaining functions | functions | vkGet*ProcAddr | see Note 3 |
1220| instance extensions | instance_extensions | vkEnumerateInstanceExtensionProperties | see Note 4 |
1221| device extensions | device_extensions | vkEnumerateDeviceExtensionProperties | see Note 5 |
1222| enable implicit | enable_environment | N/A | See Note 6 |
1223| disable implicit | enable_environment | N/A | See Note 7 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001224
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001225"file\_format\_version" is used to indicate the valid JSON syntax of the file.
1226As nodes are added or deleted which would change the parsing of this file,
1227the file_format_version should change. This version
1228is NOT the same as the layer library interface version. The interface version is a superset
1229of the "file_format_version" and includes the semantics of the nodes in the JSON file.
1230For interface version 0 the file format version must be "1.0.0"
1231
1232Note 1: Prior to deprecation, the "type" node was used to indicate which layer chain(s)
1233to activate the layer upon: instance, device, or both.
1234Distinct instance and device layers are deprecated; there are now just layers.
1235Allowable values for type (both before and after deprecation) are "INSTANCE", "GLOBAL" and, "DEVICE."
1236"DEVICE" layers are skipped over by the loader as if they were not found.
1237Thus, layers must have a type of "GLOBAL" or "INSTANCE" for the loader to include the layer in the enumerated instance layer list.
1238
1239"library\_path" is the filename, full path, or relative path to the library file.
Mark Young57551512016-06-23 11:25:03 -06001240See [Manifest File Example](#ManifestFileExample) section for more details.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001241
1242Note 2: One "implementation\_version" node is required per layer. This node gives the layer version, a single number
1243increasing with backward uncompatible changes.
1244
1245Note 3: The "functions" node is required if the layer is using alternative
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001246names for vkGetInstanceProcAddr or vkGetDeviceProcAddr. vkGetInstanceProcAddr and vkGetDeviceProcAddr
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001247are required for all layers. See further requirements in the Layer Library API section above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001248
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001249Note 4: One "instance_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001250required if any instance
1251extensions are supported by a layer, otherwise the node is optional. Each
1252element of the array must have the nodes "name" and "spec_version" which
1253correspond to VkExtensionProperties "extensionName" and "specVersion"
1254respectively.
1255
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001256Note 5: One "device_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001257required if any device
1258extensions are supported by a layer, otherwise the node is optional. Each
1259element of the array must have the nodes "name" and "spec_version" which
1260correspond to VkExtensionProperties "extensionName" and "specVersion"
1261respectively. Additionally, each element of the array of device extensions
1262must have the node "entrypoints" if the device extension adds Vulkan API commands,
1263otherwise this node is not required.
1264The "entrypoint" node is an array of the names of all entrypoints added by the
1265supported extension.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001266```
1267 "device_extensions": [
1268 {
1269 "name": "VK_EXT_debug_marker",
1270 "spec_version": "1",
1271 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1272 }
1273 ```
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001274
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001275Note 6: The "enable\_environment" node is only for implicit layers only. It is optional for implicit layers.
1276This node gives an environment variable and value required to enable an implicit layer. This
1277environment variable (which should vary with each "version" of the layer) must be set to the
1278given value or else the implicit layer is not loaded. This is for application environments (e.g. Steam) which
1279want to enable a layer(s) only for applications that they launch, and allows
1280for applications run outside of an application environment to not get that
1281implicit layer(s).
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001282
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001283Note 7: The "disable\_environment" node is only for implicit layers only. It is required for implicit layers.
1284This node gives an environment variable and value required to disable an implicit layer. In
1285rare cases of an application not working with an implicit layer, the
1286application can set this environment variable (before calling Vulkan commands)
1287in order to "blacklist" the layer. This environment variable (which should vary
1288with each "version" of the layer) must be set (not particularly to any value).
1289If both the "enable\_environment" and
1290"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001291
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001292#### Layer Dispatch Interface Version 0
1293##### Layer intercept requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001294
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001295- Layers intercept a Vulkan command by defining a C/C++ function with signature
1296identical to the Vulkan API for that command.
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001297- A layer must intercept at least vkGetInstanceProcAddr and
1298vkCreateInstance. Additionally, a layer would also intercept vkGetDeviceProcAddr and vkCreateDevice to participate in the device chain.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001299- For any Vulkan command a layer intercepts which has a non-void return value,
1300an appropriate value must be returned by the layer intercept function.
1301- The layer intercept function must call down the chain to the corresponding
1302Vulkan command in the next entity. Undefined results will occur if a layer
1303doesn't propagate calls down the chain. The two exceptions to this requirement
1304are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1305chain for Vulkan commands that they do not intercept.
1306- Layer intercept functions may insert extra calls to Vulkan commands in
1307addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1308want to add a call to vkQueueWaitIdle after calling down the chain for
1309vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1310chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001311
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001312##### Distributed dispatching requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001313
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001314- For each entry point a layer intercepts, it must keep track of the entry
1315point residing in the next entity in the chain it will call down into. In other
1316words, the layer must have a list of pointers to functions of the appropriate
1317type to call into the next entity. This can be implemented in various ways but
1318for clarity will be referred to as a dispatch table.
1319- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1320(see include/vulkan/vk_layer.h).
1321- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1322dispatch table (see include/vulkan/vk_layer.h).
1323- Layers vkGetInstanceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001324vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001325functions.
1326- Layers vkGetDeviceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001327vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001328functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001329
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001330##### Layer dispatch initialization
Jeff Julianof1619872016-02-17 17:25:42 -05001331
1332- A layer initializes its instance dispatch table within its vkCreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001333function.
Jeff Julianof1619872016-02-17 17:25:42 -05001334- A layer initializes its device dispatch table within its vkCreateDevice
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001335function.
1336- The loader passes a linked list of initialization structures to layers via
1337the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1338for vkCreateInstance and VkCreateDevice respectively.
1339- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001340instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001341include/vulkan/vk_layer.h for details.
1342- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1343"sType" field in VkLayerInstanceCreateInfo.
1344- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1345"sType" field in VkLayerDeviceCreateInfo.
1346- The "function" field indicates how the union field "u" should be interpreted
1347within VkLayer*CreateInfo. The loader will set the "function" field to
1348VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1349VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001350- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001351- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1352by a layer.
1353- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1354vkGetDeviceProcAddr used by a layer.
1355- Given the above structures set up by the loader, layer must initialize their
1356dispatch table as follows:
1357 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1358the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001359 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001360 - For CreateInstance get the next entity's vkCreateInstance by calling the
1361"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001362 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001363 - For CreateDevice get the next entity's vkCreateDevice by calling the
1364"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001365 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001366 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1367 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001368 - Initialize your layer dispatch table by calling the next entity's
1369Get*ProcAddr function once for each Vulkan command needed in your dispatch
1370table
Jon Ashburncc300a22016-02-11 14:57:30 -07001371
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001372##### Example code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001373
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001374```cpp
1375VkResult vkCreateInstance(
1376 const VkInstanceCreateInfo *pCreateInfo,
1377 const VkAllocationCallbacks *pAllocator,
1378 VkInstance *pInstance)
1379{
1380 VkLayerInstanceCreateInfo *chain_info =
1381 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1382
1383 assert(chain_info->u.pLayerInfo);
1384 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1385 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1386 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001387 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001388 if (fpCreateInstance == NULL) {
1389 return VK_ERROR_INITIALIZATION_FAILED;
1390 }
1391
1392 // Advance the link info for the next element of the chain
1393 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1394
1395 // Continue call down the chain
1396 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1397 if (result != VK_SUCCESS)
1398 return result;
1399
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001400 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001401 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001402 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001403 layer_init_instance_dispatch_table(
1404 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1405
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001406 // Other layer initialization
1407 ...
1408
1409 return VK_SUCCESS;
1410}
1411```
1412
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001413##### Example code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001414
1415```cpp
1416VkResult
1417vkCreateDevice(
1418 VkPhysicalDevice gpu,
1419 const VkDeviceCreateInfo *pCreateInfo,
1420 const VkAllocationCallbacks *pAllocator,
1421 VkDevice *pDevice)
1422{
1423 VkLayerDeviceCreateInfo *chain_info =
1424 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1425
1426 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1427 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1428 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1429 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1430 PFN_vkCreateDevice fpCreateDevice =
1431 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1432 if (fpCreateDevice == NULL) {
1433 return VK_ERROR_INITIALIZATION_FAILED;
1434 }
1435
1436 // Advance the link info for the next element on the chain
1437 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1438
1439 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1440 if (result != VK_SUCCESS) {
1441 return result;
1442 }
1443
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001444 // initialize layer's dispatch table
1445 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001446 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001447 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001448
1449 // Other layer initialization
1450 ...
1451
1452 return VK_SUCCESS;
1453}
1454```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001455
Jon Ashburncc300a22016-02-11 14:57:30 -07001456#### Special Considerations
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001457##### Associating private data with Vulkan objects within a layer
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001458A layer may want to associate it's own private data with one or more Vulkan
1459objects.
1460Two common methods to do this are hash maps and object wrapping. The loader
1461supports layers wrapping any Vulkan object including dispatchable objects.
1462Layers which wrap objects should ensure they always unwrap objects before
1463passing them down the chain. This implies the layer must intercept every Vulkan
1464command which uses the object in question. Layers above the object wrapping
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001465layer will see the wrapped object. Layers which wrap dispatchable objects must
1466ensure that the first field in the wrapping structure is a pointer to a dispatch table
1467as defined in vk_layer.h. Specifically, an instance wrapped dispatchable object
1468could be as follows:
1469```
1470struct my_wrapped_instance_obj_ {
1471 VkLayerInstanceDispatchTable *disp;
1472 // whatever data layer wants to add to this object
1473};
1474```
1475A device wrapped dispatchable object could be as follows:
1476```
1477struct my_wrapped_instance_obj_ {
1478 VkLayerDispatchTable *disp;
1479 // whatever data layer wants to add to this object
1480};
1481```
Jeff Julianof1619872016-02-17 17:25:42 -05001482
1483Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001484given object. The key to the map could be the object. Alternatively, for
1485dispatchable objects at a given level (eg device or instance) the layer may
1486want data associated with the VkDevice or VkInstance objects. Since
Jeff Julianof1619872016-02-17 17:25:42 -05001487there are multiple dispatchable objects for a given VkInstance or VkDevice, the
1488VkDevice or VkInstance object is not a great map key. Instead the layer should
1489use the dispatch table pointer within the VkDevice or VkInstance since that
1490will be unique for a given VkInstance or VkDevice.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001491
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001492##### Creating new dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001493Layers which create dispatchable objects take special care. Remember that loader
1494trampoline code normally fills in the dispatch table pointer in the newly
1495created object. Thus, the layer must fill in the dispatch table pointer if the
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001496loader trampoline will not do so. Common cases where a layer (or ICD) may create a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001497dispatchable object without loader trampoline code is as follows:
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001498- object wrapping layers that wrap dispatchable objects
1499- layers which add extensions that create dispatchable objects
1500- layers which insert extra Vulkan commands in the stream of commands they
1501intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001502- ICDs which add extensions that create dispatchable objects
1503
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001504The Windows/Linux loader provides a callback that can be used for initializing
1505a dispatchable object. The callback is passed as an extension structure via the
1506pNext field in VkInstanceCreateInfo and VkDeviceCreateInfo. The callback prototype
1507is defined as follows for instance and device callbacks respectively (see vk_layer.h):
1508```
1509VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance, void *object);
1510VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData)(VkDevice device, void *object);
1511```
1512To obtain these callbacks the layer must search through the list of structures
1513pointed to by the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo parameters to find any callback structures inserted by the loader. The salient details are as follows:
1514- For CreateInstance the callback structure pointed to by "pNext" is VkLayerInstanceCreateInfo as defined in vk_layer.h.
1515- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within VkInstanceCreateInfo parameter indicates a loader structure.
1516- Within VkLayerInstanceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1517- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetInstanceLoaderData".
1518- For CreateDevice the callback structure pointed to by "pNext" is VkLayerDeviceCreateInfo as defined in include/vulkan/vk_layer.h.
1519- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within VkDeviceCreateInfo parameter indicates a loader structure.
1520- Within VkLayerDeviceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1521- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetDeviceLoaderData".
1522
1523Alternatively, if an older loader is being used that doesn't provide these callbacks, the layer may manually initialize the newly created dispatchable object.
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001524To fill in the dispatch table pointer in newly created dispatchable object,
1525the layer should copy the dispatch pointer, which is always the first entry in the structure, from an existing parent object of the same level (instance versus
1526device). For example, if there is a newly created VkCommandBuffer object, then the dispatch pointer from the VkDevice object, which is the parent of the VkCommandBuffer object, should be copied into the newly created object.
Jon Ashburnc2972682016-02-08 15:42:01 -07001527