blob: e5df1815dcaadc9c5622ddb4b0b4174394d135bf [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----------------------
7
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07008Specify necessary functions and expected behavior of interface between the
9loader library and ICDs and layers for Windows, Linux and Android based
10systems. Also describe the application visible behaviors of the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -070011
Mark Youngcb6e6702016-07-20 11:38:53 -060012<br/>
13
14## Audience ##
Jon Ashburnc2972682016-02-08 15:42:01 -070015--------
16
Mark Youngcb6e6702016-07-20 11:38:53 -060017This document is primarily targeted at Vulkan application, driver and layer developers.
18However, it can also be used by any developer interested in understanding more about
19how the Vulkan loader and layers interact.
Jon Ashburnc2972682016-02-08 15:42:01 -070020
Mark Youngcb6e6702016-07-20 11:38:53 -060021<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -070022
23
Mark Youngcb6e6702016-07-20 11:38:53 -060024## Loader goals ##
Jon Ashburnc2972682016-02-08 15:42:01 -070025------------
26
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070027- Support multiple ICDs (Installable Client Drivers) to co-exist on a system
28without interfering with each other.
Jon Ashburnc2972682016-02-08 15:42:01 -070029
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070030- Support optional modules (layers) that can be enabled by an application,
31developer or the system and have no impact when not enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -070032
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070033- Negligible performance cost for an application calling through the loader
34to an ICD entry point.
Jon Ashburnc2972682016-02-08 15:42:01 -070035
Mark Youngcb6e6702016-07-20 11:38:53 -060036<br/>
37
38## Architectural overview of layers and loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -070039-------------------------------------------
40
Mark Youngcb6e6702016-07-20 11:38:53 -060041Vulkan is a layered architecture placing the Application on one end, the
42ICDs on the other, and the loader and some number of layers in between.
Jon Ashburnc2972682016-02-08 15:42:01 -070043
Mark Youngcb6e6702016-07-20 11:38:53 -060044Layers are implemented as libraries that can be enabled in different ways
45(including by application request) and loaded during CreateInstance. Each
46layer can chooses to hook (intercept) any Vulkan commands which in turn
47can be ignored, augmented, or simply passed along. A layer may also
48expose functionality not available in the loader or any ICD. Some examples
49of this include: the ability to perform Vulkan API tracing and debugging,
50validate API usage, or overlay additional content on the applications surfaces.
51
52The loader is responsible for working with the various layers as well as
53supporting multiple GPUs and their drivers. Any Vulkan command may
54wind up calling into a diverse set of modules: loader, layers, and ICDs.
55The loader is critical to managing the proper dispatching of Vulkan
56commands to the appropriate set of layers and ICDs. The Vulkan object
57model allows the loader to insert layers into a call chain so that the layers
58can process Vulkan commands prior to the ICD being called.
Jon Ashburnc2972682016-02-08 15:42:01 -070059
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070060Vulkan uses an object model to control the scope of a particular action /
61operation. The object to be acted on is always the first parameter of a Vulkan
Mark Young6d026a72016-06-01 17:49:30 -060062call and is a dispatchable object (see Vulkan specification section 2.3 Object
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070063Model). Under the covers, the dispatchable object handle is a pointer to a
Mark Youngcb6e6702016-07-20 11:38:53 -060064structure, which in turn, contains a pointer to a dispatch table maintained by
65the loader. This dispatch table contains pointers to the Vulkan functions appropriate to
66that object.
Jon Ashburnc2972682016-02-08 15:42:01 -070067
Mark Youngcb6e6702016-07-20 11:38:53 -060068There are two types of dispatch tables the loader maintains:
69- **Instance Dispatch Table**
70 - Contains any function that takes a VkInstance or VkPhysicalDevice as their first parameter
71 - vkEnumeratePhysicalDevices
72 - vkDestroyInstance
73 - vkCreateInstance
74 - ...
75- **Device Dispatch Table**
76 - Contains any function that takes a VkDevice, VkQueue or VkCommandBuffer as their first parameter
Jon Ashburnc2972682016-02-08 15:42:01 -070077
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070078These instance and device dispatch tables are constructed when the application
79calls vkCreateInstance and vkCreateDevice. At that time the application and/or
80system can specify optional layers to be included. The loader will initialize
81the specified layers to create a call chain for each Vulkan function and each
82entry of the dispatch table will point to the first element of that chain.
83Thus, the loader builds an instance call chain for each VkInstance that is
84created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070085
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070086For example, the diagram below represents what happens in the call chain for
87vkCreateInstance. After initializing the chain, the loader will call into the
Mark Young6d026a72016-06-01 17:49:30 -060088first layer's vkCreateInstance which will call the next finally terminating in
89the loader again where this function calls every ICD's vkCreateInstance and
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070090saves the results. This allows every enabled layer for this chain to set up
91what it needs based on the VkInstanceCreateInfo structure from the application.
Jon Ashburnc2505562016-02-15 10:19:26 -070092![Instance call chain](instance_call_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070093
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070094This also highlights some of the complexity the loader must manage when using
95instance chains. As shown here, the loader must aggregate information from
96multiple devices when they are present. This means that the loader has to know
97about instance level extensions to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -070098
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070099Device chains are created at vkCreateDevice and are generally simpler because
100they deal with only a single device and the ICD can always be the terminator of
101the chain. The below diagram also illustrates how layers (either device or
102instance) can skip intercepting any given Vulkan entry point.
Jon Ashburnc2505562016-02-15 10:19:26 -0700103![Chain skipping layers](chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -0700104
Mark Youngcb6e6702016-07-20 11:38:53 -0600105<br/>
106
107## Application interface to loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700108-------------------------------
109
Mark Young6d026a72016-06-01 17:49:30 -0600110In this section we'll discuss how an application interacts with the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700111
112- Linking to loader library for core and WSI extension symbols.
113
114- Dynamic Vulkan command lookup & application dispatch table.
115
116- Loader library filenames for linking to different Vulkan ABI versions.
117
118- Layers
119
120- Extensions
121
122- vkGetInstanceProcAddr, vkGetDeviceProcAddr
123
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700124The loader library on Windows, Linux and Android will export all core Vulkan
125and all appropriate Window System Interface (WSI) extensions. This is done to
126make it simpler to get started with Vulkan development. When an application
127links directly to the loader library in this way, the Vulkan calls are simple
128trampoline functions that jump to the appropriate dispatch table entry for the
129object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700130
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700131Applications are not required to link directly to the loader library, instead
132they can use the appropriate platform specific dynamic symbol lookup on the
Mark Young6d026a72016-06-01 17:49:30 -0600133loader library to initialize the application's own dispatch table. This allows
Jeff Julianof1619872016-02-17 17:25:42 -0500134an application to fail gracefully if the loader cannot be found, and it
135provides the fastest mechanism for the application to call Vulkan functions. An
136application will only need to query (via system calls such as dlsym()) the
137address of vkGetInstanceProcAddr from the loader library. Using
138vkGetInstanceProcAddr the application can then discover the address of all
139instance and global functions and extensions, such as vkCreateInstance,
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700140vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties
141in a platform independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700142
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700143The Vulkan loader library will be distributed in various ways including Vulkan
144SDKs, OS package distributions and IHV driver packages. These details are
145beyond the scope of this document. However, the name and versioning of the
146Vulkan loader library is specified so an app can link to the correct Vulkan ABI
147library version. Vulkan versioning is such that ABI backwards compatibility is
Jeff Julianof1619872016-02-17 17:25:42 -0500148guaranteed for all versions with the same major number (e.g. 1.0 and 1.1). On
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700149Windows, the loader library encodes the ABI version in its name such that
150multiple ABI incompatible versions of the loader can peacefully coexist on a
Mark Young6d026a72016-06-01 17:49:30 -0600151given system. The Vulkan loader library file name is "vulkan-<ABI
152version>.dll". For example, for Vulkan version 1.X on Windows the library
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700153filename is vulkan-1.dll. And this library file can typically be found in the
Mark Young6d026a72016-06-01 17:49:30 -0600154windows/system32 directory (on 64-bit Windows installs, the 32-bit version of
155the loader with the same name can be found in the windows/sysWOW64 directory).
Jon Ashburnc2972682016-02-08 15:42:01 -0700156
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700157For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
158number is not encoded in the base of the library filename as on Windows. On
159Linux an application wanting to link to the latest Vulkan ABI version would
160just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500161also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700162
Mark Young6d026a72016-06-01 17:49:30 -0600163####Layer Usage
164
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700165Applications desiring Vulkan functionality beyond what the core API offers may
166use various layers or extensions. A layer cannot add new or modify existing
167Vulkan commands, but may offer extensions that do. A common use of layers is
168for API validation. A developer can use validation layers during application
169development, but during production the layers can be disabled by the
Jeff Julianof1619872016-02-17 17:25:42 -0500170application. Thus, eliminating the overhead of validating the application's
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600171usage of the API. Layers discovered by the loader are reported to the
172application via vkEnumerateInstanceLayerProperties.
173Layers are enabled at vkCreateInstance and are active for all Vulkan commands
Mark Young6d026a72016-06-01 17:49:30 -0600174using the given VkIstance and any of it's child objects. For example, the
175ppEnabledLayerNames array in the VkInstanceCreateInfo structure is used by
176the application to list the layer names to be enabled at vkCreateInstance. At
177vkCreateInstance and vkCreateDevice, the loader will construct call chains that
178include the application specified (enabled) layers. vkCreateDevice will use the
179layers specified at vkCreateInstance. vkEnumerateDeviceLayerProperties and
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600180device layers are deprecated. Order is important in the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700181ppEnabledLayerNames array; array element 0 is the topmost (closest to the
182application) layer inserted in the chain and the last array element is closest
183to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700184
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700185Developers may want to enable layers that are not enabled by the given
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600186application they are using. On Linux and Windows, the environment variable
Mark Young6d026a72016-06-01 17:49:30 -0600187"VK\_INSTANCE\_LAYERS" can be used to enable
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700188additional layers which are not specified (enabled) by the application at
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600189vkCreateInstance. VK\_INSTANCE\_LAYERS is a colon
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700190(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
191relevant with the first layer in the list being the topmost layer (closest to
192the application) and the last layer in the list being the bottommost layer
193(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700194
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700195Application specified layers and user specified layers (via environment
196variables) are aggregated and duplicates removed by the loader when enabling
197layers. Layers specified via environment variable are topmost (closest to the
198application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700199
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700200An example of using these environment variables to activate the validation
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600201layer VK\_LAYER\_LUNARG\_parameter\_validation on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700202
203```
Mark Lobodzinski739391a2016-03-17 15:08:18 -0600204> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation
Jon Ashburnc2972682016-02-08 15:42:01 -0700205
Jon Ashburnc2972682016-02-08 15:42:01 -0700206```
207
Mark Young6d026a72016-06-01 17:49:30 -0600208#### Implicit vs Explicit Layers
209
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700210Some platforms, including Linux and Windows, support layers which are enabled
211automatically by the loader rather than explicitly by the application (or via
212environment variable). Explicit layers are those layers enabled by the
213application (or environment variable) by providing the layer name. Implicit
214layers are those layers enabled by the loader automatically. Any implicit
215layers the loader discovers on the system in the appropriate location will be
216enabled (subject to environment variable overrides described later). Discovery
217of properly installed implicit and explicit layers is described later.
218Explicitly enabling a layer that is implicitly enabled has no additional
219effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700220
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700221Extensions are optional functionality provided by a layer, the loader or an
222ICD. Extensions can modify the behavior of the Vulkan API and need to be
223specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700224
Mark Young6d026a72016-06-01 17:49:30 -0600225#### Instance/Device Extensions
226
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700227Instance extensions can be discovered via
228vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
229vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
230extensions from layers (both explicit and implicit), ICDs and the loader before
231reporting them to the application in vkEnumerate\*ExtensionProperties. The
Jeff Julianof1619872016-02-17 17:25:42 -0500232pLayerName parameter in these functions is used to select either a single layer
233or the Vulkan platform implementation. If pLayerName is NULL, extensions from
234Vulkan implementation components (including loader, implicit layers, and ICDs)
235are enumerated. If pLayerName is equal to a discovered layer module name then
236any extensions from that layer (which may be implicit or explicit) are
237enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Jon Ashburn859c7fb2016-03-02 17:26:31 -0700238support for the same extension) are eliminated by the loader. For duplicates, the
239ICD version is reported and the layer version is culled. Extensions must
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700240be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700241
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700242Extension command entry points should be queried via vkGetInstanceProcAddr or
243vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
244extension or core device entry points. Device entry points include any command
245that uses a VkDevice as the first parameter or a dispatchable object that is a
246child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
247vkGetInstanceProcAddr can be used to query either device or instance extension
248entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700249
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700250VkGetDeviceProcAddr is particularly interesting because it will provide the
251most efficient way to call into the ICD. For example, the diagram below shows
252what could happen if the application were to use vkGetDeviceProcAddr for the
Mark Young6d026a72016-06-01 17:49:30 -0600253function "vkGetDeviceQueue" and "vkDestroyDevice" but not "vkAllocateMemory".
254The resulting function pointer (fpGetDeviceQueue) would be the ICD's entry
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700255point if the loader and any enabled layers do not need to see that call. Even
Jeff Julianof1619872016-02-17 17:25:42 -0500256if an enabled layer intercepts the call (e.g. vkDestroyDevice) the loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700257trampoline code is skipped for function pointers obtained via
258vkGetDeviceProcAddr. This also means that function pointers obtained via
259vkGetDeviceProcAddr will only work with the specific VkDevice it was created
260for, using it with another device has undefined results. For extensions,
261Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700262
Jon Ashburnc2505562016-02-15 10:19:26 -0700263![Get*ProcAddr efficiency](get_proc_addr.png)
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700264
Mark Young78f88c82016-07-19 11:49:45 -0600265##### WSI Extensions
266
267Khronos approved WSI extensions are available and provide Windows System Integration
268support for various execution environments. It is important to understand that some WSI
269extensions are valid for all targets, but others are particular to a given execution
270environment (and loader). This desktop loader (currently targeting Windows and Linux)
271only enables those WSI extensions that are appropriate to the current environment.
272For the most part, the selection is done in the loader using compile-time preprocessor
273flags. All versions of the desktop loader currently expose at least the following WSI
274extension support:
275- VK_KHR_surface
276- VK_KHR_swapchain
277- VK_KHR_display
278
279In addition, each of the following OS targets for the loader support target-specific extensions:
280- **Windows** : VK_KHR_win32_surface
281- **Linux (default)** : VK_KHR_xcb_surface and VK_KHR_xlib_surface
282- **Linux (Wayland build)** : VK_KHR_wayland_surface
283- **Linux (Mir build)** : VK_KHR_mir_surface
284
285**NOTE:** Wayland and Mir targets are not fully supported at this time and should be considered
286alpha quality.
287
288It is important to understand that while the loader may support the various entry-points
289for these extensions, there is a hand-shake required to actually use them:
290* At least one physical device must support the extension(s)
291* The application must select such a physical device
292* 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).
293* The instance and/or logical device creation must succeed.
294
295Only then can you expect to properly use a WSI extension in your Vulkan program.
296
297##### New Extensions
298
299With the ability to expand Vulkan so easily, extensions will be created that the loader knows
300nothing about. If the extension is a device extension, the loader will pass the unknown
301entry-point down the device call chain ending with the appropriate ICD entry-points.
302However, if the extension is an instance extension, the loader will fail to load it.
303
304*But why doesn't the loader support unknown instance extensions?*
305<br/>
306Let's look again at the Instance call chain:
307![Instance call chain](instance_call_chain.png)
308
309Notice that for a normal instance function call, the loader has to handle passing along the
310function call to the available ICDs. If the loader has no idea of the parameters or return
311value of the instance call, it can't properly pass information along to the ICDs.
312There may be ways to do this, which will be explored in the future. However, for now, this
313loader does not support any unknown instance extensions.
314
315Because the device call-chain does not pass through the loader terminator, this is not
316a problem for device extensions. Instead, device extensions terminate directly in the
317ICD they are associated with.
318
319*Is this a big problem?*
320<br/>
321No! Most extension functionality only affects a device and not an instance or a physical
322device. Thus, the overwhelming majority of extensions will be device extensions rather than
323instance extensions.
324
Mark Youngcb6e6702016-07-20 11:38:53 -0600325<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -0700326
Mark Youngcb6e6702016-07-20 11:38:53 -0600327
328## Vulkan Installable Client Driver interface with the loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700329----------------------------------------------------------
330
331### ICD discovery
332
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700333Vulkan allows multiple drivers each with one or more devices (represented by a
334Vulkan VkPhysicalDevice object) to be used collectively. The loader is
335responsible for discovering available Vulkan ICDs on the system. Given a list
336of available ICDs, the loader can enumerate all the physical devices available
337for an application and return this information to the application. The process
338in which the loader discovers the available Installable Client Drivers (ICDs)
339on a system is platform dependent. Windows, Linux and Android ICD discovery
340details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700341
342#### Windows
343
344##### Properly-Installed ICDs
345
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700346In order to find properly-installed ICDs, the Vulkan loader will scan the
347values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700348
349HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
350
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700351For each value in this key which has DWORD data set to 0, the loader opens the
352JSON format text information file (a.k.a. "manifest file") specified by the
353name of the value. Each name must be a full pathname to the text manifest file.
354The Vulkan loader will open each manifest file to obtain the name or pathname
355of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700356
Jon Ashburncc300a22016-02-11 14:57:30 -0700357 ```
358 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700359 "file_format_version": "1.0.0",
360 "ICD": {
361 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700362 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700363 }
364 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700365 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700366
367
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700368The "library\_path" specifies either a filename, a relative pathname, or a full
369pathname to an ICD shared library file, which the loader will attempt to load
370using LoadLibrary(). If the ICD is specified via a filename, the shared library
David Pinedo3e163ee2016-04-18 16:59:59 -0600371lives in the system's DLL search path (e.g. in the "C:\Windows\System32"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700372folder). If the ICD is specified via a relative pathname, it is relative to the
373path of the manifest file. Relative pathnames are those that do not start with
374a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
375character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700376
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700377The "file\_format\_version" specifies a major.minor.patch version number in
378case the format of the text information file changes in the future. If the same
379ICD shared library supports multiple, incompatible versions of text manifest
380file format versions, it must have multiple text info files (all of which may
381point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700382
Mark Young6d026a72016-06-01 17:49:30 -0600383The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700384API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700385
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700386There are no rules about the name of the text information files (except the
387.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700388
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700389There are no rules about the name of the ICD shared library files. For example,
390if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700391
Jon Ashburncc300a22016-02-11 14:57:30 -0700392```
393[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700394
David Pinedo3e163ee2016-04-18 16:59:59 -0600395"C:\vendor a\vk_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700396
David Pinedo3e163ee2016-04-18 16:59:59 -0600397"C:\windows\system32\vendorb_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700398
David Pinedo3e163ee2016-04-18 16:59:59 -0600399"C:\windows\system32\vendorc_icd.json"=dword:00000000
Jon Ashburncc300a22016-02-11 14:57:30 -0700400```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700401then the loader will open the following text information files, with the
402specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700403
Jon Ashburncc300a22016-02-11 14:57:30 -0700404| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700405|----------------|--------------------|
David Pinedo3e163ee2016-04-18 16:59:59 -0600406|vk\_vendora.json | "ICD": { "library\_path": "C:\VENDOR A\vk_vendora.dll", "api_version": "1.0.5" } |
Tony Barbourd83f06c2016-03-08 14:50:03 -0700407| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.5" } |
408|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.5" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700409
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700410Then the loader will open the three files mentioned in the "Text File Contents"
411column, and then try to load and use the three shared libraries indicated by
412the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700413
414##### Using Pre-Production ICDs
415
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700416IHV developers (and sometimes other developers) need to use special,
417pre-production ICDs. In some cases, a pre-production ICD may be in an
418installable package. In other cases, a pre-production ICD may simply be a
419shared library in the developer's build tree. In this latter case, we want to
420allow developers to point to such an ICD without modifying the
421properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700422
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700423This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
424which will override the mechanism used for finding properly-installed ICDs. In
425other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
426"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
427text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700428
Jon Ashburncc300a22016-02-11 14:57:30 -0700429- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700430
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700431Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
432file for a developer-built ICD. A semi-colon is only used if more than one ICD
433is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700434
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700435For example, if a developer wants to refer to one ICD that they built, they
436could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700437
Jon Ashburncc300a22016-02-11 14:57:30 -0700438C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700439
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700440If a developer wants to refer to two ICDs, one of which is a properly-installed
441ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700442
Jon Ashburncc300a22016-02-11 14:57:30 -0700443C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700444
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700445Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
446"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700447
448#### Linux
449
450##### Properly-Installed ICDs
451
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700452In order to find properly-installed ICDs, the Vulkan loader will scan the files
453in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700454
455/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700456/etc/vulkan/icd.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700457$HOME/.local/share/vulkan/icd.d
458
459Where $HOME is the current home directory of the application's user id; this
460path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700461
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700462These directories will contain text information files (a.k.a. "manifest
463files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700464
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700465The Vulkan loader will open each manifest file found to obtain the name or
466pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700467
Jon Ashburncc300a22016-02-11 14:57:30 -0700468```
469{
Jon Ashburnc2972682016-02-08 15:42:01 -0700470 "file_format_version": "1.0.0",
471 "ICD": {
472 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700473 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700474 }
475}
Jon Ashburncc300a22016-02-11 14:57:30 -0700476```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700477The "library\_path" specifies either a filename, a relative pathname, or a full
478pathname to an ICD shared library file. If the ICD is specified via a filename,
479the loader will attempt to open that file as a shared object using dlopen(),
480and the file must be in a directory that dlopen is configured to look in (Note:
481various distributions are configured differently). A distribution is free to
482create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
483required to do so. If the ICD is specified via a relative pathname, it is
484relative to the path of the info file. Relative pathnames are those that do not
485start with, but do contain at least one directory separator (i.e. the '/'
486character). For example, "lib/vendora.so" and "./vendora.so" are examples of
487relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700488
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700489The "file\_format\_version" provides a major.minor.patch version number in case
490the format of the manifest file changes in the future. If the same ICD shared
491library supports multiple, incompatible versions of manifest file format
492versions, it must have multiple manifest files (all of which may point to the
493same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700494
Mark Young6d026a72016-06-01 17:49:30 -0600495The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700496API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700497
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700498The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
499Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
500ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700501
502There are no rules about the name of the text files (except the .json suffix).
503
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700504There are no rules about the name of the ICD shared library files. For example,
505if the "/usr/share/vulkan/icd.d" directory contain the following files, with
506the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700507
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700508| Text File Name | Text File Contents |
509|-------------------|------------------------|
Tony Barbourd83f06c2016-03-08 14:50:03 -0700510| vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.5" } |
511| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.5" } |
512| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.5" } |
Jon Ashburnc2972682016-02-08 15:42:01 -0700513
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700514then the loader will open the three files mentioned in the "Text File Contents"
515column, and then try to load and use the three shared libraries indicated by
516the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700517
518##### Using Pre-Production ICDs
519
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700520IHV developers (and sometimes other developers) need to use special,
521pre-production ICDs. In some cases, a pre-production ICD may be in an
522installable package. In other cases, a pre-production ICD may simply be a
523shared library in the developer's build tree. In this latter case, we want to
524allow developers to point to such an ICD without modifying the
525properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700526
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700527This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
528which will override the mechanism used for finding properly-installed ICDs. In
529other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700530
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700531The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
532manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700533
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700534- 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 -0700535
536- A full pathname (e.g. "/my\_build/my\_icd.json")
537
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700538Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
539file for a developer-built ICD. A colon is only used if more than one ICD is
540listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700541
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700542For example, if a developer wants to refer to one ICD that they built, they
543could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700544
545/my\_build/my\_icd.json
546
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700547If a developer wants to refer to two ICDs, one of which is a properly-installed
548ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700549
550vendorc\_vulkan.json:/my\_build/my\_icd.json
551
552Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
553
554NOTE: this environment variable will be ignored for suid programs.
555
556#### Android
557
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700558The Android loader lives in the system library folder. The location cannot be
559changed. The loader will load the driver/ICD via hw_get_module with the ID
560of "vulkan". Due to security policies in Android none of this can be modified
561under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700562
Mark Youngcb6e6702016-07-20 11:38:53 -0600563<br/>
Jon Ashburnc2972682016-02-08 15:42:01 -0700564
Mark Youngcb6e6702016-07-20 11:38:53 -0600565## ICD interface requirements ##
Jon Ashburncc300a22016-02-11 14:57:30 -0700566----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700567
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700568Generally, for all Vulkan commands issued by an application, the loader can be
Mark Young6d026a72016-06-01 17:49:30 -0600569viewed as a pass through. That is, the loader generally doesn't modify the
Jon Ashburn54791f62016-04-22 14:40:07 -0600570commands or their parameters, but simply calls the ICDs entry point for that
571command. There are specific additional interface requirements an ICD needs to comply with that
572are over and above any requirements from the Vulkan specification including WSI extension specification.
573These addtional requirements are versioned to allow flexibility in the future.
574These interface requirements will be set forth in the following sections: 1) describing
575which "loader-ICD" interface version is available, 2) detailing the most recent interface version;
5763) the supported, older interface requirements will be described as differences
577from the most recent interface version.
Jon Ashburnc2972682016-02-08 15:42:01 -0700578
579#### Windows and Linux
580
Jon Ashburn54791f62016-04-22 14:40:07 -0600581##### Version Negotiation Between Loader and ICDs
Jon Ashburnc2972682016-02-08 15:42:01 -0700582
Jon Ashburn54791f62016-04-22 14:40:07 -0600583All ICDs (supporting interface version 2 or higher) must export the following
584function that is used for determination of the interface version that will be used.
585This entry point is not a part of the Vulkan API itself, only a private interface
586between the loader and ICDs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700587
Jon Ashburn54791f62016-04-22 14:40:07 -0600588VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion);
Jon Ashburnc2972682016-02-08 15:42:01 -0700589
Jon Ashburn54791f62016-04-22 14:40:07 -0600590This entry point reports the "loader-ICD" interface version supported by both the loader and the ICD.
591The loader informs the ICD of it's desired interface version (typically the latest) via the
592pSupportedVersion parameter.
593This call is the first call made by the loader into the ICD (prior to any calls to
594vk\_icdGetInstanceProcAddr).
Jon Ashburnc2972682016-02-08 15:42:01 -0700595
Jon Ashburn54791f62016-04-22 14:40:07 -0600596If a loader sees that an ICD does not export this symbol it knows that it's dealing
597with a legacy ICD supporting either interface version 0 or 1.
598Similarly, if an ICD sees a call to vk\_icdGetInstanceProcAddr before a call to
599vk_icdGetLoaderICDInterfaceVersion then it knows that it's dealing with a legacy loader
600supporting version 0 or 1.
601Note if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
602otherwise the loader only supports version 0.
Jon Ashburnc2972682016-02-08 15:42:01 -0700603
Jon Ashburn54791f62016-04-22 14:40:07 -0600604The pSupportedVersion parameter is both an input and output parameter.
605It 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 -0500606
Jon Ashburn54791f62016-04-22 14:40:07 -0600607If the ICD receiving the call no longer supports the interface version provided
608by the loader (due to deprecation) then it can report VK_ERROR_INCOMPATIBLE_DRIVER error,
609otherwise it sets the value pointed by pSupportedVersion to the latest interface
610version supported by both the ICD and the loader and returns VK_SUCCESS.
611The ICD should report VK_SUCCESS in case the loader provided interface version
612is newer than that supported by the ICD, as it's the loader's responsibility to
613determine whether it can support the older interface version supported by the ICD.
614The ICD should also report VK_SUCCESS in the case it's interface version is greater
615than the loader's, but return the loader's version. Thus, upon return of VK_SUCCESS
616the pSupportedVersion will contain the desired interface version to be used by the ICD.
Jon Ashburnc2972682016-02-08 15:42:01 -0700617
Jon Ashburn54791f62016-04-22 14:40:07 -0600618If the loader receives back an interface version from the ICD that the loader no longer
619supports (due to deprecation) or it receives a VK_ERROR_INCOMPATIBLE_DRIVER error
620instead of VK_SUCCESS then the loader will treat the ICD as incompatible
621and will not load it for use. In this case the application will not see the ICDs vkPhysicalDevice
622during enumeration.
Jon Ashburnc2972682016-02-08 15:42:01 -0700623
Jon Ashburn54791f62016-04-22 14:40:07 -0600624##### Loader Version 2 Interface Requirements
Jon Ashburnc2972682016-02-08 15:42:01 -0700625
Jon Ashburn54791f62016-04-22 14:40:07 -0600626Version 2 interface has requirements in three areas: 1) ICD Vulkan entry point discovery,
6272) KHR_surface related requirements in the WSI extensions, 3) Vulkan dispatchable object
628creation requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700629
Jon Ashburn54791f62016-04-22 14:40:07 -0600630###### ICD Vulkan entry point discovery
631All ICDs must export the following function that is used for discovery of ICD Vulkan entry points.
632This 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 -0700633
Jon Ashburn54791f62016-04-22 14:40:07 -0600634VKAPI\_ATTR PFN\_vkVoidFunction VKAPI\_CALL vk\_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
635
636This function has very similar semantics to the Vulkan command vkGetInstanceProcAddr.
637vk\_icdGetInstanceProcAddr returns valid function pointers for all the global level
638and instance level Vulkan commands, and also for vkGetDeviceProcAddr.
639Global level commands are those
640which contain no dispatchable object as the first parameter, such as
641vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must
642support querying global level entry points by calling
643vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level
644commands are those that have either VkInstance, or VkPhysicalDevice as the
645first parameter dispatchable object. Both core entry points and any instance
646extension entry points the ICD supports should be available via
647vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and
648use new instance level dispatchable objects other than VkInstance and
649VkPhysicalDevice, in which case extension entry points using these newly
650defined dispatchable objects must be queryable via vk\_icdGetInstanceProcAddr.
651
652All other Vulkan entry points must either NOT be exported from the ICD
653library or else NOT use the official Vulkan function names if they are
654exported. This requirement is for ICD libraries that include other
655functionality (such as OpenGL library) and thus could be loaded by the
656application prior to when the Vulkan loader library is loaded by the
657application. In other words, the ICD library exported Vulkan symbols must not
658clash with the loader's exported Vulkan symbols.
659
660Beware of interposing by dynamic OS library loaders if the official Vulkan
661names are used. On Linux, if official names are used, the ICD library must be
662linked with -Bsymbolic.
663
664###### Handling KHR_surface objects in the WSI extensions
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700665Normally, ICDs handle object creation and destruction for various Vulkan
666objects. The WSI surface extensions for Linux and Windows
667(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
668VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
669handled differently. For these extensions, the VkSurfaceKHR object creation and
670destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700671
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006721. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
673 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700674
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006752. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
676 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700677
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006783. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
679 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700680
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006814. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
Jeff Julianof1619872016-02-17 17:25:42 -0500682 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field
683 in the structure is a VkIcdSurfaceBase enumerant that indicates whether the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700684 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700685
Jon Ashburn54791f62016-04-22 14:40:07 -0600686###### ICD dispatchable object creation
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700687As previously covered, the loader requires dispatch tables to be accessible
688within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
689VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
690dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700691
Jon Ashburncc300a22016-02-11 14:57:30 -0700692- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700693
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700694- The loader will replace the first entry with a pointer to the dispatch table
695 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700696
Jon Ashburncc300a22016-02-11 14:57:30 -07006971. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700698
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006992. This pointer points to a regular C structure with the first entry being a
700 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
701 classes. The C\++ compiler may put a vtable at offset zero if your class is
Jeff Julianof1619872016-02-17 17:25:42 -0500702 non-POD due to the use of a virtual function. In this case use a regular C
703 structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700704
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07007053. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
706 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700707
708```
709
Jon Ashburncc300a22016-02-11 14:57:30 -0700710#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700711
Jon Ashburncc300a22016-02-11 14:57:30 -0700712union _VK_LOADER_DATA {
713 uintptr loadermagic;
714 void *loaderData;
715} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700716
Jon Ashburncc300a22016-02-11 14:57:30 -0700717vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700718{
Jon Ashburncc300a22016-02-11 14:57:30 -0700719 vkObj *newObj = alloc_obj();
720 ...
721 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700722
Jon Ashburncc300a22016-02-11 14:57:30 -0700723 set_loader_magic_value(newObj);
724 ...
725 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700726}
Jon Ashburnc2972682016-02-08 15:42:01 -0700727```
728
Jon Ashburn54791f62016-04-22 14:40:07 -0600729##### Loader Version 0 and 1 Interface Differences
730
731Version 0 and 1 interfaces do not support version negotiation via vk\_icdNegotiateLoaderICDInterfaceVersion.
732ICDs can distinguish version 0 and version 1 interfaces as follows:
733if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
734otherwise the loader only supports version 0.
735
736Version 0 interface does not support vk\_icdGetInstanceProcAddr. Version 0 interface requirements for
737obtaining ICD Vulkan entry points are as follows:
738
739- vkGetInstanceProcAddr exported in the ICD library and returns valid function
740 pointers for all the Vulkan API entry points;
741
742- vkCreateInstance exported in the ICD library;
743
744- vkEnumerateInstanceExtensionProperties exported in the ICD library;
745
746
Jon Ashburnc2972682016-02-08 15:42:01 -0700747Additional Notes:
748
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700749- The loader will filter out extensions requested in vkCreateInstance and
750vkCreateDevice before calling into the ICD; Filtering will be of extensions
Jeff Julianof1619872016-02-17 17:25:42 -0500751advertised by entities (e.g. layers) different from the ICD in question.
752- The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700753properties are obtained from the layer libraries and layer JSON files.
754- If an ICD library wants to implement a layer it can do so by having the
755appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700756- The loader will not call the ICD for
757 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600758- ICDs creating new dispatchable objects via device extensions need to initialize
Jon Ashburn54791f62016-04-22 14:40:07 -0600759the created dispatchable object. The loader has generic trampoline code for unknown
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600760device extensions. This generic trampoline code doesn't initialize the dispatch table within
Jon Ashburn54791f62016-04-22 14:40:07 -0600761the newly created object. See the section for more information on how to initialize created
762dispatchable objects for extensions non known by the loader. [layer link](#creating-new-dispatchable-objects)
Jeff Julianof1619872016-02-17 17:25:42 -0500763
Jon Ashburnc2972682016-02-08 15:42:01 -0700764#### Android
765
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700766The Android loader uses the same protocol for initializing the dispatch
767table as described above. The only difference is that the Android
768loader queries layer and extension information directly from the
769respective libraries and does not use the json manifest files used
770by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700771
Mark Youngcb6e6702016-07-20 11:38:53 -0600772<br/>
773
774## Vulkan layer interface with the loader ##
Jon Ashburnc2972682016-02-08 15:42:01 -0700775--------------------------------------
776
777### Layer discovery
778
779#### Windows
780
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600781<a name="ManifestFileExample"></a>
Jon Ashburnc2972682016-02-08 15:42:01 -0700782##### Properly-Installed Layers
783
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700784In order to find properly-installed layers, the Vulkan loader will use a
785similar mechanism as used for ICDs. Text information files (aka manifest
786files), that use a JSON format, are read in order to identify the names and
787attributes of layers and their extensions. The use of manifest files allows the
788loader to avoid loading any shared library files when the application does not
789query nor request any extensions. Layers and extensions have additional
790complexity, and so their manifest files contain more information than ICD info
791files. For example, a layer shared library file may contain multiple
792layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700793
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700794In order to find properly-installed layers, the Vulkan loader will scan the
795values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700796
797HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
798
799HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
800
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700801Explicit layers are those which are enabled by an application (e.g. with the
802vkCreateInstance function), or by an environment variable (as mentioned
803previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700804
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700805Implicit layers are those which are enabled by their existence. For example,
806certain application environments (e.g. Steam or an automotive infotainment
807system) may have layers which they always want enabled for all applications
808that they start. Other implicit layers may be for all applications started on a
809given system (e.g. layers that overlay frames-per-second). Implicit layers are
810enabled automatically, whereas explicit layers must be enabled explicitly. What
811distinguishes a layer as implicit or explicit is by which registry key its
812layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700813
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700814For each value in these keys which has DWORD data set to 0, the loader opens
815the JSON manifest file specified by the name of the value. Each name must be a
816full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700817
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700818The Vulkan loader will open each info file to obtain information about the
819layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700820
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600821This manifest file is in the JSON format as shown in the following example.
822See 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 -0700823
Jon Ashburncc300a22016-02-11 14:57:30 -0700824```
Jon Ashburnc2972682016-02-08 15:42:01 -0700825{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600826 "file_format_version" : "1.0.0",
827 "layer": {
828 "name": "VK_LAYER_LUNARG_overlay",
829 "type": "INSTANCE",
830 "library_path": "vkOverlayLayer.dll"
831 "api_version" : "1.0.5",
832 "implementation_version" : "2",
833 "description" : "LunarG HUD layer",
834 "functions": {
835 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
836 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
837 },
838 "instance_extensions": [
839 {
840 "name": "VK_EXT_debug_report",
841 "spec_version": "1"
842 },
843 {
844 "name": "VK_VENDOR_ext_x",
845 "spec_version": "3"
846 }
847 ],
848 "device_extensions": [
849 {
850 "name": "VK_EXT_debug_marker",
851 "spec_version": "1",
852 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
853 }
854 ],
855 "enable_environment": {
856 "ENABLE_LAYER_OVERLAY_1": "1"
857 }
858 "disable_environment": {
859 "DISABLE_LAYER_OVERLAY_1": ""
860 }
861 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700862}
Jon Ashburncc300a22016-02-11 14:57:30 -0700863```
Jon Ashburnc2972682016-02-08 15:42:01 -0700864
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700865The "library\_path" specifies either a filename, a relative pathname, or a full
866pathname to a layer shared library (".dll") file, which the loader will attempt
867to load using LoadLibrary(). If the layer is specified via a relative pathname,
868it is relative to the path of the info file (e.g. for cases when an application
869provides a layer that is in the same folder hierarchy as the rest of the
870application files). If the layer is specified via a filename, the shared
871library lives in the system's DLL search path (e.g. in the
872"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700873
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600874If defining multiple layers in a single JSON file prior to "file\_format\_version"
8751.0.1, you would simply define multiple "layer" objects. However, this is not
876valid JSON syntax. Instead, you should now define "file\_format\_version"
8771.0.1 (or newer) and use the new "layers" array object as seen in the
878following example:
879
880```
881{
882 "file_format_version" : "1.0.1",
883 "layers": [
884 {
885 "name": "VK_LAYER_layer_name1",
886 "type": "INSTANCE",
887 ...
888 },
889 {
890 "name": "VK_LAYER_layer_name2",
891 "type": "INSTANCE",
892 ...
893 }
894 ]
895}
896```
897
898You could use the "layers" array object to define a single layer, as long as
899your "file\_format\_version" is defined to at least 1.0.1. It is functionally the
900same as using a single "layer" object.
901
Jon Ashburnc2972682016-02-08 15:42:01 -0700902There are no rules about the name of the text files (except the .json suffix).
903
904There are no rules about the name of the layer shared library files.
905
906##### Using Pre-Production Layers
907
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700908As with ICDs, developers may need to use special, pre-production layers,
909without modifying the properly-installed layers. This need is met with the use
910of the "VK\_LAYER\_PATH" environment variable, which will override the
911mechanism using for finding properly-installed layers. Because many layers may
912exist on a system, this environment variable is a semi-colon-separated list of
913folders that contain layer info files. Only the folder listed in
914"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
915entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700916
917- The full pathname of a folder containing layer info files
918
919#### Linux
920
921##### Properly-Installed Layers
922
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700923In order to find properly-installed layers, the Vulkan loader will use a
924similar mechanism as used for ICDs. Text information files, that use a JSON
925format, are read in order to identify the names and attributes of layers and
926their extensions. The use of text info files allows the loader to avoid loading
927any shared library files when the application does not query nor request any
928extensions. Layers and extensions have additional complexity, and so their info
929files contain more information than ICD info files. For example, a layer shared
930library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700931
932The Vulkan loader will scan the files in the following Linux directories:
933
934/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700935/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700936/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700937/etc/vulkan/implicit\_layer.d
David Pinedo3e163ee2016-04-18 16:59:59 -0600938\$HOME/.local/share/vulkan/explicit\_layer.d
939\$HOME/.local/share/vulkan/implicit\_layer.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700940
941Where $HOME is the current home directory of the application's user id; this
942path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700943
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700944Explicit layers are those which are enabled by an application (e.g. with the
945vkCreateInstance function), or by an environment variable (as mentioned
946previously). Implicit layers are those which are enabled by their existence.
947For example, certain application environments (e.g. Steam or an automotive
948infotainment system) may have layers which they always want enabled for all
949applications that they start. Other implicit layers may be for all applications
950started on a given system (e.g. layers that overlay frames-per-second).
951Implicit layers are enabled automatically, whereas explicit layers must be
952enabled explicitly. What distinguishes a layer as implicit or explicit is by
953which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700954
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700955The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
956installed from Linux-distribution-provided packages. The
957"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
958non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700959
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600960This manifest file is in the JSON format as shown in the following example.
961See 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 -0700962
Jon Ashburncc300a22016-02-11 14:57:30 -0700963```
Jon Ashburnc2972682016-02-08 15:42:01 -0700964{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600965 "file_format_version" : "1.0.0",
966 "layer": {
967 "name": "VK_LAYER_LUNARG_overlay",
968 "type": "INSTANCE",
969 "library_path": "libvkOverlayLayer.so"
970 "api_version" : "1.0.5",
971 "implementation_version" : "2",
972 "description" : "LunarG HUD layer",
973 "functions": {
974 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
975 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
976 },
977 "instance_extensions": [
978 {
979 "name": "VK_EXT_debug_report",
980 "spec_version": "1"
981 },
982 {
983 "name": "VK_VENDOR_ext_x",
984 "spec_version": "3"
985 }
986 ],
987 "device_extensions": [
988 {
989 "name": "VK_EXT_debug_marker",
990 "spec_version": "1",
991 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
992 }
993 ],
994 "enable_environment": {
995 "ENABLE_LAYER_OVERLAY_1": "1"
996 },
997 "disable_environment": {
998 "DISABLE_LAYER_OVERLAY_1": ""
999 }
1000 }
Jon Ashburnc2972682016-02-08 15:42:01 -07001001}
Jon Ashburncc300a22016-02-11 14:57:30 -07001002```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001003The "library\_path" specifies either a filename, a relative pathname, or a full
1004pathname to a layer shared library (".so") file, which the loader will attempt
1005to load using dlopen(). If the layer is specified via a filename, the loader
1006will attempt to open that file as a shared object using dlopen(), and the file
1007must be in a directory that dlopen is configured to look in (Note: various
1008distributions are configured differently). A distribution is free to create
1009Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
1010required to do so. If the layer is specified via a relative pathname, it is
1011relative to the path of the info file (e.g. for cases when an application
1012provides a layer that is in the same directory hierarchy as the rest of the
1013application files).
Jon Ashburnc2972682016-02-08 15:42:01 -07001014
1015There are no rules about the name of the text files (except the .json suffix).
1016
1017There are no rules about the name of the layer shared library files.
1018
1019##### Using Pre-Production Layers
1020
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001021As with ICDs, developers may need to use special, pre-production layers,
1022without modifying the properly-installed layers. This need is met with the use
1023of the "VK\_LAYER\_PATH" environment variable, which will override the
1024mechanism using for finding properly-installed layers. Because many layers may
1025exist on a system, this environment variable is a colon-separated list of
1026directories that contain layer info files. Only the directories listed in
1027"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
1028is:
Jon Ashburnc2972682016-02-08 15:42:01 -07001029
1030- The full pathname of a directory containing layer info files
1031
1032NOTE: these environment variables will be ignored for suid programs.
1033
1034#### Android
1035
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001036The recommended way to enable layers is for applications
1037to programatically enable them. The layers are provided by the application
1038and must live in the application's library folder. The application
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001039enables the layers at vkCreateInstance as any Vulkan
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001040application would.
1041An application enabled for debug has more options. It can enumerate and enable
1042layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -07001043
Mark Youngcb6e6702016-07-20 11:38:53 -06001044<br/>
1045
1046## Layer interface requirements ##
Jon Ashburncc300a22016-02-11 14:57:30 -07001047------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -07001048
1049#### Architectural interface overview
1050
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001051There are two key architectural features that drive the loader to layer library
1052interface: 1) separate and distinct instance and device call chains, and 2)
1053distributed dispatch. First these architectural features will be described and
1054then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -07001055
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001056Call chains are the links of calls for a given Vulkan command from layer module
1057to layer module with the loader and or the ICD being the bottom most command.
1058Call chains are constructed at both the instance level and the device level by
1059the loader with cooperation from the layer libraries. Instance call chains are
1060constructed by the loader when layers are enabled at vkCreateInstance. Device
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001061call chains are constructed by the loader when layers are enabled, by the loader, at
ttyio0811cec2016-04-10 22:09:44 +08001062vkCreateDevice. A layer can intercept Vulkan instance commands, device commands
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001063or both. For a layer to intercept instance commands, it must participate in the
1064instance call chain. For a layer to intercept device commands, it must
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001065participate in the device chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001066
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001067Normally, when a layer intercepts a given Vulkan command, it will call down the
1068instance or device chain as needed. The loader and all layer libraries that
1069participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001070from one entity to the next. This group effort for call chain sequencing is
Jeff Julianof1619872016-02-17 17:25:42 -05001071hereinafter referred to as distributed dispatch. In distributed dispatch, since
1072each layer is responsible for properly calling the next entity in the device or
1073instance chain, a dispatch mechanism is required for all Vulkan commands a
1074layer intercepts. For Vulkan commands that are not intercepted by a layer, or
1075if the layer chooses to terminate a given Vulkan command by not calling down
1076the chain, then no dispatch mechanism is needed for that particular Vulkan
1077command. Only for those Vulkan commands, which may be a subset of all Vulkan
1078commands, that a layer intercepts is a dispatching mechanism by the layer
1079needed. The loader is responsible for dispatching all core and instance
1080extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001081
Jeff Julianof1619872016-02-17 17:25:42 -05001082Instance level Vulkan commands are those that have the dispatchable objects
1083VkInstance, or VkPhysicalDevice as the first parameter and also includes
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001084vkCreateInstance.
Jeff Julianof1619872016-02-17 17:25:42 -05001085
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001086Device level Vulkan commands are those that use VkDevice, VkQueue or
1087VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1088extensions may introduce new instance or device level dispatchable objects, so
1089the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001090
Chia-I Wucb24fec2016-04-20 06:23:24 +08001091#### Layer Library Interface
Jeff Julianof1619872016-02-17 17:25:42 -05001092
Chia-I Wucb24fec2016-04-20 06:23:24 +08001093A layer library is a container of layers. This section defines an extensible
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001094interface to discover layers contained in layer libraries.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001095The extensible programming interface is used on Android only. For Windows and Linux,
1096the layer manifest JSON files are used.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001097
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001098It also specifies the minimal conventions
1099and rules a layer must follow. Other sections might have other guidelines that layers should follow.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001100
1101##### Layer Conventions and Rules
1102
1103A layer, when inserted into an otherwise compliant Vulkan implementation, must
1104still result in a compliant Vulkan implementation[\*]. It must additionally
1105follow some conventions and rules.
1106
1107A layer is always chained with other layers. It must not make invalid calls
1108to or rely on undefined behaviors of its lower layers. When it changes the
1109behavior of a command, it must make sure its upper layers do not make invalid
1110calls to or rely on undefined behaviors of its lower layers because of the
1111changed behavior. For example, when a layer intercepts an object creation
1112command to wrap the objects created by its lower layers, it must make sure its
1113lower layers never see the wrapping objects, directly from itself or
1114indirectly from its upper layers.
1115
Chia-I Wub5e850e2016-05-06 08:41:52 +08001116When a layer requires host memory, it may ignore the provided allocators. It
1117should use memory allocators if the layer is intended to run in a production
1118environment, such as an implicit layer that is always enabled. That will
1119allow applications to include the layer's memory usage.
1120
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001121`vkEnumerateInstanceLayerProperties` must enumerate and only enumerate the
1122layer itself.
1123
1124`vkEnumerateInstanceExtensionProperties` must handle the case where
1125`pLayerName` is itself. It must return `VK_ERROR_LAYER_NOT_PRESENT`
1126otherwise, including when `pLayerName` is `NULL`.
1127
1128`vkEnumerateDeviceLayerProperties` is deprecated and may be omitted. The
1129behavior is undefined.
1130
Chia-I Wuadac8342016-04-22 08:12:19 +08001131`vkEnumerateDeviceExtensionProperties` must handle the case where `pLayerName`
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001132is itself. In other cases, it should normally chain to other layers.
1133
1134`vkCreateInstance` must not generate an error for unrecognized layer names and
1135extension names. It may assume the layer names and extension names have been
1136validated.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001137
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001138`vkGetInstanceProcAddr` intercepts a Vulkan command by returning a local entry point,
1139otherwise it returns the value obtained by calling down the instance chain.
1140 These commands must be intercepted
1141 - vkGetInstanceProcAddr
1142 - vkCreateInstance
1143 - vkCreateDevice (only required for any device-level chaining)
Chia-I Wucb24fec2016-04-20 06:23:24 +08001144
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001145 For compatibility with older layer libraries,
1146 - when `pName` is `vkCreateDevice`, it ignores `instance`.
1147
1148`vkGetDeviceProcAddr` intercepts a Vulkan command by returning a local entry point,
1149otherwise it returns the value obtained by calling down the device chain.
1150
1151The specification requires `NULL` to be returned from `vkGetInstanceProcAddr` and
1152`vkGetDeviceProcAddr` for disabled commands. A layer may return `NULL` itself or
1153rely on the following layers to do so.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001154
Chia-I Wucb24fec2016-04-20 06:23:24 +08001155[\*]: The intention is for layers to have a well-defined baseline behavior.
1156Some of the conventions or rules, for example, may be considered abuses of the
1157specification.
1158
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001159##### Layer Library API Version 0
Chia-I Wucb24fec2016-04-20 06:23:24 +08001160
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001161A layer library supporting interface version 0 must define and export these
1162introspection functions, unrelated to any Vulkan command despite the names,
1163signatures, and other similarities:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001164
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001165 - `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
1166 library. This function never fails.
1167
1168 When a layer library contains only one layer, this function may be an alias
1169 to the layer's `vkEnumerateInstanceLayerProperties`.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001170
1171 - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001172 layers in a layer library. `pLayerName` is always a valid layer name.
1173 This function never fails.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001174
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001175 When a layer library contains only one layer, this function may be an alias
1176 to the layer's `vkEnumerateInstanceExtensionProperties`.
1177
1178 - `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
1179 proper, or empty subset) of layers in a layer library. `physicalDevice` is
1180 always `VK_NULL_HANDLE`. This function never fails.
1181
1182 If a layer is not enumerated by this function, it will not participate in
1183 device command interception.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001184
1185 - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001186 layers in a layer library. `physicalDevice` is always `VK_NULL_HANDLE`.
1187 `pLayerName` is always a valid layer name. This function never fails.
1188
1189The introspection functions are not used by the desktop loader.
1190
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001191It must also define and export these functions one for each layer in the library:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001192
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001193 - `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a layer's vkGetInstanceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001194
1195 When a layer library contains only one layer, this function may
1196 alternatively be named `vkGetInstanceProcAddr`.
1197
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001198 - `<layerName>GetDeviceProcAddr` behaves identically to a layer's vkGetDeviceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001199
1200 When a layer library contains only one layer, this function may
1201 alternatively be named `vkGetDeviceProcAddr`.
1202
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001203All layers contained within a library must support [`vk_layer.h`][]. They do not need to
1204implement commands that they do not intercept. They are recommended not to export
1205any commands.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001206
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001207<a name="LayerLibraryManifestFile"></a>
1208##### Layer Library Manifest File Version 0
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001209On Windows and Linux (desktop), the loader uses manifest files to discover
1210layer libraries and layers. The desktop loader doesn't directly query the
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001211layer library except during chaining.
1212On Android, the loader queries the layer libraries via the introspection functions as outlined above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001213
1214The layer libraries and the manifest files must be kept in sync.
1215
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001216The following table associates the desktop JSON nodes with the layer library introspection queries. It also indicates requirements.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001217
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001218| Property | JSON node | Introspection query | Notes |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001219|----------|-----------|-----------------------|-------|
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001220| file version | file_format_version | N/A | one node required per JSON file |
1221| layers in library | layer | vkEnumerateInstanceLayerProperties | one node required per layer |
1222| layer name | name | vkEnumerateInstanceLayerProperties | one node is required |
1223| layer type | type | vkEnumerate*LayerProperties | see Note 1 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001224| library location | library_path | N/A | one node is required |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001225| vulkan spec version | api_version | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001226| layer implementation version | api_version | vkEnumerateInstanceLayerProperties | see Note 2 |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001227| layer description | description | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001228| chaining functions | functions | vkGet*ProcAddr | see Note 3 |
1229| instance extensions | instance_extensions | vkEnumerateInstanceExtensionProperties | see Note 4 |
1230| device extensions | device_extensions | vkEnumerateDeviceExtensionProperties | see Note 5 |
1231| enable implicit | enable_environment | N/A | See Note 6 |
1232| disable implicit | enable_environment | N/A | See Note 7 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001233
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001234"file\_format\_version" is used to indicate the valid JSON syntax of the file.
1235As nodes are added or deleted which would change the parsing of this file,
1236the file_format_version should change. This version
1237is NOT the same as the layer library interface version. The interface version is a superset
1238of the "file_format_version" and includes the semantics of the nodes in the JSON file.
1239For interface version 0 the file format version must be "1.0.0"
1240
1241Note 1: Prior to deprecation, the "type" node was used to indicate which layer chain(s)
1242to activate the layer upon: instance, device, or both.
1243Distinct instance and device layers are deprecated; there are now just layers.
1244Allowable values for type (both before and after deprecation) are "INSTANCE", "GLOBAL" and, "DEVICE."
1245"DEVICE" layers are skipped over by the loader as if they were not found.
1246Thus, layers must have a type of "GLOBAL" or "INSTANCE" for the loader to include the layer in the enumerated instance layer list.
1247
1248"library\_path" is the filename, full path, or relative path to the library file.
Mark Young57551512016-06-23 11:25:03 -06001249See [Manifest File Example](#ManifestFileExample) section for more details.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001250
1251Note 2: One "implementation\_version" node is required per layer. This node gives the layer version, a single number
1252increasing with backward uncompatible changes.
1253
1254Note 3: The "functions" node is required if the layer is using alternative
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001255names for vkGetInstanceProcAddr or vkGetDeviceProcAddr. vkGetInstanceProcAddr and vkGetDeviceProcAddr
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001256are required for all layers. See further requirements in the Layer Library API section above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001257
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001258Note 4: One "instance_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001259required if any instance
1260extensions are supported by a layer, otherwise the node is optional. Each
1261element of the array must have the nodes "name" and "spec_version" which
1262correspond to VkExtensionProperties "extensionName" and "specVersion"
1263respectively.
1264
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001265Note 5: One "device_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001266required if any device
1267extensions are supported by a layer, otherwise the node is optional. Each
1268element of the array must have the nodes "name" and "spec_version" which
1269correspond to VkExtensionProperties "extensionName" and "specVersion"
1270respectively. Additionally, each element of the array of device extensions
1271must have the node "entrypoints" if the device extension adds Vulkan API commands,
1272otherwise this node is not required.
1273The "entrypoint" node is an array of the names of all entrypoints added by the
1274supported extension.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001275```
1276 "device_extensions": [
1277 {
1278 "name": "VK_EXT_debug_marker",
1279 "spec_version": "1",
1280 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1281 }
1282 ```
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001283
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001284Note 6: The "enable\_environment" node is only for implicit layers only. It is optional for implicit layers.
1285This node gives an environment variable and value required to enable an implicit layer. This
1286environment variable (which should vary with each "version" of the layer) must be set to the
1287given value or else the implicit layer is not loaded. This is for application environments (e.g. Steam) which
1288want to enable a layer(s) only for applications that they launch, and allows
1289for applications run outside of an application environment to not get that
1290implicit layer(s).
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001291
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001292Note 7: The "disable\_environment" node is only for implicit layers only. It is required for implicit layers.
1293This node gives an environment variable and value required to disable an implicit layer. In
1294rare cases of an application not working with an implicit layer, the
1295application can set this environment variable (before calling Vulkan commands)
1296in order to "blacklist" the layer. This environment variable (which should vary
1297with each "version" of the layer) must be set (not particularly to any value).
1298If both the "enable\_environment" and
1299"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001300
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001301#### Layer Dispatch Interface Version 0
1302##### Layer intercept requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001303
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001304- Layers intercept a Vulkan command by defining a C/C++ function with signature
1305identical to the Vulkan API for that command.
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001306- A layer must intercept at least vkGetInstanceProcAddr and
1307vkCreateInstance. Additionally, a layer would also intercept vkGetDeviceProcAddr and vkCreateDevice to participate in the device chain.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001308- For any Vulkan command a layer intercepts which has a non-void return value,
1309an appropriate value must be returned by the layer intercept function.
1310- The layer intercept function must call down the chain to the corresponding
1311Vulkan command in the next entity. Undefined results will occur if a layer
1312doesn't propagate calls down the chain. The two exceptions to this requirement
1313are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1314chain for Vulkan commands that they do not intercept.
1315- Layer intercept functions may insert extra calls to Vulkan commands in
1316addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1317want to add a call to vkQueueWaitIdle after calling down the chain for
1318vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1319chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001320
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001321##### Distributed dispatching requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001322
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001323- For each entry point a layer intercepts, it must keep track of the entry
1324point residing in the next entity in the chain it will call down into. In other
1325words, the layer must have a list of pointers to functions of the appropriate
1326type to call into the next entity. This can be implemented in various ways but
1327for clarity will be referred to as a dispatch table.
1328- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1329(see include/vulkan/vk_layer.h).
1330- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1331dispatch table (see include/vulkan/vk_layer.h).
1332- Layers vkGetInstanceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001333vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001334functions.
1335- Layers vkGetDeviceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001336vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001337functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001338
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001339##### Layer dispatch initialization
Jeff Julianof1619872016-02-17 17:25:42 -05001340
1341- A layer initializes its instance dispatch table within its vkCreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001342function.
Jeff Julianof1619872016-02-17 17:25:42 -05001343- A layer initializes its device dispatch table within its vkCreateDevice
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001344function.
1345- The loader passes a linked list of initialization structures to layers via
1346the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1347for vkCreateInstance and VkCreateDevice respectively.
1348- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001349instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001350include/vulkan/vk_layer.h for details.
1351- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1352"sType" field in VkLayerInstanceCreateInfo.
1353- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1354"sType" field in VkLayerDeviceCreateInfo.
1355- The "function" field indicates how the union field "u" should be interpreted
1356within VkLayer*CreateInfo. The loader will set the "function" field to
1357VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1358VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001359- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001360- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1361by a layer.
1362- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1363vkGetDeviceProcAddr used by a layer.
1364- Given the above structures set up by the loader, layer must initialize their
1365dispatch table as follows:
1366 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1367the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001368 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001369 - For CreateInstance get the next entity's vkCreateInstance by calling the
1370"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001371 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001372 - For CreateDevice get the next entity's vkCreateDevice by calling the
1373"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001374 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001375 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1376 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001377 - Initialize your layer dispatch table by calling the next entity's
1378Get*ProcAddr function once for each Vulkan command needed in your dispatch
1379table
Jon Ashburncc300a22016-02-11 14:57:30 -07001380
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001381##### Example code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001382
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001383```cpp
1384VkResult vkCreateInstance(
1385 const VkInstanceCreateInfo *pCreateInfo,
1386 const VkAllocationCallbacks *pAllocator,
1387 VkInstance *pInstance)
1388{
1389 VkLayerInstanceCreateInfo *chain_info =
1390 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1391
1392 assert(chain_info->u.pLayerInfo);
1393 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1394 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1395 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001396 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001397 if (fpCreateInstance == NULL) {
1398 return VK_ERROR_INITIALIZATION_FAILED;
1399 }
1400
1401 // Advance the link info for the next element of the chain
1402 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1403
1404 // Continue call down the chain
1405 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1406 if (result != VK_SUCCESS)
1407 return result;
1408
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001409 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001410 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001411 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001412 layer_init_instance_dispatch_table(
1413 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1414
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001415 // Other layer initialization
1416 ...
1417
1418 return VK_SUCCESS;
1419}
1420```
1421
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001422##### Example code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001423
1424```cpp
1425VkResult
1426vkCreateDevice(
1427 VkPhysicalDevice gpu,
1428 const VkDeviceCreateInfo *pCreateInfo,
1429 const VkAllocationCallbacks *pAllocator,
1430 VkDevice *pDevice)
1431{
1432 VkLayerDeviceCreateInfo *chain_info =
1433 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1434
1435 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1436 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1437 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1438 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1439 PFN_vkCreateDevice fpCreateDevice =
1440 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1441 if (fpCreateDevice == NULL) {
1442 return VK_ERROR_INITIALIZATION_FAILED;
1443 }
1444
1445 // Advance the link info for the next element on the chain
1446 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1447
1448 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1449 if (result != VK_SUCCESS) {
1450 return result;
1451 }
1452
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001453 // initialize layer's dispatch table
1454 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001455 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001456 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001457
1458 // Other layer initialization
1459 ...
1460
1461 return VK_SUCCESS;
1462}
1463```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001464
Jon Ashburncc300a22016-02-11 14:57:30 -07001465#### Special Considerations
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001466##### Associating private data with Vulkan objects within a layer
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001467A layer may want to associate it's own private data with one or more Vulkan
1468objects.
1469Two common methods to do this are hash maps and object wrapping. The loader
1470supports layers wrapping any Vulkan object including dispatchable objects.
1471Layers which wrap objects should ensure they always unwrap objects before
1472passing them down the chain. This implies the layer must intercept every Vulkan
1473command which uses the object in question. Layers above the object wrapping
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001474layer will see the wrapped object. Layers which wrap dispatchable objects must
1475ensure that the first field in the wrapping structure is a pointer to a dispatch table
1476as defined in vk_layer.h. Specifically, an instance wrapped dispatchable object
1477could be as follows:
1478```
1479struct my_wrapped_instance_obj_ {
1480 VkLayerInstanceDispatchTable *disp;
1481 // whatever data layer wants to add to this object
1482};
1483```
1484A device wrapped dispatchable object could be as follows:
1485```
1486struct my_wrapped_instance_obj_ {
1487 VkLayerDispatchTable *disp;
1488 // whatever data layer wants to add to this object
1489};
1490```
Jeff Julianof1619872016-02-17 17:25:42 -05001491
1492Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001493given object. The key to the map could be the object. Alternatively, for
1494dispatchable objects at a given level (eg device or instance) the layer may
1495want data associated with the VkDevice or VkInstance objects. Since
Jeff Julianof1619872016-02-17 17:25:42 -05001496there are multiple dispatchable objects for a given VkInstance or VkDevice, the
1497VkDevice or VkInstance object is not a great map key. Instead the layer should
1498use the dispatch table pointer within the VkDevice or VkInstance since that
1499will be unique for a given VkInstance or VkDevice.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001500
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001501##### Creating new dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001502Layers which create dispatchable objects take special care. Remember that loader
1503trampoline code normally fills in the dispatch table pointer in the newly
1504created object. Thus, the layer must fill in the dispatch table pointer if the
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001505loader trampoline will not do so. Common cases where a layer (or ICD) may create a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001506dispatchable object without loader trampoline code is as follows:
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001507- object wrapping layers that wrap dispatchable objects
1508- layers which add extensions that create dispatchable objects
1509- layers which insert extra Vulkan commands in the stream of commands they
1510intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001511- ICDs which add extensions that create dispatchable objects
1512
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001513The Windows/Linux loader provides a callback that can be used for initializing
1514a dispatchable object. The callback is passed as an extension structure via the
1515pNext field in VkInstanceCreateInfo and VkDeviceCreateInfo. The callback prototype
1516is defined as follows for instance and device callbacks respectively (see vk_layer.h):
1517```
1518VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance, void *object);
1519VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData)(VkDevice device, void *object);
1520```
1521To obtain these callbacks the layer must search through the list of structures
1522pointed 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:
1523- For CreateInstance the callback structure pointed to by "pNext" is VkLayerInstanceCreateInfo as defined in vk_layer.h.
1524- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within VkInstanceCreateInfo parameter indicates a loader structure.
1525- Within VkLayerInstanceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1526- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetInstanceLoaderData".
1527- For CreateDevice the callback structure pointed to by "pNext" is VkLayerDeviceCreateInfo as defined in include/vulkan/vk_layer.h.
1528- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within VkDeviceCreateInfo parameter indicates a loader structure.
1529- Within VkLayerDeviceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1530- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetDeviceLoaderData".
1531
1532Alternatively, 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 -07001533To fill in the dispatch table pointer in newly created dispatchable object,
1534the 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
1535device). 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 -07001536