blob: ca71fae5cee76af8a58a5ad36cccb018100713e7 [file] [log] [blame] [view]
Jon Ashburnc2972682016-02-08 15:42:01 -07001# Vulkan Loader Specification and Architecture Overview
2
3
4Goals of this document
5----------------------
6
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07007Specify necessary functions and expected behavior of interface between the
8loader library and ICDs and layers for Windows, Linux and Android based
9systems. Also describe the application visible behaviors of the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -070010
11Audience
12--------
13
14Application, Vulkan driver and Vulkan layer developers.
15
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070016Any developers interested in understanding more about loader and layer behavior
17and architecture.
Jon Ashburnc2972682016-02-08 15:42:01 -070018
19
20Loader goals
21------------
22
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070023- Support multiple ICDs (Installable Client Drivers) to co-exist on a system
24without interfering with each other.
Jon Ashburnc2972682016-02-08 15:42:01 -070025
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070026- Support optional modules (layers) that can be enabled by an application,
27developer or the system and have no impact when not enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -070028
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070029- Negligible performance cost for an application calling through the loader
30to an ICD entry point.
Jon Ashburnc2972682016-02-08 15:42:01 -070031
32Architectural overview of layers and loader
33-------------------------------------------
34
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070035Vulkan is a layered architecture. Layers can hook (intercept) Vulkan commands to
Mark Young6d026a72016-06-01 17:49:30 -060036achieve various functionality that a Vulkan driver (aka ICD) or loader doesn't
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070037support. Functionality such as Vulkan API tracing and debugging, API usage
38validation, and other tools such as framebuffer overlays are all natural
39candidates for Vulkan layers. Layers are implemented as libraries that are
40inserted between the application and the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -070041
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070042Not only is Vulkan a layered architecture but it also supports multiple GPUs
43and their drivers. Vulkan commands called by an application may wind up calling
44into a diverse set of modules: loader, layers, and ICDs. The loader is critical
45to managing the proper dispatching of Vulkan commands to the appropriate set of
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070046layers and ICDs. The Vulkan object model allows the loader to insert layers
47into a call chain so the layers can process Vulkan commands prior to the
48ICD being called.
Jon Ashburnc2972682016-02-08 15:42:01 -070049
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070050Vulkan uses an object model to control the scope of a particular action /
51operation. The object to be acted on is always the first parameter of a Vulkan
Mark Young6d026a72016-06-01 17:49:30 -060052call and is a dispatchable object (see Vulkan specification section 2.3 Object
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070053Model). Under the covers, the dispatchable object handle is a pointer to a
54structure that contains a pointer to a dispatch table maintained by the loader.
55This dispatch table contains pointers to the Vulkan functions appropriate to
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070056that object. There are two types of dispatch tables the loader maintains,
Mark Young6d026a72016-06-01 17:49:30 -060057Instance and Device. I.e. a VkInstance object's dispatch table will point to Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070058functions such as vkEnumeratePhysicalDevices, vkDestroyInstance,
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070059vkCreateInstance, etc. Instance functions take a VkInstance or VkPhysicalDevice as
60their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070061
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070062Device objects have a separate dispatch table containing the appropriate
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070063function pointers. The device dispatch table is used for all functions that
64take a VkDevice, VkQueue or VkCommandBuffer as their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070065
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070066These instance and device dispatch tables are constructed when the application
67calls vkCreateInstance and vkCreateDevice. At that time the application and/or
68system can specify optional layers to be included. The loader will initialize
69the specified layers to create a call chain for each Vulkan function and each
70entry of the dispatch table will point to the first element of that chain.
71Thus, the loader builds an instance call chain for each VkInstance that is
72created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070073
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070074For example, the diagram below represents what happens in the call chain for
75vkCreateInstance. After initializing the chain, the loader will call into the
Mark Young6d026a72016-06-01 17:49:30 -060076first layer's vkCreateInstance which will call the next finally terminating in
77the loader again where this function calls every ICD's vkCreateInstance and
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070078saves the results. This allows every enabled layer for this chain to set up
79what it needs based on the VkInstanceCreateInfo structure from the application.
Jon Ashburnc2505562016-02-15 10:19:26 -070080![Instance call chain](instance_call_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070081
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070082This also highlights some of the complexity the loader must manage when using
83instance chains. As shown here, the loader must aggregate information from
84multiple devices when they are present. This means that the loader has to know
85about instance level extensions to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -070086
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070087Device chains are created at vkCreateDevice and are generally simpler because
88they deal with only a single device and the ICD can always be the terminator of
89the chain. The below diagram also illustrates how layers (either device or
90instance) can skip intercepting any given Vulkan entry point.
Jon Ashburnc2505562016-02-15 10:19:26 -070091![Chain skipping layers](chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070092
93Application interface to loader
94-------------------------------
95
Mark Young6d026a72016-06-01 17:49:30 -060096In this section we'll discuss how an application interacts with the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -070097
98- Linking to loader library for core and WSI extension symbols.
99
100- Dynamic Vulkan command lookup & application dispatch table.
101
102- Loader library filenames for linking to different Vulkan ABI versions.
103
104- Layers
105
106- Extensions
107
108- vkGetInstanceProcAddr, vkGetDeviceProcAddr
109
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700110The loader library on Windows, Linux and Android will export all core Vulkan
111and all appropriate Window System Interface (WSI) extensions. This is done to
112make it simpler to get started with Vulkan development. When an application
113links directly to the loader library in this way, the Vulkan calls are simple
114trampoline functions that jump to the appropriate dispatch table entry for the
115object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700116
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700117Applications are not required to link directly to the loader library, instead
118they can use the appropriate platform specific dynamic symbol lookup on the
Mark Young6d026a72016-06-01 17:49:30 -0600119loader library to initialize the application's own dispatch table. This allows
Jeff Julianof1619872016-02-17 17:25:42 -0500120an application to fail gracefully if the loader cannot be found, and it
121provides the fastest mechanism for the application to call Vulkan functions. An
122application will only need to query (via system calls such as dlsym()) the
123address of vkGetInstanceProcAddr from the loader library. Using
124vkGetInstanceProcAddr the application can then discover the address of all
125instance and global functions and extensions, such as vkCreateInstance,
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700126vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties
127in a platform independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700128
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700129The Vulkan loader library will be distributed in various ways including Vulkan
130SDKs, OS package distributions and IHV driver packages. These details are
131beyond the scope of this document. However, the name and versioning of the
132Vulkan loader library is specified so an app can link to the correct Vulkan ABI
133library version. Vulkan versioning is such that ABI backwards compatibility is
Jeff Julianof1619872016-02-17 17:25:42 -0500134guaranteed for all versions with the same major number (e.g. 1.0 and 1.1). On
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700135Windows, the loader library encodes the ABI version in its name such that
136multiple ABI incompatible versions of the loader can peacefully coexist on a
Mark Young6d026a72016-06-01 17:49:30 -0600137given system. The Vulkan loader library file name is "vulkan-<ABI
138version>.dll". For example, for Vulkan version 1.X on Windows the library
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700139filename is vulkan-1.dll. And this library file can typically be found in the
Mark Young6d026a72016-06-01 17:49:30 -0600140windows/system32 directory (on 64-bit Windows installs, the 32-bit version of
141the loader with the same name can be found in the windows/sysWOW64 directory).
Jon Ashburnc2972682016-02-08 15:42:01 -0700142
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700143For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
144number is not encoded in the base of the library filename as on Windows. On
145Linux an application wanting to link to the latest Vulkan ABI version would
146just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
Jeff Julianof1619872016-02-17 17:25:42 -0500147also be linked to by applications (e.g. libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700148
Mark Young6d026a72016-06-01 17:49:30 -0600149####Layer Usage
150
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700151Applications desiring Vulkan functionality beyond what the core API offers may
152use various layers or extensions. A layer cannot add new or modify existing
153Vulkan commands, but may offer extensions that do. A common use of layers is
154for API validation. A developer can use validation layers during application
155development, but during production the layers can be disabled by the
Jeff Julianof1619872016-02-17 17:25:42 -0500156application. Thus, eliminating the overhead of validating the application's
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600157usage of the API. Layers discovered by the loader are reported to the
158application via vkEnumerateInstanceLayerProperties.
159Layers are enabled at vkCreateInstance and are active for all Vulkan commands
Mark Young6d026a72016-06-01 17:49:30 -0600160using the given VkIstance and any of it's child objects. For example, the
161ppEnabledLayerNames array in the VkInstanceCreateInfo structure is used by
162the application to list the layer names to be enabled at vkCreateInstance. At
163vkCreateInstance and vkCreateDevice, the loader will construct call chains that
164include the application specified (enabled) layers. vkCreateDevice will use the
165layers specified at vkCreateInstance. vkEnumerateDeviceLayerProperties and
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600166device layers are deprecated. Order is important in the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700167ppEnabledLayerNames array; array element 0 is the topmost (closest to the
168application) layer inserted in the chain and the last array element is closest
169to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700170
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700171Developers may want to enable layers that are not enabled by the given
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600172application they are using. On Linux and Windows, the environment variable
Mark Young6d026a72016-06-01 17:49:30 -0600173"VK\_INSTANCE\_LAYERS" can be used to enable
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700174additional layers which are not specified (enabled) by the application at
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600175vkCreateInstance. VK\_INSTANCE\_LAYERS is a colon
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700176(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
177relevant with the first layer in the list being the topmost layer (closest to
178the application) and the last layer in the list being the bottommost layer
179(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700180
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700181Application specified layers and user specified layers (via environment
182variables) are aggregated and duplicates removed by the loader when enabling
183layers. Layers specified via environment variable are topmost (closest to the
184application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700185
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700186An example of using these environment variables to activate the validation
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600187layer VK\_LAYER\_LUNARG\_parameter\_validation on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700188
189```
Mark Lobodzinski739391a2016-03-17 15:08:18 -0600190> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation
Jon Ashburnc2972682016-02-08 15:42:01 -0700191
Jon Ashburnc2972682016-02-08 15:42:01 -0700192```
193
Mark Young6d026a72016-06-01 17:49:30 -0600194#### Implicit vs Explicit Layers
195
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700196Some platforms, including Linux and Windows, support layers which are enabled
197automatically by the loader rather than explicitly by the application (or via
198environment variable). Explicit layers are those layers enabled by the
199application (or environment variable) by providing the layer name. Implicit
200layers are those layers enabled by the loader automatically. Any implicit
201layers the loader discovers on the system in the appropriate location will be
202enabled (subject to environment variable overrides described later). Discovery
203of properly installed implicit and explicit layers is described later.
204Explicitly enabling a layer that is implicitly enabled has no additional
205effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700206
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700207Extensions are optional functionality provided by a layer, the loader or an
208ICD. Extensions can modify the behavior of the Vulkan API and need to be
209specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700210
Mark Young6d026a72016-06-01 17:49:30 -0600211#### Instance/Device Extensions
212
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700213Instance extensions can be discovered via
214vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
215vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
216extensions from layers (both explicit and implicit), ICDs and the loader before
217reporting them to the application in vkEnumerate\*ExtensionProperties. The
Jeff Julianof1619872016-02-17 17:25:42 -0500218pLayerName parameter in these functions is used to select either a single layer
219or the Vulkan platform implementation. If pLayerName is NULL, extensions from
220Vulkan implementation components (including loader, implicit layers, and ICDs)
221are enumerated. If pLayerName is equal to a discovered layer module name then
222any extensions from that layer (which may be implicit or explicit) are
223enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report
Jon Ashburn859c7fb2016-03-02 17:26:31 -0700224support for the same extension) are eliminated by the loader. For duplicates, the
225ICD version is reported and the layer version is culled. Extensions must
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700226be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700227
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700228Extension command entry points should be queried via vkGetInstanceProcAddr or
229vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
230extension or core device entry points. Device entry points include any command
231that uses a VkDevice as the first parameter or a dispatchable object that is a
232child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
233vkGetInstanceProcAddr can be used to query either device or instance extension
234entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700235
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700236VkGetDeviceProcAddr is particularly interesting because it will provide the
237most efficient way to call into the ICD. For example, the diagram below shows
238what could happen if the application were to use vkGetDeviceProcAddr for the
Mark Young6d026a72016-06-01 17:49:30 -0600239function "vkGetDeviceQueue" and "vkDestroyDevice" but not "vkAllocateMemory".
240The resulting function pointer (fpGetDeviceQueue) would be the ICD's entry
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700241point if the loader and any enabled layers do not need to see that call. Even
Jeff Julianof1619872016-02-17 17:25:42 -0500242if an enabled layer intercepts the call (e.g. vkDestroyDevice) the loader
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700243trampoline code is skipped for function pointers obtained via
244vkGetDeviceProcAddr. This also means that function pointers obtained via
245vkGetDeviceProcAddr will only work with the specific VkDevice it was created
246for, using it with another device has undefined results. For extensions,
247Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700248
Jon Ashburnc2505562016-02-15 10:19:26 -0700249![Get*ProcAddr efficiency](get_proc_addr.png)
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700250
Mark Young78f88c82016-07-19 11:49:45 -0600251##### WSI Extensions
252
253Khronos approved WSI extensions are available and provide Windows System Integration
254support for various execution environments. It is important to understand that some WSI
255extensions are valid for all targets, but others are particular to a given execution
256environment (and loader). This desktop loader (currently targeting Windows and Linux)
257only enables those WSI extensions that are appropriate to the current environment.
258For the most part, the selection is done in the loader using compile-time preprocessor
259flags. All versions of the desktop loader currently expose at least the following WSI
260extension support:
261- VK_KHR_surface
262- VK_KHR_swapchain
263- VK_KHR_display
264
265In addition, each of the following OS targets for the loader support target-specific extensions:
266- **Windows** : VK_KHR_win32_surface
267- **Linux (default)** : VK_KHR_xcb_surface and VK_KHR_xlib_surface
268- **Linux (Wayland build)** : VK_KHR_wayland_surface
269- **Linux (Mir build)** : VK_KHR_mir_surface
270
271**NOTE:** Wayland and Mir targets are not fully supported at this time and should be considered
272alpha quality.
273
274It is important to understand that while the loader may support the various entry-points
275for these extensions, there is a hand-shake required to actually use them:
276* At least one physical device must support the extension(s)
277* The application must select such a physical device
278* 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).
279* The instance and/or logical device creation must succeed.
280
281Only then can you expect to properly use a WSI extension in your Vulkan program.
282
283##### New Extensions
284
285With the ability to expand Vulkan so easily, extensions will be created that the loader knows
286nothing about. If the extension is a device extension, the loader will pass the unknown
287entry-point down the device call chain ending with the appropriate ICD entry-points.
288However, if the extension is an instance extension, the loader will fail to load it.
289
290*But why doesn't the loader support unknown instance extensions?*
291<br/>
292Let's look again at the Instance call chain:
293![Instance call chain](instance_call_chain.png)
294
295Notice that for a normal instance function call, the loader has to handle passing along the
296function call to the available ICDs. If the loader has no idea of the parameters or return
297value of the instance call, it can't properly pass information along to the ICDs.
298There may be ways to do this, which will be explored in the future. However, for now, this
299loader does not support any unknown instance extensions.
300
301Because the device call-chain does not pass through the loader terminator, this is not
302a problem for device extensions. Instead, device extensions terminate directly in the
303ICD they are associated with.
304
305*Is this a big problem?*
306<br/>
307No! Most extension functionality only affects a device and not an instance or a physical
308device. Thus, the overwhelming majority of extensions will be device extensions rather than
309instance extensions.
310
Jon Ashburnc2972682016-02-08 15:42:01 -0700311
312Vulkan Installable Client Driver interface with the loader
313----------------------------------------------------------
314
315### ICD discovery
316
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700317Vulkan allows multiple drivers each with one or more devices (represented by a
318Vulkan VkPhysicalDevice object) to be used collectively. The loader is
319responsible for discovering available Vulkan ICDs on the system. Given a list
320of available ICDs, the loader can enumerate all the physical devices available
321for an application and return this information to the application. The process
322in which the loader discovers the available Installable Client Drivers (ICDs)
323on a system is platform dependent. Windows, Linux and Android ICD discovery
324details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700325
326#### Windows
327
328##### Properly-Installed ICDs
329
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700330In order to find properly-installed ICDs, the Vulkan loader will scan the
331values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700332
333HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
334
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700335For each value in this key which has DWORD data set to 0, the loader opens the
336JSON format text information file (a.k.a. "manifest file") specified by the
337name of the value. Each name must be a full pathname to the text manifest file.
338The Vulkan loader will open each manifest file to obtain the name or pathname
339of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700340
Jon Ashburncc300a22016-02-11 14:57:30 -0700341 ```
342 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700343 "file_format_version": "1.0.0",
344 "ICD": {
345 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700346 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700347 }
348 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700349 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700350
351
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700352The "library\_path" specifies either a filename, a relative pathname, or a full
353pathname to an ICD shared library file, which the loader will attempt to load
354using LoadLibrary(). If the ICD is specified via a filename, the shared library
David Pinedo3e163ee2016-04-18 16:59:59 -0600355lives in the system's DLL search path (e.g. in the "C:\Windows\System32"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700356folder). If the ICD is specified via a relative pathname, it is relative to the
357path of the manifest file. Relative pathnames are those that do not start with
358a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
359character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700360
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700361The "file\_format\_version" specifies a major.minor.patch version number in
362case the format of the text information file changes in the future. If the same
363ICD shared library supports multiple, incompatible versions of text manifest
364file format versions, it must have multiple text info files (all of which may
365point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700366
Mark Young6d026a72016-06-01 17:49:30 -0600367The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700368API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700369
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700370There are no rules about the name of the text information files (except the
371.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700372
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700373There are no rules about the name of the ICD shared library files. For example,
374if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700375
Jon Ashburncc300a22016-02-11 14:57:30 -0700376```
377[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700378
David Pinedo3e163ee2016-04-18 16:59:59 -0600379"C:\vendor a\vk_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700380
David Pinedo3e163ee2016-04-18 16:59:59 -0600381"C:\windows\system32\vendorb_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700382
David Pinedo3e163ee2016-04-18 16:59:59 -0600383"C:\windows\system32\vendorc_icd.json"=dword:00000000
Jon Ashburncc300a22016-02-11 14:57:30 -0700384```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700385then the loader will open the following text information files, with the
386specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700387
Jon Ashburncc300a22016-02-11 14:57:30 -0700388| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700389|----------------|--------------------|
David Pinedo3e163ee2016-04-18 16:59:59 -0600390|vk\_vendora.json | "ICD": { "library\_path": "C:\VENDOR A\vk_vendora.dll", "api_version": "1.0.5" } |
Tony Barbourd83f06c2016-03-08 14:50:03 -0700391| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.5" } |
392|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.5" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700393
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700394Then the loader will open the three files mentioned in the "Text File Contents"
395column, and then try to load and use the three shared libraries indicated by
396the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700397
398##### Using Pre-Production ICDs
399
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700400IHV developers (and sometimes other developers) need to use special,
401pre-production ICDs. In some cases, a pre-production ICD may be in an
402installable package. In other cases, a pre-production ICD may simply be a
403shared library in the developer's build tree. In this latter case, we want to
404allow developers to point to such an ICD without modifying the
405properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700406
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700407This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
408which will override the mechanism used for finding properly-installed ICDs. In
409other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
410"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
411text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700412
Jon Ashburncc300a22016-02-11 14:57:30 -0700413- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700414
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700415Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
416file for a developer-built ICD. A semi-colon is only used if more than one ICD
417is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700418
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700419For example, if a developer wants to refer to one ICD that they built, they
420could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700421
Jon Ashburncc300a22016-02-11 14:57:30 -0700422C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700423
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700424If a developer wants to refer to two ICDs, one of which is a properly-installed
425ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700426
Jon Ashburncc300a22016-02-11 14:57:30 -0700427C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700428
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700429Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
430"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700431
432#### Linux
433
434##### Properly-Installed ICDs
435
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700436In order to find properly-installed ICDs, the Vulkan loader will scan the files
437in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700438
439/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700440/etc/vulkan/icd.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700441$HOME/.local/share/vulkan/icd.d
442
443Where $HOME is the current home directory of the application's user id; this
444path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700445
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700446These directories will contain text information files (a.k.a. "manifest
447files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700448
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700449The Vulkan loader will open each manifest file found to obtain the name or
450pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700451
Jon Ashburncc300a22016-02-11 14:57:30 -0700452```
453{
Jon Ashburnc2972682016-02-08 15:42:01 -0700454 "file_format_version": "1.0.0",
455 "ICD": {
456 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700457 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700458 }
459}
Jon Ashburncc300a22016-02-11 14:57:30 -0700460```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700461The "library\_path" specifies either a filename, a relative pathname, or a full
462pathname to an ICD shared library file. If the ICD is specified via a filename,
463the loader will attempt to open that file as a shared object using dlopen(),
464and the file must be in a directory that dlopen is configured to look in (Note:
465various distributions are configured differently). A distribution is free to
466create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
467required to do so. If the ICD is specified via a relative pathname, it is
468relative to the path of the info file. Relative pathnames are those that do not
469start with, but do contain at least one directory separator (i.e. the '/'
470character). For example, "lib/vendora.so" and "./vendora.so" are examples of
471relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700472
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700473The "file\_format\_version" provides a major.minor.patch version number in case
474the format of the manifest file changes in the future. If the same ICD shared
475library supports multiple, incompatible versions of manifest file format
476versions, it must have multiple manifest files (all of which may point to the
477same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700478
Mark Young6d026a72016-06-01 17:49:30 -0600479The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700480API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700481
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700482The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
483Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
484ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700485
486There are no rules about the name of the text files (except the .json suffix).
487
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700488There are no rules about the name of the ICD shared library files. For example,
489if the "/usr/share/vulkan/icd.d" directory contain the following files, with
490the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700491
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700492| Text File Name | Text File Contents |
493|-------------------|------------------------|
Tony Barbourd83f06c2016-03-08 14:50:03 -0700494| vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.5" } |
495| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.5" } |
496| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.5" } |
Jon Ashburnc2972682016-02-08 15:42:01 -0700497
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700498then the loader will open the three files mentioned in the "Text File Contents"
499column, and then try to load and use the three shared libraries indicated by
500the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700501
502##### Using Pre-Production ICDs
503
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700504IHV developers (and sometimes other developers) need to use special,
505pre-production ICDs. In some cases, a pre-production ICD may be in an
506installable package. In other cases, a pre-production ICD may simply be a
507shared library in the developer's build tree. In this latter case, we want to
508allow developers to point to such an ICD without modifying the
509properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700510
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700511This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
512which will override the mechanism used for finding properly-installed ICDs. In
513other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700514
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700515The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
516manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700517
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700518- 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 -0700519
520- A full pathname (e.g. "/my\_build/my\_icd.json")
521
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700522Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
523file for a developer-built ICD. A colon is only used if more than one ICD is
524listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700525
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700526For example, if a developer wants to refer to one ICD that they built, they
527could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700528
529/my\_build/my\_icd.json
530
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700531If a developer wants to refer to two ICDs, one of which is a properly-installed
532ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700533
534vendorc\_vulkan.json:/my\_build/my\_icd.json
535
536Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
537
538NOTE: this environment variable will be ignored for suid programs.
539
540#### Android
541
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700542The Android loader lives in the system library folder. The location cannot be
543changed. The loader will load the driver/ICD via hw_get_module with the ID
544of "vulkan". Due to security policies in Android none of this can be modified
545under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700546
547
Jon Ashburncc300a22016-02-11 14:57:30 -0700548ICD interface requirements
549----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700550
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700551Generally, for all Vulkan commands issued by an application, the loader can be
Mark Young6d026a72016-06-01 17:49:30 -0600552viewed as a pass through. That is, the loader generally doesn't modify the
Jon Ashburn54791f62016-04-22 14:40:07 -0600553commands or their parameters, but simply calls the ICDs entry point for that
554command. There are specific additional interface requirements an ICD needs to comply with that
555are over and above any requirements from the Vulkan specification including WSI extension specification.
556These addtional requirements are versioned to allow flexibility in the future.
557These interface requirements will be set forth in the following sections: 1) describing
558which "loader-ICD" interface version is available, 2) detailing the most recent interface version;
5593) the supported, older interface requirements will be described as differences
560from the most recent interface version.
Jon Ashburnc2972682016-02-08 15:42:01 -0700561
562#### Windows and Linux
563
Jon Ashburn54791f62016-04-22 14:40:07 -0600564##### Version Negotiation Between Loader and ICDs
Jon Ashburnc2972682016-02-08 15:42:01 -0700565
Jon Ashburn54791f62016-04-22 14:40:07 -0600566All ICDs (supporting interface version 2 or higher) must export the following
567function that is used for determination of the interface version that will be used.
568This entry point is not a part of the Vulkan API itself, only a private interface
569between the loader and ICDs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700570
Jon Ashburn54791f62016-04-22 14:40:07 -0600571VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion);
Jon Ashburnc2972682016-02-08 15:42:01 -0700572
Jon Ashburn54791f62016-04-22 14:40:07 -0600573This entry point reports the "loader-ICD" interface version supported by both the loader and the ICD.
574The loader informs the ICD of it's desired interface version (typically the latest) via the
575pSupportedVersion parameter.
576This call is the first call made by the loader into the ICD (prior to any calls to
577vk\_icdGetInstanceProcAddr).
Jon Ashburnc2972682016-02-08 15:42:01 -0700578
Jon Ashburn54791f62016-04-22 14:40:07 -0600579If a loader sees that an ICD does not export this symbol it knows that it's dealing
580with a legacy ICD supporting either interface version 0 or 1.
581Similarly, if an ICD sees a call to vk\_icdGetInstanceProcAddr before a call to
582vk_icdGetLoaderICDInterfaceVersion then it knows that it's dealing with a legacy loader
583supporting version 0 or 1.
584Note if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
585otherwise the loader only supports version 0.
Jon Ashburnc2972682016-02-08 15:42:01 -0700586
Jon Ashburn54791f62016-04-22 14:40:07 -0600587The pSupportedVersion parameter is both an input and output parameter.
588It 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 -0500589
Jon Ashburn54791f62016-04-22 14:40:07 -0600590If the ICD receiving the call no longer supports the interface version provided
591by the loader (due to deprecation) then it can report VK_ERROR_INCOMPATIBLE_DRIVER error,
592otherwise it sets the value pointed by pSupportedVersion to the latest interface
593version supported by both the ICD and the loader and returns VK_SUCCESS.
594The ICD should report VK_SUCCESS in case the loader provided interface version
595is newer than that supported by the ICD, as it's the loader's responsibility to
596determine whether it can support the older interface version supported by the ICD.
597The ICD should also report VK_SUCCESS in the case it's interface version is greater
598than the loader's, but return the loader's version. Thus, upon return of VK_SUCCESS
599the pSupportedVersion will contain the desired interface version to be used by the ICD.
Jon Ashburnc2972682016-02-08 15:42:01 -0700600
Jon Ashburn54791f62016-04-22 14:40:07 -0600601If the loader receives back an interface version from the ICD that the loader no longer
602supports (due to deprecation) or it receives a VK_ERROR_INCOMPATIBLE_DRIVER error
603instead of VK_SUCCESS then the loader will treat the ICD as incompatible
604and will not load it for use. In this case the application will not see the ICDs vkPhysicalDevice
605during enumeration.
Jon Ashburnc2972682016-02-08 15:42:01 -0700606
Jon Ashburn54791f62016-04-22 14:40:07 -0600607##### Loader Version 2 Interface Requirements
Jon Ashburnc2972682016-02-08 15:42:01 -0700608
Jon Ashburn54791f62016-04-22 14:40:07 -0600609Version 2 interface has requirements in three areas: 1) ICD Vulkan entry point discovery,
6102) KHR_surface related requirements in the WSI extensions, 3) Vulkan dispatchable object
611creation requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700612
Jon Ashburn54791f62016-04-22 14:40:07 -0600613###### ICD Vulkan entry point discovery
614All ICDs must export the following function that is used for discovery of ICD Vulkan entry points.
615This 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 -0700616
Jon Ashburn54791f62016-04-22 14:40:07 -0600617VKAPI\_ATTR PFN\_vkVoidFunction VKAPI\_CALL vk\_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
618
619This function has very similar semantics to the Vulkan command vkGetInstanceProcAddr.
620vk\_icdGetInstanceProcAddr returns valid function pointers for all the global level
621and instance level Vulkan commands, and also for vkGetDeviceProcAddr.
622Global level commands are those
623which contain no dispatchable object as the first parameter, such as
624vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must
625support querying global level entry points by calling
626vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level
627commands are those that have either VkInstance, or VkPhysicalDevice as the
628first parameter dispatchable object. Both core entry points and any instance
629extension entry points the ICD supports should be available via
630vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and
631use new instance level dispatchable objects other than VkInstance and
632VkPhysicalDevice, in which case extension entry points using these newly
633defined dispatchable objects must be queryable via vk\_icdGetInstanceProcAddr.
634
635All other Vulkan entry points must either NOT be exported from the ICD
636library or else NOT use the official Vulkan function names if they are
637exported. This requirement is for ICD libraries that include other
638functionality (such as OpenGL library) and thus could be loaded by the
639application prior to when the Vulkan loader library is loaded by the
640application. In other words, the ICD library exported Vulkan symbols must not
641clash with the loader's exported Vulkan symbols.
642
643Beware of interposing by dynamic OS library loaders if the official Vulkan
644names are used. On Linux, if official names are used, the ICD library must be
645linked with -Bsymbolic.
646
647###### Handling KHR_surface objects in the WSI extensions
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700648Normally, ICDs handle object creation and destruction for various Vulkan
649objects. The WSI surface extensions for Linux and Windows
650(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
651VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
652handled differently. For these extensions, the VkSurfaceKHR object creation and
653destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700654
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006551. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
656 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700657
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006582. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
659 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700660
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006613. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
662 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700663
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006644. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
Jeff Julianof1619872016-02-17 17:25:42 -0500665 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field
666 in the structure is a VkIcdSurfaceBase enumerant that indicates whether the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700667 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700668
Jon Ashburn54791f62016-04-22 14:40:07 -0600669###### ICD dispatchable object creation
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700670As previously covered, the loader requires dispatch tables to be accessible
671within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
672VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
673dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700674
Jon Ashburncc300a22016-02-11 14:57:30 -0700675- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700676
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700677- The loader will replace the first entry with a pointer to the dispatch table
678 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700679
Jon Ashburncc300a22016-02-11 14:57:30 -07006801. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700681
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006822. This pointer points to a regular C structure with the first entry being a
683 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
684 classes. The C\++ compiler may put a vtable at offset zero if your class is
Jeff Julianof1619872016-02-17 17:25:42 -0500685 non-POD due to the use of a virtual function. In this case use a regular C
686 structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700687
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006883. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
689 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700690
691```
692
Jon Ashburncc300a22016-02-11 14:57:30 -0700693#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700694
Jon Ashburncc300a22016-02-11 14:57:30 -0700695union _VK_LOADER_DATA {
696 uintptr loadermagic;
697 void *loaderData;
698} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700699
Jon Ashburncc300a22016-02-11 14:57:30 -0700700vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700701{
Jon Ashburncc300a22016-02-11 14:57:30 -0700702 vkObj *newObj = alloc_obj();
703 ...
704 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700705
Jon Ashburncc300a22016-02-11 14:57:30 -0700706 set_loader_magic_value(newObj);
707 ...
708 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700709}
Jon Ashburnc2972682016-02-08 15:42:01 -0700710```
711
Jon Ashburn54791f62016-04-22 14:40:07 -0600712##### Loader Version 0 and 1 Interface Differences
713
714Version 0 and 1 interfaces do not support version negotiation via vk\_icdNegotiateLoaderICDInterfaceVersion.
715ICDs can distinguish version 0 and version 1 interfaces as follows:
716if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
717otherwise the loader only supports version 0.
718
719Version 0 interface does not support vk\_icdGetInstanceProcAddr. Version 0 interface requirements for
720obtaining ICD Vulkan entry points are as follows:
721
722- vkGetInstanceProcAddr exported in the ICD library and returns valid function
723 pointers for all the Vulkan API entry points;
724
725- vkCreateInstance exported in the ICD library;
726
727- vkEnumerateInstanceExtensionProperties exported in the ICD library;
728
729
Jon Ashburnc2972682016-02-08 15:42:01 -0700730Additional Notes:
731
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700732- The loader will filter out extensions requested in vkCreateInstance and
733vkCreateDevice before calling into the ICD; Filtering will be of extensions
Jeff Julianof1619872016-02-17 17:25:42 -0500734advertised by entities (e.g. layers) different from the ICD in question.
735- The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700736properties are obtained from the layer libraries and layer JSON files.
737- If an ICD library wants to implement a layer it can do so by having the
738appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700739- The loader will not call the ICD for
740 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600741- ICDs creating new dispatchable objects via device extensions need to initialize
Jon Ashburn54791f62016-04-22 14:40:07 -0600742the created dispatchable object. The loader has generic trampoline code for unknown
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600743device extensions. This generic trampoline code doesn't initialize the dispatch table within
Jon Ashburn54791f62016-04-22 14:40:07 -0600744the newly created object. See the section for more information on how to initialize created
745dispatchable objects for extensions non known by the loader. [layer link](#creating-new-dispatchable-objects)
Jeff Julianof1619872016-02-17 17:25:42 -0500746
Jon Ashburnc2972682016-02-08 15:42:01 -0700747#### Android
748
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700749The Android loader uses the same protocol for initializing the dispatch
750table as described above. The only difference is that the Android
751loader queries layer and extension information directly from the
752respective libraries and does not use the json manifest files used
753by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700754
755Vulkan layer interface with the loader
756--------------------------------------
757
758### Layer discovery
759
760#### Windows
761
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600762<a name="ManifestFileExample"></a>
Jon Ashburnc2972682016-02-08 15:42:01 -0700763##### Properly-Installed Layers
764
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700765In order to find properly-installed layers, the Vulkan loader will use a
766similar mechanism as used for ICDs. Text information files (aka manifest
767files), that use a JSON format, are read in order to identify the names and
768attributes of layers and their extensions. The use of manifest files allows the
769loader to avoid loading any shared library files when the application does not
770query nor request any extensions. Layers and extensions have additional
771complexity, and so their manifest files contain more information than ICD info
772files. For example, a layer shared library file may contain multiple
773layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700774
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700775In order to find properly-installed layers, the Vulkan loader will scan the
776values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700777
778HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
779
780HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
781
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700782Explicit layers are those which are enabled by an application (e.g. with the
783vkCreateInstance function), or by an environment variable (as mentioned
784previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700785
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700786Implicit layers are those which are enabled by their existence. For example,
787certain application environments (e.g. Steam or an automotive infotainment
788system) may have layers which they always want enabled for all applications
789that they start. Other implicit layers may be for all applications started on a
790given system (e.g. layers that overlay frames-per-second). Implicit layers are
791enabled automatically, whereas explicit layers must be enabled explicitly. What
792distinguishes a layer as implicit or explicit is by which registry key its
793layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700794
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700795For each value in these keys which has DWORD data set to 0, the loader opens
796the JSON manifest file specified by the name of the value. Each name must be a
797full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700798
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700799The Vulkan loader will open each info file to obtain information about the
800layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700801
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600802This manifest file is in the JSON format as shown in the following example.
803See 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 -0700804
Jon Ashburncc300a22016-02-11 14:57:30 -0700805```
Jon Ashburnc2972682016-02-08 15:42:01 -0700806{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600807 "file_format_version" : "1.0.0",
808 "layer": {
809 "name": "VK_LAYER_LUNARG_overlay",
810 "type": "INSTANCE",
811 "library_path": "vkOverlayLayer.dll"
812 "api_version" : "1.0.5",
813 "implementation_version" : "2",
814 "description" : "LunarG HUD layer",
815 "functions": {
816 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
817 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
818 },
819 "instance_extensions": [
820 {
821 "name": "VK_EXT_debug_report",
822 "spec_version": "1"
823 },
824 {
825 "name": "VK_VENDOR_ext_x",
826 "spec_version": "3"
827 }
828 ],
829 "device_extensions": [
830 {
831 "name": "VK_EXT_debug_marker",
832 "spec_version": "1",
833 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
834 }
835 ],
836 "enable_environment": {
837 "ENABLE_LAYER_OVERLAY_1": "1"
838 }
839 "disable_environment": {
840 "DISABLE_LAYER_OVERLAY_1": ""
841 }
842 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700843}
Jon Ashburncc300a22016-02-11 14:57:30 -0700844```
Jon Ashburnc2972682016-02-08 15:42:01 -0700845
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700846The "library\_path" specifies either a filename, a relative pathname, or a full
847pathname to a layer shared library (".dll") file, which the loader will attempt
848to load using LoadLibrary(). If the layer is specified via a relative pathname,
849it is relative to the path of the info file (e.g. for cases when an application
850provides a layer that is in the same folder hierarchy as the rest of the
851application files). If the layer is specified via a filename, the shared
852library lives in the system's DLL search path (e.g. in the
853"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700854
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600855If defining multiple layers in a single JSON file prior to "file\_format\_version"
8561.0.1, you would simply define multiple "layer" objects. However, this is not
857valid JSON syntax. Instead, you should now define "file\_format\_version"
8581.0.1 (or newer) and use the new "layers" array object as seen in the
859following example:
860
861```
862{
863 "file_format_version" : "1.0.1",
864 "layers": [
865 {
866 "name": "VK_LAYER_layer_name1",
867 "type": "INSTANCE",
868 ...
869 },
870 {
871 "name": "VK_LAYER_layer_name2",
872 "type": "INSTANCE",
873 ...
874 }
875 ]
876}
877```
878
879You could use the "layers" array object to define a single layer, as long as
880your "file\_format\_version" is defined to at least 1.0.1. It is functionally the
881same as using a single "layer" object.
882
Jon Ashburnc2972682016-02-08 15:42:01 -0700883There are no rules about the name of the text files (except the .json suffix).
884
885There are no rules about the name of the layer shared library files.
886
887##### Using Pre-Production Layers
888
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700889As with ICDs, developers may need to use special, pre-production layers,
890without modifying the properly-installed layers. This need is met with the use
891of the "VK\_LAYER\_PATH" environment variable, which will override the
892mechanism using for finding properly-installed layers. Because many layers may
893exist on a system, this environment variable is a semi-colon-separated list of
894folders that contain layer info files. Only the folder listed in
895"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
896entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700897
898- The full pathname of a folder containing layer info files
899
900#### Linux
901
902##### Properly-Installed Layers
903
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700904In order to find properly-installed layers, the Vulkan loader will use a
905similar mechanism as used for ICDs. Text information files, that use a JSON
906format, are read in order to identify the names and attributes of layers and
907their extensions. The use of text info files allows the loader to avoid loading
908any shared library files when the application does not query nor request any
909extensions. Layers and extensions have additional complexity, and so their info
910files contain more information than ICD info files. For example, a layer shared
911library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700912
913The Vulkan loader will scan the files in the following Linux directories:
914
915/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700916/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700917/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700918/etc/vulkan/implicit\_layer.d
David Pinedo3e163ee2016-04-18 16:59:59 -0600919\$HOME/.local/share/vulkan/explicit\_layer.d
920\$HOME/.local/share/vulkan/implicit\_layer.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700921
922Where $HOME is the current home directory of the application's user id; this
923path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700924
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700925Explicit layers are those which are enabled by an application (e.g. with the
926vkCreateInstance function), or by an environment variable (as mentioned
927previously). Implicit layers are those which are enabled by their existence.
928For example, certain application environments (e.g. Steam or an automotive
929infotainment system) may have layers which they always want enabled for all
930applications that they start. Other implicit layers may be for all applications
931started on a given system (e.g. layers that overlay frames-per-second).
932Implicit layers are enabled automatically, whereas explicit layers must be
933enabled explicitly. What distinguishes a layer as implicit or explicit is by
934which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700935
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700936The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
937installed from Linux-distribution-provided packages. The
938"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
939non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700940
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600941This manifest file is in the JSON format as shown in the following example.
942See 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 -0700943
Jon Ashburncc300a22016-02-11 14:57:30 -0700944```
Jon Ashburnc2972682016-02-08 15:42:01 -0700945{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600946 "file_format_version" : "1.0.0",
947 "layer": {
948 "name": "VK_LAYER_LUNARG_overlay",
949 "type": "INSTANCE",
950 "library_path": "libvkOverlayLayer.so"
951 "api_version" : "1.0.5",
952 "implementation_version" : "2",
953 "description" : "LunarG HUD layer",
954 "functions": {
955 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
956 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
957 },
958 "instance_extensions": [
959 {
960 "name": "VK_EXT_debug_report",
961 "spec_version": "1"
962 },
963 {
964 "name": "VK_VENDOR_ext_x",
965 "spec_version": "3"
966 }
967 ],
968 "device_extensions": [
969 {
970 "name": "VK_EXT_debug_marker",
971 "spec_version": "1",
972 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
973 }
974 ],
975 "enable_environment": {
976 "ENABLE_LAYER_OVERLAY_1": "1"
977 },
978 "disable_environment": {
979 "DISABLE_LAYER_OVERLAY_1": ""
980 }
981 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700982}
Jon Ashburncc300a22016-02-11 14:57:30 -0700983```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700984The "library\_path" specifies either a filename, a relative pathname, or a full
985pathname to a layer shared library (".so") file, which the loader will attempt
986to load using dlopen(). If the layer is specified via a filename, the loader
987will attempt to open that file as a shared object using dlopen(), and the file
988must be in a directory that dlopen is configured to look in (Note: various
989distributions are configured differently). A distribution is free to create
990Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
991required to do so. If the layer is specified via a relative pathname, it is
992relative to the path of the info file (e.g. for cases when an application
993provides a layer that is in the same directory hierarchy as the rest of the
994application files).
Jon Ashburnc2972682016-02-08 15:42:01 -0700995
996There are no rules about the name of the text files (except the .json suffix).
997
998There are no rules about the name of the layer shared library files.
999
1000##### Using Pre-Production Layers
1001
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001002As with ICDs, developers may need to use special, pre-production layers,
1003without modifying the properly-installed layers. This need is met with the use
1004of the "VK\_LAYER\_PATH" environment variable, which will override the
1005mechanism using for finding properly-installed layers. Because many layers may
1006exist on a system, this environment variable is a colon-separated list of
1007directories that contain layer info files. Only the directories listed in
1008"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
1009is:
Jon Ashburnc2972682016-02-08 15:42:01 -07001010
1011- The full pathname of a directory containing layer info files
1012
1013NOTE: these environment variables will be ignored for suid programs.
1014
1015#### Android
1016
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001017The recommended way to enable layers is for applications
1018to programatically enable them. The layers are provided by the application
1019and must live in the application's library folder. The application
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001020enables the layers at vkCreateInstance as any Vulkan
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001021application would.
1022An application enabled for debug has more options. It can enumerate and enable
1023layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -07001024
Jon Ashburncc300a22016-02-11 14:57:30 -07001025Layer interface requirements
1026------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -07001027
1028#### Architectural interface overview
1029
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001030There are two key architectural features that drive the loader to layer library
1031interface: 1) separate and distinct instance and device call chains, and 2)
1032distributed dispatch. First these architectural features will be described and
1033then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -07001034
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001035Call chains are the links of calls for a given Vulkan command from layer module
1036to layer module with the loader and or the ICD being the bottom most command.
1037Call chains are constructed at both the instance level and the device level by
1038the loader with cooperation from the layer libraries. Instance call chains are
1039constructed by the loader when layers are enabled at vkCreateInstance. Device
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001040call chains are constructed by the loader when layers are enabled, by the loader, at
ttyio0811cec2016-04-10 22:09:44 +08001041vkCreateDevice. A layer can intercept Vulkan instance commands, device commands
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001042or both. For a layer to intercept instance commands, it must participate in the
1043instance call chain. For a layer to intercept device commands, it must
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001044participate in the device chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001045
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001046Normally, when a layer intercepts a given Vulkan command, it will call down the
1047instance or device chain as needed. The loader and all layer libraries that
1048participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001049from one entity to the next. This group effort for call chain sequencing is
Jeff Julianof1619872016-02-17 17:25:42 -05001050hereinafter referred to as distributed dispatch. In distributed dispatch, since
1051each layer is responsible for properly calling the next entity in the device or
1052instance chain, a dispatch mechanism is required for all Vulkan commands a
1053layer intercepts. For Vulkan commands that are not intercepted by a layer, or
1054if the layer chooses to terminate a given Vulkan command by not calling down
1055the chain, then no dispatch mechanism is needed for that particular Vulkan
1056command. Only for those Vulkan commands, which may be a subset of all Vulkan
1057commands, that a layer intercepts is a dispatching mechanism by the layer
1058needed. The loader is responsible for dispatching all core and instance
1059extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001060
Jeff Julianof1619872016-02-17 17:25:42 -05001061Instance level Vulkan commands are those that have the dispatchable objects
1062VkInstance, or VkPhysicalDevice as the first parameter and also includes
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001063vkCreateInstance.
Jeff Julianof1619872016-02-17 17:25:42 -05001064
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001065Device level Vulkan commands are those that use VkDevice, VkQueue or
1066VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1067extensions may introduce new instance or device level dispatchable objects, so
1068the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001069
Chia-I Wucb24fec2016-04-20 06:23:24 +08001070#### Layer Library Interface
Jeff Julianof1619872016-02-17 17:25:42 -05001071
Chia-I Wucb24fec2016-04-20 06:23:24 +08001072A layer library is a container of layers. This section defines an extensible
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001073interface to discover layers contained in layer libraries.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001074The extensible programming interface is used on Android only. For Windows and Linux,
1075the layer manifest JSON files are used.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001076
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001077It also specifies the minimal conventions
1078and rules a layer must follow. Other sections might have other guidelines that layers should follow.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001079
1080##### Layer Conventions and Rules
1081
1082A layer, when inserted into an otherwise compliant Vulkan implementation, must
1083still result in a compliant Vulkan implementation[\*]. It must additionally
1084follow some conventions and rules.
1085
1086A layer is always chained with other layers. It must not make invalid calls
1087to or rely on undefined behaviors of its lower layers. When it changes the
1088behavior of a command, it must make sure its upper layers do not make invalid
1089calls to or rely on undefined behaviors of its lower layers because of the
1090changed behavior. For example, when a layer intercepts an object creation
1091command to wrap the objects created by its lower layers, it must make sure its
1092lower layers never see the wrapping objects, directly from itself or
1093indirectly from its upper layers.
1094
Chia-I Wub5e850e2016-05-06 08:41:52 +08001095When a layer requires host memory, it may ignore the provided allocators. It
1096should use memory allocators if the layer is intended to run in a production
1097environment, such as an implicit layer that is always enabled. That will
1098allow applications to include the layer's memory usage.
1099
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001100`vkEnumerateInstanceLayerProperties` must enumerate and only enumerate the
1101layer itself.
1102
1103`vkEnumerateInstanceExtensionProperties` must handle the case where
1104`pLayerName` is itself. It must return `VK_ERROR_LAYER_NOT_PRESENT`
1105otherwise, including when `pLayerName` is `NULL`.
1106
1107`vkEnumerateDeviceLayerProperties` is deprecated and may be omitted. The
1108behavior is undefined.
1109
Chia-I Wuadac8342016-04-22 08:12:19 +08001110`vkEnumerateDeviceExtensionProperties` must handle the case where `pLayerName`
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001111is itself. In other cases, it should normally chain to other layers.
1112
1113`vkCreateInstance` must not generate an error for unrecognized layer names and
1114extension names. It may assume the layer names and extension names have been
1115validated.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001116
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001117`vkGetInstanceProcAddr` intercepts a Vulkan command by returning a local entry point,
1118otherwise it returns the value obtained by calling down the instance chain.
1119 These commands must be intercepted
1120 - vkGetInstanceProcAddr
1121 - vkCreateInstance
1122 - vkCreateDevice (only required for any device-level chaining)
Chia-I Wucb24fec2016-04-20 06:23:24 +08001123
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001124 For compatibility with older layer libraries,
1125 - when `pName` is `vkCreateDevice`, it ignores `instance`.
1126
1127`vkGetDeviceProcAddr` intercepts a Vulkan command by returning a local entry point,
1128otherwise it returns the value obtained by calling down the device chain.
1129
1130The specification requires `NULL` to be returned from `vkGetInstanceProcAddr` and
1131`vkGetDeviceProcAddr` for disabled commands. A layer may return `NULL` itself or
1132rely on the following layers to do so.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001133
Chia-I Wucb24fec2016-04-20 06:23:24 +08001134[\*]: The intention is for layers to have a well-defined baseline behavior.
1135Some of the conventions or rules, for example, may be considered abuses of the
1136specification.
1137
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001138##### Layer Library API Version 0
Chia-I Wucb24fec2016-04-20 06:23:24 +08001139
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001140A layer library supporting interface version 0 must define and export these
1141introspection functions, unrelated to any Vulkan command despite the names,
1142signatures, and other similarities:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001143
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001144 - `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
1145 library. This function never fails.
1146
1147 When a layer library contains only one layer, this function may be an alias
1148 to the layer's `vkEnumerateInstanceLayerProperties`.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001149
1150 - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001151 layers in a layer library. `pLayerName` is always a valid layer name.
1152 This function never fails.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001153
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001154 When a layer library contains only one layer, this function may be an alias
1155 to the layer's `vkEnumerateInstanceExtensionProperties`.
1156
1157 - `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
1158 proper, or empty subset) of layers in a layer library. `physicalDevice` is
1159 always `VK_NULL_HANDLE`. This function never fails.
1160
1161 If a layer is not enumerated by this function, it will not participate in
1162 device command interception.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001163
1164 - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001165 layers in a layer library. `physicalDevice` is always `VK_NULL_HANDLE`.
1166 `pLayerName` is always a valid layer name. This function never fails.
1167
1168The introspection functions are not used by the desktop loader.
1169
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001170It must also define and export these functions one for each layer in the library:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001171
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001172 - `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a layer's vkGetInstanceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001173
1174 When a layer library contains only one layer, this function may
1175 alternatively be named `vkGetInstanceProcAddr`.
1176
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001177 - `<layerName>GetDeviceProcAddr` behaves identically to a layer's vkGetDeviceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001178
1179 When a layer library contains only one layer, this function may
1180 alternatively be named `vkGetDeviceProcAddr`.
1181
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001182All layers contained within a library must support [`vk_layer.h`][]. They do not need to
1183implement commands that they do not intercept. They are recommended not to export
1184any commands.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001185
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001186<a name="LayerLibraryManifestFile"></a>
1187##### Layer Library Manifest File Version 0
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001188On Windows and Linux (desktop), the loader uses manifest files to discover
1189layer libraries and layers. The desktop loader doesn't directly query the
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001190layer library except during chaining.
1191On Android, the loader queries the layer libraries via the introspection functions as outlined above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001192
1193The layer libraries and the manifest files must be kept in sync.
1194
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001195The following table associates the desktop JSON nodes with the layer library introspection queries. It also indicates requirements.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001196
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001197| Property | JSON node | Introspection query | Notes |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001198|----------|-----------|-----------------------|-------|
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001199| file version | file_format_version | N/A | one node required per JSON file |
1200| layers in library | layer | vkEnumerateInstanceLayerProperties | one node required per layer |
1201| layer name | name | vkEnumerateInstanceLayerProperties | one node is required |
1202| layer type | type | vkEnumerate*LayerProperties | see Note 1 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001203| library location | library_path | N/A | one node is required |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001204| vulkan spec version | api_version | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001205| layer implementation version | api_version | vkEnumerateInstanceLayerProperties | see Note 2 |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001206| layer description | description | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001207| chaining functions | functions | vkGet*ProcAddr | see Note 3 |
1208| instance extensions | instance_extensions | vkEnumerateInstanceExtensionProperties | see Note 4 |
1209| device extensions | device_extensions | vkEnumerateDeviceExtensionProperties | see Note 5 |
1210| enable implicit | enable_environment | N/A | See Note 6 |
1211| disable implicit | enable_environment | N/A | See Note 7 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001212
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001213"file\_format\_version" is used to indicate the valid JSON syntax of the file.
1214As nodes are added or deleted which would change the parsing of this file,
1215the file_format_version should change. This version
1216is NOT the same as the layer library interface version. The interface version is a superset
1217of the "file_format_version" and includes the semantics of the nodes in the JSON file.
1218For interface version 0 the file format version must be "1.0.0"
1219
1220Note 1: Prior to deprecation, the "type" node was used to indicate which layer chain(s)
1221to activate the layer upon: instance, device, or both.
1222Distinct instance and device layers are deprecated; there are now just layers.
1223Allowable values for type (both before and after deprecation) are "INSTANCE", "GLOBAL" and, "DEVICE."
1224"DEVICE" layers are skipped over by the loader as if they were not found.
1225Thus, layers must have a type of "GLOBAL" or "INSTANCE" for the loader to include the layer in the enumerated instance layer list.
1226
1227"library\_path" is the filename, full path, or relative path to the library file.
Mark Young57551512016-06-23 11:25:03 -06001228See [Manifest File Example](#ManifestFileExample) section for more details.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001229
1230Note 2: One "implementation\_version" node is required per layer. This node gives the layer version, a single number
1231increasing with backward uncompatible changes.
1232
1233Note 3: The "functions" node is required if the layer is using alternative
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001234names for vkGetInstanceProcAddr or vkGetDeviceProcAddr. vkGetInstanceProcAddr and vkGetDeviceProcAddr
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001235are required for all layers. See further requirements in the Layer Library API section above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001236
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001237Note 4: One "instance_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001238required if any instance
1239extensions are supported by a layer, otherwise the node is optional. Each
1240element of the array must have the nodes "name" and "spec_version" which
1241correspond to VkExtensionProperties "extensionName" and "specVersion"
1242respectively.
1243
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001244Note 5: One "device_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001245required if any device
1246extensions are supported by a layer, otherwise the node is optional. Each
1247element of the array must have the nodes "name" and "spec_version" which
1248correspond to VkExtensionProperties "extensionName" and "specVersion"
1249respectively. Additionally, each element of the array of device extensions
1250must have the node "entrypoints" if the device extension adds Vulkan API commands,
1251otherwise this node is not required.
1252The "entrypoint" node is an array of the names of all entrypoints added by the
1253supported extension.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001254```
1255 "device_extensions": [
1256 {
1257 "name": "VK_EXT_debug_marker",
1258 "spec_version": "1",
1259 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1260 }
1261 ```
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001262
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001263Note 6: The "enable\_environment" node is only for implicit layers only. It is optional for implicit layers.
1264This node gives an environment variable and value required to enable an implicit layer. This
1265environment variable (which should vary with each "version" of the layer) must be set to the
1266given value or else the implicit layer is not loaded. This is for application environments (e.g. Steam) which
1267want to enable a layer(s) only for applications that they launch, and allows
1268for applications run outside of an application environment to not get that
1269implicit layer(s).
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001270
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001271Note 7: The "disable\_environment" node is only for implicit layers only. It is required for implicit layers.
1272This node gives an environment variable and value required to disable an implicit layer. In
1273rare cases of an application not working with an implicit layer, the
1274application can set this environment variable (before calling Vulkan commands)
1275in order to "blacklist" the layer. This environment variable (which should vary
1276with each "version" of the layer) must be set (not particularly to any value).
1277If both the "enable\_environment" and
1278"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001279
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001280#### Layer Dispatch Interface Version 0
1281##### Layer intercept requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001282
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001283- Layers intercept a Vulkan command by defining a C/C++ function with signature
1284identical to the Vulkan API for that command.
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001285- A layer must intercept at least vkGetInstanceProcAddr and
1286vkCreateInstance. Additionally, a layer would also intercept vkGetDeviceProcAddr and vkCreateDevice to participate in the device chain.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001287- For any Vulkan command a layer intercepts which has a non-void return value,
1288an appropriate value must be returned by the layer intercept function.
1289- The layer intercept function must call down the chain to the corresponding
1290Vulkan command in the next entity. Undefined results will occur if a layer
1291doesn't propagate calls down the chain. The two exceptions to this requirement
1292are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1293chain for Vulkan commands that they do not intercept.
1294- Layer intercept functions may insert extra calls to Vulkan commands in
1295addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1296want to add a call to vkQueueWaitIdle after calling down the chain for
1297vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1298chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001299
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001300##### Distributed dispatching requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001301
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001302- For each entry point a layer intercepts, it must keep track of the entry
1303point residing in the next entity in the chain it will call down into. In other
1304words, the layer must have a list of pointers to functions of the appropriate
1305type to call into the next entity. This can be implemented in various ways but
1306for clarity will be referred to as a dispatch table.
1307- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1308(see include/vulkan/vk_layer.h).
1309- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1310dispatch table (see include/vulkan/vk_layer.h).
1311- Layers vkGetInstanceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001312vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001313functions.
1314- Layers vkGetDeviceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001315vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001316functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001317
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001318##### Layer dispatch initialization
Jeff Julianof1619872016-02-17 17:25:42 -05001319
1320- A layer initializes its instance dispatch table within its vkCreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001321function.
Jeff Julianof1619872016-02-17 17:25:42 -05001322- A layer initializes its device dispatch table within its vkCreateDevice
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001323function.
1324- The loader passes a linked list of initialization structures to layers via
1325the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1326for vkCreateInstance and VkCreateDevice respectively.
1327- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001328instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001329include/vulkan/vk_layer.h for details.
1330- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1331"sType" field in VkLayerInstanceCreateInfo.
1332- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1333"sType" field in VkLayerDeviceCreateInfo.
1334- The "function" field indicates how the union field "u" should be interpreted
1335within VkLayer*CreateInfo. The loader will set the "function" field to
1336VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1337VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001338- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001339- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1340by a layer.
1341- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1342vkGetDeviceProcAddr used by a layer.
1343- Given the above structures set up by the loader, layer must initialize their
1344dispatch table as follows:
1345 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1346the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001347 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001348 - For CreateInstance get the next entity's vkCreateInstance by calling the
1349"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001350 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001351 - For CreateDevice get the next entity's vkCreateDevice by calling the
1352"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001353 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001354 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1355 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001356 - Initialize your layer dispatch table by calling the next entity's
1357Get*ProcAddr function once for each Vulkan command needed in your dispatch
1358table
Jon Ashburncc300a22016-02-11 14:57:30 -07001359
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001360##### Example code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001361
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001362```cpp
1363VkResult vkCreateInstance(
1364 const VkInstanceCreateInfo *pCreateInfo,
1365 const VkAllocationCallbacks *pAllocator,
1366 VkInstance *pInstance)
1367{
1368 VkLayerInstanceCreateInfo *chain_info =
1369 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1370
1371 assert(chain_info->u.pLayerInfo);
1372 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1373 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1374 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001375 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001376 if (fpCreateInstance == NULL) {
1377 return VK_ERROR_INITIALIZATION_FAILED;
1378 }
1379
1380 // Advance the link info for the next element of the chain
1381 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1382
1383 // Continue call down the chain
1384 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1385 if (result != VK_SUCCESS)
1386 return result;
1387
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001388 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001389 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001390 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001391 layer_init_instance_dispatch_table(
1392 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1393
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001394 // Other layer initialization
1395 ...
1396
1397 return VK_SUCCESS;
1398}
1399```
1400
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001401##### Example code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001402
1403```cpp
1404VkResult
1405vkCreateDevice(
1406 VkPhysicalDevice gpu,
1407 const VkDeviceCreateInfo *pCreateInfo,
1408 const VkAllocationCallbacks *pAllocator,
1409 VkDevice *pDevice)
1410{
1411 VkLayerDeviceCreateInfo *chain_info =
1412 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1413
1414 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1415 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1416 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1417 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1418 PFN_vkCreateDevice fpCreateDevice =
1419 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1420 if (fpCreateDevice == NULL) {
1421 return VK_ERROR_INITIALIZATION_FAILED;
1422 }
1423
1424 // Advance the link info for the next element on the chain
1425 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1426
1427 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1428 if (result != VK_SUCCESS) {
1429 return result;
1430 }
1431
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001432 // initialize layer's dispatch table
1433 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001434 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001435 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001436
1437 // Other layer initialization
1438 ...
1439
1440 return VK_SUCCESS;
1441}
1442```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001443
Jon Ashburncc300a22016-02-11 14:57:30 -07001444#### Special Considerations
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001445##### Associating private data with Vulkan objects within a layer
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001446A layer may want to associate it's own private data with one or more Vulkan
1447objects.
1448Two common methods to do this are hash maps and object wrapping. The loader
1449supports layers wrapping any Vulkan object including dispatchable objects.
1450Layers which wrap objects should ensure they always unwrap objects before
1451passing them down the chain. This implies the layer must intercept every Vulkan
1452command which uses the object in question. Layers above the object wrapping
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001453layer will see the wrapped object. Layers which wrap dispatchable objects must
1454ensure that the first field in the wrapping structure is a pointer to a dispatch table
1455as defined in vk_layer.h. Specifically, an instance wrapped dispatchable object
1456could be as follows:
1457```
1458struct my_wrapped_instance_obj_ {
1459 VkLayerInstanceDispatchTable *disp;
1460 // whatever data layer wants to add to this object
1461};
1462```
1463A device wrapped dispatchable object could be as follows:
1464```
1465struct my_wrapped_instance_obj_ {
1466 VkLayerDispatchTable *disp;
1467 // whatever data layer wants to add to this object
1468};
1469```
Jeff Julianof1619872016-02-17 17:25:42 -05001470
1471Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001472given object. The key to the map could be the object. Alternatively, for
1473dispatchable objects at a given level (eg device or instance) the layer may
1474want data associated with the VkDevice or VkInstance objects. Since
Jeff Julianof1619872016-02-17 17:25:42 -05001475there are multiple dispatchable objects for a given VkInstance or VkDevice, the
1476VkDevice or VkInstance object is not a great map key. Instead the layer should
1477use the dispatch table pointer within the VkDevice or VkInstance since that
1478will be unique for a given VkInstance or VkDevice.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001479
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001480##### Creating new dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001481Layers which create dispatchable objects take special care. Remember that loader
1482trampoline code normally fills in the dispatch table pointer in the newly
1483created object. Thus, the layer must fill in the dispatch table pointer if the
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001484loader trampoline will not do so. Common cases where a layer (or ICD) may create a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001485dispatchable object without loader trampoline code is as follows:
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001486- object wrapping layers that wrap dispatchable objects
1487- layers which add extensions that create dispatchable objects
1488- layers which insert extra Vulkan commands in the stream of commands they
1489intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001490- ICDs which add extensions that create dispatchable objects
1491
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001492The Windows/Linux loader provides a callback that can be used for initializing
1493a dispatchable object. The callback is passed as an extension structure via the
1494pNext field in VkInstanceCreateInfo and VkDeviceCreateInfo. The callback prototype
1495is defined as follows for instance and device callbacks respectively (see vk_layer.h):
1496```
1497VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance, void *object);
1498VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData)(VkDevice device, void *object);
1499```
1500To obtain these callbacks the layer must search through the list of structures
1501pointed 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:
1502- For CreateInstance the callback structure pointed to by "pNext" is VkLayerInstanceCreateInfo as defined in vk_layer.h.
1503- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within VkInstanceCreateInfo parameter indicates a loader structure.
1504- Within VkLayerInstanceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1505- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetInstanceLoaderData".
1506- For CreateDevice the callback structure pointed to by "pNext" is VkLayerDeviceCreateInfo as defined in include/vulkan/vk_layer.h.
1507- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within VkDeviceCreateInfo parameter indicates a loader structure.
1508- Within VkLayerDeviceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1509- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetDeviceLoaderData".
1510
1511Alternatively, 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 -07001512To fill in the dispatch table pointer in newly created dispatchable object,
1513the 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
1514device). 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 -07001515