blob: f5a222c0426f862f0ee816a5ffd550aae1a40df9 [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 Goeltzenleuchtera1473762016-02-14 09:31:24 -070035Vulkan is layered architecture. Layers can hook (intercept) Vulkan commands to
36achieve 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
46layers and ICDs. The loader inserts layers into a call chain so they can
47intercept Vulkan commands prior to the proper ICD being called. To achieve
48proper dispatching of Vulkan command to layers and ICDs the loader uses the
49Vulkan object model.
Jon Ashburnc2972682016-02-08 15:42:01 -070050
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070051Vulkan uses an object model to control the scope of a particular action /
52operation. The object to be acted on is always the first parameter of a Vulkan
53call and is a dispatchable object (see Vulkan specification section 2.2 Object
54Model). Under the covers, the dispatchable object handle is a pointer to a
55structure that contains a pointer to a dispatch table maintained by the loader.
56This dispatch table contains pointers to the Vulkan functions appropriate to
57that object. I.e. a VkInstance object’s dispatch table will point to Vulkan
58functions such as vkEnumeratePhysicalDevices, vkDestroyInstance,
59vkCreateInstance, etc.
Jon Ashburnc2972682016-02-08 15:42:01 -070060
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070061Device objects have a separate dispatch table containing the appropriate
62function pointers.
Jon Ashburnc2972682016-02-08 15:42:01 -070063
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070064These instance and device dispatch tables are constructed when the application
65calls vkCreateInstance and vkCreateDevice. At that time the application and/or
66system can specify optional layers to be included. The loader will initialize
67the specified layers to create a call chain for each Vulkan function and each
68entry of the dispatch table will point to the first element of that chain.
69Thus, the loader builds an instance call chain for each VkInstance that is
70created and a device call chain for each VkDevice that is created.
Jon Ashburnc2972682016-02-08 15:42:01 -070071
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070072For example, the diagram below represents what happens in the call chain for
73vkCreateInstance. After initializing the chain, the loader will call into the
74first layer’s vkCreateInstance which will call the next finally terminating in
75the loader again where this function calls every ICD’s vkCreateInstance and
76saves the results. This allows every enabled layer for this chain to set up
77what it needs based on the VkInstanceCreateInfo structure from the application.
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -070078![Instance call chain](/images/instance_call_chain.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070079
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070080This also highlights some of the complexity the loader must manage when using
81instance chains. As shown here, the loader must aggregate information from
82multiple devices when they are present. This means that the loader has to know
83about instance level extensions to aggregate them correctly.
Jon Ashburnc2972682016-02-08 15:42:01 -070084
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -070085Device chains are created at vkCreateDevice and are generally simpler because
86they deal with only a single device and the ICD can always be the terminator of
87the chain. The below diagram also illustrates how layers (either device or
88instance) can skip intercepting any given Vulkan entry point.
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -070089![Chain skipping layers](/images/chain_skipping_layers.png)
Jon Ashburnc2972682016-02-08 15:42:01 -070090
91Application interface to loader
92-------------------------------
93
94In this section we’ll discuss how an application interacts with the loader.
95
96- Linking to loader library for core and WSI extension symbols.
97
98- Dynamic Vulkan command lookup & application dispatch table.
99
100- Loader library filenames for linking to different Vulkan ABI versions.
101
102- Layers
103
104- Extensions
105
106- vkGetInstanceProcAddr, vkGetDeviceProcAddr
107
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700108The loader library on Windows, Linux and Android will export all core Vulkan
109and all appropriate Window System Interface (WSI) extensions. This is done to
110make it simpler to get started with Vulkan development. When an application
111links directly to the loader library in this way, the Vulkan calls are simple
112trampoline functions that jump to the appropriate dispatch table entry for the
113object they are given.
Jon Ashburnc2972682016-02-08 15:42:01 -0700114
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700115Applications are not required to link directly to the loader library, instead
116they can use the appropriate platform specific dynamic symbol lookup on the
117loader library to initialize the application’s own dispatch table. This allows
118an application to fail gracefully if the loader cannot be found and provide the
119fastest mechanism for the application to call Vulkan functions. An application
120will only need to query (via system calls such as dlsym()) the address of
121vkGetInstanceProcAddr from the loader library. Using vkGetInstanceProcAddr the
122application can then discover the address of all instance and global functions
123and extensions, such as vkCreateInstance,
124vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties
125in a platform independent way.
Jon Ashburnc2972682016-02-08 15:42:01 -0700126
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700127The Vulkan loader library will be distributed in various ways including Vulkan
128SDKs, OS package distributions and IHV driver packages. These details are
129beyond the scope of this document. However, the name and versioning of the
130Vulkan loader library is specified so an app can link to the correct Vulkan ABI
131library version. Vulkan versioning is such that ABI backwards compatibility is
132guaranteed for all versions with the same major number (eg 1.0 and 1.1). On
133Windows, the loader library encodes the ABI version in its name such that
134multiple ABI incompatible versions of the loader can peacefully coexist on a
135given system. The vulkan loader library key name is “vulkan-<ABI
136version>”. For example, for Vulkan version 1.X on Windows the library
137filename is vulkan-1.dll. And this library file can typically be found in the
138windows/system32 directory.
Jon Ashburnc2972682016-02-08 15:42:01 -0700139
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700140For Linux, shared libraries are versioned based on a suffix. Thus, the ABI
141number is not encoded in the base of the library filename as on Windows. On
142Linux an application wanting to link to the latest Vulkan ABI version would
143just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can
144also be linked to by applications (eg libvulkan.so.1).
Jon Ashburnc2972682016-02-08 15:42:01 -0700145
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700146Applications desiring Vulkan functionality beyond what the core API offers may
147use various layers or extensions. A layer cannot add new or modify existing
148Vulkan commands, but may offer extensions that do. A common use of layers is
149for API validation. A developer can use validation layers during application
150development, but during production the layers can be disabled by the
151application. Thus, eliminating the overhead of validating the applications
152usage of the API. Layers discovered by the loader can be reported to the
153application via vkEnumerateInstanceLayerProperties and
154vkEnumerateDeviceLayerProperties, for instance and device layers respectively.
155Instance layers are enabled at vkCreateInstance; device layers are enabled at
156vkCreateDevice. For example, the ppEnabledLayerNames array in the
157VkDeviceCreateInfo structure is used by the application to list the device
158layer names to be enabled at vkCreateDevice. At vkCreateInstance and
159vkCreateDevice, the loader will construct call chains that include the
160application specified (enabled) layers. Order is important in the
161ppEnabledLayerNames array; array element 0 is the topmost (closest to the
162application) layer inserted in the chain and the last array element is closest
163to the driver.
Jon Ashburnc2972682016-02-08 15:42:01 -0700164
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700165Developers may want to enable layers that are not enabled by the given
166application they are using. On Linux and Windows, the environment variables
167“VK\_INSTANCE\_LAYERS” and “VK\_DEVICE\_LAYERS” can be used to enable
168additional layers which are not specified (enabled) by the application at
169vkCreateInstance/vkCreateDevice. VK\_INSTANCE\_LAYERS is a colon
170(Linux)/semi-colon (Windows) separated list of layer names to enable. Order is
171relevant with the first layer in the list being the topmost layer (closest to
172the application) and the last layer in the list being the bottommost layer
173(closest to the driver).
Jon Ashburnc2972682016-02-08 15:42:01 -0700174
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700175Application specified layers and user specified layers (via environment
176variables) are aggregated and duplicates removed by the loader when enabling
177layers. Layers specified via environment variable are topmost (closest to the
178application) while layers specified by the application are bottommost.
Jon Ashburnc2972682016-02-08 15:42:01 -0700179
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700180An example of using these environment variables to activate the validation
181layer VK\_LAYER\_LUNARG\_param\_checker on Windows or Linux is as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700182
183```
Jon Ashburncc300a22016-02-11 14:57:30 -0700184> $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700185
Jon Ashburncc300a22016-02-11 14:57:30 -0700186> $ export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_param_checker
Jon Ashburnc2972682016-02-08 15:42:01 -0700187```
188
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700189**Note**: Many layers, including all LunarG validation layers are “global”
190(i.e. both instance and device) layers and *must* be enabled on both the
191instance and device chains to function properly. This is required for “global”
192layers regardless of which method is used to enable the layer (application or
193environment variable).
Jon Ashburnc2972682016-02-08 15:42:01 -0700194
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700195Some platforms, including Linux and Windows, support layers which are enabled
196automatically by the loader rather than explicitly by the application (or via
197environment variable). Explicit layers are those layers enabled by the
198application (or environment variable) by providing the layer name. Implicit
199layers are those layers enabled by the loader automatically. Any implicit
200layers the loader discovers on the system in the appropriate location will be
201enabled (subject to environment variable overrides described later). Discovery
202of properly installed implicit and explicit layers is described later.
203Explicitly enabling a layer that is implicitly enabled has no additional
204effect: the layer will still be enabled implicitly by the loader.
Jon Ashburnc2972682016-02-08 15:42:01 -0700205
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700206Extensions are optional functionality provided by a layer, the loader or an
207ICD. Extensions can modify the behavior of the Vulkan API and need to be
208specified and registered with Khronos.
Jon Ashburnc2972682016-02-08 15:42:01 -0700209
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700210Instance extensions can be discovered via
211vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via
212vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all
213extensions from layers (both explicit and implicit), ICDs and the loader before
214reporting them to the application in vkEnumerate\*ExtensionProperties. The
215pLayerName parameter in these functions are used to select either a single
216layer or the Vulkan platform implementation. If pLayerName is NULL, extensions
217from Vulkan implementation components (including loader, implicit layers, and
218ICDs) are enumerated. If pLayerName is equal to a discovered layer module name
219then any extensions from that layer (which may be implicit or explicit) are
220enumerated. Duplicate extensions (eg an implicit layer and ICD might report
221support for the same extension) are eliminated by the loader. Extensions must
222be enabled (in vkCreateInstance or vkCreateDevice) before they can be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700223
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700224Extension command entry points should be queried via vkGetInstanceProcAddr or
225vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device
226extension or core device entry points. Device entry points include any command
227that uses a VkDevice as the first parameter or a dispatchable object that is a
228child of a VkDevice (currently this includes VkQueue and VkCommandBuffer).
229vkGetInstanceProcAddr can be used to query either device or instance extension
230entry points in addition to all core entry points.
Jon Ashburnc2972682016-02-08 15:42:01 -0700231
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700232VkGetDeviceProcAddr is particularly interesting because it will provide the
233most efficient way to call into the ICD. For example, the diagram below shows
234what could happen if the application were to use vkGetDeviceProcAddr for the
235function “vkGetDeviceQueue” and “vkDestroyDevice” but not “vkAllocateMemory”.
236The resulting function pointer (fpGetDeviceQueue) would be the ICD’s entry
237point if the loader and any enabled layers do not need to see that call. Even
238if an enabled layer intercepts the call (eg vkDestroyDevice) the loader
239trampoline code is skipped for function pointers obtained via
240vkGetDeviceProcAddr. This also means that function pointers obtained via
241vkGetDeviceProcAddr will only work with the specific VkDevice it was created
242for, using it with another device has undefined results. For extensions,
243Get\*ProcAddr will often be the only way to access extension API features.
Jon Ashburnc2972682016-02-08 15:42:01 -0700244
Courtney Goeltzenleuchterab3a4662016-02-14 10:48:22 -0700245![Get*ProcAddr efficiency](/images/get_proc_addr.png)
246
Jon Ashburnc2972682016-02-08 15:42:01 -0700247
248Vulkan Installable Client Driver interface with the loader
249----------------------------------------------------------
250
251### ICD discovery
252
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700253Vulkan allows multiple drivers each with one or more devices (represented by a
254Vulkan VkPhysicalDevice object) to be used collectively. The loader is
255responsible for discovering available Vulkan ICDs on the system. Given a list
256of available ICDs, the loader can enumerate all the physical devices available
257for an application and return this information to the application. The process
258in which the loader discovers the available Installable Client Drivers (ICDs)
259on a system is platform dependent. Windows, Linux and Android ICD discovery
260details are listed below.
Jon Ashburnc2972682016-02-08 15:42:01 -0700261
262#### Windows
263
264##### Properly-Installed ICDs
265
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700266In order to find properly-installed ICDs, the Vulkan loader will scan the
267values in the following Windows registry key:
Jon Ashburnc2972682016-02-08 15:42:01 -0700268
269HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers
270
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700271For each value in this key which has DWORD data set to 0, the loader opens the
272JSON format text information file (a.k.a. "manifest file") specified by the
273name of the value. Each name must be a full pathname to the text manifest file.
274The Vulkan loader will open each manifest file to obtain the name or pathname
275of an ICD shared library (".dll") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700276
Jon Ashburncc300a22016-02-11 14:57:30 -0700277 ```
278 {
Jon Ashburnc2972682016-02-08 15:42:01 -0700279 "file_format_version": "1.0.0",
280 "ICD": {
281 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700282 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700283 }
284 }
Jon Ashburncc300a22016-02-11 14:57:30 -0700285 ```
Jon Ashburnc2972682016-02-08 15:42:01 -0700286
287
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700288The "library\_path" specifies either a filename, a relative pathname, or a full
289pathname to an ICD shared library file, which the loader will attempt to load
290using LoadLibrary(). If the ICD is specified via a filename, the shared library
291lives in the system's DLL search path (e.g. in the "C:\\\\Windows\\\\System32"
292folder). If the ICD is specified via a relative pathname, it is relative to the
293path of the manifest file. Relative pathnames are those that do not start with
294a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\'
295character), but do contain at least one directory separator.
Jon Ashburnc2972682016-02-08 15:42:01 -0700296
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700297The "file\_format\_version" specifies a major.minor.patch version number in
298case the format of the text information file changes in the future. If the same
299ICD shared library supports multiple, incompatible versions of text manifest
300file format versions, it must have multiple text info files (all of which may
301point to the same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700302
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700303The “api\_version” specifies the major.minor.patch version number of the Vulkan
304API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700305
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700306There are no rules about the name of the text information files (except the
307.json suffix).
Jon Ashburnc2972682016-02-08 15:42:01 -0700308
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700309There are no rules about the name of the ICD shared library files. For example,
310if the registry contains the following values,
Jon Ashburnc2972682016-02-08 15:42:01 -0700311
Jon Ashburncc300a22016-02-11 14:57:30 -0700312```
313[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\]
Jon Ashburnc2972682016-02-08 15:42:01 -0700314
Jon Ashburncc300a22016-02-11 14:57:30 -0700315"C:\vendor a\vk\_vendora.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700316
Jon Ashburncc300a22016-02-11 14:57:30 -0700317"C:\windows\system32\vendorb\_vk.json"=dword:00000000
Jon Ashburnc2972682016-02-08 15:42:01 -0700318
Jon Ashburncc300a22016-02-11 14:57:30 -0700319"C:\windows\system32\vendorc\_icd.json"=dword:00000000
320```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700321then the loader will open the following text information files, with the
322specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700323
Jon Ashburncc300a22016-02-11 14:57:30 -0700324| Text File Name | Text File Contents |
325|-------------------------------------|
326|vk\_vendora.json | "ICD": { "library\_path": "C:\\\\VENDORA\\\\vk\_vendora.dll", "api_version": "1.0.3" } |
327| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.3" } |
328|vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.3" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700329
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700330Then the loader will open the three files mentioned in the "Text File Contents"
331column, and then try to load and use the three shared libraries indicated by
332the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700333
334##### Using Pre-Production ICDs
335
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700336IHV developers (and sometimes other developers) need to use special,
337pre-production ICDs. In some cases, a pre-production ICD may be in an
338installable package. In other cases, a pre-production ICD may simply be a
339shared library in the developer's build tree. In this latter case, we want to
340allow developers to point to such an ICD without modifying the
341properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700342
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700343This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
344which will override the mechanism used for finding properly-installed ICDs. In
345other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The
346"VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD
347text information files (aka manifest files), containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700348
Jon Ashburncc300a22016-02-11 14:57:30 -0700349- A full pathname (e.g. "C:\\my\_build\\my\_icd.json")
Jon Ashburnc2972682016-02-08 15:42:01 -0700350
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700351Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
352file for a developer-built ICD. A semi-colon is only used if more than one ICD
353is listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700354
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700355For example, if a developer wants to refer to one ICD that they built, they
356could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700357
Jon Ashburncc300a22016-02-11 14:57:30 -0700358C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700359
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700360If a developer wants to refer to two ICDs, one of which is a properly-installed
361ICD, they can use the full pathname of the text file:
Jon Ashburnc2972682016-02-08 15:42:01 -0700362
Jon Ashburncc300a22016-02-11 14:57:30 -0700363C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json
Jon Ashburnc2972682016-02-08 15:42:01 -0700364
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700365Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and
366"C:\\my\_build\\my\_icd.json".
Jon Ashburnc2972682016-02-08 15:42:01 -0700367
368#### Linux
369
370##### Properly-Installed ICDs
371
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700372In order to find properly-installed ICDs, the Vulkan loader will scan the files
373in the following Linux directories:
Jon Ashburnc2972682016-02-08 15:42:01 -0700374
375/usr/share/vulkan/icd.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700376/etc/vulkan/icd.d
377
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700378These directories will contain text information files (a.k.a. "manifest
379files"), that use a JSON format.
Jon Ashburnc2972682016-02-08 15:42:01 -0700380
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700381The Vulkan loader will open each manifest file found to obtain the name or
382pathname of an ICD shared library (".so") file. For example:
Jon Ashburnc2972682016-02-08 15:42:01 -0700383
Jon Ashburncc300a22016-02-11 14:57:30 -0700384```
385{
Jon Ashburnc2972682016-02-08 15:42:01 -0700386 "file_format_version": "1.0.0",
387 "ICD": {
388 "library_path": "path to ICD library",
Tony Barbourcd489512016-02-10 15:59:32 -0700389 "api_version": "1.0.3"
Jon Ashburnc2972682016-02-08 15:42:01 -0700390 }
391}
Jon Ashburncc300a22016-02-11 14:57:30 -0700392```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700393The "library\_path" specifies either a filename, a relative pathname, or a full
394pathname to an ICD shared library file. If the ICD is specified via a filename,
395the loader will attempt to open that file as a shared object using dlopen(),
396and the file must be in a directory that dlopen is configured to look in (Note:
397various distributions are configured differently). A distribution is free to
398create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not
399required to do so. If the ICD is specified via a relative pathname, it is
400relative to the path of the info file. Relative pathnames are those that do not
401start with, but do contain at least one directory separator (i.e. the '/'
402character). For example, "lib/vendora.so" and "./vendora.so" are examples of
403relative pathnames.
Jon Ashburnc2972682016-02-08 15:42:01 -0700404
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700405The "file\_format\_version" provides a major.minor.patch version number in case
406the format of the manifest file changes in the future. If the same ICD shared
407library supports multiple, incompatible versions of manifest file format
408versions, it must have multiple manifest files (all of which may point to the
409same shared library).
Jon Ashburnc2972682016-02-08 15:42:01 -0700410
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700411The “api\_version” specifies the major.minor.patch version number of the Vulkan
412API that the shared library (referenced by "library\_path") was built with.
Jon Ashburnc2972682016-02-08 15:42:01 -0700413
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700414The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from
415Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for
416ICDs that are installed from non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700417
418There are no rules about the name of the text files (except the .json suffix).
419
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700420There are no rules about the name of the ICD shared library files. For example,
421if the "/usr/share/vulkan/icd.d" directory contain the following files, with
422the specified contents:
Jon Ashburnc2972682016-02-08 15:42:01 -0700423
Jon Ashburncc300a22016-02-11 14:57:30 -0700424| Text File Name | Text File Contents |
425|-----------------|--------------------|
426|vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.3" } |
427| vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.3" } |
428| vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.1" }|
Jon Ashburnc2972682016-02-08 15:42:01 -0700429
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700430then the loader will open the three files mentioned in the "Text File Contents"
431column, and then try to load and use the three shared libraries indicated by
432the ICD.library\_path value.
Jon Ashburnc2972682016-02-08 15:42:01 -0700433
434##### Using Pre-Production ICDs
435
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700436IHV developers (and sometimes other developers) need to use special,
437pre-production ICDs. In some cases, a pre-production ICD may be in an
438installable package. In other cases, a pre-production ICD may simply be a
439shared library in the developer's build tree. In this latter case, we want to
440allow developers to point to such an ICD without modifying the
441properly-installed ICD(s) on their system.
Jon Ashburnc2972682016-02-08 15:42:01 -0700442
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700443This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable,
444which will override the mechanism used for finding properly-installed ICDs. In
445other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used.
Jon Ashburnc2972682016-02-08 15:42:01 -0700446
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700447The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD
448manifest files, containing the following:
Jon Ashburnc2972682016-02-08 15:42:01 -0700449
450- A filename (e.g. "libvkicd.json") in the "/usr/share/vulkan/icd.d" or "/etc/vulkan/icd.d" system directories
451
452- A full pathname (e.g. "/my\_build/my\_icd.json")
453
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700454Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info
455file for a developer-built ICD. A colon is only used if more than one ICD is
456listed.
Jon Ashburnc2972682016-02-08 15:42:01 -0700457
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700458For example, if a developer wants to refer to one ICD that they built, they
459could set the "VK\_ICD\_FILENAMES" environment variable to:
Jon Ashburnc2972682016-02-08 15:42:01 -0700460
461/my\_build/my\_icd.json
462
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700463If a developer wants to refer to two ICDs, one of which is a properly-installed
464ICD, they can use the name of the text file in the system directory:
Jon Ashburnc2972682016-02-08 15:42:01 -0700465
466vendorc\_vulkan.json:/my\_build/my\_icd.json
467
468Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json".
469
470NOTE: this environment variable will be ignored for suid programs.
471
472#### Android
473
474TODO: Fill out this section
475
476
Jon Ashburncc300a22016-02-11 14:57:30 -0700477ICD interface requirements
478----------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700479
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700480Generally, for all Vulkan commands issued by an application, the loader can be
481viewed as a pass through. That is, the loader generally doesn’t modified the
482commands or their parameters but simply calls the ICDs entry point for that
483command. Thus, the loader to ICD interface requirements will be specified by
484covering two areas: 1) Obtaining ICD Vulkan entry points; 2) Specifying
485requirements for a given Vulkan command(s) over and above the Vulkan
486specification requirements.
Jon Ashburnc2972682016-02-08 15:42:01 -0700487
488#### Windows and Linux
489
490##### Obtaining ICD entry points
491
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700492Currently, two methods of the loader finding ICD entry points are supported on
493Linux and Windows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700494
4951) Recommended
496
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700497- vk\_icdGetInstanceProcAddr exported in the ICD library and it returns valid
498 function pointers for all the global level and instance level Vulkan commands,
499 and also vkGetDeviceProcAddr. Global level commands are those which contain no
500 dispatchable object as the first parameter, such as vkCreateInstance and
501 vkEnumerateInstanceExtensionProperties. The ICD must support querying global
502 level entry points by calling vk\_icdGetInstanceProcAddr with a NULL VkInstance
503 parameter. Instance level commands are those that have either VkInstance, or
504 VkPhysicalDevice as the first parameter dispatchable object. Both core entry
505 points and any instance extension entry points the ICD supports should be
506 available via vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may
507 define and use new instance level dispatchable objects other than VkInstance
508 and VkPhysicalDevice, in which case, extensions entry points using these newly
509 defined dispatchable oibjects must be queryable via vk\_icdGetInstanceProcAddr.
Jon Ashburnc2972682016-02-08 15:42:01 -0700510
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700511- All other Vulkan entry points must either NOT be exported from the ICD
512 library or else NOT use the official Vulkan function names if they are
513 exported. This requirement is for ICD libraries that include other
514 functionality (such as OpenGL library) and thus could be loaded by the
515 application prior to when the Vulkan loader library is loaded by the
516 application. In other words, the ICD library exported Vulkan symbols must not
517 clash with the loader's exported Vulkan symbols.
Jon Ashburnc2972682016-02-08 15:42:01 -0700518
5192) Deprecated
520
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700521- vkGetInstanceProcAddr exported in the ICD library and returns valid function
522 pointers for all the Vulkan API entrypoints.
Jon Ashburnc2972682016-02-08 15:42:01 -0700523
524- vkCreateInstance exported in the ICD library;
525
526- vkEnumerateInstanceExtensionProperties exported in the ICD library;
527
528##### Loader specific requirements for Vulkan commands
529
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700530Normally, ICDs handle object creation and destruction for various Vulkan
531objects. The WSI surface extensions for Linux and Windows
532(VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface,
533VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are
534handled differently. For these extensions, the VkSurfaceKHR object creation and
535destruction is handled by the loader as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700536
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005371. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR()
538 functions including creating/destroying the VkSurfaceKHR object.
Jon Ashburnc2972682016-02-08 15:42:01 -0700539
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005402. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as
541 defined in include/vulkan/vk\_icd.h.
Jon Ashburnc2972682016-02-08 15:42:01 -0700542
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005433. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate
544 VkIcdSurface\* structure.
Jon Ashburnc2972682016-02-08 15:42:01 -0700545
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005464. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb,
547 VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field in
548 the structure is a VkIcdSurfaceBase enumerant that indicates westher the
549 surface object is Win32, Xcb, Xlib, Mir, or Wayland.
Jon Ashburnc2972682016-02-08 15:42:01 -0700550
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700551As previously covered, the loader requires dispatch tables to be accessible
552within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice,
553VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all
554dispatchable objects created by ICDs are as follows:
Jon Ashburnc2972682016-02-08 15:42:01 -0700555
Jon Ashburncc300a22016-02-11 14:57:30 -0700556- All dispatchable objects created by an ICD can be cast to void \*\*
Jon Ashburnc2972682016-02-08 15:42:01 -0700557
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700558- The loader will replace the first entry with a pointer to the dispatch table
559 which is owned by the loader. This implies three things for ICD drivers:
Jon Ashburnc2972682016-02-08 15:42:01 -0700560
Jon Ashburncc300a22016-02-11 14:57:30 -07005611. The ICD must return a pointer for the opaque dispatchable object handle.
Jon Ashburnc2972682016-02-08 15:42:01 -0700562
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005632. This pointer points to a regular C structure with the first entry being a
564 pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++
565 classes. The C\++ compiler may put a vtable at offset zero if your class is
566 virtual. In this case use a regular C structure (see below).
Jon Ashburnc2972682016-02-08 15:42:01 -0700567
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07005683. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created
569 dispatchable objects, as follows (see include/vulkan/vk\_icd.h):
Jon Ashburnc2972682016-02-08 15:42:01 -0700570
571```
572
Jon Ashburncc300a22016-02-11 14:57:30 -0700573#include "vk_icd.h"
Jon Ashburnc2972682016-02-08 15:42:01 -0700574
Jon Ashburncc300a22016-02-11 14:57:30 -0700575union _VK_LOADER_DATA {
576 uintptr loadermagic;
577 void *loaderData;
578} VK_LOADER_DATA;
Jon Ashburnc2972682016-02-08 15:42:01 -0700579
Jon Ashburncc300a22016-02-11 14:57:30 -0700580vkObj alloc_icd_obj()
Jon Ashburnc2972682016-02-08 15:42:01 -0700581{
Jon Ashburncc300a22016-02-11 14:57:30 -0700582 vkObj *newObj = alloc_obj();
583 ...
584 // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC
Jon Ashburnc2972682016-02-08 15:42:01 -0700585
Jon Ashburncc300a22016-02-11 14:57:30 -0700586 set_loader_magic_value(newObj);
587 ...
588 return newObj;
Jon Ashburnc2972682016-02-08 15:42:01 -0700589}
Jon Ashburnc2972682016-02-08 15:42:01 -0700590```
591
592Additional Notes:
593
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700594- The loader will filter out extensions requested in vkCreateInstance and
595vkCreateDevice before calling into the ICD; Filtering will be of extensions
596advertised by entities (eg layers) different from the ICD in question.
597- The loader will not call ICD for vkEnumerate\*LayerProperties() as layer
598properties are obtained from the layer libraries and layer JSON files.
599- If an ICD library wants to implement a layer it can do so by having the
600appropriate layer JSON manifest file refer to the ICD library file.
601- The loader will not call ICD for vkEnumerate\*ExtensionProperties(pLayerName
602!= NULL).
Jon Ashburnc2972682016-02-08 15:42:01 -0700603- The ICD may or may not implement a dispatch table.
604
605#### Android
606
607TODO: Fill out this section
608
609Vulkan layer interface with the loader
610--------------------------------------
611
612### Layer discovery
613
614#### Windows
615
616##### Properly-Installed Layers
617
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700618In order to find properly-installed layers, the Vulkan loader will use a
619similar mechanism as used for ICDs. Text information files (aka manifest
620files), that use a JSON format, are read in order to identify the names and
621attributes of layers and their extensions. The use of manifest files allows the
622loader to avoid loading any shared library files when the application does not
623query nor request any extensions. Layers and extensions have additional
624complexity, and so their manifest files contain more information than ICD info
625files. For example, a layer shared library file may contain multiple
626layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700627
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700628In order to find properly-installed layers, the Vulkan loader will scan the
629values in the following Windows registry keys:
Jon Ashburnc2972682016-02-08 15:42:01 -0700630
631HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers
632
633HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers
634
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700635Explicit layers are those which are enabled by an application (e.g. with the
636vkCreateInstance function), or by an environment variable (as mentioned
637previously).
Jon Ashburnc2972682016-02-08 15:42:01 -0700638
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700639Implicit layers are those which are enabled by their existence. For example,
640certain application environments (e.g. Steam or an automotive infotainment
641system) may have layers which they always want enabled for all applications
642that they start. Other implicit layers may be for all applications started on a
643given system (e.g. layers that overlay frames-per-second). Implicit layers are
644enabled automatically, whereas explicit layers must be enabled explicitly. What
645distinguishes a layer as implicit or explicit is by which registry key its
646layer information file is referenced by.
Jon Ashburnc2972682016-02-08 15:42:01 -0700647
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700648For each value in these keys which has DWORD data set to 0, the loader opens
649the JSON manifest file specified by the name of the value. Each name must be a
650full pathname to the manifest file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700651
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700652The Vulkan loader will open each info file to obtain information about the
653layer, including the name or pathname of a shared library (".dll") file.
Jon Ashburnc2972682016-02-08 15:42:01 -0700654
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700655This manifest file is in the JSON format and contains the following
656information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700657
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700658- (required) "file\_format\_version" - same as for ICDs, except that the format
659version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700660
661- (required) "name" - layer name
662
663- (required) "type" - which layer chains should the layer be activated on.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700664Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
665both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700666
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700667- (required) "library\_path" - filename / full path / relative path to the
668library file
Jon Ashburnc2972682016-02-08 15:42:01 -0700669
670- (required) "api\_version" - same as for ICDs.
671
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700672- (required) "implementation\_version" - layer version, a single number
673increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700674
675- (required) "description" - informative description of the layer.
676
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700677- (optional) "device\_extensions" or "instance\_extensions" - array of
678extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700679
Jon Ashburncc300a22016-02-11 14:57:30 -0700680 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700681
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700682 - (required) extension "spec\_version" - extension specification version, a
683single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700684
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700685 - (required for device\_extensions with entry points) extension
686"entrypoints" - array of device extension entrypoints; not used for instance
687extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700688
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700689- (sometimes required) "functions" - mapping list of function entry points. If
690multiple layers exist within the same shared library (or if a layer is in the
691same shared library as an ICD), this must be specified to allow each layer to
692have its own vkGet\*ProcAddr entrypoints that can be found by the loader. At
693this time, only the following two functions are required:
Jon Ashburnc2972682016-02-08 15:42:01 -0700694
Jon Ashburncc300a22016-02-11 14:57:30 -0700695 - "vkGetInstanceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700696
Jon Ashburncc300a22016-02-11 14:57:30 -0700697 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700698
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700699- (optional for implicit layers) "enable\_environment" requirement(s) -
700environment variable and value required to enable an implicit layer. This
701environment variable (which should vary with each "version" of the layer, as in
702"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
703layer is not loaded. This is for application environments (e.g. Steam) which
704want to enable a layer(s) only for applications that they launch, and allows
705for applications run outside of an application environment to not get that
706implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700707
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700708- (required for implicit layers) "disable\_environment" requirement(s) -
709environment variable and value required to disable an implicit layer. Note: in
710rare cases of an application not working with an implicit layer, the
711application can set this environment variable (before calling Vulkan functions)
712in order to "blacklist" the layer. This environment variable (which should vary
713with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
714(not particularly to any value). If both the "enable\_environment" and
715"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700716
717For example:
718
Jon Ashburncc300a22016-02-11 14:57:30 -0700719```
Jon Ashburnc2972682016-02-08 15:42:01 -0700720{
Jon Ashburncc300a22016-02-11 14:57:30 -0700721"file_format_version" : "1.0.0",
722"layer": {
723 "name": "VK_LAYER_LUNARG_OverlayLayer",
724 "type": "DEVICE",
725 "library_path": "vkOverlayLayer.dll"
726 "api_version" : "1.0.3",
727 "implementation_version" : "2",
728 "description" : "LunarG HUD layer",
729 "functions": {
730 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
731 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
732 },
733 instance_extensions": [
734 {
735 "name": "VK_debug_report_EXT",
736 "spec_version": "1"
737 },
738 {
739 "name": "VK_VENDOR_DEBUG_X",
740 "spec_version": "3"
741 }
742 ],
743 device_extensions": [
744 {
745 "name": "VK_LUNARG_DEBUG_MARKER",
746 "spec_version": "1",
747 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
748 }
749 ],
750 "disable_environment": {
751 "DISABLE_LAYER_OVERLAY_1": ""
752 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700753}
Jon Ashburnc2972682016-02-08 15:42:01 -0700754}
Jon Ashburncc300a22016-02-11 14:57:30 -0700755```
Jon Ashburnc2972682016-02-08 15:42:01 -0700756
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700757The "library\_path" specifies either a filename, a relative pathname, or a full
758pathname to a layer shared library (".dll") file, which the loader will attempt
759to load using LoadLibrary(). If the layer is specified via a relative pathname,
760it is relative to the path of the info file (e.g. for cases when an application
761provides a layer that is in the same folder hierarchy as the rest of the
762application files). If the layer is specified via a filename, the shared
763library lives in the system's DLL search path (e.g. in the
764"C:\\Windows\\System32" folder).
Jon Ashburnc2972682016-02-08 15:42:01 -0700765
766There are no rules about the name of the text files (except the .json suffix).
767
768There are no rules about the name of the layer shared library files.
769
770##### Using Pre-Production Layers
771
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700772As with ICDs, developers may need to use special, pre-production layers,
773without modifying the properly-installed layers. This need is met with the use
774of the "VK\_LAYER\_PATH" environment variable, which will override the
775mechanism using for finding properly-installed layers. Because many layers may
776exist on a system, this environment variable is a semi-colon-separated list of
777folders that contain layer info files. Only the folder listed in
778"VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated
779entry is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700780
781- The full pathname of a folder containing layer info files
782
783#### Linux
784
785##### Properly-Installed Layers
786
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700787In order to find properly-installed layers, the Vulkan loader will use a
788similar mechanism as used for ICDs. Text information files, that use a JSON
789format, are read in order to identify the names and attributes of layers and
790their extensions. The use of text info files allows the loader to avoid loading
791any shared library files when the application does not query nor request any
792extensions. Layers and extensions have additional complexity, and so their info
793files contain more information than ICD info files. For example, a layer shared
794library file may contain multiple layers/extensions (perhaps even an ICD).
Jon Ashburnc2972682016-02-08 15:42:01 -0700795
796The Vulkan loader will scan the files in the following Linux directories:
797
798/usr/share/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700799/usr/share/vulkan/implicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700800/etc/vulkan/explicit\_layer.d
Jon Ashburnc2972682016-02-08 15:42:01 -0700801/etc/vulkan/implicit\_layer.d
802
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700803Explicit layers are those which are enabled by an application (e.g. with the
804vkCreateInstance function), or by an environment variable (as mentioned
805previously). Implicit layers are those which are enabled by their existence.
806For example, certain application environments (e.g. Steam or an automotive
807infotainment system) may have layers which they always want enabled for all
808applications that they start. Other implicit layers may be for all applications
809started on a given system (e.g. layers that overlay frames-per-second).
810Implicit layers are enabled automatically, whereas explicit layers must be
811enabled explicitly. What distinguishes a layer as implicit or explicit is by
812which directory its layer information file exists in.
Jon Ashburnc2972682016-02-08 15:42:01 -0700813
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700814The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are
815installed from Linux-distribution-provided packages. The
816"/etc/vulkan/\*\_layer.d" directories are for layers that are installed from
817non-Linux-distribution-provided packages.
Jon Ashburnc2972682016-02-08 15:42:01 -0700818
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700819The information file is in the JSON format and contains the following
820information:
Jon Ashburnc2972682016-02-08 15:42:01 -0700821
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700822- (required) "file\_format\_version" – same as for ICDs, except that the format
823version can vary independently for ICDs and layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700824
825- (required) "name" - layer name
826
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700827- (required) "type" - which layer chains should the layer be activated on.
828Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on
829both device and instance chains.
Jon Ashburnc2972682016-02-08 15:42:01 -0700830
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700831- (required) "library\_path" - filename / full path / relative path to the text
832file
Jon Ashburnc2972682016-02-08 15:42:01 -0700833
834- (required) "api\_version" – same as for ICDs.
835
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700836- (required) "implementation\_version" – layer version, a single number
837increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700838
839- (required) "description" – informative decription of the layer.
840
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700841- (optional) "device\_extensions" or "instance\_extensions" - array of
842extension information as follows
Jon Ashburnc2972682016-02-08 15:42:01 -0700843
Jon Ashburncc300a22016-02-11 14:57:30 -0700844 - (required) extension "name" - Vulkan registered name
Jon Ashburnc2972682016-02-08 15:42:01 -0700845
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700846 - (required) extension "spec\_version" - extension specification version, a
847single number, increasing with backward compatible changes.
Jon Ashburnc2972682016-02-08 15:42:01 -0700848
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700849 - (required for device extensions with entry points) extension
850"entrypoints" - array of device extension entrypoints; not used for instance
851extensions
Jon Ashburnc2972682016-02-08 15:42:01 -0700852
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700853- (sometimes required) "functions" - mapping list of function entry points. If
854multiple layers exist within the same shared library (or if a layer is in the
855same shared library as an ICD), this must be specified to allow each layer to
856have its own vkGet\*ProcAddr entrypoints that can be found by the loader. At
857this time, only the following two functions are required:
Jon Ashburncc300a22016-02-11 14:57:30 -0700858 - "vkGetInstanceProcAddr" name
859 - "vkGetDeviceProcAddr" name
Jon Ashburnc2972682016-02-08 15:42:01 -0700860
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700861- (optional for implicit layers) "enable\_environment" requirement(s) -
862environment variable and value required to enable an implicit layer. This
863environment variable (which should vary with each "version" of the layer, as in
864"ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit
865layer is not loaded. This is for application environments (e.g. Steam) which
866want to enable a layer(s) only for applications that they launch, and allows
867for applications run outside of an application environment to not get that
868implicit layer(s).
Jon Ashburnc2972682016-02-08 15:42:01 -0700869
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700870- (required for implicit layers) "disable\_environment" requirement(s) -
871environment variable and value required to disable an implicit layer. Note: in
872rare cases of an application not working with an implicit layer, the
873application can set this environment variable (before calling Vulkan functions)
874in order to "blacklist" the layer. This environment variable (which should vary
875with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set
876(not particularly to any value). If both the "enable\_environment" and
877"disable\_environment" variables are set, the implicit layer is disabled.
Jon Ashburnc2972682016-02-08 15:42:01 -0700878
879For example:
Jon Ashburncc300a22016-02-11 14:57:30 -0700880```
Jon Ashburnc2972682016-02-08 15:42:01 -0700881{
Jon Ashburncc300a22016-02-11 14:57:30 -0700882"file_format_version" : "1.0.0",
Jon Ashburnc2972682016-02-08 15:42:01 -0700883"layer": {
Jon Ashburncc300a22016-02-11 14:57:30 -0700884 "name": "VK_LAYER_LUNARG_OverlayLayer",
885 "type": "DEVICE",
886 "library_path": "vkOverlayLayer.dll"
887 "api_version" : "1.0.3",
888 "implementation_version" : "2",
889 "description" : "LunarG HUD layer",
890 "functions": {
891 "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr",
892 "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr"
893 },
894 instance_extensions": [
895 {
896 "name": "VK_debug_report_EXT",
897 "spec_version": "1"
898 },
899 {
900 "name": "VK_VENDOR_DEBUG_X",
901 "spec_version": "3"
902 }
903 ],
904 device_extensions": [
905 {
906 "name": "VK_LUNARG_DEBUG_MARKER",
907 "spec_version": "1",
908 "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"]
909 }
910 ],
911 "disable_environment": {
912 "DISABLE_LAYER_OVERLAY_1": ""
913 }
Jon Ashburnc2972682016-02-08 15:42:01 -0700914}
Jon Ashburnc2972682016-02-08 15:42:01 -0700915}
Jon Ashburncc300a22016-02-11 14:57:30 -0700916```
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700917The "library\_path" specifies either a filename, a relative pathname, or a full
918pathname to a layer shared library (".so") file, which the loader will attempt
919to load using dlopen(). If the layer is specified via a filename, the loader
920will attempt to open that file as a shared object using dlopen(), and the file
921must be in a directory that dlopen is configured to look in (Note: various
922distributions are configured differently). A distribution is free to create
923Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not
924required to do so. If the layer is specified via a relative pathname, it is
925relative to the path of the info file (e.g. for cases when an application
926provides a layer that is in the same directory hierarchy as the rest of the
927application files).
Jon Ashburnc2972682016-02-08 15:42:01 -0700928
929There are no rules about the name of the text files (except the .json suffix).
930
931There are no rules about the name of the layer shared library files.
932
933##### Using Pre-Production Layers
934
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700935As with ICDs, developers may need to use special, pre-production layers,
936without modifying the properly-installed layers. This need is met with the use
937of the "VK\_LAYER\_PATH" environment variable, which will override the
938mechanism using for finding properly-installed layers. Because many layers may
939exist on a system, this environment variable is a colon-separated list of
940directories that contain layer info files. Only the directories listed in
941"VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry
942is:
Jon Ashburnc2972682016-02-08 15:42:01 -0700943
944- The full pathname of a directory containing layer info files
945
946NOTE: these environment variables will be ignored for suid programs.
947
948#### Android
949
950TODO: Fill out this section
951
Jon Ashburncc300a22016-02-11 14:57:30 -0700952Layer interface requirements
953------------------------------------------------------
Jon Ashburnc2972682016-02-08 15:42:01 -0700954
955#### Architectural interface overview
956
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700957There are two key architectural features that drive the loader to layer library
958interface: 1) separate and distinct instance and device call chains, and 2)
959distributed dispatch. First these architectural features will be described and
960then the detailed interface will be specified.
Jon Ashburnc2972682016-02-08 15:42:01 -0700961
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700962Call chains are the links of calls for a given Vulkan command from layer module
963to layer module with the loader and or the ICD being the bottom most command.
964Call chains are constructed at both the instance level and the device level by
965the loader with cooperation from the layer libraries. Instance call chains are
966constructed by the loader when layers are enabled at vkCreateInstance. Device
967call chains are constructed by the loader when layers are enabled at
968CreateDevice. A layer can intercept Vulkan instance commands, device commands
969or both. For a layer to intercept instance commands, it must participate in the
970instance call chain. For a layer to intercept device commands, it must
971participate in the device chain. Layers which participate in intercepting calls
972in both the intance and device chains are called global layers.
Jon Ashburnc2972682016-02-08 15:42:01 -0700973
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700974Normally, when a layer intercepts a given Vulkan command, it will call down the
975instance or device chain as needed. The loader and all layer libraries that
976participate in a call chain cooperate to ensure the correct sequencing of calls
977from one entity to the next. This group effort for call cahin sequencing is
978hereinafter referred to as disitributed dispatch. In distributed dispatch,
979since each layer is responsible for properly calling the next entity in the
980device or instance chain, a dispatch mechanism is required for all Vulkan
981commands a layer intercepts. For Vulkan commands that are not intercepted by a
982layer, or if the layer chooses to terminate a given Vulkman command by not
983calling down the chain, then no dispatch mechanism is needed for that
984particular Vulkan command. Only for those Vulkan commands, which may be a
985subset of all Vulkan commands, that a layer intercepts is a dispatching
986mechanism by the layer needed. The loader is responsible for dispatching all
987core and instance extension Vulkan commands to the first entity in the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -0700988
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700989Instance level Vulkan commands are those that have the disapatchable objects
990VkInstance, or VkPhysicalDevice as the first parameter and alos includes
991vkCreateInstance.
992Device level Vulkan commands are those that use VkDevice, VkQueue or
993VkCommandBuffer as the first parameter and also include vkCreateDevice. Future
994extensions may introduce new instance or device level dispatchable objects, so
995the above lists may be extended in the future.
Jon Ashburnc2972682016-02-08 15:42:01 -0700996
997#### Discovery of layer entrypoints
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -0700998For the layer libraries that have been discovered by the loader, their
999intercepting entry points that will participate in a device or instance call
1000chain need to be available to the loader or whatever layer is before them in
1001the chain. Layers having the following requirements in this area.
1002- A layer intercepting instance level Vulkan commands (aka an instance level
1003layer) must implement a vkGetInstanceProcAddr type of function.
1004- This vkGetInstanceProcAddr type function must be exported by the layer
1005library. The name of this function is specified in various ways: 1) the layer
1006manifest JSON file in the "functions", "vkGetInstanceProcAddr" node
1007(Linux/Windows); 2) it is named "vkGetInstanceProcAddr"; 3) it is
1008"<layerName>GetInstanceProcAddr (Android).
1009- A layer intercepting device level Vulkan commands (aka a device level layer)
1010must implement a vkGetDeviceProcAddr type of function.
1011- This vkGetDeviceProcAddr type function must be exported by the layer library.
1012The name of this function is specified in various ways: 1) the layer manifest
1013JSON file in the "functions", "vkGetDeviceProcAddr" node (Linux/Windows); 2) it
1014is named "vkGetDeviceProcAddr"; 3) it is "<layerName>GetDeviceProcAddr
1015(Android).
1016- A layer's vkGetInstanceProcAddr function (irregardless of it's name) must
1017return the local entry points for all instance level Vulkan commands it
1018intercepts. At a minimum, this includes vkGetInstanceProcAddr and
1019vkCreateInstance.
1020- A layer's vkGetDeviceProcAddr function (irregardless of it's name) must
1021return the entry points for all device level Vulkan commands it intercepts. At
1022a minimum, this includes vkGetDeviceProcAddr and vkCreateDevice.
1023- There are no requirements on the names of the intercepting functions a layer
1024implements except those listed above for vkGetInstanceProcAddr and
1025vkGetDeviceProcAddr.
1026- Currently a layer's VkGetInstanceProcAddr must be able to handle a VkInstance
1027parameter equal to NULL for
Jon Ashburnc2972682016-02-08 15:42:01 -07001028instance level commands it intercepts including vkCreateDevice.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001029- Currently a layer's VkGetDeviceProcAddr must be able to handle a VkDevice
1030parameter equal to NULL for device level commands it intercepts.
Jon Ashburnc2972682016-02-08 15:42:01 -07001031
1032#### Layer intercept requirements
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001033- Layers intercept a Vulkan command by defining a C/C++ function with signature
1034identical to the Vulkan API for that command.
1035- Other than the two vkGet*ProcAddr, all other functions intercepted by a layer
1036need NOT be exported by the layer.
1037- For any Vulkan command a layer intercepts which has a non-void return value,
1038an appropriate value must be returned by the layer intercept function.
1039- The layer intercept function must call down the chain to the corresponding
1040Vulkan command in the next entity. Undefined results will occur if a layer
1041doesn't propagate calls down the chain. The two exceptions to this requirement
1042are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the
1043chain for Vulkan commands that they do not intercept.
1044- Layer intercept functions may insert extra calls to Vulkan commands in
1045addition to the intercept. For example, a layer intercepting vkQueueSubmit may
1046want to add a call to vkQueueWaitIdle after calling down the chain for
1047vkQueueSubmit. Any additional calls inserted by a layer must be on the same
1048chain. They should call down the chain.
Jon Ashburnc2972682016-02-08 15:42:01 -07001049
1050#### Distributed dispatching requirements
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001051- For each entry point a layer intercepts, it must keep track of the entry
1052point residing in the next entity in the chain it will call down into. In other
1053words, the layer must have a list of pointers to functions of the appropriate
1054type to call into the next entity. This can be implemented in various ways but
1055for clarity will be referred to as a dispatch table.
1056- A layer can use the VkLayerDispatchTable structure as a device dispatch table
1057(see include/vulkan/vk_layer.h).
1058- A layer can use the VkLayerInstanceDispatchTable structure as a instance
1059dispatch table (see include/vulkan/vk_layer.h).
1060- Layers vkGetInstanceProcAddr function uses the next entity's
1061vkGetInstanceProcAddr to call down the chain for unknown (ie non-intercepted)
1062functions.
1063- Layers vkGetDeviceProcAddr function uses the next entity's
1064vkGetDeviceProcAddr to call down the chain for unknown (ie non-intercepted)
1065functions.
Jon Ashburnc2972682016-02-08 15:42:01 -07001066
1067#### Layer dispatch initialization
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001068- A layer intializes it's instance dispatch table within it's vkCreateInstance
1069function.
1070- A layer intializes it's device dispatch table within it's vkCreateDevice
1071function.
1072- The loader passes a linked list of initialization structures to layers via
1073the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures
1074for vkCreateInstance and VkCreateDevice respectively.
1075- The head node in this linked list is of type VkLayerInstanceCreateInfo for
1076instance and VkLayerDeviceCreateInfo for device. See file
1077include/vulkan/vk_layer.h for details.
1078- A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the
1079"sType" field in VkLayerInstanceCreateInfo.
1080- A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the
1081"sType" field in VkLayerDeviceCreateInfo.
1082- The "function" field indicates how the union field "u" should be interpreted
1083within VkLayer*CreateInfo. The loader will set the "function" field to
1084VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or
1085VkLayerDeviceLink.
Jon Ashburnc2972682016-02-08 15:42:01 -07001086- The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001087- The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used
1088by a layer.
1089- The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and
1090vkGetDeviceProcAddr used by a layer.
1091- Given the above structures set up by the loader, layer must initialize their
1092dispatch table as follows:
1093 - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in
1094the VkInstanceCreateInfo/VkDeviceCreateInfo structure.
Jon Ashburncc300a22016-02-11 14:57:30 -07001095 - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field.
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001096 - For CreateInstance get the next entity's vkCreateInstance by calling the
1097"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001098 pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance").
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001099 - For CreateDevice get the next entity's vkCreateDevice by calling the
1100"pfnNextGetInstanceProcAddr":
Jon Ashburnc2972682016-02-08 15:42:01 -07001101 pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice").
Jon Ashburncc300a22016-02-11 14:57:30 -07001102 - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext.
1103 - Call down the chain either CreateDevice or CreateInstance
Courtney Goeltzenleuchtera1473762016-02-14 09:31:24 -07001104 - Initialize your layer dispatch table by calling the next entity's
1105Get*ProcAddr function once for each Vulkan command needed in your dispatch
1106table
Jon Ashburncc300a22016-02-11 14:57:30 -07001107
1108Example code for CreateInstance:
1109Example code for CreateDevice
1110#### Special Considerations
1111Wrapping versus maps.
1112create dispatchable objects
Jon Ashburnc2972682016-02-08 15:42:01 -07001113