blob: 3f0fef86568ac9319fa776bc4ee08c259c45e539 [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
Jon Ashburnc2972682016-02-08 15:42:01 -0700251
252Vulkan Installable Client Driver interface with the loader
253----------------------------------------------------------
254
255### ICD discovery
256
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700257Vulkan allows multiple drivers each with one or more devices (represented by a
258Vulkan VkPhysicalDevice object) to be used collectively. The loader is
259responsible for discovering available Vulkan ICDs on the system. Given a list
260of available ICDs, the loader can enumerate all the physical devices available
261for an application and return this information to the application. The process
262in which the loader discovers the available Installable Client Drivers (ICDs)
263on a system is platform dependent. Windows, Linux and Android ICD discovery
264details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700265
266#### Windows
267
268##### Properly-Installed ICDs
269
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700270In order to find properly-installed ICDs, the Vulkan loader will scan the
271values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700272
273HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
274
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700275For each value in this key which has DWORD data set to 0, the loader opens the
276JSON format text information file (a.k.a. "manifest file") specified by the
277name of the value. Each name must be a full pathname to the text manifest file.
278The Vulkan loader will open each manifest file to obtain the name or pathname
279of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700280
Jon Ashburncc300a22016-02-11 14:57:30 -0700281 ```
282 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700283 "file_format_version": "1.0.0",
284 "ICD": {
285 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700286 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700287 }
288 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700289 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700290
291
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700292The "library\_path" specifies either a filename, a relative pathname, or a full
293pathname to an ICD shared library file, which the loader will attempt to load
294using LoadLibrary(). If the ICD is specified via a filename, the shared library
David Pinedo3e163ee2016-04-18 16:59:59 -0600295lives in the system's DLL search path (e.g. in the "C:\Windows\System32"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700296folder). If the ICD is specified via a relative pathname, it is relative to the
297path of the manifest file. Relative pathnames are those that do not start with
298a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
299character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700300
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700301The "file\_format\_version" specifies a major.minor.patch version number in
302case the format of the text information file changes in the future. If the same
303ICD shared library supports multiple, incompatible versions of text manifest
304file format versions, it must have multiple text info files (all of which may
305point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700306
Mark Young6d026a72016-06-01 17:49:30 -0600307The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700308API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700309
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700310There are no rules about the name of the text information files (except the
311.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700312
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700313There are no rules about the name of the ICD shared library files. For example,
314if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700315
Jon Ashburncc300a22016-02-11 14:57:30 -0700316```
317[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700318
David Pinedo3e163ee2016-04-18 16:59:59 -0600319"C:\vendor a\vk_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700320
David Pinedo3e163ee2016-04-18 16:59:59 -0600321"C:\windows\system32\vendorb_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700322
David Pinedo3e163ee2016-04-18 16:59:59 -0600323"C:\windows\system32\vendorc_icd.json"=dword:00000000
Jon Ashburncc300a22016-02-11 14:57:30 -0700324```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700325then the loader will open the following text information files, with the
326specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700327
Jon Ashburncc300a22016-02-11 14:57:30 -0700328| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700329|----------------|--------------------|
David Pinedo3e163ee2016-04-18 16:59:59 -0600330|vk\_vendora.json | "ICD": { "library\_path": "C:\VENDOR A\vk_vendora.dll", "api_version": "1.0.5" } |
Tony Barbourd83f06c2016-03-08 14:50:03 -0700331| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.5" } |
332|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.5" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700333
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700334Then the loader will open the three files mentioned in the "Text File Contents"
335column, and then try to load and use the three shared libraries indicated by
336the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700337
338##### Using Pre-Production ICDs
339
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700340IHV developers (and sometimes other developers) need to use special,
341pre-production ICDs. In some cases, a pre-production ICD may be in an
342installable package. In other cases, a pre-production ICD may simply be a
343shared library in the developer's build tree. In this latter case, we want to
344allow developers to point to such an ICD without modifying the
345properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700346
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700347This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
348which will override the mechanism used for finding properly-installed ICDs. In
349other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
350"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
351text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700352
Jon Ashburncc300a22016-02-11 14:57:30 -0700353- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700354
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700355Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
356file for a developer-built ICD. A semi-colon is only used if more than one ICD
357is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700358
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700359For example, if a developer wants to refer to one ICD that they built, they
360could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700361
Jon Ashburncc300a22016-02-11 14:57:30 -0700362C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700363
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700364If a developer wants to refer to two ICDs, one of which is a properly-installed
365ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700366
Jon Ashburncc300a22016-02-11 14:57:30 -0700367C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700368
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700369Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
370"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700371
372#### Linux
373
374##### Properly-Installed ICDs
375
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700376In order to find properly-installed ICDs, the Vulkan loader will scan the files
377in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700378
379/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700380/etc/vulkan/icd.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700381$HOME/.local/share/vulkan/icd.d
382
383Where $HOME is the current home directory of the application's user id; this
384path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700385
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700386These directories will contain text information files (a.k.a. "manifest
387files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700388
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700389The Vulkan loader will open each manifest file found to obtain the name or
390pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700391
Jon Ashburncc300a22016-02-11 14:57:30 -0700392```
393{
Jon Ashburnc2972682016-02-08 15:42:01 -0700394 "file_format_version": "1.0.0",
395 "ICD": {
396 "library_path": "path to ICD library",
Tony Barbourd83f06c2016-03-08 14:50:03 -0700397 "api_version": "1.0.5"
Jon Ashburnc2972682016-02-08 15:42:01 -0700398 }
399}
Jon Ashburncc300a22016-02-11 14:57:30 -0700400```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700401The "library\_path" specifies either a filename, a relative pathname, or a full
402pathname to an ICD shared library file. If the ICD is specified via a filename,
403the loader will attempt to open that file as a shared object using dlopen(),
404and the file must be in a directory that dlopen is configured to look in (Note:
405various distributions are configured differently). A distribution is free to
406create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
407required to do so. If the ICD is specified via a relative pathname, it is
408relative to the path of the info file. Relative pathnames are those that do not
409start with, but do contain at least one directory separator (i.e. the '/'
410character). For example, "lib/vendora.so" and "./vendora.so" are examples of
411relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700412
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700413The "file\_format\_version" provides a major.minor.patch version number in case
414the format of the manifest file changes in the future. If the same ICD shared
415library supports multiple, incompatible versions of manifest file format
416versions, it must have multiple manifest files (all of which may point to the
417same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700418
Mark Young6d026a72016-06-01 17:49:30 -0600419The "api\_version" specifies the major.minor.patch version number of the Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700420API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700421
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700422The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
423Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
424ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700425
426There are no rules about the name of the text files (except the .json suffix).
427
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700428There are no rules about the name of the ICD shared library files. For example,
429if the "/usr/share/vulkan/icd.d" directory contain the following files, with
430the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700431
Jon Ashburn26ed3f32016-02-14 21:54:52 -0700432| Text File Name | Text File Contents |
433|-------------------|------------------------|
Tony Barbourd83f06c2016-03-08 14:50:03 -0700434| vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.5" } |
435| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.5" } |
436| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.5" } |
Jon Ashburnc2972682016-02-08 15:42:01 -0700437
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700438then the loader will open the three files mentioned in the "Text File Contents"
439column, and then try to load and use the three shared libraries indicated by
440the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700441
442##### Using Pre-Production ICDs
443
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700444IHV developers (and sometimes other developers) need to use special,
445pre-production ICDs. In some cases, a pre-production ICD may be in an
446installable package. In other cases, a pre-production ICD may simply be a
447shared library in the developer's build tree. In this latter case, we want to
448allow developers to point to such an ICD without modifying the
449properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700450
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700451This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
452which will override the mechanism used for finding properly-installed ICDs. In
453other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700454
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700455The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
456manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700457
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700458- 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 -0700459
460- A full pathname (e.g. "/my\_build/my\_icd.json")
461
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700462Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
463file for a developer-built ICD. A colon is only used if more than one ICD is
464listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700465
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700466For example, if a developer wants to refer to one ICD that they built, they
467could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700468
469/my\_build/my\_icd.json
470
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700471If a developer wants to refer to two ICDs, one of which is a properly-installed
472ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700473
474vendorc\_vulkan.json:/my\_build/my\_icd.json
475
476Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
477
478NOTE: this environment variable will be ignored for suid programs.
479
480#### Android
481
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700482The Android loader lives in the system library folder. The location cannot be
483changed. The loader will load the driver/ICD via hw_get_module with the ID
484of "vulkan". Due to security policies in Android none of this can be modified
485under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700486
487
Jon Ashburncc300a22016-02-11 14:57:30 -0700488ICD interface requirements
489----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700490
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700491Generally, for all Vulkan commands issued by an application, the loader can be
Mark Young6d026a72016-06-01 17:49:30 -0600492viewed as a pass through. That is, the loader generally doesn't modify the
Jon Ashburn54791f62016-04-22 14:40:07 -0600493commands or their parameters, but simply calls the ICDs entry point for that
494command. There are specific additional interface requirements an ICD needs to comply with that
495are over and above any requirements from the Vulkan specification including WSI extension specification.
496These addtional requirements are versioned to allow flexibility in the future.
497These interface requirements will be set forth in the following sections: 1) describing
498which "loader-ICD" interface version is available, 2) detailing the most recent interface version;
4993) the supported, older interface requirements will be described as differences
500from the most recent interface version.
Jon Ashburnc2972682016-02-08 15:42:01 -0700501
502#### Windows and Linux
503
Jon Ashburn54791f62016-04-22 14:40:07 -0600504##### Version Negotiation Between Loader and ICDs
Jon Ashburnc2972682016-02-08 15:42:01 -0700505
Jon Ashburn54791f62016-04-22 14:40:07 -0600506All ICDs (supporting interface version 2 or higher) must export the following
507function that is used for determination of the interface version that will be used.
508This entry point is not a part of the Vulkan API itself, only a private interface
509between the loader and ICDs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700510
Jon Ashburn54791f62016-04-22 14:40:07 -0600511VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion);
Jon Ashburnc2972682016-02-08 15:42:01 -0700512
Jon Ashburn54791f62016-04-22 14:40:07 -0600513This entry point reports the "loader-ICD" interface version supported by both the loader and the ICD.
514The loader informs the ICD of it's desired interface version (typically the latest) via the
515pSupportedVersion parameter.
516This call is the first call made by the loader into the ICD (prior to any calls to
517vk\_icdGetInstanceProcAddr).
Jon Ashburnc2972682016-02-08 15:42:01 -0700518
Jon Ashburn54791f62016-04-22 14:40:07 -0600519If a loader sees that an ICD does not export this symbol it knows that it's dealing
520with a legacy ICD supporting either interface version 0 or 1.
521Similarly, if an ICD sees a call to vk\_icdGetInstanceProcAddr before a call to
522vk_icdGetLoaderICDInterfaceVersion then it knows that it's dealing with a legacy loader
523supporting version 0 or 1.
524Note if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
525otherwise the loader only supports version 0.
Jon Ashburnc2972682016-02-08 15:42:01 -0700526
Jon Ashburn54791f62016-04-22 14:40:07 -0600527The pSupportedVersion parameter is both an input and output parameter.
528It 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 -0500529
Jon Ashburn54791f62016-04-22 14:40:07 -0600530If the ICD receiving the call no longer supports the interface version provided
531by the loader (due to deprecation) then it can report VK_ERROR_INCOMPATIBLE_DRIVER error,
532otherwise it sets the value pointed by pSupportedVersion to the latest interface
533version supported by both the ICD and the loader and returns VK_SUCCESS.
534The ICD should report VK_SUCCESS in case the loader provided interface version
535is newer than that supported by the ICD, as it's the loader's responsibility to
536determine whether it can support the older interface version supported by the ICD.
537The ICD should also report VK_SUCCESS in the case it's interface version is greater
538than the loader's, but return the loader's version. Thus, upon return of VK_SUCCESS
539the pSupportedVersion will contain the desired interface version to be used by the ICD.
Jon Ashburnc2972682016-02-08 15:42:01 -0700540
Jon Ashburn54791f62016-04-22 14:40:07 -0600541If the loader receives back an interface version from the ICD that the loader no longer
542supports (due to deprecation) or it receives a VK_ERROR_INCOMPATIBLE_DRIVER error
543instead of VK_SUCCESS then the loader will treat the ICD as incompatible
544and will not load it for use. In this case the application will not see the ICDs vkPhysicalDevice
545during enumeration.
Jon Ashburnc2972682016-02-08 15:42:01 -0700546
Jon Ashburn54791f62016-04-22 14:40:07 -0600547##### Loader Version 2 Interface Requirements
Jon Ashburnc2972682016-02-08 15:42:01 -0700548
Jon Ashburn54791f62016-04-22 14:40:07 -0600549Version 2 interface has requirements in three areas: 1) ICD Vulkan entry point discovery,
5502) KHR_surface related requirements in the WSI extensions, 3) Vulkan dispatchable object
551creation requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700552
Jon Ashburn54791f62016-04-22 14:40:07 -0600553###### ICD Vulkan entry point discovery
554All ICDs must export the following function that is used for discovery of ICD Vulkan entry points.
555This 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 -0700556
Jon Ashburn54791f62016-04-22 14:40:07 -0600557VKAPI\_ATTR PFN\_vkVoidFunction VKAPI\_CALL vk\_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
558
559This function has very similar semantics to the Vulkan command vkGetInstanceProcAddr.
560vk\_icdGetInstanceProcAddr returns valid function pointers for all the global level
561and instance level Vulkan commands, and also for vkGetDeviceProcAddr.
562Global level commands are those
563which contain no dispatchable object as the first parameter, such as
564vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must
565support querying global level entry points by calling
566vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level
567commands are those that have either VkInstance, or VkPhysicalDevice as the
568first parameter dispatchable object. Both core entry points and any instance
569extension entry points the ICD supports should be available via
570vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and
571use new instance level dispatchable objects other than VkInstance and
572VkPhysicalDevice, in which case extension entry points using these newly
573defined dispatchable objects must be queryable via vk\_icdGetInstanceProcAddr.
574
575All other Vulkan entry points must either NOT be exported from the ICD
576library or else NOT use the official Vulkan function names if they are
577exported. This requirement is for ICD libraries that include other
578functionality (such as OpenGL library) and thus could be loaded by the
579application prior to when the Vulkan loader library is loaded by the
580application. In other words, the ICD library exported Vulkan symbols must not
581clash with the loader's exported Vulkan symbols.
582
583Beware of interposing by dynamic OS library loaders if the official Vulkan
584names are used. On Linux, if official names are used, the ICD library must be
585linked with -Bsymbolic.
586
587###### Handling KHR_surface objects in the WSI extensions
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700588Normally, ICDs handle object creation and destruction for various Vulkan
589objects. The WSI surface extensions for Linux and Windows
590(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
591VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
592handled differently. For these extensions, the VkSurfaceKHR object creation and
593destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700594
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005951. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
596 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700597
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005982. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
599 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700600
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006013. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
602 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700603
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006044. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
Jeff Julianof1619872016-02-17 17:25:42 -0500605 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field
606 in the structure is a VkIcdSurfaceBase enumerant that indicates whether the
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700607 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700608
Jon Ashburn54791f62016-04-22 14:40:07 -0600609###### ICD dispatchable object creation
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700610As previously covered, the loader requires dispatch tables to be accessible
611within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
612VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
613dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700614
Jon Ashburncc300a22016-02-11 14:57:30 -0700615- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700616
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700617- The loader will replace the first entry with a pointer to the dispatch table
618 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700619
Jon Ashburncc300a22016-02-11 14:57:30 -07006201. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700621
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006222. This pointer points to a regular C structure with the first entry being a
623 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
624 classes. The C\++ compiler may put a vtable at offset zero if your class is
Jeff Julianof1619872016-02-17 17:25:42 -0500625 non-POD due to the use of a virtual function. In this case use a regular C
626 structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700627
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07006283. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
629 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700630
631```
632
Jon Ashburncc300a22016-02-11 14:57:30 -0700633#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700634
Jon Ashburncc300a22016-02-11 14:57:30 -0700635union _VK_LOADER_DATA {
636 uintptr loadermagic;
637 void *loaderData;
638} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700639
Jon Ashburncc300a22016-02-11 14:57:30 -0700640vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700641{
Jon Ashburncc300a22016-02-11 14:57:30 -0700642 vkObj *newObj = alloc_obj();
643 ...
644 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700645
Jon Ashburncc300a22016-02-11 14:57:30 -0700646 set_loader_magic_value(newObj);
647 ...
648 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700649}
Jon Ashburnc2972682016-02-08 15:42:01 -0700650```
651
Jon Ashburn54791f62016-04-22 14:40:07 -0600652##### Loader Version 0 and 1 Interface Differences
653
654Version 0 and 1 interfaces do not support version negotiation via vk\_icdNegotiateLoaderICDInterfaceVersion.
655ICDs can distinguish version 0 and version 1 interfaces as follows:
656if the loader calls vk\_icdGetInstanceProcAddr first it supports version 1,
657otherwise the loader only supports version 0.
658
659Version 0 interface does not support vk\_icdGetInstanceProcAddr. Version 0 interface requirements for
660obtaining ICD Vulkan entry points are as follows:
661
662- vkGetInstanceProcAddr exported in the ICD library and returns valid function
663 pointers for all the Vulkan API entry points;
664
665- vkCreateInstance exported in the ICD library;
666
667- vkEnumerateInstanceExtensionProperties exported in the ICD library;
668
669
Jon Ashburnc2972682016-02-08 15:42:01 -0700670Additional Notes:
671
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700672- The loader will filter out extensions requested in vkCreateInstance and
673vkCreateDevice before calling into the ICD; Filtering will be of extensions
Jeff Julianof1619872016-02-17 17:25:42 -0500674advertised by entities (e.g. layers) different from the ICD in question.
675- The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700676properties are obtained from the layer libraries and layer JSON files.
677- If an ICD library wants to implement a layer it can do so by having the
678appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700679- The loader will not call the ICD for
680 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600681- ICDs creating new dispatchable objects via device extensions need to initialize
Jon Ashburn54791f62016-04-22 14:40:07 -0600682the created dispatchable object. The loader has generic trampoline code for unknown
Jon Ashburn2b2f6182016-04-04 16:37:37 -0600683device extensions. This generic trampoline code doesn't initialize the dispatch table within
Jon Ashburn54791f62016-04-22 14:40:07 -0600684the newly created object. See the section for more information on how to initialize created
685dispatchable objects for extensions non known by the loader. [layer link](#creating-new-dispatchable-objects)
Jeff Julianof1619872016-02-17 17:25:42 -0500686
Jon Ashburnc2972682016-02-08 15:42:01 -0700687#### Android
688
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700689The Android loader uses the same protocol for initializing the dispatch
690table as described above. The only difference is that the Android
691loader queries layer and extension information directly from the
692respective libraries and does not use the json manifest files used
693by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700694
695Vulkan layer interface with the loader
696--------------------------------------
697
698### Layer discovery
699
700#### Windows
701
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600702<a name="ManifestFileExample"></a>
Jon Ashburnc2972682016-02-08 15:42:01 -0700703##### Properly-Installed Layers
704
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700705In order to find properly-installed layers, the Vulkan loader will use a
706similar mechanism as used for ICDs. Text information files (aka manifest
707files), that use a JSON format, are read in order to identify the names and
708attributes of layers and their extensions. The use of manifest files allows the
709loader to avoid loading any shared library files when the application does not
710query nor request any extensions. Layers and extensions have additional
711complexity, and so their manifest files contain more information than ICD info
712files. For example, a layer shared library file may contain multiple
713layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700714
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700715In order to find properly-installed layers, the Vulkan loader will scan the
716values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700717
718HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
719
720HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
721
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700722Explicit layers are those which are enabled by an application (e.g. with the
723vkCreateInstance function), or by an environment variable (as mentioned
724previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700725
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700726Implicit layers are those which are enabled by their existence. For example,
727certain application environments (e.g. Steam or an automotive infotainment
728system) may have layers which they always want enabled for all applications
729that they start. Other implicit layers may be for all applications started on a
730given system (e.g. layers that overlay frames-per-second). Implicit layers are
731enabled automatically, whereas explicit layers must be enabled explicitly. What
732distinguishes a layer as implicit or explicit is by which registry key its
733layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700734
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700735For each value in these keys which has DWORD data set to 0, the loader opens
736the JSON manifest file specified by the name of the value. Each name must be a
737full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700738
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700739The Vulkan loader will open each info file to obtain information about the
740layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700741
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600742This manifest file is in the JSON format as shown in the following example.
743See 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 -0700744
Jon Ashburncc300a22016-02-11 14:57:30 -0700745```
Jon Ashburnc2972682016-02-08 15:42:01 -0700746{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600747 "file_format_version" : "1.0.0",
748 "layer": {
749 "name": "VK_LAYER_LUNARG_overlay",
750 "type": "INSTANCE",
751 "library_path": "vkOverlayLayer.dll"
752 "api_version" : "1.0.5",
753 "implementation_version" : "2",
754 "description" : "LunarG HUD layer",
755 "functions": {
756 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
757 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
758 },
759 "instance_extensions": [
760 {
761 "name": "VK_EXT_debug_report",
762 "spec_version": "1"
763 },
764 {
765 "name": "VK_VENDOR_ext_x",
766 "spec_version": "3"
767 }
768 ],
769 "device_extensions": [
770 {
771 "name": "VK_EXT_debug_marker",
772 "spec_version": "1",
773 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
774 }
775 ],
776 "enable_environment": {
777 "ENABLE_LAYER_OVERLAY_1": "1"
778 }
779 "disable_environment": {
780 "DISABLE_LAYER_OVERLAY_1": ""
781 }
782 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700783}
Jon Ashburncc300a22016-02-11 14:57:30 -0700784```
Jon Ashburnc2972682016-02-08 15:42:01 -0700785
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700786The "library\_path" specifies either a filename, a relative pathname, or a full
787pathname to a layer shared library (".dll") file, which the loader will attempt
788to load using LoadLibrary(). If the layer is specified via a relative pathname,
789it is relative to the path of the info file (e.g. for cases when an application
790provides a layer that is in the same folder hierarchy as the rest of the
791application files). If the layer is specified via a filename, the shared
792library lives in the system's DLL search path (e.g. in the
793"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700794
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600795If defining multiple layers in a single JSON file prior to "file\_format\_version"
7961.0.1, you would simply define multiple "layer" objects. However, this is not
797valid JSON syntax. Instead, you should now define "file\_format\_version"
7981.0.1 (or newer) and use the new "layers" array object as seen in the
799following example:
800
801```
802{
803 "file_format_version" : "1.0.1",
804 "layers": [
805 {
806 "name": "VK_LAYER_layer_name1",
807 "type": "INSTANCE",
808 ...
809 },
810 {
811 "name": "VK_LAYER_layer_name2",
812 "type": "INSTANCE",
813 ...
814 }
815 ]
816}
817```
818
819You could use the "layers" array object to define a single layer, as long as
820your "file\_format\_version" is defined to at least 1.0.1. It is functionally the
821same as using a single "layer" object.
822
Jon Ashburnc2972682016-02-08 15:42:01 -0700823There are no rules about the name of the text files (except the .json suffix).
824
825There are no rules about the name of the layer shared library files.
826
827##### Using Pre-Production Layers
828
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700829As with ICDs, developers may need to use special, pre-production layers,
830without modifying the properly-installed layers. This need is met with the use
831of the "VK\_LAYER\_PATH" environment variable, which will override the
832mechanism using for finding properly-installed layers. Because many layers may
833exist on a system, this environment variable is a semi-colon-separated list of
834folders that contain layer info files. Only the folder listed in
835"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
836entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700837
838- The full pathname of a folder containing layer info files
839
840#### Linux
841
842##### Properly-Installed Layers
843
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700844In order to find properly-installed layers, the Vulkan loader will use a
845similar mechanism as used for ICDs. Text information files, that use a JSON
846format, are read in order to identify the names and attributes of layers and
847their extensions. The use of text info files allows the loader to avoid loading
848any shared library files when the application does not query nor request any
849extensions. Layers and extensions have additional complexity, and so their info
850files contain more information than ICD info files. For example, a layer shared
851library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700852
853The Vulkan loader will scan the files in the following Linux directories:
854
855/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700856/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700857/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700858/etc/vulkan/implicit\_layer.d
David Pinedo3e163ee2016-04-18 16:59:59 -0600859\$HOME/.local/share/vulkan/explicit\_layer.d
860\$HOME/.local/share/vulkan/implicit\_layer.d
Jon Ashburn7f00ca82016-02-24 12:00:55 -0700861
862Where $HOME is the current home directory of the application's user id; this
863path will be ignored for suid programs.
Jon Ashburnc2972682016-02-08 15:42:01 -0700864
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700865Explicit layers are those which are enabled by an application (e.g. with the
866vkCreateInstance function), or by an environment variable (as mentioned
867previously). Implicit layers are those which are enabled by their existence.
868For example, certain application environments (e.g. Steam or an automotive
869infotainment system) may have layers which they always want enabled for all
870applications that they start. Other implicit layers may be for all applications
871started on a given system (e.g. layers that overlay frames-per-second).
872Implicit layers are enabled automatically, whereas explicit layers must be
873enabled explicitly. What distinguishes a layer as implicit or explicit is by
874which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700875
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700876The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
877installed from Linux-distribution-provided packages. The
878"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
879non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700880
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -0600881This manifest file is in the JSON format as shown in the following example.
882See 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 -0700883
Jon Ashburncc300a22016-02-11 14:57:30 -0700884```
Jon Ashburnc2972682016-02-08 15:42:01 -0700885{
Mark Youngc3a6d2e2016-06-13 14:49:53 -0600886 "file_format_version" : "1.0.0",
887 "layer": {
888 "name": "VK_LAYER_LUNARG_overlay",
889 "type": "INSTANCE",
890 "library_path": "libvkOverlayLayer.so"
891 "api_version" : "1.0.5",
892 "implementation_version" : "2",
893 "description" : "LunarG HUD layer",
894 "functions": {
895 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
896 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
897 },
898 "instance_extensions": [
899 {
900 "name": "VK_EXT_debug_report",
901 "spec_version": "1"
902 },
903 {
904 "name": "VK_VENDOR_ext_x",
905 "spec_version": "3"
906 }
907 ],
908 "device_extensions": [
909 {
910 "name": "VK_EXT_debug_marker",
911 "spec_version": "1",
912 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
913 }
914 ],
915 "enable_environment": {
916 "ENABLE_LAYER_OVERLAY_1": "1"
917 },
918 "disable_environment": {
919 "DISABLE_LAYER_OVERLAY_1": ""
920 }
921 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700922}
Jon Ashburncc300a22016-02-11 14:57:30 -0700923```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700924The "library\_path" specifies either a filename, a relative pathname, or a full
925pathname to a layer shared library (".so") file, which the loader will attempt
926to load using dlopen(). If the layer is specified via a filename, the loader
927will attempt to open that file as a shared object using dlopen(), and the file
928must be in a directory that dlopen is configured to look in (Note: various
929distributions are configured differently). A distribution is free to create
930Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
931required to do so. If the layer is specified via a relative pathname, it is
932relative to the path of the info file (e.g. for cases when an application
933provides a layer that is in the same directory hierarchy as the rest of the
934application files).
Jon Ashburnc2972682016-02-08 15:42:01 -0700935
936There are no rules about the name of the text files (except the .json suffix).
937
938There are no rules about the name of the layer shared library files.
939
940##### Using Pre-Production Layers
941
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700942As with ICDs, developers may need to use special, pre-production layers,
943without modifying the properly-installed layers. This need is met with the use
944of the "VK\_LAYER\_PATH" environment variable, which will override the
945mechanism using for finding properly-installed layers. Because many layers may
946exist on a system, this environment variable is a colon-separated list of
947directories that contain layer info files. Only the directories listed in
948"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
949is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700950
951- The full pathname of a directory containing layer info files
952
953NOTE: these environment variables will be ignored for suid programs.
954
955#### Android
956
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700957The recommended way to enable layers is for applications
958to programatically enable them. The layers are provided by the application
959and must live in the application's library folder. The application
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600960enables the layers at vkCreateInstance as any Vulkan
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700961application would.
962An application enabled for debug has more options. It can enumerate and enable
963layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -0700964
Jon Ashburncc300a22016-02-11 14:57:30 -0700965Layer interface requirements
966------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700967
968#### Architectural interface overview
969
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700970There are two key architectural features that drive the loader to layer library
971interface: 1) separate and distinct instance and device call chains, and 2)
972distributed dispatch. First these architectural features will be described and
973then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -0700974
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700975Call chains are the links of calls for a given Vulkan command from layer module
976to layer module with the loader and or the ICD being the bottom most command.
977Call chains are constructed at both the instance level and the device level by
978the loader with cooperation from the layer libraries. Instance call chains are
979constructed by the loader when layers are enabled at vkCreateInstance. Device
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600980call chains are constructed by the loader when layers are enabled, by the loader, at
ttyio0811cec2016-04-10 22:09:44 +0800981vkCreateDevice. A layer can intercept Vulkan instance commands, device commands
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700982or both. For a layer to intercept instance commands, it must participate in the
983instance call chain. For a layer to intercept device commands, it must
Jon Ashburnc9d7fc92016-05-18 14:07:47 -0600984participate in the device chain.
Jon Ashburnc2972682016-02-08 15:42:01 -0700985
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700986Normally, when a layer intercepts a given Vulkan command, it will call down the
987instance or device chain as needed. The loader and all layer libraries that
988participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700989from one entity to the next. This group effort for call chain sequencing is
Jeff Julianof1619872016-02-17 17:25:42 -0500990hereinafter referred to as distributed dispatch. In distributed dispatch, since
991each layer is responsible for properly calling the next entity in the device or
992instance chain, a dispatch mechanism is required for all Vulkan commands a
993layer intercepts. For Vulkan commands that are not intercepted by a layer, or
994if the layer chooses to terminate a given Vulkan command by not calling down
995the chain, then no dispatch mechanism is needed for that particular Vulkan
996command. Only for those Vulkan commands, which may be a subset of all Vulkan
997commands, that a layer intercepts is a dispatching mechanism by the layer
998needed. The loader is responsible for dispatching all core and instance
999extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001000
Jeff Julianof1619872016-02-17 17:25:42 -05001001Instance level Vulkan commands are those that have the dispatchable objects
1002VkInstance, or VkPhysicalDevice as the first parameter and also includes
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001003vkCreateInstance.
Jeff Julianof1619872016-02-17 17:25:42 -05001004
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001005Device level Vulkan commands are those that use VkDevice, VkQueue or
1006VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1007extensions may introduce new instance or device level dispatchable objects, so
1008the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001009
Chia-I Wucb24fec2016-04-20 06:23:24 +08001010#### Layer Library Interface
Jeff Julianof1619872016-02-17 17:25:42 -05001011
Chia-I Wucb24fec2016-04-20 06:23:24 +08001012A layer library is a container of layers. This section defines an extensible
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001013interface to discover layers contained in layer libraries.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001014The extensible programming interface is used on Android only. For Windows and Linux,
1015the layer manifest JSON files are used.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001016
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001017It also specifies the minimal conventions
1018and rules a layer must follow. Other sections might have other guidelines that layers should follow.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001019
1020##### Layer Conventions and Rules
1021
1022A layer, when inserted into an otherwise compliant Vulkan implementation, must
1023still result in a compliant Vulkan implementation[\*]. It must additionally
1024follow some conventions and rules.
1025
1026A layer is always chained with other layers. It must not make invalid calls
1027to or rely on undefined behaviors of its lower layers. When it changes the
1028behavior of a command, it must make sure its upper layers do not make invalid
1029calls to or rely on undefined behaviors of its lower layers because of the
1030changed behavior. For example, when a layer intercepts an object creation
1031command to wrap the objects created by its lower layers, it must make sure its
1032lower layers never see the wrapping objects, directly from itself or
1033indirectly from its upper layers.
1034
Chia-I Wub5e850e2016-05-06 08:41:52 +08001035When a layer requires host memory, it may ignore the provided allocators. It
1036should use memory allocators if the layer is intended to run in a production
1037environment, such as an implicit layer that is always enabled. That will
1038allow applications to include the layer's memory usage.
1039
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001040`vkEnumerateInstanceLayerProperties` must enumerate and only enumerate the
1041layer itself.
1042
1043`vkEnumerateInstanceExtensionProperties` must handle the case where
1044`pLayerName` is itself. It must return `VK_ERROR_LAYER_NOT_PRESENT`
1045otherwise, including when `pLayerName` is `NULL`.
1046
1047`vkEnumerateDeviceLayerProperties` is deprecated and may be omitted. The
1048behavior is undefined.
1049
Chia-I Wuadac8342016-04-22 08:12:19 +08001050`vkEnumerateDeviceExtensionProperties` must handle the case where `pLayerName`
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001051is itself. In other cases, it should normally chain to other layers.
1052
1053`vkCreateInstance` must not generate an error for unrecognized layer names and
1054extension names. It may assume the layer names and extension names have been
1055validated.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001056
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001057`vkGetInstanceProcAddr` intercepts a Vulkan command by returning a local entry point,
1058otherwise it returns the value obtained by calling down the instance chain.
1059 These commands must be intercepted
1060 - vkGetInstanceProcAddr
1061 - vkCreateInstance
1062 - vkCreateDevice (only required for any device-level chaining)
Chia-I Wucb24fec2016-04-20 06:23:24 +08001063
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001064 For compatibility with older layer libraries,
1065 - when `pName` is `vkCreateDevice`, it ignores `instance`.
1066
1067`vkGetDeviceProcAddr` intercepts a Vulkan command by returning a local entry point,
1068otherwise it returns the value obtained by calling down the device chain.
1069
1070The specification requires `NULL` to be returned from `vkGetInstanceProcAddr` and
1071`vkGetDeviceProcAddr` for disabled commands. A layer may return `NULL` itself or
1072rely on the following layers to do so.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001073
Chia-I Wucb24fec2016-04-20 06:23:24 +08001074[\*]: The intention is for layers to have a well-defined baseline behavior.
1075Some of the conventions or rules, for example, may be considered abuses of the
1076specification.
1077
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001078##### Layer Library API Version 0
Chia-I Wucb24fec2016-04-20 06:23:24 +08001079
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001080A layer library supporting interface version 0 must define and export these
1081introspection functions, unrelated to any Vulkan command despite the names,
1082signatures, and other similarities:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001083
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001084 - `vkEnumerateInstanceLayerProperties` enumerates all layers in a layer
1085 library. This function never fails.
1086
1087 When a layer library contains only one layer, this function may be an alias
1088 to the layer's `vkEnumerateInstanceLayerProperties`.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001089
1090 - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001091 layers in a layer library. `pLayerName` is always a valid layer name.
1092 This function never fails.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001093
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001094 When a layer library contains only one layer, this function may be an alias
1095 to the layer's `vkEnumerateInstanceExtensionProperties`.
1096
1097 - `vkEnumerateDeviceLayerProperties` enumerates a subset (can be full,
1098 proper, or empty subset) of layers in a layer library. `physicalDevice` is
1099 always `VK_NULL_HANDLE`. This function never fails.
1100
1101 If a layer is not enumerated by this function, it will not participate in
1102 device command interception.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001103
1104 - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of
Chia-I Wu0e9aae72016-05-19 10:45:02 +08001105 layers in a layer library. `physicalDevice` is always `VK_NULL_HANDLE`.
1106 `pLayerName` is always a valid layer name. This function never fails.
1107
1108The introspection functions are not used by the desktop loader.
1109
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001110It must also define and export these functions one for each layer in the library:
Chia-I Wucb24fec2016-04-20 06:23:24 +08001111
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001112 - `<layerName>GetInstanceProcAddr(instance, pName)` behaves identically to a layer's vkGetInstanceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001113
1114 When a layer library contains only one layer, this function may
1115 alternatively be named `vkGetInstanceProcAddr`.
1116
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001117 - `<layerName>GetDeviceProcAddr` behaves identically to a layer's vkGetDeviceProcAddr except it is exported.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001118
1119 When a layer library contains only one layer, this function may
1120 alternatively be named `vkGetDeviceProcAddr`.
1121
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001122All layers contained within a library must support [`vk_layer.h`][]. They do not need to
1123implement commands that they do not intercept. They are recommended not to export
1124any commands.
Chia-I Wucb24fec2016-04-20 06:23:24 +08001125
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001126<a name="LayerLibraryManifestFile"></a>
1127##### Layer Library Manifest File Version 0
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001128On Windows and Linux (desktop), the loader uses manifest files to discover
1129layer libraries and layers. The desktop loader doesn't directly query the
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001130layer library except during chaining.
1131On Android, the loader queries the layer libraries via the introspection functions as outlined above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001132
1133The layer libraries and the manifest files must be kept in sync.
1134
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001135The following table associates the desktop JSON nodes with the layer library introspection queries. It also indicates requirements.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001136
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001137| Property | JSON node | Introspection query | Notes |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001138|----------|-----------|-----------------------|-------|
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001139| file version | file_format_version | N/A | one node required per JSON file |
1140| layers in library | layer | vkEnumerateInstanceLayerProperties | one node required per layer |
1141| layer name | name | vkEnumerateInstanceLayerProperties | one node is required |
1142| layer type | type | vkEnumerate*LayerProperties | see Note 1 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001143| library location | library_path | N/A | one node is required |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001144| vulkan spec version | api_version | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001145| layer implementation version | api_version | vkEnumerateInstanceLayerProperties | see Note 2 |
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001146| layer description | description | vkEnumerateInstanceLayerProperties | one node is required |
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001147| chaining functions | functions | vkGet*ProcAddr | see Note 3 |
1148| instance extensions | instance_extensions | vkEnumerateInstanceExtensionProperties | see Note 4 |
1149| device extensions | device_extensions | vkEnumerateDeviceExtensionProperties | see Note 5 |
1150| enable implicit | enable_environment | N/A | See Note 6 |
1151| disable implicit | enable_environment | N/A | See Note 7 |
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001152
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001153"file\_format\_version" is used to indicate the valid JSON syntax of the file.
1154As nodes are added or deleted which would change the parsing of this file,
1155the file_format_version should change. This version
1156is NOT the same as the layer library interface version. The interface version is a superset
1157of the "file_format_version" and includes the semantics of the nodes in the JSON file.
1158For interface version 0 the file format version must be "1.0.0"
1159
1160Note 1: Prior to deprecation, the "type" node was used to indicate which layer chain(s)
1161to activate the layer upon: instance, device, or both.
1162Distinct instance and device layers are deprecated; there are now just layers.
1163Allowable values for type (both before and after deprecation) are "INSTANCE", "GLOBAL" and, "DEVICE."
1164"DEVICE" layers are skipped over by the loader as if they were not found.
1165Thus, layers must have a type of "GLOBAL" or "INSTANCE" for the loader to include the layer in the enumerated instance layer list.
1166
1167"library\_path" is the filename, full path, or relative path to the library file.
Mark Young57551512016-06-23 11:25:03 -06001168See [Manifest File Example](#ManifestFileExample) section for more details.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001169
1170Note 2: One "implementation\_version" node is required per layer. This node gives the layer version, a single number
1171increasing with backward uncompatible changes.
1172
1173Note 3: The "functions" node is required if the layer is using alternative
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001174names for vkGetInstanceProcAddr or vkGetDeviceProcAddr. vkGetInstanceProcAddr and vkGetDeviceProcAddr
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001175are required for all layers. See further requirements in the Layer Library API section above.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001176
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001177Note 4: One "instance_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001178required if any instance
1179extensions are supported by a layer, otherwise the node is optional. Each
1180element of the array must have the nodes "name" and "spec_version" which
1181correspond to VkExtensionProperties "extensionName" and "specVersion"
1182respectively.
1183
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001184Note 5: One "device_extensions" node with an array of one or more elements
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001185required if any device
1186extensions are supported by a layer, otherwise the node is optional. Each
1187element of the array must have the nodes "name" and "spec_version" which
1188correspond to VkExtensionProperties "extensionName" and "specVersion"
1189respectively. Additionally, each element of the array of device extensions
1190must have the node "entrypoints" if the device extension adds Vulkan API commands,
1191otherwise this node is not required.
1192The "entrypoint" node is an array of the names of all entrypoints added by the
1193supported extension.
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001194```
1195 "device_extensions": [
1196 {
1197 "name": "VK_EXT_debug_marker",
1198 "spec_version": "1",
1199 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
1200 }
1201 ```
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001202
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001203Note 6: The "enable\_environment" node is only for implicit layers only. It is optional for implicit layers.
1204This node gives an environment variable and value required to enable an implicit layer. This
1205environment variable (which should vary with each "version" of the layer) must be set to the
1206given value or else the implicit layer is not loaded. This is for application environments (e.g. Steam) which
1207want to enable a layer(s) only for applications that they launch, and allows
1208for applications run outside of an application environment to not get that
1209implicit layer(s).
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001210
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001211Note 7: The "disable\_environment" node is only for implicit layers only. It is required for implicit layers.
1212This node gives an environment variable and value required to disable an implicit layer. In
1213rare cases of an application not working with an implicit layer, the
1214application can set this environment variable (before calling Vulkan commands)
1215in order to "blacklist" the layer. This environment variable (which should vary
1216with each "version" of the layer) must be set (not particularly to any value).
1217If both the "enable\_environment" and
1218"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburn6bda65b2016-05-10 09:24:52 -06001219
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001220#### Layer Dispatch Interface Version 0
1221##### Layer intercept requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001222
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001223- Layers intercept a Vulkan command by defining a C/C++ function with signature
1224identical to the Vulkan API for that command.
Jon Ashburnc9d7fc92016-05-18 14:07:47 -06001225- A layer must intercept at least vkGetInstanceProcAddr and
1226vkCreateInstance. Additionally, a layer would also intercept vkGetDeviceProcAddr and vkCreateDevice to participate in the device chain.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001227- For any Vulkan command a layer intercepts which has a non-void return value,
1228an appropriate value must be returned by the layer intercept function.
1229- The layer intercept function must call down the chain to the corresponding
1230Vulkan command in the next entity. Undefined results will occur if a layer
1231doesn't propagate calls down the chain. The two exceptions to this requirement
1232are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1233chain for Vulkan commands that they do not intercept.
1234- Layer intercept functions may insert extra calls to Vulkan commands in
1235addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1236want to add a call to vkQueueWaitIdle after calling down the chain for
1237vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1238chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001239
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001240##### Distributed dispatching requirements
Jeff Julianof1619872016-02-17 17:25:42 -05001241
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001242- For each entry point a layer intercepts, it must keep track of the entry
1243point residing in the next entity in the chain it will call down into. In other
1244words, the layer must have a list of pointers to functions of the appropriate
1245type to call into the next entity. This can be implemented in various ways but
1246for clarity will be referred to as a dispatch table.
1247- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1248(see include/vulkan/vk_layer.h).
1249- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1250dispatch table (see include/vulkan/vk_layer.h).
1251- Layers vkGetInstanceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001252vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001253functions.
1254- Layers vkGetDeviceProcAddr function uses the next entity's
Jeff Julianof1619872016-02-17 17:25:42 -05001255vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted)
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001256functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001257
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001258##### Layer dispatch initialization
Jeff Julianof1619872016-02-17 17:25:42 -05001259
1260- A layer initializes its instance dispatch table within its vkCreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001261function.
Jeff Julianof1619872016-02-17 17:25:42 -05001262- A layer initializes its device dispatch table within its vkCreateDevice
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001263function.
1264- The loader passes a linked list of initialization structures to layers via
1265the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1266for vkCreateInstance and VkCreateDevice respectively.
1267- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001268instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001269include/vulkan/vk_layer.h for details.
1270- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1271"sType" field in VkLayerInstanceCreateInfo.
1272- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1273"sType" field in VkLayerDeviceCreateInfo.
1274- The "function" field indicates how the union field "u" should be interpreted
1275within VkLayer*CreateInfo. The loader will set the "function" field to
1276VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1277VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001278- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001279- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1280by a layer.
1281- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1282vkGetDeviceProcAddr used by a layer.
1283- Given the above structures set up by the loader, layer must initialize their
1284dispatch table as follows:
1285 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1286the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001287 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001288 - For CreateInstance get the next entity's vkCreateInstance by calling the
1289"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001290 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001291 - For CreateDevice get the next entity's vkCreateDevice by calling the
1292"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001293 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001294 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1295 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001296 - Initialize your layer dispatch table by calling the next entity's
1297Get*ProcAddr function once for each Vulkan command needed in your dispatch
1298table
Jon Ashburncc300a22016-02-11 14:57:30 -07001299
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001300##### Example code for CreateInstance
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001301
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001302```cpp
1303VkResult vkCreateInstance(
1304 const VkInstanceCreateInfo *pCreateInfo,
1305 const VkAllocationCallbacks *pAllocator,
1306 VkInstance *pInstance)
1307{
1308 VkLayerInstanceCreateInfo *chain_info =
1309 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1310
1311 assert(chain_info->u.pLayerInfo);
1312 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1313 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1314 PFN_vkCreateInstance fpCreateInstance =
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001315 (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001316 if (fpCreateInstance == NULL) {
1317 return VK_ERROR_INITIALIZATION_FAILED;
1318 }
1319
1320 // Advance the link info for the next element of the chain
1321 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1322
1323 // Continue call down the chain
1324 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
1325 if (result != VK_SUCCESS)
1326 return result;
1327
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001328 // Init layer's dispatch table using GetInstanceProcAddr of
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001329 // next layer in the chain.
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001330 instance_dispatch_table = new VkLayerInstanceDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001331 layer_init_instance_dispatch_table(
1332 *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
1333
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001334 // Other layer initialization
1335 ...
1336
1337 return VK_SUCCESS;
1338}
1339```
1340
Jon Ashburn2b4d7bb2016-05-23 13:05:21 -06001341##### Example code for CreateDevice
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001342
1343```cpp
1344VkResult
1345vkCreateDevice(
1346 VkPhysicalDevice gpu,
1347 const VkDeviceCreateInfo *pCreateInfo,
1348 const VkAllocationCallbacks *pAllocator,
1349 VkDevice *pDevice)
1350{
1351 VkLayerDeviceCreateInfo *chain_info =
1352 get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
1353
1354 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr =
1355 chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
1356 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr =
1357 chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
1358 PFN_vkCreateDevice fpCreateDevice =
1359 (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
1360 if (fpCreateDevice == NULL) {
1361 return VK_ERROR_INITIALIZATION_FAILED;
1362 }
1363
1364 // Advance the link info for the next element on the chain
1365 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
1366
1367 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
1368 if (result != VK_SUCCESS) {
1369 return result;
1370 }
1371
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001372 // initialize layer's dispatch table
1373 device_dispatch_table = new VkLayerDispatchTable;
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001374 layer_init_device_dispatch_table(
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001375 *pDevice, device_dispatch_table, fpGetDeviceProcAddr);
Courtney Goeltzenleuchterf6abc202016-02-15 15:05:16 -07001376
1377 // Other layer initialization
1378 ...
1379
1380 return VK_SUCCESS;
1381}
1382```
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001383
Jon Ashburncc300a22016-02-11 14:57:30 -07001384#### Special Considerations
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001385##### Associating private data with Vulkan objects within a layer
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001386A layer may want to associate it's own private data with one or more Vulkan
1387objects.
1388Two common methods to do this are hash maps and object wrapping. The loader
1389supports layers wrapping any Vulkan object including dispatchable objects.
1390Layers which wrap objects should ensure they always unwrap objects before
1391passing them down the chain. This implies the layer must intercept every Vulkan
1392command which uses the object in question. Layers above the object wrapping
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001393layer will see the wrapped object. Layers which wrap dispatchable objects must
1394ensure that the first field in the wrapping structure is a pointer to a dispatch table
1395as defined in vk_layer.h. Specifically, an instance wrapped dispatchable object
1396could be as follows:
1397```
1398struct my_wrapped_instance_obj_ {
1399 VkLayerInstanceDispatchTable *disp;
1400 // whatever data layer wants to add to this object
1401};
1402```
1403A device wrapped dispatchable object could be as follows:
1404```
1405struct my_wrapped_instance_obj_ {
1406 VkLayerDispatchTable *disp;
1407 // whatever data layer wants to add to this object
1408};
1409```
Jeff Julianof1619872016-02-17 17:25:42 -05001410
1411Alternatively, a layer may want to use a hash map to associate data with a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001412given object. The key to the map could be the object. Alternatively, for
1413dispatchable objects at a given level (eg device or instance) the layer may
1414want data associated with the VkDevice or VkInstance objects. Since
Jeff Julianof1619872016-02-17 17:25:42 -05001415there are multiple dispatchable objects for a given VkInstance or VkDevice, the
1416VkDevice or VkInstance object is not a great map key. Instead the layer should
1417use the dispatch table pointer within the VkDevice or VkInstance since that
1418will be unique for a given VkInstance or VkDevice.
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001419
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001420##### Creating new dispatchable objects
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001421Layers which create dispatchable objects take special care. Remember that loader
1422trampoline code normally fills in the dispatch table pointer in the newly
1423created object. Thus, the layer must fill in the dispatch table pointer if the
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001424loader trampoline will not do so. Common cases where a layer (or ICD) may create a
Courtney Goeltzenleuchter7221a5a2016-02-15 14:59:37 -07001425dispatchable object without loader trampoline code is as follows:
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001426- object wrapping layers that wrap dispatchable objects
1427- layers which add extensions that create dispatchable objects
1428- layers which insert extra Vulkan commands in the stream of commands they
1429intercept from the application
Jon Ashburn859c7fb2016-03-02 17:26:31 -07001430- ICDs which add extensions that create dispatchable objects
1431
Jon Ashburn2b2f6182016-04-04 16:37:37 -06001432The Windows/Linux loader provides a callback that can be used for initializing
1433a dispatchable object. The callback is passed as an extension structure via the
1434pNext field in VkInstanceCreateInfo and VkDeviceCreateInfo. The callback prototype
1435is defined as follows for instance and device callbacks respectively (see vk_layer.h):
1436```
1437VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance, void *object);
1438VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData)(VkDevice device, void *object);
1439```
1440To obtain these callbacks the layer must search through the list of structures
1441pointed 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:
1442- For CreateInstance the callback structure pointed to by "pNext" is VkLayerInstanceCreateInfo as defined in vk_layer.h.
1443- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within VkInstanceCreateInfo parameter indicates a loader structure.
1444- Within VkLayerInstanceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1445- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetInstanceLoaderData".
1446- For CreateDevice the callback structure pointed to by "pNext" is VkLayerDeviceCreateInfo as defined in include/vulkan/vk_layer.h.
1447- A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within VkDeviceCreateInfo parameter indicates a loader structure.
1448- Within VkLayerDeviceCreateInfo, the "function" field indicates how the union field "u" should be interpreted.
1449- A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetDeviceLoaderData".
1450
1451Alternatively, 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 -07001452To fill in the dispatch table pointer in newly created dispatchable object,
1453the 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
1454device). 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 -07001455