blob: 019322850fdeaf0938398a94073c36a5206b805e [file] [log] [blame] [view]
Jon Ashburnc2972682016-02-08 15:42:01 -07001# Vulkan Loader Specification and Architecture Overview
2
3
4Goals of this document
5----------------------
6
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07007Specify necessary functions and expected behavior of interface between the
8loader library and ICDs and layers for Windows, Linux and Android based
9systems. Also describe the application visible behaviors of the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -070010
11Audience
12--------
13
14Application, Vulkan driver and Vulkan layer developers.
15
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070016Any developers interested in understanding more about loader and layer behavior
17and architecture.
Jon Ashburnc2972682016-02-08 15:42:01 -070018
19
20Loader goals
21------------
22
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070023- Support multiple ICDs (Installable Client Drivers) to co-exist on a system
24without interfering with each other.
Jon Ashburnc2972682016-02-08 15:42:01 -070025
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070026- Support optional modules (layers) that can be enabled by an application,
27developer or the system and have no impact when not enabled.
Jon Ashburnc2972682016-02-08 15:42:01 -070028
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070029- Negligible performance cost for an application calling through the loader
30to an ICD entry point.
Jon Ashburnc2972682016-02-08 15:42:01 -070031
32Architectural overview of layers and loader
33-------------------------------------------
34
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070035Vulkan is a layered architecture. Layers can hook (intercept) Vulkan commands to
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070036achieve various functionality that a Vulkan driver (aka ICD) or loader doesn’t
37support. Functionality such as Vulkan API tracing and debugging, API usage
38validation, and other tools such as framebuffer overlays are all natural
39candidates for Vulkan layers. Layers are implemented as libraries that are
40inserted between the application and the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -070041
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070042Not only is Vulkan a layered architecture but it also supports multiple GPUs
43and their drivers. Vulkan commands called by an application may wind up calling
44into a diverse set of modules: loader, layers, and ICDs. The loader is critical
45to managing the proper dispatching of Vulkan commands to the appropriate set of
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070046layers and ICDs. The Vulkan object model allows the loader to insert layers
47into a call chain so the layers can process Vulkan commands prior to the
48ICD being called.
Jon Ashburnc2972682016-02-08 15:42:01 -070049
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070050Vulkan uses an object model to control the scope of a particular action /
51operation. The object to be acted on is always the first parameter of a Vulkan
52call and is a dispatchable object (see Vulkan specification section 2.2 Object
53Model). Under the covers, the dispatchable object handle is a pointer to a
54structure that contains a pointer to a dispatch table maintained by the loader.
55This dispatch table contains pointers to the Vulkan functions appropriate to
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070056that object. There are two types of dispatch tables the loader maintains,
57Instance and Device. I.e. a VkInstance object’s dispatch table will point to Vulkan
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070058functions such as vkEnumeratePhysicalDevices, vkDestroyInstance,
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070059vkCreateInstance, etc. Instance functions take a VkInstance or VkPhysicalDevice as
60their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070061
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070062Device objects have a separate dispatch table containing the appropriate
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -070063function pointers. The device dispatch table is used for all functions that
64take a VkDevice, VkQueue or VkCommandBuffer as their first argument.
Jon Ashburnc2972682016-02-08 15:42:01 -070065
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070066These instance and device dispatch tables are constructed when the application
67calls vkCreateInstance and vkCreateDevice. At that time the application and/or
68system can specify optional layers to be included. The loader will initialize
69the specified layers to create a call chain for each Vulkan function and each
70entry of the dispatch table will point to the first element of that chain.
71Thus, the loader builds an instance call chain for each VkInstance that is
72created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070073
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070074For example, the diagram below represents what happens in the call chain for
75vkCreateInstance. After initializing the chain, the loader will call into the
76first layer’s vkCreateInstance which will call the next finally terminating in
77the loader again where this function calls every ICD’s vkCreateInstance and
78saves the results. This allows every enabled layer for this chain to set up
79what it needs based on the VkInstanceCreateInfo structure from the application.
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -070080![Instance call chain](/images/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.
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -070091![Chain skipping layers](/images/chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070092
93Application interface to loader
94-------------------------------
95
96In this section we’ll discuss how an application interacts with the loader.
97
98- Linking to loader library for core and WSI extension symbols.
99
100- Dynamic Vulkan command lookup & application dispatch table.
101
102- Loader library filenames for linking to different Vulkan ABI versions.
103
104- Layers
105
106- Extensions
107
108- vkGetInstanceProcAddr, vkGetDeviceProcAddr
109
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700110The loader library on Windows, Linux and Android will export all core Vulkan
111and all appropriate Window System Interface (WSI) extensions. This is done to
112make it simpler to get started with Vulkan development. When an application
113links directly to the loader library in this way, the Vulkan calls are simple
114trampoline functions that jump to the appropriate dispatch table entry for the
115object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700116
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700117Applications are not required to link directly to the loader library, instead
118they can use the appropriate platform specific dynamic symbol lookup on the
119loader library to initialize the application’s own dispatch table. This allows
120an application to fail gracefully if the loader cannot be found and provide the
121fastest mechanism for the application to call Vulkan functions. An application
122will only need to query (via system calls such as dlsym()) the address of
123vkGetInstanceProcAddr from the loader library. Using vkGetInstanceProcAddr the
124application can then discover the address of all instance and global functions
125and extensions, such as vkCreateInstance,
126vkEnumerateInstanceExtensionProperties 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
134guaranteed for all versions with the same major number (eg 1.0 and 1.1). On
135Windows, the loader library encodes the ABI version in its name such that
136multiple ABI incompatible versions of the loader can peacefully coexist on a
137given system. The vulkan loader library key name is “vulkan-<ABI
138version>”. For example, for Vulkan version 1.X on Windows the library
139filename is vulkan-1.dll. And this library file can typically be found in the
140windows/system32 directory.
Jon Ashburnc2972682016-02-08 15:42:01 -0700141
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700142For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
143number is not encoded in the base of the library filename as on Windows. On
144Linux an application wanting to link to the latest Vulkan ABI version would
145just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
146also be linked to by applications (eg libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700147
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700148Applications desiring Vulkan functionality beyond what the core API offers may
149use various layers or extensions. A layer cannot add new or modify existing
150Vulkan commands, but may offer extensions that do. A common use of layers is
151for API validation. A developer can use validation layers during application
152development, but during production the layers can be disabled by the
153application. Thus, eliminating the overhead of validating the applications
154usage of the API. Layers discovered by the loader can be reported to the
155application via vkEnumerateInstanceLayerProperties and
156vkEnumerateDeviceLayerProperties, for instance and device layers respectively.
157Instance layers are enabled at vkCreateInstance; device layers are enabled at
158vkCreateDevice. For example, the ppEnabledLayerNames array in the
159VkDeviceCreateInfo structure is used by the application to list the device
160layer names to be enabled at vkCreateDevice. At vkCreateInstance and
161vkCreateDevice, the loader will construct call chains that include the
162application specified (enabled) layers. Order is important in the
163ppEnabledLayerNames array; array element 0 is the topmost (closest to the
164application) layer inserted in the chain and the last array element is closest
165to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700166
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700167Developers may want to enable layers that are not enabled by the given
168application they are using. On Linux and Windows, the environment variables
169“VK\_INSTANCE\_LAYERS” and “VK\_DEVICE\_LAYERS” can be used to enable
170additional layers which are not specified (enabled) by the application at
171vkCreateInstance/vkCreateDevice. VK\_INSTANCE\_LAYERS is a colon
172(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
173relevant with the first layer in the list being the topmost layer (closest to
174the application) and the last layer in the list being the bottommost layer
175(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700176
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700177Application specified layers and user specified layers (via environment
178variables) are aggregated and duplicates removed by the loader when enabling
179layers. Layers specified via environment variable are topmost (closest to the
180application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700181
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700182An example of using these environment variables to activate the validation
183layer VK\_LAYER\_LUNARG\_param\_checker on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700184
185```
Jon Ashburncc300a22016-02-11 14:57:30 -0700186> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700187
Jon Ashburncc300a22016-02-11 14:57:30 -0700188> $ export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700189```
190
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700191**Note**: Many layers, including all LunarG validation layers are “global”
192(i.e. both instance and device) layers and *must* be enabled on both the
193instance and device chains to function properly. This is required for “global”
194layers regardless of which method is used to enable the layer (application or
195environment variable).
Jon Ashburnc2972682016-02-08 15:42:01 -0700196
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700197Some platforms, including Linux and Windows, support layers which are enabled
198automatically by the loader rather than explicitly by the application (or via
199environment variable). Explicit layers are those layers enabled by the
200application (or environment variable) by providing the layer name. Implicit
201layers are those layers enabled by the loader automatically. Any implicit
202layers the loader discovers on the system in the appropriate location will be
203enabled (subject to environment variable overrides described later). Discovery
204of properly installed implicit and explicit layers is described later.
205Explicitly enabling a layer that is implicitly enabled has no additional
206effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700207
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700208Extensions are optional functionality provided by a layer, the loader or an
209ICD. Extensions can modify the behavior of the Vulkan API and need to be
210specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700211
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700212Instance extensions can be discovered via
213vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
214vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
215extensions from layers (both explicit and implicit), ICDs and the loader before
216reporting them to the application in vkEnumerate\*ExtensionProperties. The
217pLayerName parameter in these functions are used to select either a single
218layer or the Vulkan platform implementation. If pLayerName is NULL, extensions
219from Vulkan implementation components (including loader, implicit layers, and
220ICDs) are enumerated. If pLayerName is equal to a discovered layer module name
221then any extensions from that layer (which may be implicit or explicit) are
222enumerated. Duplicate extensions (eg an implicit layer and ICD might report
223support for the same extension) are eliminated by the loader. Extensions must
224be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700225
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700226Extension command entry points should be queried via vkGetInstanceProcAddr or
227vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
228extension or core device entry points. Device entry points include any command
229that uses a VkDevice as the first parameter or a dispatchable object that is a
230child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
231vkGetInstanceProcAddr can be used to query either device or instance extension
232entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700233
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700234VkGetDeviceProcAddr is particularly interesting because it will provide the
235most efficient way to call into the ICD. For example, the diagram below shows
236what could happen if the application were to use vkGetDeviceProcAddr for the
237function “vkGetDeviceQueue” and “vkDestroyDevice” but not “vkAllocateMemory”.
238The resulting function pointer (fpGetDeviceQueue) would be the ICD’s entry
239point if the loader and any enabled layers do not need to see that call. Even
240if an enabled layer intercepts the call (eg vkDestroyDevice) the loader
241trampoline code is skipped for function pointers obtained via
242vkGetDeviceProcAddr. This also means that function pointers obtained via
243vkGetDeviceProcAddr will only work with the specific VkDevice it was created
244for, using it with another device has undefined results. For extensions,
245Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700246
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700247![Get*ProcAddr efficiency](/images/get_proc_addr.png)
248
Jon Ashburnc2972682016-02-08 15:42:01 -0700249
250Vulkan Installable Client Driver interface with the loader
251----------------------------------------------------------
252
253### ICD discovery
254
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700255Vulkan allows multiple drivers each with one or more devices (represented by a
256Vulkan VkPhysicalDevice object) to be used collectively. The loader is
257responsible for discovering available Vulkan ICDs on the system. Given a list
258of available ICDs, the loader can enumerate all the physical devices available
259for an application and return this information to the application. The process
260in which the loader discovers the available Installable Client Drivers (ICDs)
261on a system is platform dependent. Windows, Linux and Android ICD discovery
262details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700263
264#### Windows
265
266##### Properly-Installed ICDs
267
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700268In order to find properly-installed ICDs, the Vulkan loader will scan the
269values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700270
271HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
272
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700273For each value in this key which has DWORD data set to 0, the loader opens the
274JSON format text information file (a.k.a. "manifest file") specified by the
275name of the value. Each name must be a full pathname to the text manifest file.
276The Vulkan loader will open each manifest file to obtain the name or pathname
277of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700278
Jon Ashburncc300a22016-02-11 14:57:30 -0700279 ```
280 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700281 "file_format_version": "1.0.0",
282 "ICD": {
283 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700284 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700285 }
286 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700287 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700288
289
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700290The "library\_path" specifies either a filename, a relative pathname, or a full
291pathname to an ICD shared library file, which the loader will attempt to load
292using LoadLibrary(). If the ICD is specified via a filename, the shared library
293lives in the system's DLL search path (e.g. in the "C:\\\\Windows\\\\System32"
294folder). If the ICD is specified via a relative pathname, it is relative to the
295path of the manifest file. Relative pathnames are those that do not start with
296a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
297character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700298
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700299The "file\_format\_version" specifies a major.minor.patch version number in
300case the format of the text information file changes in the future. If the same
301ICD shared library supports multiple, incompatible versions of text manifest
302file format versions, it must have multiple text info files (all of which may
303point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700304
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700305The “api\_version” specifies the major.minor.patch version number of the Vulkan
306API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700307
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700308There are no rules about the name of the text information files (except the
309.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700310
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700311There are no rules about the name of the ICD shared library files. For example,
312if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700313
Jon Ashburncc300a22016-02-11 14:57:30 -0700314```
315[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700316
Jon Ashburncc300a22016-02-11 14:57:30 -0700317"C:\vendor a\vk\_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700318
Jon Ashburncc300a22016-02-11 14:57:30 -0700319"C:\windows\system32\vendorb\_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700320
Jon Ashburncc300a22016-02-11 14:57:30 -0700321"C:\windows\system32\vendorc\_icd.json"=dword:00000000
322```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700323then the loader will open the following text information files, with the
324specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700325
Jon Ashburncc300a22016-02-11 14:57:30 -0700326| Text File Name | Text File Contents |
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700327|----------------|--------------------|
Jon Ashburncc300a22016-02-11 14:57:30 -0700328|vk\_vendora.json | "ICD": { "library\_path": "C:\\\\VENDORA\\\\vk\_vendora.dll", "api_version": "1.0.3" } |
329| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.3" } |
330|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.3" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700331
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700332Then the loader will open the three files mentioned in the "Text File Contents"
333column, and then try to load and use the three shared libraries indicated by
334the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700335
336##### Using Pre-Production ICDs
337
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700338IHV developers (and sometimes other developers) need to use special,
339pre-production ICDs. In some cases, a pre-production ICD may be in an
340installable package. In other cases, a pre-production ICD may simply be a
341shared library in the developer's build tree. In this latter case, we want to
342allow developers to point to such an ICD without modifying the
343properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700344
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700345This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
346which will override the mechanism used for finding properly-installed ICDs. In
347other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
348"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
349text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700350
Jon Ashburncc300a22016-02-11 14:57:30 -0700351- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700352
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700353Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
354file for a developer-built ICD. A semi-colon is only used if more than one ICD
355is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700356
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700357For example, if a developer wants to refer to one ICD that they built, they
358could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700359
Jon Ashburncc300a22016-02-11 14:57:30 -0700360C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700361
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700362If a developer wants to refer to two ICDs, one of which is a properly-installed
363ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700364
Jon Ashburncc300a22016-02-11 14:57:30 -0700365C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700366
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700367Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
368"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700369
370#### Linux
371
372##### Properly-Installed ICDs
373
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700374In order to find properly-installed ICDs, the Vulkan loader will scan the files
375in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700376
377/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700378/etc/vulkan/icd.d
379
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700380These directories will contain text information files (a.k.a. "manifest
381files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700382
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700383The Vulkan loader will open each manifest file found to obtain the name or
384pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700385
Jon Ashburncc300a22016-02-11 14:57:30 -0700386```
387{
Jon Ashburnc2972682016-02-08 15:42:01 -0700388 "file_format_version": "1.0.0",
389 "ICD": {
390 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700391 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700392 }
393}
Jon Ashburncc300a22016-02-11 14:57:30 -0700394```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700395The "library\_path" specifies either a filename, a relative pathname, or a full
396pathname to an ICD shared library file. If the ICD is specified via a filename,
397the loader will attempt to open that file as a shared object using dlopen(),
398and the file must be in a directory that dlopen is configured to look in (Note:
399various distributions are configured differently). A distribution is free to
400create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
401required to do so. If the ICD is specified via a relative pathname, it is
402relative to the path of the info file. Relative pathnames are those that do not
403start with, but do contain at least one directory separator (i.e. the '/'
404character). For example, "lib/vendora.so" and "./vendora.so" are examples of
405relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700406
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700407The "file\_format\_version" provides a major.minor.patch version number in case
408the format of the manifest file changes in the future. If the same ICD shared
409library supports multiple, incompatible versions of manifest file format
410versions, it must have multiple manifest files (all of which may point to the
411same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700412
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700413The “api\_version” specifies the major.minor.patch version number of the Vulkan
414API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700415
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700416The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
417Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
418ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700419
420There are no rules about the name of the text files (except the .json suffix).
421
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700422There are no rules about the name of the ICD shared library files. For example,
423if the "/usr/share/vulkan/icd.d" directory contain the following files, with
424the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700425
Jon Ashburncc300a22016-02-11 14:57:30 -0700426| Text File Name | Text File Contents |
Jon Ashburnfe630fb2016-02-14 21:40:34 -0700427|--------------------------------------|
Jon Ashburncc300a22016-02-11 14:57:30 -0700428|vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.3" } |
429| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.3" } |
430| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.1" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700431
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700432then the loader will open the three files mentioned in the "Text File Contents"
433column, and then try to load and use the three shared libraries indicated by
434the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700435
436##### Using Pre-Production ICDs
437
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700438IHV developers (and sometimes other developers) need to use special,
439pre-production ICDs. In some cases, a pre-production ICD may be in an
440installable package. In other cases, a pre-production ICD may simply be a
441shared library in the developer's build tree. In this latter case, we want to
442allow developers to point to such an ICD without modifying the
443properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700444
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700445This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
446which will override the mechanism used for finding properly-installed ICDs. In
447other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700448
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700449The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
450manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700451
452- A filename (e.g. "libvkicd.json") in the "/usr/share/vulkan/icd.d" or "/etc/vulkan/icd.d" system directories
453
454- A full pathname (e.g. "/my\_build/my\_icd.json")
455
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700456Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
457file for a developer-built ICD. A colon is only used if more than one ICD is
458listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700459
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700460For example, if a developer wants to refer to one ICD that they built, they
461could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700462
463/my\_build/my\_icd.json
464
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700465If a developer wants to refer to two ICDs, one of which is a properly-installed
466ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700467
468vendorc\_vulkan.json:/my\_build/my\_icd.json
469
470Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
471
472NOTE: this environment variable will be ignored for suid programs.
473
474#### Android
475
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700476The Android loader lives in the system library folder. The location cannot be
477changed. The loader will load the driver/ICD via hw_get_module with the ID
478of "vulkan". Due to security policies in Android none of this can be modified
479under normal use.
Jon Ashburnc2972682016-02-08 15:42:01 -0700480
481
Jon Ashburncc300a22016-02-11 14:57:30 -0700482ICD interface requirements
483----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700484
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700485Generally, for all Vulkan commands issued by an application, the loader can be
486viewed as a pass through. That is, the loader generally doesn’t modified the
487commands or their parameters but simply calls the ICDs entry point for that
488command. Thus, the loader to ICD interface requirements will be specified by
489covering two areas: 1) Obtaining ICD Vulkan entry points; 2) Specifying
490requirements for a given Vulkan command(s) over and above the Vulkan
491specification requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700492
493#### Windows and Linux
494
495##### Obtaining ICD entry points
496
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700497Currently, two methods of the loader finding ICD entry points are supported on
498Linux and Windows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700499
5001) Recommended
501
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700502- vk\_icdGetInstanceProcAddr exported in the ICD library and it returns valid
503 function pointers for all the global level and instance level Vulkan commands,
504 and also vkGetDeviceProcAddr. Global level commands are those which contain no
505 dispatchable object as the first parameter, such as vkCreateInstance and
506 vkEnumerateInstanceExtensionProperties. The ICD must support querying global
507 level entry points by calling vk\_icdGetInstanceProcAddr with a NULL VkInstance
508 parameter. Instance level commands are those that have either VkInstance, or
509 VkPhysicalDevice as the first parameter dispatchable object. Both core entry
510 points and any instance extension entry points the ICD supports should be
511 available via vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may
512 define and use new instance level dispatchable objects other than VkInstance
513 and VkPhysicalDevice, in which case, extensions entry points using these newly
514 defined dispatchable oibjects must be queryable via vk\_icdGetInstanceProcAddr.
Jon Ashburnc2972682016-02-08 15:42:01 -0700515
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700516- All other Vulkan entry points must either NOT be exported from the ICD
517 library or else NOT use the official Vulkan function names if they are
518 exported. This requirement is for ICD libraries that include other
519 functionality (such as OpenGL library) and thus could be loaded by the
520 application prior to when the Vulkan loader library is loaded by the
521 application. In other words, the ICD library exported Vulkan symbols must not
522 clash with the loader's exported Vulkan symbols.
Jon Ashburnc2972682016-02-08 15:42:01 -0700523
Jon Ashburnfe630fb2016-02-14 21:40:34 -0700524- Beware of interposing by dynamic OS library loaders if the offical Vulkan names
525are used. On Linux, if offical names are used, the ICD library must be linked with -Bsymbolic.
Jon Ashburnc2972682016-02-08 15:42:01 -07005262) Deprecated
527
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700528- vkGetInstanceProcAddr exported in the ICD library and returns valid function
529 pointers for all the Vulkan API entrypoints.
Jon Ashburnc2972682016-02-08 15:42:01 -0700530
531- vkCreateInstance exported in the ICD library;
532
533- vkEnumerateInstanceExtensionProperties exported in the ICD library;
534
535##### Loader specific requirements for Vulkan commands
536
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700537Normally, ICDs handle object creation and destruction for various Vulkan
538objects. The WSI surface extensions for Linux and Windows
539(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
540VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
541handled differently. For these extensions, the VkSurfaceKHR object creation and
542destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700543
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005441. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
545 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700546
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005472. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
548 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700549
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005503. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
551 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700552
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005534. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
554 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field in
555 the structure is a VkIcdSurfaceBase enumerant that indicates westher the
556 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700557
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700558As previously covered, the loader requires dispatch tables to be accessible
559within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
560VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
561dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700562
Jon Ashburncc300a22016-02-11 14:57:30 -0700563- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700564
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700565- The loader will replace the first entry with a pointer to the dispatch table
566 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700567
Jon Ashburncc300a22016-02-11 14:57:30 -07005681. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700569
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005702. This pointer points to a regular C structure with the first entry being a
571 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
572 classes. The C\++ compiler may put a vtable at offset zero if your class is
573 virtual. In this case use a regular C structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700574
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005753. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
576 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700577
578```
579
Jon Ashburncc300a22016-02-11 14:57:30 -0700580#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700581
Jon Ashburncc300a22016-02-11 14:57:30 -0700582union _VK_LOADER_DATA {
583 uintptr loadermagic;
584 void *loaderData;
585} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700586
Jon Ashburncc300a22016-02-11 14:57:30 -0700587vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700588{
Jon Ashburncc300a22016-02-11 14:57:30 -0700589 vkObj *newObj = alloc_obj();
590 ...
591 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700592
Jon Ashburncc300a22016-02-11 14:57:30 -0700593 set_loader_magic_value(newObj);
594 ...
595 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700596}
Jon Ashburnc2972682016-02-08 15:42:01 -0700597```
598
599Additional Notes:
600
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700601- The loader will filter out extensions requested in vkCreateInstance and
602vkCreateDevice before calling into the ICD; Filtering will be of extensions
603advertised by entities (eg layers) different from the ICD in question.
604- The loader will not call ICD for vkEnumerate\*LayerProperties() as layer
605properties are obtained from the layer libraries and layer JSON files.
606- If an ICD library wants to implement a layer it can do so by having the
607appropriate layer JSON manifest file refer to the ICD library file.
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700608- The loader will not call the ICD for
609 vkEnumerate\*ExtensionProperties(pLayerName != NULL).
Jon Ashburnc2972682016-02-08 15:42:01 -0700610- The ICD may or may not implement a dispatch table.
611
612#### Android
613
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700614The Android loader uses the same protocol for initializing the dispatch
615table as described above. The only difference is that the Android
616loader queries layer and extension information directly from the
617respective libraries and does not use the json manifest files used
618by the Windows and Linux loaders.
Jon Ashburnc2972682016-02-08 15:42:01 -0700619
620Vulkan layer interface with the loader
621--------------------------------------
622
623### Layer discovery
624
625#### Windows
626
627##### Properly-Installed Layers
628
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700629In order to find properly-installed layers, the Vulkan loader will use a
630similar mechanism as used for ICDs. Text information files (aka manifest
631files), that use a JSON format, are read in order to identify the names and
632attributes of layers and their extensions. The use of manifest files allows the
633loader to avoid loading any shared library files when the application does not
634query nor request any extensions. Layers and extensions have additional
635complexity, and so their manifest files contain more information than ICD info
636files. For example, a layer shared library file may contain multiple
637layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700638
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700639In order to find properly-installed layers, the Vulkan loader will scan the
640values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700641
642HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
643
644HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
645
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700646Explicit layers are those which are enabled by an application (e.g. with the
647vkCreateInstance function), or by an environment variable (as mentioned
648previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700649
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700650Implicit layers are those which are enabled by their existence. For example,
651certain application environments (e.g. Steam or an automotive infotainment
652system) may have layers which they always want enabled for all applications
653that they start. Other implicit layers may be for all applications started on a
654given system (e.g. layers that overlay frames-per-second). Implicit layers are
655enabled automatically, whereas explicit layers must be enabled explicitly. What
656distinguishes a layer as implicit or explicit is by which registry key its
657layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700658
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700659For each value in these keys which has DWORD data set to 0, the loader opens
660the JSON manifest file specified by the name of the value. Each name must be a
661full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700662
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700663The Vulkan loader will open each info file to obtain information about the
664layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700665
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700666This manifest file is in the JSON format and contains the following
667information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700668
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700669- (required) "file\_format\_version" - same as for ICDs, except that the format
670version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700671
672- (required) "name" - layer name
673
674- (required) "type" - which layer chains should the layer be activated on.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700675Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
676both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700677
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700678- (required) "library\_path" - filename / full path / relative path to the
679library file
Jon Ashburnc2972682016-02-08 15:42:01 -0700680
681- (required) "api\_version" - same as for ICDs.
682
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700683- (required) "implementation\_version" - layer version, a single number
684increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700685
686- (required) "description" - informative description of the layer.
687
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700688- (optional) "device\_extensions" or "instance\_extensions" - array of
689extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700690
Jon Ashburncc300a22016-02-11 14:57:30 -0700691 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700692
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700693 - (required) extension "spec\_version" - extension specification version, a
694single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700695
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700696 - (required for device\_extensions with entry points) extension
697"entrypoints" - array of device extension entrypoints; not used for instance
698extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700699
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700700- (sometimes required) "functions" - mapping list of function entry points. If
701multiple layers exist within the same shared library (or if a layer is in the
702same shared library as an ICD), this must be specified to allow each layer to
703have its own vkGet\*ProcAddr entrypoints that can be found by the loader. At
704this time, only the following two functions are required:
Jon Ashburnc2972682016-02-08 15:42:01 -0700705
Jon Ashburncc300a22016-02-11 14:57:30 -0700706 - "vkGetInstanceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700707
Jon Ashburncc300a22016-02-11 14:57:30 -0700708 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700709
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700710- (optional for implicit layers) "enable\_environment" requirement(s) -
711environment variable and value required to enable an implicit layer. This
712environment variable (which should vary with each "version" of the layer, as in
713"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
714layer is not loaded. This is for application environments (e.g. Steam) which
715want to enable a layer(s) only for applications that they launch, and allows
716for applications run outside of an application environment to not get that
717implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700718
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700719- (required for implicit layers) "disable\_environment" requirement(s) -
720environment variable and value required to disable an implicit layer. Note: in
721rare cases of an application not working with an implicit layer, the
722application can set this environment variable (before calling Vulkan functions)
723in order to "blacklist" the layer. This environment variable (which should vary
724with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
725(not particularly to any value). If both the "enable\_environment" and
726"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700727
728For example:
729
Jon Ashburncc300a22016-02-11 14:57:30 -0700730```
Jon Ashburnc2972682016-02-08 15:42:01 -0700731{
Jon Ashburncc300a22016-02-11 14:57:30 -0700732"file_format_version" : "1.0.0",
733"layer": {
734 "name": "VK_LAYER_LUNARG_OverlayLayer",
735 "type": "DEVICE",
736 "library_path": "vkOverlayLayer.dll"
737 "api_version" : "1.0.3",
738 "implementation_version" : "2",
739 "description" : "LunarG HUD layer",
740 "functions": {
741 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
742 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
743 },
744 instance_extensions": [
745 {
746 "name": "VK_debug_report_EXT",
747 "spec_version": "1"
748 },
749 {
750 "name": "VK_VENDOR_DEBUG_X",
751 "spec_version": "3"
752 }
753 ],
754 device_extensions": [
755 {
756 "name": "VK_LUNARG_DEBUG_MARKER",
757 "spec_version": "1",
758 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
759 }
760 ],
761 "disable_environment": {
762 "DISABLE_LAYER_OVERLAY_1": ""
763 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700764}
Jon Ashburnc2972682016-02-08 15:42:01 -0700765}
Jon Ashburncc300a22016-02-11 14:57:30 -0700766```
Jon Ashburnc2972682016-02-08 15:42:01 -0700767
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700768The "library\_path" specifies either a filename, a relative pathname, or a full
769pathname to a layer shared library (".dll") file, which the loader will attempt
770to load using LoadLibrary(). If the layer is specified via a relative pathname,
771it is relative to the path of the info file (e.g. for cases when an application
772provides a layer that is in the same folder hierarchy as the rest of the
773application files). If the layer is specified via a filename, the shared
774library lives in the system's DLL search path (e.g. in the
775"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700776
777There are no rules about the name of the text files (except the .json suffix).
778
779There are no rules about the name of the layer shared library files.
780
781##### Using Pre-Production Layers
782
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700783As with ICDs, developers may need to use special, pre-production layers,
784without modifying the properly-installed layers. This need is met with the use
785of the "VK\_LAYER\_PATH" environment variable, which will override the
786mechanism using for finding properly-installed layers. Because many layers may
787exist on a system, this environment variable is a semi-colon-separated list of
788folders that contain layer info files. Only the folder listed in
789"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
790entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700791
792- The full pathname of a folder containing layer info files
793
794#### Linux
795
796##### Properly-Installed Layers
797
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700798In order to find properly-installed layers, the Vulkan loader will use a
799similar mechanism as used for ICDs. Text information files, that use a JSON
800format, are read in order to identify the names and attributes of layers and
801their extensions. The use of text info files allows the loader to avoid loading
802any shared library files when the application does not query nor request any
803extensions. Layers and extensions have additional complexity, and so their info
804files contain more information than ICD info files. For example, a layer shared
805library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700806
807The Vulkan loader will scan the files in the following Linux directories:
808
809/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700810/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700811/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700812/etc/vulkan/implicit\_layer.d
813
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700814Explicit layers are those which are enabled by an application (e.g. with the
815vkCreateInstance function), or by an environment variable (as mentioned
816previously). Implicit layers are those which are enabled by their existence.
817For example, certain application environments (e.g. Steam or an automotive
818infotainment system) may have layers which they always want enabled for all
819applications that they start. Other implicit layers may be for all applications
820started on a given system (e.g. layers that overlay frames-per-second).
821Implicit layers are enabled automatically, whereas explicit layers must be
822enabled explicitly. What distinguishes a layer as implicit or explicit is by
823which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700824
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700825The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
826installed from Linux-distribution-provided packages. The
827"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
828non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700829
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700830The information file is in the JSON format and contains the following
831information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700832
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700833- (required) "file\_format\_version" – same as for ICDs, except that the format
834version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700835
836- (required) "name" - layer name
837
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700838- (required) "type" - which layer chains should the layer be activated on.
839Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
840both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700841
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700842- (required) "library\_path" - filename / full path / relative path to the text
843file
Jon Ashburnc2972682016-02-08 15:42:01 -0700844
845- (required) "api\_version" – same as for ICDs.
846
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700847- (required) "implementation\_version" – layer version, a single number
848increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700849
850- (required) "description" – informative decription of the layer.
851
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700852- (optional) "device\_extensions" or "instance\_extensions" - array of
853extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700854
Jon Ashburncc300a22016-02-11 14:57:30 -0700855 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700856
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700857 - (required) extension "spec\_version" - extension specification version, a
858single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700859
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700860 - (required for device extensions with entry points) extension
861"entrypoints" - array of device extension entrypoints; not used for instance
862extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700863
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700864- (sometimes required) "functions" - mapping list of function entry points. If
865multiple layers exist within the same shared library (or if a layer is in the
866same shared library as an ICD), this must be specified to allow each layer to
867have its own vkGet\*ProcAddr entrypoints that can be found by the loader. At
868this time, only the following two functions are required:
Jon Ashburncc300a22016-02-11 14:57:30 -0700869 - "vkGetInstanceProcAddr" name
870 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700871
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700872- (optional for implicit layers) "enable\_environment" requirement(s) -
873environment variable and value required to enable an implicit layer. This
874environment variable (which should vary with each "version" of the layer, as in
875"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
876layer is not loaded. This is for application environments (e.g. Steam) which
877want to enable a layer(s) only for applications that they launch, and allows
878for applications run outside of an application environment to not get that
879implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700880
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700881- (required for implicit layers) "disable\_environment" requirement(s) -
882environment variable and value required to disable an implicit layer. Note: in
883rare cases of an application not working with an implicit layer, the
884application can set this environment variable (before calling Vulkan functions)
885in order to "blacklist" the layer. This environment variable (which should vary
886with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
887(not particularly to any value). If both the "enable\_environment" and
888"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700889
890For example:
Jon Ashburncc300a22016-02-11 14:57:30 -0700891```
Jon Ashburnc2972682016-02-08 15:42:01 -0700892{
Jon Ashburncc300a22016-02-11 14:57:30 -0700893"file_format_version" : "1.0.0",
Jon Ashburnc2972682016-02-08 15:42:01 -0700894"layer": {
Jon Ashburncc300a22016-02-11 14:57:30 -0700895 "name": "VK_LAYER_LUNARG_OverlayLayer",
896 "type": "DEVICE",
897 "library_path": "vkOverlayLayer.dll"
898 "api_version" : "1.0.3",
899 "implementation_version" : "2",
900 "description" : "LunarG HUD layer",
901 "functions": {
902 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
903 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
904 },
905 instance_extensions": [
906 {
907 "name": "VK_debug_report_EXT",
908 "spec_version": "1"
909 },
910 {
911 "name": "VK_VENDOR_DEBUG_X",
912 "spec_version": "3"
913 }
914 ],
915 device_extensions": [
916 {
917 "name": "VK_LUNARG_DEBUG_MARKER",
918 "spec_version": "1",
919 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
920 }
921 ],
922 "disable_environment": {
923 "DISABLE_LAYER_OVERLAY_1": ""
924 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700925}
Jon Ashburnc2972682016-02-08 15:42:01 -0700926}
Jon Ashburncc300a22016-02-11 14:57:30 -0700927```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700928The "library\_path" specifies either a filename, a relative pathname, or a full
929pathname to a layer shared library (".so") file, which the loader will attempt
930to load using dlopen(). If the layer is specified via a filename, the loader
931will attempt to open that file as a shared object using dlopen(), and the file
932must be in a directory that dlopen is configured to look in (Note: various
933distributions are configured differently). A distribution is free to create
934Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
935required to do so. If the layer is specified via a relative pathname, it is
936relative to the path of the info file (e.g. for cases when an application
937provides a layer that is in the same directory hierarchy as the rest of the
938application files).
Jon Ashburnc2972682016-02-08 15:42:01 -0700939
940There are no rules about the name of the text files (except the .json suffix).
941
942There are no rules about the name of the layer shared library files.
943
944##### Using Pre-Production Layers
945
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700946As with ICDs, developers may need to use special, pre-production layers,
947without modifying the properly-installed layers. This need is met with the use
948of the "VK\_LAYER\_PATH" environment variable, which will override the
949mechanism using for finding properly-installed layers. Because many layers may
950exist on a system, this environment variable is a colon-separated list of
951directories that contain layer info files. Only the directories listed in
952"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
953is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700954
955- The full pathname of a directory containing layer info files
956
957NOTE: these environment variables will be ignored for suid programs.
958
959#### Android
960
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700961The recommended way to enable layers is for applications
962to programatically enable them. The layers are provided by the application
963and must live in the application's library folder. The application
964enables the layers at vkCreateInstance and vkCreateDevice as any Vulkan
965application would.
966An application enabled for debug has more options. It can enumerate and enable
967layers located in /data/local/vulkan/debug.
Jon Ashburnc2972682016-02-08 15:42:01 -0700968
Jon Ashburncc300a22016-02-11 14:57:30 -0700969Layer interface requirements
970------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700971
972#### Architectural interface overview
973
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700974There are two key architectural features that drive the loader to layer library
975interface: 1) separate and distinct instance and device call chains, and 2)
976distributed dispatch. First these architectural features will be described and
977then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -0700978
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700979Call chains are the links of calls for a given Vulkan command from layer module
980to layer module with the loader and or the ICD being the bottom most command.
981Call chains are constructed at both the instance level and the device level by
982the loader with cooperation from the layer libraries. Instance call chains are
983constructed by the loader when layers are enabled at vkCreateInstance. Device
984call chains are constructed by the loader when layers are enabled at
985CreateDevice. A layer can intercept Vulkan instance commands, device commands
986or both. For a layer to intercept instance commands, it must participate in the
987instance call chain. For a layer to intercept device commands, it must
988participate in the device chain. Layers which participate in intercepting calls
989in both the intance and device chains are called global layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700990
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700991Normally, when a layer intercepts a given Vulkan command, it will call down the
992instance or device chain as needed. The loader and all layer libraries that
993participate in a call chain cooperate to ensure the correct sequencing of calls
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -0700994from one entity to the next. This group effort for call chain sequencing is
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700995hereinafter referred to as disitributed dispatch. In distributed dispatch,
996since each layer is responsible for properly calling the next entity in the
997device or instance chain, a dispatch mechanism is required for all Vulkan
998commands a layer intercepts. For Vulkan commands that are not intercepted by a
999layer, or if the layer chooses to terminate a given Vulkman command by not
1000calling down the chain, then no dispatch mechanism is needed for that
1001particular Vulkan command. Only for those Vulkan commands, which may be a
1002subset of all Vulkan commands, that a layer intercepts is a dispatching
1003mechanism by the layer needed. The loader is responsible for dispatching all
1004core and instance extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001005
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001006Instance level Vulkan commands are those that have the disapatchable objects
1007VkInstance, or VkPhysicalDevice as the first parameter and alos includes
1008vkCreateInstance.
1009Device level Vulkan commands are those that use VkDevice, VkQueue or
1010VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
1011extensions may introduce new instance or device level dispatchable objects, so
1012the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -07001013
1014#### Discovery of layer entrypoints
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001015For the layer libraries that have been discovered by the loader, their
1016intercepting entry points that will participate in a device or instance call
1017chain need to be available to the loader or whatever layer is before them in
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001018the chain. Layers have the following requirements in this area.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001019- A layer intercepting instance level Vulkan commands (aka an instance level
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001020layer) must implement a vkGetInstanceProcAddr type of function.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001021- This vkGetInstanceProcAddr type function must be exported by the layer
1022library. The name of this function is specified in various ways: 1) the layer
1023manifest JSON file in the "functions", "vkGetInstanceProcAddr" node
1024(Linux/Windows); 2) it is named "vkGetInstanceProcAddr"; 3) it is
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001025"<layerName>GetInstanceProcAddr" (Android).
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001026- A layer intercepting device level Vulkan commands (aka a device level layer)
1027must implement a vkGetDeviceProcAddr type of function.
1028- This vkGetDeviceProcAddr type function must be exported by the layer library.
1029The name of this function is specified in various ways: 1) the layer manifest
1030JSON file in the "functions", "vkGetDeviceProcAddr" node (Linux/Windows); 2) it
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001031is named "vkGetDeviceProcAddr"; 3) it is "<layerName>GetDeviceProcAddr"
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001032(Android).
1033- A layer's vkGetInstanceProcAddr function (irregardless of it's name) must
1034return the local entry points for all instance level Vulkan commands it
1035intercepts. At a minimum, this includes vkGetInstanceProcAddr and
1036vkCreateInstance.
1037- A layer's vkGetDeviceProcAddr function (irregardless of it's name) must
1038return the entry points for all device level Vulkan commands it intercepts. At
1039a minimum, this includes vkGetDeviceProcAddr and vkCreateDevice.
1040- There are no requirements on the names of the intercepting functions a layer
1041implements except those listed above for vkGetInstanceProcAddr and
1042vkGetDeviceProcAddr.
1043- Currently a layer's VkGetInstanceProcAddr must be able to handle a VkInstance
1044parameter equal to NULL for
Jon Ashburnc2972682016-02-08 15:42:01 -07001045instance level commands it intercepts including vkCreateDevice.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001046- Currently a layer's VkGetDeviceProcAddr must be able to handle a VkDevice
1047parameter equal to NULL for device level commands it intercepts.
Jon Ashburnc2972682016-02-08 15:42:01 -07001048
1049#### Layer intercept requirements
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001050- Layers intercept a Vulkan command by defining a C/C++ function with signature
1051identical to the Vulkan API for that command.
1052- Other than the two vkGet*ProcAddr, all other functions intercepted by a layer
1053need NOT be exported by the layer.
1054- For any Vulkan command a layer intercepts which has a non-void return value,
1055an appropriate value must be returned by the layer intercept function.
1056- The layer intercept function must call down the chain to the corresponding
1057Vulkan command in the next entity. Undefined results will occur if a layer
1058doesn't propagate calls down the chain. The two exceptions to this requirement
1059are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1060chain for Vulkan commands that they do not intercept.
1061- Layer intercept functions may insert extra calls to Vulkan commands in
1062addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1063want to add a call to vkQueueWaitIdle after calling down the chain for
1064vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1065chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001066
1067#### Distributed dispatching requirements
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001068- For each entry point a layer intercepts, it must keep track of the entry
1069point residing in the next entity in the chain it will call down into. In other
1070words, the layer must have a list of pointers to functions of the appropriate
1071type to call into the next entity. This can be implemented in various ways but
1072for clarity will be referred to as a dispatch table.
1073- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1074(see include/vulkan/vk_layer.h).
1075- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1076dispatch table (see include/vulkan/vk_layer.h).
1077- Layers vkGetInstanceProcAddr function uses the next entity's
1078vkGetInstanceProcAddr to call down the chain for unknown (ie non-intercepted)
1079functions.
1080- Layers vkGetDeviceProcAddr function uses the next entity's
1081vkGetDeviceProcAddr to call down the chain for unknown (ie non-intercepted)
1082functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001083
1084#### Layer dispatch initialization
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001085- A layer intializes it's instance dispatch table within it's vkCreateInstance
1086function.
1087- A layer intializes it's device dispatch table within it's vkCreateDevice
1088function.
1089- The loader passes a linked list of initialization structures to layers via
1090the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1091for vkCreateInstance and VkCreateDevice respectively.
1092- The head node in this linked list is of type VkLayerInstanceCreateInfo for
Courtney Goeltzenleuchter42c4cdb2016-02-14 11:42:24 -07001093instance and VkLayerDeviceCreateInfo for device. See file
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001094include/vulkan/vk_layer.h for details.
1095- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1096"sType" field in VkLayerInstanceCreateInfo.
1097- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1098"sType" field in VkLayerDeviceCreateInfo.
1099- The "function" field indicates how the union field "u" should be interpreted
1100within VkLayer*CreateInfo. The loader will set the "function" field to
1101VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1102VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001103- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001104- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1105by a layer.
1106- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1107vkGetDeviceProcAddr used by a layer.
1108- Given the above structures set up by the loader, layer must initialize their
1109dispatch table as follows:
1110 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1111the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001112 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001113 - For CreateInstance get the next entity's vkCreateInstance by calling the
1114"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001115 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001116 - For CreateDevice get the next entity's vkCreateDevice by calling the
1117"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001118 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001119 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1120 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001121 - Initialize your layer dispatch table by calling the next entity's
1122Get*ProcAddr function once for each Vulkan command needed in your dispatch
1123table
Jon Ashburncc300a22016-02-11 14:57:30 -07001124
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001125TODO: Example code for CreateInstance.
1126
1127TODO: Example code for CreateDevice.
1128
Jon Ashburncc300a22016-02-11 14:57:30 -07001129#### Special Considerations
Jon Ashburnfe630fb2016-02-14 21:40:34 -07001130A layer may want to associate it's own private data with one or more Vulkan objects.
1131Two common methods to do this are hash maps and object wrapping. The loader
1132supports layers wrapping any Vulkan object including dispatchable objects.
1133Layers which wrap objects should ensure they always unwrap objects before
1134passing them down the chain. This implies the layer must intercept every Vulkan
1135command which uses the object in question. Layers above the object wrapping
1136layer will see the wrapped object.
1137
1138Alternatively, a layer may want to use a hash map to associate data with a given object.
1139The key to the map could be the object. Alternatively, for dispatchable objects
1140at a given level (eg device or instance) the may layer may want data associated with the all command for the VkDevice or VkInstance. Since there are multiple
1141dispatchable objects for a given VkInstance or VkDevice, the VkDevice or
1142VkInstance object is not a great map key. Instead the layer should use the
1143dispatch table pointer withbin the VkDevice or VkInstance since that will be
1144unique for a given VkInstance or VkDevice.
1145
1146Layers which create dispatchable objects take special care. Remember that loader
1147trampoline code normally fills in the dispatch table pointer in the newly
1148created object. Thus, the layer must fill in the dispatch table pointer if the
1149loader trampoline will not do so. Common cases a layer may create a dispatchable
1150object without loader trampoline code is as follows:
1151- object wrapping layers that wrap dispatchable objects
1152- layers which add extensions that create dispatchable objects
1153- layers which insert extra Vulkan commands in the stream of commands they
1154intercept from the application
Jon Ashburnc2972682016-02-08 15:42:01 -07001155