blob: ba859f1c2b869afabbb010b13ebb13373c0e1a75 [file] [log] [blame] [view]
Jon Ashburnc2972682016-02-08 15:42:01 -07001# Vulkan Loader Specification and Architecture Overview
2
3
4Goals of this document
5----------------------
6
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
11Audience
12--------
13
14Application, Vulkan driver and Vulkan layer developers.
15
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070016Any developers interested in understanding more about loader and layer behavior
17and architecture.
Jon Ashburnc2972682016-02-08 15:42:01 -070018
19
20Loader goals
21------------
22
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070023- Support multiple ICDs (Installable Client Drivers) to co-exist on a system
24without interfering with each other.
Jon Ashburnc2972682016-02-08 15:42:01 -070025
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070026- Support optional modules (layers) that can be enabled by an application,
27developer or the system and have no impact when not enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -070028
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070029- Negligible performance cost for an application calling through the loader
30to an ICD entry point.
Jon Ashburnc2972682016-02-08 15:42:01 -070031
32Architectural overview of layers and loader
33-------------------------------------------
34
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070035Vulkan is a layered architecture. Layers can hook (intercept) Vulkan commands to
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070036achieve various functionality that a Vulkan driver (aka ICD) or loader doesn’t
37support. Functionality such as Vulkan API tracing and debugging, API usage
38validation, and other tools such as framebuffer overlays are all natural
39candidates for Vulkan layers. Layers are implemented as libraries that are
40inserted between the application and the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -070041
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070042Not only is Vulkan a layered architecture but it also supports multiple GPUs
43and their drivers. Vulkan commands called by an application may wind up calling
44into a diverse set of modules: loader, layers, and ICDs. The loader is critical
45to managing the proper dispatching of Vulkan commands to the appropriate set of
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070046layers and ICDs. The Vulkan object model allows the loader to insert layers
47into a call chain so the layers can process Vulkan commands prior to the
48ICD being called.
Jon Ashburnc2972682016-02-08 15:42:01 -070049
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070050Vulkan uses an object model to control the scope of a particular action /
51operation. The object to be acted on is always the first parameter of a Vulkan
52call and is a dispatchable object (see Vulkan specification section 2.2 Object
53Model). Under the covers, the dispatchable object handle is a pointer to a
54structure that contains a pointer to a dispatch table maintained by the loader.
55This dispatch table contains pointers to the Vulkan functions appropriate to
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070056that object. There are two types of dispatch tables the loader maintains,
57Instance and Device. I.e. a VkInstance object’s dispatch table will point to Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070058functions such as vkEnumeratePhysicalDevices, vkDestroyInstance,
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070059vkCreateInstance, etc. Instance functions take a VkInstance or VkPhysicalDevice as
60their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070061
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070062Device objects have a separate dispatch table containing the appropriate
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070063function pointers. The device dispatch table is used for all functions that
64take a VkDevice, VkQueue or VkCommandBuffer as their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070065
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070066These instance and device dispatch tables are constructed when the application
67calls vkCreateInstance and vkCreateDevice. At that time the application and/or
68system can specify optional layers to be included. The loader will initialize
69the specified layers to create a call chain for each Vulkan function and each
70entry of the dispatch table will point to the first element of that chain.
71Thus, the loader builds an instance call chain for each VkInstance that is
72created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070073
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070074For example, the diagram below represents what happens in the call chain for
75vkCreateInstance. After initializing the chain, the loader will call into the
76first layer’s vkCreateInstance which will call the next finally terminating in
77the loader again where this function calls every ICD’s vkCreateInstance and
78saves the results. This allows every enabled layer for this chain to set up
79what it needs based on the VkInstanceCreateInfo structure from the application.
Jon Ashburnc2505562016-02-15 10:19:26 -070080![Instance call chain](instance_call_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070081
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070082This also highlights some of the complexity the loader must manage when using
83instance chains. As shown here, the loader must aggregate information from
84multiple devices when they are present. This means that the loader has to know
85about instance level extensions to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -070086
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070087Device chains are created at vkCreateDevice and are generally simpler because
88they deal with only a single device and the ICD can always be the terminator of
89the chain. The below diagram also illustrates how layers (either device or
90instance) can skip intercepting any given Vulkan entry point.
Jon Ashburnc2505562016-02-15 10:19:26 -070091![Chain skipping layers](chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070092
93Application interface to loader
94-------------------------------
95
96In this section we’ll discuss how an application interacts with the loader.
97
98- Linking to loader library for core and WSI extension symbols.
99
100- Dynamic Vulkan command lookup & application dispatch table.
101
102- Loader library filenames for linking to different Vulkan ABI versions.
103
104- Layers
105
106- Extensions
107
108- vkGetInstanceProcAddr, vkGetDeviceProcAddr
109
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700110The loader library on Windows, Linux and Android will export all core Vulkan
111and all appropriate Window System Interface (WSI) extensions. This is done to
112make it simpler to get started with Vulkan development. When an application
113links directly to the loader library in this way, the Vulkan calls are simple
114trampoline functions that jump to the appropriate dispatch table entry for the
115object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700116
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700117Applications are not required to link directly to the loader library, instead
118they can use the appropriate platform specific dynamic symbol lookup on the
119loader library to initialize the application’s own dispatch table. This allows
Jeff Julianof1619872016-02-17 17:25:42 -0500120an application to fail gracefully if the loader cannot be found, and it
121provides the fastest mechanism for the application to call Vulkan functions. An
122application will only need to query (via system calls such as dlsym()) the
123address of vkGetInstanceProcAddr from the loader library. Using
124vkGetInstanceProcAddr the application can then discover the address of all
125instance and global functions and extensions, such as vkCreateInstance,
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700126vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties
127in a platform independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700128
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700129The Vulkan loader library will be distributed in various ways including Vulkan
130SDKs, OS package distributions and IHV driver packages. These details are
131beyond the scope of this document. However, the name and versioning of the
132Vulkan loader library is specified so an app can link to the correct Vulkan ABI
133library version. Vulkan versioning is such that ABI backwards compatibility is
Jeff Julianof1619872016-02-17 17:25:42 -0500134guaranteed for all versions with the same major number (e.g. 1.0 and 1.1). On
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700135Windows, the loader library encodes the ABI version in its name such that
136multiple ABI incompatible versions of the loader can peacefully coexist on a
Jeff Julianof1619872016-02-17 17:25:42 -0500137given system. The Vulkan loader library file name is “vulkan-<ABI
138version>.dll”. For example, for Vulkan version 1.X on Windows the library
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700139filename is vulkan-1.dll. And this library file can typically be found in the
140windows/system32 directory.
Jon Ashburnc2972682016-02-08 15:42:01 -0700141
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700142For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
143number is not encoded in the base of the library filename as on Windows. On
144Linux an application wanting to link to the latest Vulkan ABI version would
145just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500146also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700147
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700148Applications desiring Vulkan functionality beyond what the core API offers may
149use various layers or extensions. A layer cannot add new or modify existing
150Vulkan commands, but may offer extensions that do. A common use of layers is
151for API validation. A developer can use validation layers during application
152development, but during production the layers can be disabled by the
Jeff Julianof1619872016-02-17 17:25:42 -0500153application. Thus, eliminating the overhead of validating the application's
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700154usage of the API. Layers discovered by the loader can be reported to the
155application via vkEnumerateInstanceLayerProperties and
156vkEnumerateDeviceLayerProperties, for instance and device layers respectively.
157Instance layers are enabled at vkCreateInstance; device layers are enabled at
158vkCreateDevice. For example, the ppEnabledLayerNames array in the
159VkDeviceCreateInfo structure is used by the application to list the device
160layer names to be enabled at vkCreateDevice. At vkCreateInstance and
161vkCreateDevice, the loader will construct call chains that include the
162application specified (enabled) layers. Order is important in the
163ppEnabledLayerNames array; array element 0 is the topmost (closest to the
164application) layer inserted in the chain and the last array element is closest
165to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700166
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700167Developers may want to enable layers that are not enabled by the given
168application they are using. On Linux and Windows, the environment variables
169“VK\_INSTANCE\_LAYERS” and “VK\_DEVICE\_LAYERS” can be used to enable
170additional layers which are not specified (enabled) by the application at
171vkCreateInstance/vkCreateDevice. VK\_INSTANCE\_LAYERS is a colon
172(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
173relevant with the first layer in the list being the topmost layer (closest to
174the application) and the last layer in the list being the bottommost layer
175(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700176
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700177Application specified layers and user specified layers (via environment
178variables) are aggregated and duplicates removed by the loader when enabling
179layers. Layers specified via environment variable are topmost (closest to the
180application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700181
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700182An example of using these environment variables to activate the validation
183layer VK\_LAYER\_LUNARG\_param\_checker on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700184
185```
Jon Ashburncc300a22016-02-11 14:57:30 -0700186> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700187
Jon Ashburncc300a22016-02-11 14:57:30 -0700188> $ export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700189```
190
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700191**Note**: Many layers, including all LunarG validation layers are “global”
192(i.e. both instance and device) layers and *must* be enabled on both the
193instance and device chains to function properly. This is required for “global”
194layers regardless of which method is used to enable the layer (application or
195environment variable).
Jon Ashburnc2972682016-02-08 15:42:01 -0700196
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700197Some platforms, including Linux and Windows, support layers which are enabled
198automatically by the loader rather than explicitly by the application (or via
199environment variable). Explicit layers are those layers enabled by the
200application (or environment variable) by providing the layer name. Implicit
201layers are those layers enabled by the loader automatically. Any implicit
202layers the loader discovers on the system in the appropriate location will be
203enabled (subject to environment variable overrides described later). Discovery
204of properly installed implicit and explicit layers is described later.
205Explicitly enabling a layer that is implicitly enabled has no additional
206effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700207
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700208Extensions are optional functionality provided by a layer, the loader or an
209ICD. Extensions can modify the behavior of the Vulkan API and need to be
210specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700211
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700212Instance extensions can be discovered via
213vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
214vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
215extensions from layers (both explicit and implicit), ICDs and the loader before
216reporting them to the application in vkEnumerate\*ExtensionProperties. The
Jeff Julianof1619872016-02-17 17:25:42 -0500217pLayerName parameter in these functions is used to select either a single layer
218or the Vulkan platform implementation. If pLayerName is NULL, extensions from
219Vulkan implementation components (including loader, implicit layers, and ICDs)
220are enumerated. If pLayerName is equal to a discovered layer module name then
221any extensions from that layer (which may be implicit or explicit) are
222enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700223support for the same extension) are eliminated by the loader. Extensions must
224be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700225
Jeff Julianof1619872016-02-17 17:25:42 -0500226[jjuliano] In previous paragraph, which survives, and which is duplicated?
227 E.g., if a layer and an ICD both expose the same extension, is the layer's
228 version culled, or is the ICD's version culled?
229
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700230Extension command entry points should be queried via vkGetInstanceProcAddr or
231vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
232extension or core device entry points. Device entry points include any command
233that uses a VkDevice as the first parameter or a dispatchable object that is a
234child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
235vkGetInstanceProcAddr can be used to query either device or instance extension
236entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700237
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700238VkGetDeviceProcAddr is particularly interesting because it will provide the
239most efficient way to call into the ICD. For example, the diagram below shows
240what could happen if the application were to use vkGetDeviceProcAddr for the
241function “vkGetDeviceQueue” and “vkDestroyDevice” but not “vkAllocateMemory”.
242The resulting function pointer (fpGetDeviceQueue) would be the ICD’s entry
243point if the loader and any enabled layers do not need to see that call. Even
Jeff Julianof1619872016-02-17 17:25:42 -0500244if an enabled layer intercepts the call (e.g. vkDestroyDevice) the loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700245trampoline code is skipped for function pointers obtained via
246vkGetDeviceProcAddr. This also means that function pointers obtained via
247vkGetDeviceProcAddr will only work with the specific VkDevice it was created
248for, using it with another device has undefined results. For extensions,
249Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700250
Jon Ashburnc2505562016-02-15 10:19:26 -0700251![Get*ProcAddr efficiency](get_proc_addr.png)
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700252
Jon Ashburnc2972682016-02-08 15:42:01 -0700253
254Vulkan Installable Client Driver interface with the loader
255----------------------------------------------------------
256
257### ICD discovery
258
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700259Vulkan allows multiple drivers each with one or more devices (represented by a
260Vulkan VkPhysicalDevice object) to be used collectively. The loader is
261responsible for discovering available Vulkan ICDs on the system. Given a list
262of available ICDs, the loader can enumerate all the physical devices available
263for an application and return this information to the application. The process
264in which the loader discovers the available Installable Client Drivers (ICDs)
265on a system is platform dependent. Windows, Linux and Android ICD discovery
266details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700267
268#### Windows
269
270##### Properly-Installed ICDs
271
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700272In order to find properly-installed ICDs, the Vulkan loader will scan the
273values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700274
275HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
276
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700277For each value in this key which has DWORD data set to 0, the loader opens the
278JSON format text information file (a.k.a. "manifest file") specified by the
279name of the value. Each name must be a full pathname to the text manifest file.
280The Vulkan loader will open each manifest file to obtain the name or pathname
281of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700282
Jon Ashburncc300a22016-02-11 14:57:30 -0700283 ```
284 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700285 "file_format_version": "1.0.0",
286 "ICD": {
287 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700288 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700289 }
290 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700291 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700292
293
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700294The "library\_path" specifies either a filename, a relative pathname, or a full
295pathname to an ICD shared library file, which the loader will attempt to load
296using LoadLibrary(). If the ICD is specified via a filename, the shared library
297lives in the system's DLL search path (e.g. in the "C:\\\\Windows\\\\System32"
298folder). If the ICD is specified via a relative pathname, it is relative to the
299path of the manifest file. Relative pathnames are those that do not start with
300a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
301character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700302
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700303The "file\_format\_version" specifies a major.minor.patch version number in
304case the format of the text information file changes in the future. If the same
305ICD shared library supports multiple, incompatible versions of text manifest
306file format versions, it must have multiple text info files (all of which may
307point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700308
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700309The “api\_version” specifies the major.minor.patch version number of the Vulkan
310API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700311
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700312There are no rules about the name of the text information files (except the
313.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700314
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700315There are no rules about the name of the ICD shared library files. For example,
316if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700317
Jon Ashburncc300a22016-02-11 14:57:30 -0700318```
319[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700320
Jon Ashburncc300a22016-02-11 14:57:30 -0700321"C:\vendor a\vk\_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700322
Jon Ashburncc300a22016-02-11 14:57:30 -0700323"C:\windows\system32\vendorb\_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700324
Jon Ashburncc300a22016-02-11 14:57:30 -0700325"C:\windows\system32\vendorc\_icd.json"=dword:00000000
326```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700327then the loader will open the following text information files, with the
328specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700329
Jon Ashburncc300a22016-02-11 14:57:30 -0700330| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700331|----------------|--------------------|
Jon Ashburncc300a22016-02-11 14:57:30 -0700332|vk\_vendora.json | "ICD": { "library\_path": "C:\\\\VENDORA\\\\vk\_vendora.dll", "api_version": "1.0.3" } |
333| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.3" } |
334|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.3" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700335
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700336Then the loader will open the three files mentioned in the "Text File Contents"
337column, and then try to load and use the three shared libraries indicated by
338the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700339
340##### Using Pre-Production ICDs
341
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700342IHV developers (and sometimes other developers) need to use special,
343pre-production ICDs. In some cases, a pre-production ICD may be in an
344installable package. In other cases, a pre-production ICD may simply be a
345shared library in the developer's build tree. In this latter case, we want to
346allow developers to point to such an ICD without modifying the
347properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700348
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700349This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
350which will override the mechanism used for finding properly-installed ICDs. In
351other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
352"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
353text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700354
Jon Ashburncc300a22016-02-11 14:57:30 -0700355- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700356
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700357Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
358file for a developer-built ICD. A semi-colon is only used if more than one ICD
359is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700360
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700361For example, if a developer wants to refer to one ICD that they built, they
362could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700363
Jon Ashburncc300a22016-02-11 14:57:30 -0700364C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700365
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700366If a developer wants to refer to two ICDs, one of which is a properly-installed
367ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700368
Jon Ashburncc300a22016-02-11 14:57:30 -0700369C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700370
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700371Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
372"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700373
374#### Linux
375
376##### Properly-Installed ICDs
377
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700378In order to find properly-installed ICDs, the Vulkan loader will scan the files
379in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700380
381/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700382/etc/vulkan/icd.d
383
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700384These directories will contain text information files (a.k.a. "manifest
385files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700386
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700387The Vulkan loader will open each manifest file found to obtain the name or
388pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700389
Jon Ashburncc300a22016-02-11 14:57:30 -0700390```
391{
Jon Ashburnc2972682016-02-08 15:42:01 -0700392 "file_format_version": "1.0.0",
393 "ICD": {
394 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700395 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700396 }
397}
Jon Ashburncc300a22016-02-11 14:57:30 -0700398```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700399The "library\_path" specifies either a filename, a relative pathname, or a full
400pathname to an ICD shared library file. If the ICD is specified via a filename,
401the loader will attempt to open that file as a shared object using dlopen(),
402and the file must be in a directory that dlopen is configured to look in (Note:
403various distributions are configured differently). A distribution is free to
404create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
405required to do so. If the ICD is specified via a relative pathname, it is
406relative to the path of the info file. Relative pathnames are those that do not
407start with, but do contain at least one directory separator (i.e. the '/'
408character). For example, "lib/vendora.so" and "./vendora.so" are examples of
409relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700410
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700411The "file\_format\_version" provides a major.minor.patch version number in case
412the format of the manifest file changes in the future. If the same ICD shared
413library supports multiple, incompatible versions of manifest file format
414versions, it must have multiple manifest files (all of which may point to the
415same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700416
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700417The “api\_version” specifies the major.minor.patch version number of the Vulkan
418API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700419
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700420The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
421Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
422ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700423
424There are no rules about the name of the text files (except the .json suffix).
425
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700426There are no rules about the name of the ICD shared library files. For example,
427if the "/usr/share/vulkan/icd.d" directory contain the following files, with
428the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700429
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700430| Text File Name | Text File Contents |
431|-------------------|------------------------|
432| vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.3" } |
Jon Ashburncc300a22016-02-11 14:57:30 -0700433| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.3" } |
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700434| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.3" } |
Jon Ashburnc2972682016-02-08 15:42:01 -0700435
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700436then the loader will open the three files mentioned in the "Text File Contents"
437column, and then try to load and use the three shared libraries indicated by
438the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700439
440##### Using Pre-Production ICDs
441
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700442IHV developers (and sometimes other developers) need to use special,
443pre-production ICDs. In some cases, a pre-production ICD may be in an
444installable package. In other cases, a pre-production ICD may simply be a
445shared library in the developer's build tree. In this latter case, we want to
446allow developers to point to such an ICD without modifying the
447properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700448
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700449This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
450which will override the mechanism used for finding properly-installed ICDs. In
451other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700452
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700453The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
454manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700455
456- A filename (e.g. "libvkicd.json") in the "/usr/share/vulkan/icd.d" or "/etc/vulkan/icd.d" system directories
457
458- A full pathname (e.g. "/my\_build/my\_icd.json")
459
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700460Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
461file for a developer-built ICD. A colon is only used if more than one ICD is
462listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700463
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700464For example, if a developer wants to refer to one ICD that they built, they
465could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700466
467/my\_build/my\_icd.json
468
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700469If a developer wants to refer to two ICDs, one of which is a properly-installed
470ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700471
472vendorc\_vulkan.json:/my\_build/my\_icd.json
473
474Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
475
476NOTE: this environment variable will be ignored for suid programs.
477
478#### Android
479
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700480The Android loader lives in the system library folder. The location cannot be
481changed. The loader will load the driver/ICD via hw_get_module with the ID
482of "vulkan". Due to security policies in Android none of this can be modified
483under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700484
485
Jon Ashburncc300a22016-02-11 14:57:30 -0700486ICD interface requirements
487----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700488
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700489Generally, for all Vulkan commands issued by an application, the loader can be
490viewed as a pass through. That is, the loader generally doesn’t modified the
491commands or their parameters but simply calls the ICDs entry point for that
492command. Thus, the loader to ICD interface requirements will be specified by
493covering two areas: 1) Obtaining ICD Vulkan entry points; 2) Specifying
494requirements for a given Vulkan command(s) over and above the Vulkan
495specification requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700496
497#### Windows and Linux
498
499##### Obtaining ICD entry points
500
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700501Currently, two methods of the loader finding ICD entry points are supported on
502Linux and Windows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700503
5041) Recommended
505
Jeff Julianof1619872016-02-17 17:25:42 -0500506- vk\_icdGetInstanceProcAddr is exported by the ICD library and it returns
507 valid function pointers for all the global level and instance level Vulkan
508 commands, and also for vkGetDeviceProcAddr. Global level commands are those
509 which contain no dispatchable object as the first parameter, such as
510 vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must
511 support querying global level entry points by calling
512 vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level
513 commands are those that have either VkInstance, or VkPhysicalDevice as the
514 first parameter dispatchable object. Both core entry points and any instance
515 extension entry points the ICD supports should be available via
516 vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and
517 use new instance level dispatchable objects other than VkInstance and
518 VkPhysicalDevice, in which case extension entry points using these newly
519 defined dispatchable objects must be queryable via
520 vk\_icdGetInstanceProcAddr.
Jon Ashburnc2972682016-02-08 15:42:01 -0700521
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700522- All other Vulkan entry points must either NOT be exported from the ICD
523 library or else NOT use the official Vulkan function names if they are
524 exported. This requirement is for ICD libraries that include other
525 functionality (such as OpenGL library) and thus could be loaded by the
526 application prior to when the Vulkan loader library is loaded by the
527 application. In other words, the ICD library exported Vulkan symbols must not
528 clash with the loader's exported Vulkan symbols.
Jon Ashburnc2972682016-02-08 15:42:01 -0700529
Jeff Julianof1619872016-02-17 17:25:42 -0500530- Beware of interposing by dynamic OS library loaders if the official Vulkan
531 names are used. On Linux, if official names are used, the ICD library must be
532 linked with -Bsymbolic.
533
Jon Ashburnc2972682016-02-08 15:42:01 -07005342) Deprecated
535
Jeff Julianof1619872016-02-17 17:25:42 -0500536[jjuliano] Is it time to remove the deprecated method?
537
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700538- vkGetInstanceProcAddr exported in the ICD library and returns valid function
Jeff Julianof1619872016-02-17 17:25:42 -0500539 pointers for all the Vulkan API entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700540
541- vkCreateInstance exported in the ICD library;
542
543- vkEnumerateInstanceExtensionProperties exported in the ICD library;
544
545##### Loader specific requirements for Vulkan commands
546
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700547Normally, ICDs handle object creation and destruction for various Vulkan
548objects. The WSI surface extensions for Linux and Windows
549(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
550VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
551handled differently. For these extensions, the VkSurfaceKHR object creation and
552destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700553
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005541. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
555 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700556
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005572. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
558 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700559
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005603. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
561 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700562
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005634. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
Jeff Julianof1619872016-02-17 17:25:42 -0500564 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field
565 in the structure is a VkIcdSurfaceBase enumerant that indicates whether the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700566 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700567
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700568As previously covered, the loader requires dispatch tables to be accessible
569within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
570VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
571dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700572
Jon Ashburncc300a22016-02-11 14:57:30 -0700573- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700574
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700575- The loader will replace the first entry with a pointer to the dispatch table
576 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700577
Jon Ashburncc300a22016-02-11 14:57:30 -07005781. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700579
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005802. This pointer points to a regular C structure with the first entry being a
581 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
582 classes. The C\++ compiler may put a vtable at offset zero if your class is
Jeff Julianof1619872016-02-17 17:25:42 -0500583 non-POD due to the use of a virtual function. In this case use a regular C
584 structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700585
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005863. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
587 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700588
589```
590
Jon Ashburncc300a22016-02-11 14:57:30 -0700591#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700592
Jon Ashburncc300a22016-02-11 14:57:30 -0700593union _VK_LOADER_DATA {
594 uintptr loadermagic;
595 void *loaderData;
596} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700597
Jon Ashburncc300a22016-02-11 14:57:30 -0700598vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700599{
Jon Ashburncc300a22016-02-11 14:57:30 -0700600 vkObj *newObj = alloc_obj();
601 ...
602 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700603
Jon Ashburncc300a22016-02-11 14:57:30 -0700604 set_loader_magic_value(newObj);
605 ...
606 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700607}
Jon Ashburnc2972682016-02-08 15:42:01 -0700608```
609
610Additional Notes:
611
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700612- The loader will filter out extensions requested in vkCreateInstance and
613vkCreateDevice before calling into the ICD; Filtering will be of extensions
Jeff Julianof1619872016-02-17 17:25:42 -0500614advertised by entities (e.g. layers) different from the ICD in question.
615- The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700616properties are obtained from the layer libraries and layer JSON files.
617- If an ICD library wants to implement a layer it can do so by having the
618appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700619- The loader will not call the ICD for
620 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburnc2972682016-02-08 15:42:01 -0700621- The ICD may or may not implement a dispatch table.
622
Jeff Julianof1619872016-02-17 17:25:42 -0500623[jjuliano] what is the value of pointing out the optional presence of a
624 dispatch table?
625
Jon Ashburnc2972682016-02-08 15:42:01 -0700626#### Android
627
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700628The Android loader uses the same protocol for initializing the dispatch
629table as described above. The only difference is that the Android
630loader queries layer and extension information directly from the
631respective libraries and does not use the json manifest files used
632by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700633
634Vulkan layer interface with the loader
635--------------------------------------
636
637### Layer discovery
638
639#### Windows
640
641##### Properly-Installed Layers
642
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700643In order to find properly-installed layers, the Vulkan loader will use a
644similar mechanism as used for ICDs. Text information files (aka manifest
645files), that use a JSON format, are read in order to identify the names and
646attributes of layers and their extensions. The use of manifest files allows the
647loader to avoid loading any shared library files when the application does not
648query nor request any extensions. Layers and extensions have additional
649complexity, and so their manifest files contain more information than ICD info
650files. For example, a layer shared library file may contain multiple
651layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700652
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700653In order to find properly-installed layers, the Vulkan loader will scan the
654values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700655
656HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
657
658HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
659
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700660Explicit layers are those which are enabled by an application (e.g. with the
661vkCreateInstance function), or by an environment variable (as mentioned
662previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700663
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700664Implicit layers are those which are enabled by their existence. For example,
665certain application environments (e.g. Steam or an automotive infotainment
666system) may have layers which they always want enabled for all applications
667that they start. Other implicit layers may be for all applications started on a
668given system (e.g. layers that overlay frames-per-second). Implicit layers are
669enabled automatically, whereas explicit layers must be enabled explicitly. What
670distinguishes a layer as implicit or explicit is by which registry key its
671layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700672
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700673For each value in these keys which has DWORD data set to 0, the loader opens
674the JSON manifest file specified by the name of the value. Each name must be a
675full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700676
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700677The Vulkan loader will open each info file to obtain information about the
678layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700679
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700680This manifest file is in the JSON format and contains the following
681information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700682
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700683- (required) "file\_format\_version" - same as for ICDs, except that the format
684version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700685
686- (required) "name" - layer name
687
688- (required) "type" - which layer chains should the layer be activated on.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700689Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
690both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700691
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700692- (required) "library\_path" - filename / full path / relative path to the
693library file
Jon Ashburnc2972682016-02-08 15:42:01 -0700694
695- (required) "api\_version" - same as for ICDs.
696
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700697- (required) "implementation\_version" - layer version, a single number
698increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700699
700- (required) "description" - informative description of the layer.
701
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700702- (optional) "device\_extensions" or "instance\_extensions" - array of
703extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700704
Jon Ashburncc300a22016-02-11 14:57:30 -0700705 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700706
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700707 - (required) extension "spec\_version" - extension specification version, a
708single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700709
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700710 - (required for device\_extensions with entry points) extension
Jeff Julianof1619872016-02-17 17:25:42 -0500711"entrypoints" - array of device extension entry points; not used for instance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700712extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700713
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700714- (sometimes required) "functions" - mapping list of function entry points. If
715multiple layers exist within the same shared library (or if a layer is in the
716same shared library as an ICD), this must be specified to allow each layer to
Jeff Julianof1619872016-02-17 17:25:42 -0500717have its own vkGet\*ProcAddr entry points that can be found by the loader. At
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700718this time, only the following two functions are required:
Jon Ashburnc2972682016-02-08 15:42:01 -0700719
Jon Ashburncc300a22016-02-11 14:57:30 -0700720 - "vkGetInstanceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700721
Jon Ashburncc300a22016-02-11 14:57:30 -0700722 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700723
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700724- (optional for implicit layers) "enable\_environment" requirement(s) -
725environment variable and value required to enable an implicit layer. This
726environment variable (which should vary with each "version" of the layer, as in
727"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
728layer is not loaded. This is for application environments (e.g. Steam) which
729want to enable a layer(s) only for applications that they launch, and allows
730for applications run outside of an application environment to not get that
731implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700732
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700733- (required for implicit layers) "disable\_environment" requirement(s) -
734environment variable and value required to disable an implicit layer. Note: in
735rare cases of an application not working with an implicit layer, the
736application can set this environment variable (before calling Vulkan functions)
737in order to "blacklist" the layer. This environment variable (which should vary
738with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
739(not particularly to any value). If both the "enable\_environment" and
740"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700741
742For example:
743
Jon Ashburncc300a22016-02-11 14:57:30 -0700744```
Jon Ashburnc2972682016-02-08 15:42:01 -0700745{
Jon Ashburncc300a22016-02-11 14:57:30 -0700746"file_format_version" : "1.0.0",
747"layer": {
748 "name": "VK_LAYER_LUNARG_OverlayLayer",
749 "type": "DEVICE",
750 "library_path": "vkOverlayLayer.dll"
751 "api_version" : "1.0.3",
752 "implementation_version" : "2",
753 "description" : "LunarG HUD layer",
754 "functions": {
755 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
756 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
757 },
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700758 "instance_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700759 {
760 "name": "VK_debug_report_EXT",
761 "spec_version": "1"
762 },
763 {
764 "name": "VK_VENDOR_DEBUG_X",
765 "spec_version": "3"
766 }
767 ],
Courtney Goeltzenleuchter84a75ce2016-02-15 15:07:54 -0700768 "device_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700769 {
770 "name": "VK_LUNARG_DEBUG_MARKER",
771 "spec_version": "1",
772 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
773 }
774 ],
775 "disable_environment": {
776 "DISABLE_LAYER_OVERLAY_1": ""
777 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700778}
Jon Ashburnc2972682016-02-08 15:42:01 -0700779}
Jon Ashburncc300a22016-02-11 14:57:30 -0700780```
Jon Ashburnc2972682016-02-08 15:42:01 -0700781
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700782The "library\_path" specifies either a filename, a relative pathname, or a full
783pathname to a layer shared library (".dll") file, which the loader will attempt
784to load using LoadLibrary(). If the layer is specified via a relative pathname,
785it is relative to the path of the info file (e.g. for cases when an application
786provides a layer that is in the same folder hierarchy as the rest of the
787application files). If the layer is specified via a filename, the shared
788library lives in the system's DLL search path (e.g. in the
789"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700790
791There are no rules about the name of the text files (except the .json suffix).
792
793There are no rules about the name of the layer shared library files.
794
795##### Using Pre-Production Layers
796
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700797As with ICDs, developers may need to use special, pre-production layers,
798without modifying the properly-installed layers. This need is met with the use
799of the "VK\_LAYER\_PATH" environment variable, which will override the
800mechanism using for finding properly-installed layers. Because many layers may
801exist on a system, this environment variable is a semi-colon-separated list of
802folders that contain layer info files. Only the folder listed in
803"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
804entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700805
806- The full pathname of a folder containing layer info files
807
808#### Linux
809
810##### Properly-Installed Layers
811
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700812In order to find properly-installed layers, the Vulkan loader will use a
813similar mechanism as used for ICDs. Text information files, that use a JSON
814format, are read in order to identify the names and attributes of layers and
815their extensions. The use of text info files allows the loader to avoid loading
816any shared library files when the application does not query nor request any
817extensions. Layers and extensions have additional complexity, and so their info
818files contain more information than ICD info files. For example, a layer shared
819library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700820
821The Vulkan loader will scan the files in the following Linux directories:
822
823/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700824/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700825/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700826/etc/vulkan/implicit\_layer.d
827
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700828Explicit layers are those which are enabled by an application (e.g. with the
829vkCreateInstance function), or by an environment variable (as mentioned
830previously). Implicit layers are those which are enabled by their existence.
831For example, certain application environments (e.g. Steam or an automotive
832infotainment system) may have layers which they always want enabled for all
833applications that they start. Other implicit layers may be for all applications
834started on a given system (e.g. layers that overlay frames-per-second).
835Implicit layers are enabled automatically, whereas explicit layers must be
836enabled explicitly. What distinguishes a layer as implicit or explicit is by
837which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700838
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700839The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
840installed from Linux-distribution-provided packages. The
841"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
842non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700843
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700844The information file is in the JSON format and contains the following
845information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700846
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700847- (required) "file\_format\_version" – same as for ICDs, except that the format
848version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700849
850- (required) "name" - layer name
851
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700852- (required) "type" - which layer chains should the layer be activated on.
853Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
854both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700855
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700856- (required) "library\_path" - filename / full path / relative path to the text
857file
Jon Ashburnc2972682016-02-08 15:42:01 -0700858
859- (required) "api\_version" – same as for ICDs.
860
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700861- (required) "implementation\_version" – layer version, a single number
862increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700863
Jeff Julianof1619872016-02-17 17:25:42 -0500864- (required) "description" – informative description of the layer.
Jon Ashburnc2972682016-02-08 15:42:01 -0700865
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700866- (optional) "device\_extensions" or "instance\_extensions" - array of
867extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700868
Jon Ashburncc300a22016-02-11 14:57:30 -0700869 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700870
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700871 - (required) extension "spec\_version" - extension specification version, a
872single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700873
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700874 - (required for device extensions with entry points) extension
Jeff Julianof1619872016-02-17 17:25:42 -0500875"entrypoints" - array of device extension entry points; not used for instance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700876extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700877
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700878- (sometimes required) "functions" - mapping list of function entry points. If
879multiple layers exist within the same shared library (or if a layer is in the
880same shared library as an ICD), this must be specified to allow each layer to
Jeff Julianof1619872016-02-17 17:25:42 -0500881have its own vkGet\*ProcAddr entry points that can be found by the loader. At
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700882this time, only the following two functions are required:
Jon Ashburncc300a22016-02-11 14:57:30 -0700883 - "vkGetInstanceProcAddr" name
884 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700885
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700886- (optional for implicit layers) "enable\_environment" requirement(s) -
887environment variable and value required to enable an implicit layer. This
888environment variable (which should vary with each "version" of the layer, as in
889"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
890layer is not loaded. This is for application environments (e.g. Steam) which
891want to enable a layer(s) only for applications that they launch, and allows
892for applications run outside of an application environment to not get that
893implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700894
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700895- (required for implicit layers) "disable\_environment" requirement(s) -
896environment variable and value required to disable an implicit layer. Note: in
897rare cases of an application not working with an implicit layer, the
898application can set this environment variable (before calling Vulkan functions)
899in order to "blacklist" the layer. This environment variable (which should vary
900with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
901(not particularly to any value). If both the "enable\_environment" and
902"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700903
904For example:
Jon Ashburncc300a22016-02-11 14:57:30 -0700905```
Jon Ashburnc2972682016-02-08 15:42:01 -0700906{
Jon Ashburncc300a22016-02-11 14:57:30 -0700907"file_format_version" : "1.0.0",
Jon Ashburnc2972682016-02-08 15:42:01 -0700908"layer": {
Jon Ashburncc300a22016-02-11 14:57:30 -0700909 "name": "VK_LAYER_LUNARG_OverlayLayer",
910 "type": "DEVICE",
911 "library_path": "vkOverlayLayer.dll"
912 "api_version" : "1.0.3",
913 "implementation_version" : "2",
914 "description" : "LunarG HUD layer",
915 "functions": {
916 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
917 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
918 },
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700919 "instance_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700920 {
921 "name": "VK_debug_report_EXT",
922 "spec_version": "1"
923 },
924 {
925 "name": "VK_VENDOR_DEBUG_X",
926 "spec_version": "3"
927 }
928 ],
Courtney Goeltzenleuchter84a75ce2016-02-15 15:07:54 -0700929 "device_extensions": [
Jon Ashburncc300a22016-02-11 14:57:30 -0700930 {
931 "name": "VK_LUNARG_DEBUG_MARKER",
932 "spec_version": "1",
933 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
934 }
935 ],
936 "disable_environment": {
937 "DISABLE_LAYER_OVERLAY_1": ""
938 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700939}
Jon Ashburnc2972682016-02-08 15:42:01 -0700940}
Jon Ashburncc300a22016-02-11 14:57:30 -0700941```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700942The "library\_path" specifies either a filename, a relative pathname, or a full
943pathname to a layer shared library (".so") file, which the loader will attempt
944to load using dlopen(). If the layer is specified via a filename, the loader
945will attempt to open that file as a shared object using dlopen(), and the file
946must be in a directory that dlopen is configured to look in (Note: various
947distributions are configured differently). A distribution is free to create
948Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
949required to do so. If the layer is specified via a relative pathname, it is
950relative to the path of the info file (e.g. for cases when an application
951provides a layer that is in the same directory hierarchy as the rest of the
952application files).
Jon Ashburnc2972682016-02-08 15:42:01 -0700953
954There are no rules about the name of the text files (except the .json suffix).
955
956There are no rules about the name of the layer shared library files.
957
958##### Using Pre-Production Layers
959
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700960As with ICDs, developers may need to use special, pre-production layers,
961without modifying the properly-installed layers. This need is met with the use
962of the "VK\_LAYER\_PATH" environment variable, which will override the
963mechanism using for finding properly-installed layers. Because many layers may
964exist on a system, this environment variable is a colon-separated list of
965directories that contain layer info files. Only the directories listed in
966"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
967is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700968
969- The full pathname of a directory containing layer info files
970
971NOTE: these environment variables will be ignored for suid programs.
972
973#### Android
974
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700975The recommended way to enable layers is for applications
976to programatically enable them. The layers are provided by the application
977and must live in the application's library folder. The application
978enables the layers at vkCreateInstance and vkCreateDevice as any Vulkan
979application would.
980An application enabled for debug has more options. It can enumerate and enable
981layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -0700982
Jon Ashburncc300a22016-02-11 14:57:30 -0700983Layer interface requirements
984------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700985
986#### Architectural interface overview
987
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700988There are two key architectural features that drive the loader to layer library
989interface: 1) separate and distinct instance and device call chains, and 2)
990distributed dispatch. First these architectural features will be described and
991then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -0700992
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700993Call chains are the links of calls for a given Vulkan command from layer module
994to layer module with the loader and or the ICD being the bottom most command.
995Call chains are constructed at both the instance level and the device level by
996the loader with cooperation from the layer libraries. Instance call chains are
997constructed by the loader when layers are enabled at vkCreateInstance. Device
998call chains are constructed by the loader when layers are enabled at
999CreateDevice. A layer can intercept Vulkan instance commands, device commands
1000or both. For a layer to intercept instance commands, it must participate in the
1001instance call chain. For a layer to intercept device commands, it must
1002participate in the device chain. Layers which participate in intercepting calls
Jeff Julianof1619872016-02-17 17:25:42 -05001003in both the instance and device chains are called global layers.
Jon Ashburnc2972682016-02-08 15:42:01 -07001004
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001005Normally, when a layer intercepts a given Vulkan command, it will call down the
1006instance or device chain as needed. The loader and all layer libraries that
1007participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001008from one entity to the next. This group effort for call chain sequencing is
Jeff Julianof1619872016-02-17 17:25:42 -05001009hereinafter referred to as distributed dispatch. In distributed dispatch, since
1010each layer is responsible for properly calling the next entity in the device or
1011instance chain, a dispatch mechanism is required for all Vulkan commands a
1012layer intercepts. For Vulkan commands that are not intercepted by a layer, or
1013if the layer chooses to terminate a given Vulkan command by not calling down
1014the chain, then no dispatch mechanism is needed for that particular Vulkan
1015command. Only for those Vulkan commands, which may be a subset of all Vulkan
1016commands, that a layer intercepts is a dispatching mechanism by the layer
1017needed. The loader is responsible for dispatching all core and instance
1018extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001019
Jeff Julianof1619872016-02-17 17:25:42 -05001020Instance level Vulkan commands are those that have the dispatchable objects
1021VkInstance, or VkPhysicalDevice as the first parameter and also includes
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001022vkCreateInstance.
Jeff Julianof1619872016-02-17 17:25:42 -05001023
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001024Device level Vulkan commands are those that use VkDevice, VkQueue or
1025VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1026extensions may introduce new instance or device level dispatchable objects, so
1027the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001028
Jeff Julianof1619872016-02-17 17:25:42 -05001029#### Discovery of layer entry points
1030
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001031For the layer libraries that have been discovered by the loader, their
1032intercepting entry points that will participate in a device or instance call
1033chain need to be available to the loader or whatever layer is before them in
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001034the chain. Layers have the following requirements in this area.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001035- A layer intercepting instance level Vulkan commands (aka an instance level
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001036layer) must implement a vkGetInstanceProcAddr type of function.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001037- This vkGetInstanceProcAddr type function must be exported by the layer
1038library. The name of this function is specified in various ways: 1) the layer
1039manifest JSON file in the "functions", "vkGetInstanceProcAddr" node
1040(Linux/Windows); 2) it is named "vkGetInstanceProcAddr"; 3) it is
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001041"<layerName>GetInstanceProcAddr" (Android).
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001042- A layer intercepting device level Vulkan commands (aka a device level layer)
1043must implement a vkGetDeviceProcAddr type of function.
1044- This vkGetDeviceProcAddr type function must be exported by the layer library.
1045The name of this function is specified in various ways: 1) the layer manifest
1046JSON file in the "functions", "vkGetDeviceProcAddr" node (Linux/Windows); 2) it
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001047is named "vkGetDeviceProcAddr"; 3) it is "<layerName>GetDeviceProcAddr"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001048(Android).
Jeff Julianof1619872016-02-17 17:25:42 -05001049- A layer's vkGetInstanceProcAddr function (regardless of its name) must return
1050the local entry points for all instance level Vulkan commands it intercepts. At
1051a minimum, this includes vkGetInstanceProcAddr and vkCreateInstance.
1052- A layer's vkGetDeviceProcAddr function (regardless of its name) must return
1053the entry points for all device level Vulkan commands it intercepts. At a
1054minimum, this includes vkGetDeviceProcAddr and vkCreateDevice.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001055- There are no requirements on the names of the intercepting functions a layer
1056implements except those listed above for vkGetInstanceProcAddr and
1057vkGetDeviceProcAddr.
1058- Currently a layer's VkGetInstanceProcAddr must be able to handle a VkInstance
1059parameter equal to NULL for
Jon Ashburnc2972682016-02-08 15:42:01 -07001060instance level commands it intercepts including vkCreateDevice.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001061- Currently a layer's VkGetDeviceProcAddr must be able to handle a VkDevice
1062parameter equal to NULL for device level commands it intercepts.
Jon Ashburnc2972682016-02-08 15:42:01 -07001063
1064#### Layer intercept requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001065
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001066- Layers intercept a Vulkan command by defining a C/C++ function with signature
1067identical to the Vulkan API for that command.
1068- Other than the two vkGet*ProcAddr, all other functions intercepted by a layer
1069need NOT be exported by the layer.
1070- For any Vulkan command a layer intercepts which has a non-void return value,
1071an appropriate value must be returned by the layer intercept function.
1072- The layer intercept function must call down the chain to the corresponding
1073Vulkan command in the next entity. Undefined results will occur if a layer
1074doesn't propagate calls down the chain. The two exceptions to this requirement
1075are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1076chain for Vulkan commands that they do not intercept.
1077- Layer intercept functions may insert extra calls to Vulkan commands in
1078addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1079want to add a call to vkQueueWaitIdle after calling down the chain for
1080vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1081chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001082
1083#### Distributed dispatching requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001084
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001085- For each entry point a layer intercepts, it must keep track of the entry
1086point residing in the next entity in the chain it will call down into. In other
1087words, the layer must have a list of pointers to functions of the appropriate
1088type to call into the next entity. This can be implemented in various ways but
1089for clarity will be referred to as a dispatch table.
1090- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1091(see include/vulkan/vk_layer.h).
1092- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1093dispatch table (see include/vulkan/vk_layer.h).
1094- Layers vkGetInstanceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001095vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001096functions.
1097- Layers vkGetDeviceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001098vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001099functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001100
1101#### Layer dispatch initialization
Jeff Julianof1619872016-02-17 17:25:42 -05001102
1103- A layer initializes its instance dispatch table within its vkCreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001104function.
Jeff Julianof1619872016-02-17 17:25:42 -05001105- A layer initializes its device dispatch table within its vkCreateDevice
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001106function.
1107- The loader passes a linked list of initialization structures to layers via
1108the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1109for vkCreateInstance and VkCreateDevice respectively.
1110- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001111instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001112include/vulkan/vk_layer.h for details.
1113- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1114"sType" field in VkLayerInstanceCreateInfo.
1115- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1116"sType" field in VkLayerDeviceCreateInfo.
1117- The "function" field indicates how the union field "u" should be interpreted
1118within VkLayer*CreateInfo. The loader will set the "function" field to
1119VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1120VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001121- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001122- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1123by a layer.
1124- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1125vkGetDeviceProcAddr used by a layer.
1126- Given the above structures set up by the loader, layer must initialize their
1127dispatch table as follows:
1128 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1129the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001130 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001131 - For CreateInstance get the next entity's vkCreateInstance by calling the
1132"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001133 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001134 - For CreateDevice get the next entity's vkCreateDevice by calling the
1135"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001136 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001137 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1138 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001139 - Initialize your layer dispatch table by calling the next entity's
1140Get*ProcAddr function once for each Vulkan command needed in your dispatch
1141table
Jon Ashburncc300a22016-02-11 14:57:30 -07001142
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001143#### Example code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001144
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001145```cpp
1146VkResult vkCreateInstance(
1147 const VkInstanceCreateInfo *pCreateInfo,
1148 const VkAllocationCallbacks *pAllocator,
1149 VkInstance *pInstance)
1150{
1151 VkLayerInstanceCreateInfo *chain_info =
1152 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1153
1154 assert(chain_info->u.pLayerInfo);
1155 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1156 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1157 PFN_vkCreateInstance fpCreateInstance =
1158 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
1159 if (fpCreateInstance == NULL) {
1160 return VK_ERROR_INITIALIZATION_FAILED;
1161 }
1162
1163 // Advance the link info for the next element of the chain
1164 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1165
1166 // Continue call down the chain
1167 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1168 if (result != VK_SUCCESS)
1169 return result;
1170
1171 // Allocate new structure to store peristent data
1172 layer_data *my_data = new layer_data;
1173
1174 // Associate this instance with the newly allocated data
1175 // layer will store any persistent state it needs for
1176 // this instance in the my_data structure
1177 layer_data_map[get_dispatch_key(*pInstance)] = my_data;
1178
1179 // Create layer's dispatch table using GetInstanceProcAddr of
1180 // next layer in the chain.
1181 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
1182 layer_init_instance_dispatch_table(
1183 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1184
1185 // Keep track of any extensions that were enabled for this
1186 // instance. In this case check for VK_EXT_debug_report
1187 my_data->report_data = debug_report_create_instance(
1188 my_data->instance_dispatch_table, *pInstance,
1189 pCreateInfo->enabledExtensionCount,
1190 pCreateInfo->ppEnabledExtensionNames);
1191
1192 // Other layer initialization
1193 ...
1194
1195 return VK_SUCCESS;
1196}
1197```
1198
1199#### Example code for CreateDevice
1200
1201```cpp
1202VkResult
1203vkCreateDevice(
1204 VkPhysicalDevice gpu,
1205 const VkDeviceCreateInfo *pCreateInfo,
1206 const VkAllocationCallbacks *pAllocator,
1207 VkDevice *pDevice)
1208{
1209 VkLayerDeviceCreateInfo *chain_info =
1210 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1211
1212 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1213 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1214 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1215 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1216 PFN_vkCreateDevice fpCreateDevice =
1217 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1218 if (fpCreateDevice == NULL) {
1219 return VK_ERROR_INITIALIZATION_FAILED;
1220 }
1221
1222 // Advance the link info for the next element on the chain
1223 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1224
1225 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1226 if (result != VK_SUCCESS) {
1227 return result;
1228 }
1229
1230 // Allocate new structure to store peristent data
1231 layer_data *my_data = new layer_data;
1232
1233 // Associate this instance with the newly allocated data
1234 // layer will store any persistent state it needs for
1235 // this instance in the my_data structure
1236 layer_data_map[get_dispatch_key(*pDevice)] = my_data;
1237
1238 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
1239 layer_init_device_dispatch_table(
1240 *pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
1241
1242 // Keep track of any extensions that were enabled for this
1243 // instance. In this case check for VK_EXT_debug_report
1244 my_data->report_data = debug_report_create_instance(
1245 my_instance_data->report_data, *pDevice);
1246
1247 // Other layer initialization
1248 ...
1249
1250 return VK_SUCCESS;
1251}
1252```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001253
Jon Ashburncc300a22016-02-11 14:57:30 -07001254#### Special Considerations
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001255A layer may want to associate it's own private data with one or more Vulkan
1256objects.
1257Two common methods to do this are hash maps and object wrapping. The loader
1258supports layers wrapping any Vulkan object including dispatchable objects.
1259Layers which wrap objects should ensure they always unwrap objects before
1260passing them down the chain. This implies the layer must intercept every Vulkan
1261command which uses the object in question. Layers above the object wrapping
1262layer will see the wrapped object.
Jeff Julianof1619872016-02-17 17:25:42 -05001263
1264Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001265given object. The key to the map could be the object. Alternatively, for
1266dispatchable objects at a given level (eg device or instance) the layer may
1267want data associated with the VkDevice or VkInstance objects. Since
Jeff Julianof1619872016-02-17 17:25:42 -05001268there are multiple dispatchable objects for a given VkInstance or VkDevice, the
1269VkDevice or VkInstance object is not a great map key. Instead the layer should
1270use the dispatch table pointer within the VkDevice or VkInstance since that
1271will be unique for a given VkInstance or VkDevice.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001272
1273Layers which create dispatchable objects take special care. Remember that loader
1274trampoline code normally fills in the dispatch table pointer in the newly
1275created object. Thus, the layer must fill in the dispatch table pointer if the
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001276loader trampoline will not do so. Common cases where a layer may create a
1277dispatchable object without loader trampoline code is as follows:
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001278- object wrapping layers that wrap dispatchable objects
1279- layers which add extensions that create dispatchable objects
1280- layers which insert extra Vulkan commands in the stream of commands they
1281intercept from the application
Jon Ashburnc2972682016-02-08 15:42:01 -07001282