Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1 | # Vulkan Loader Specification and Architecture Overview |
| 2 | |
| 3 | |
| 4 | Goals of this document |
| 5 | ---------------------- |
| 6 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 7 | Specify necessary functions and expected behavior of interface between the |
| 8 | loader library and ICDs and layers for Windows, Linux and Android based |
| 9 | systems. Also describe the application visible behaviors of the loader. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 10 | |
| 11 | Audience |
| 12 | -------- |
| 13 | |
| 14 | Application, Vulkan driver and Vulkan layer developers. |
| 15 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 16 | Any developers interested in understanding more about loader and layer behavior |
| 17 | and architecture. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 18 | |
| 19 | |
| 20 | Loader goals |
| 21 | ------------ |
| 22 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 23 | - Support multiple ICDs (Installable Client Drivers) to co-exist on a system |
| 24 | without interfering with each other. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 25 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 26 | - Support optional modules (layers) that can be enabled by an application, |
| 27 | developer or the system and have no impact when not enabled. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 28 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 29 | - Negligible performance cost for an application calling through the loader |
| 30 | to an ICD entry point. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 31 | |
| 32 | Architectural overview of layers and loader |
| 33 | ------------------------------------------- |
| 34 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 35 | Vulkan is a layered architecture. Layers can hook (intercept) Vulkan commands to |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 36 | achieve various functionality that a Vulkan driver (aka ICD) or loader doesn’t |
| 37 | support. Functionality such as Vulkan API tracing and debugging, API usage |
| 38 | validation, and other tools such as framebuffer overlays are all natural |
| 39 | candidates for Vulkan layers. Layers are implemented as libraries that are |
| 40 | inserted between the application and the driver. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 41 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 42 | Not only is Vulkan a layered architecture but it also supports multiple GPUs |
| 43 | and their drivers. Vulkan commands called by an application may wind up calling |
| 44 | into a diverse set of modules: loader, layers, and ICDs. The loader is critical |
| 45 | to managing the proper dispatching of Vulkan commands to the appropriate set of |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 46 | layers and ICDs. The Vulkan object model allows the loader to insert layers |
| 47 | into a call chain so the layers can process Vulkan commands prior to the |
| 48 | ICD being called. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 49 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 50 | Vulkan uses an object model to control the scope of a particular action / |
| 51 | operation. The object to be acted on is always the first parameter of a Vulkan |
| 52 | call and is a dispatchable object (see Vulkan specification section 2.2 Object |
| 53 | Model). Under the covers, the dispatchable object handle is a pointer to a |
| 54 | structure that contains a pointer to a dispatch table maintained by the loader. |
| 55 | This dispatch table contains pointers to the Vulkan functions appropriate to |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 56 | that object. There are two types of dispatch tables the loader maintains, |
| 57 | Instance and Device. I.e. a VkInstance object’s dispatch table will point to Vulkan |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 58 | functions such as vkEnumeratePhysicalDevices, vkDestroyInstance, |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 59 | vkCreateInstance, etc. Instance functions take a VkInstance or VkPhysicalDevice as |
| 60 | their first argument. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 61 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 62 | Device objects have a separate dispatch table containing the appropriate |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 63 | function pointers. The device dispatch table is used for all functions that |
| 64 | take a VkDevice, VkQueue or VkCommandBuffer as their first argument. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 65 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 66 | These instance and device dispatch tables are constructed when the application |
| 67 | calls vkCreateInstance and vkCreateDevice. At that time the application and/or |
| 68 | system can specify optional layers to be included. The loader will initialize |
| 69 | the specified layers to create a call chain for each Vulkan function and each |
| 70 | entry of the dispatch table will point to the first element of that chain. |
| 71 | Thus, the loader builds an instance call chain for each VkInstance that is |
| 72 | created and a device call chain for each VkDevice that is created. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 73 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 74 | For example, the diagram below represents what happens in the call chain for |
| 75 | vkCreateInstance. After initializing the chain, the loader will call into the |
| 76 | first layer’s vkCreateInstance which will call the next finally terminating in |
| 77 | the loader again where this function calls every ICD’s vkCreateInstance and |
| 78 | saves the results. This allows every enabled layer for this chain to set up |
| 79 | what it needs based on the VkInstanceCreateInfo structure from the application. |
Courtney Goeltzenleuchter | ab3a466 | 2016-02-14 10:48:22 -0700 | [diff] [blame] | 80 |  |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 81 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 82 | This also highlights some of the complexity the loader must manage when using |
| 83 | instance chains. As shown here, the loader must aggregate information from |
| 84 | multiple devices when they are present. This means that the loader has to know |
| 85 | about instance level extensions to aggregate them correctly. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 86 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 87 | Device chains are created at vkCreateDevice and are generally simpler because |
| 88 | they deal with only a single device and the ICD can always be the terminator of |
| 89 | the chain. The below diagram also illustrates how layers (either device or |
| 90 | instance) can skip intercepting any given Vulkan entry point. |
Courtney Goeltzenleuchter | ab3a466 | 2016-02-14 10:48:22 -0700 | [diff] [blame] | 91 |  |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 92 | |
| 93 | Application interface to loader |
| 94 | ------------------------------- |
| 95 | |
| 96 | In 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 Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 110 | The loader library on Windows, Linux and Android will export all core Vulkan |
| 111 | and all appropriate Window System Interface (WSI) extensions. This is done to |
| 112 | make it simpler to get started with Vulkan development. When an application |
| 113 | links directly to the loader library in this way, the Vulkan calls are simple |
| 114 | trampoline functions that jump to the appropriate dispatch table entry for the |
| 115 | object they are given. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 116 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 117 | Applications are not required to link directly to the loader library, instead |
| 118 | they can use the appropriate platform specific dynamic symbol lookup on the |
| 119 | loader library to initialize the application’s own dispatch table. This allows |
| 120 | an application to fail gracefully if the loader cannot be found and provide the |
| 121 | fastest mechanism for the application to call Vulkan functions. An application |
| 122 | will only need to query (via system calls such as dlsym()) the address of |
| 123 | vkGetInstanceProcAddr from the loader library. Using vkGetInstanceProcAddr the |
| 124 | application can then discover the address of all instance and global functions |
| 125 | and extensions, such as vkCreateInstance, |
| 126 | vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties |
| 127 | in a platform independent way. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 128 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 129 | The Vulkan loader library will be distributed in various ways including Vulkan |
| 130 | SDKs, OS package distributions and IHV driver packages. These details are |
| 131 | beyond the scope of this document. However, the name and versioning of the |
| 132 | Vulkan loader library is specified so an app can link to the correct Vulkan ABI |
| 133 | library version. Vulkan versioning is such that ABI backwards compatibility is |
| 134 | guaranteed for all versions with the same major number (eg 1.0 and 1.1). On |
| 135 | Windows, the loader library encodes the ABI version in its name such that |
| 136 | multiple ABI incompatible versions of the loader can peacefully coexist on a |
| 137 | given system. The vulkan loader library key name is “vulkan-<ABI |
| 138 | version>”. For example, for Vulkan version 1.X on Windows the library |
| 139 | filename is vulkan-1.dll. And this library file can typically be found in the |
| 140 | windows/system32 directory. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 141 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 142 | For Linux, shared libraries are versioned based on a suffix. Thus, the ABI |
| 143 | number is not encoded in the base of the library filename as on Windows. On |
| 144 | Linux an application wanting to link to the latest Vulkan ABI version would |
| 145 | just link to the name vulkan (libvulkan.so). A specific Vulkan ABI version can |
| 146 | also be linked to by applications (eg libvulkan.so.1). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 147 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 148 | Applications desiring Vulkan functionality beyond what the core API offers may |
| 149 | use various layers or extensions. A layer cannot add new or modify existing |
| 150 | Vulkan commands, but may offer extensions that do. A common use of layers is |
| 151 | for API validation. A developer can use validation layers during application |
| 152 | development, but during production the layers can be disabled by the |
| 153 | application. Thus, eliminating the overhead of validating the applications |
| 154 | usage of the API. Layers discovered by the loader can be reported to the |
| 155 | application via vkEnumerateInstanceLayerProperties and |
| 156 | vkEnumerateDeviceLayerProperties, for instance and device layers respectively. |
| 157 | Instance layers are enabled at vkCreateInstance; device layers are enabled at |
| 158 | vkCreateDevice. For example, the ppEnabledLayerNames array in the |
| 159 | VkDeviceCreateInfo structure is used by the application to list the device |
| 160 | layer names to be enabled at vkCreateDevice. At vkCreateInstance and |
| 161 | vkCreateDevice, the loader will construct call chains that include the |
| 162 | application specified (enabled) layers. Order is important in the |
| 163 | ppEnabledLayerNames array; array element 0 is the topmost (closest to the |
| 164 | application) layer inserted in the chain and the last array element is closest |
| 165 | to the driver. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 166 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 167 | Developers may want to enable layers that are not enabled by the given |
| 168 | application they are using. On Linux and Windows, the environment variables |
| 169 | “VK\_INSTANCE\_LAYERS” and “VK\_DEVICE\_LAYERS” can be used to enable |
| 170 | additional layers which are not specified (enabled) by the application at |
| 171 | vkCreateInstance/vkCreateDevice. VK\_INSTANCE\_LAYERS is a colon |
| 172 | (Linux)/semi-colon (Windows) separated list of layer names to enable. Order is |
| 173 | relevant with the first layer in the list being the topmost layer (closest to |
| 174 | the application) and the last layer in the list being the bottommost layer |
| 175 | (closest to the driver). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 176 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 177 | Application specified layers and user specified layers (via environment |
| 178 | variables) are aggregated and duplicates removed by the loader when enabling |
| 179 | layers. Layers specified via environment variable are topmost (closest to the |
| 180 | application) while layers specified by the application are bottommost. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 181 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 182 | An example of using these environment variables to activate the validation |
| 183 | layer VK\_LAYER\_LUNARG\_param\_checker on Windows or Linux is as follows: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 184 | |
| 185 | ``` |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 186 | > $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_param_checker |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 187 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 188 | > $ export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_param_checker |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 189 | ``` |
| 190 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 191 | **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 |
| 193 | instance and device chains to function properly. This is required for “global” |
| 194 | layers regardless of which method is used to enable the layer (application or |
| 195 | environment variable). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 196 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 197 | Some platforms, including Linux and Windows, support layers which are enabled |
| 198 | automatically by the loader rather than explicitly by the application (or via |
| 199 | environment variable). Explicit layers are those layers enabled by the |
| 200 | application (or environment variable) by providing the layer name. Implicit |
| 201 | layers are those layers enabled by the loader automatically. Any implicit |
| 202 | layers the loader discovers on the system in the appropriate location will be |
| 203 | enabled (subject to environment variable overrides described later). Discovery |
| 204 | of properly installed implicit and explicit layers is described later. |
| 205 | Explicitly enabling a layer that is implicitly enabled has no additional |
| 206 | effect: the layer will still be enabled implicitly by the loader. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 207 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 208 | Extensions are optional functionality provided by a layer, the loader or an |
| 209 | ICD. Extensions can modify the behavior of the Vulkan API and need to be |
| 210 | specified and registered with Khronos. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 211 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 212 | Instance extensions can be discovered via |
| 213 | vkEnumerateInstanceExtensionProperties. Device extensions can be discovered via |
| 214 | vkEnumerateDeviceExtensionProperties. The loader discovers and aggregates all |
| 215 | extensions from layers (both explicit and implicit), ICDs and the loader before |
| 216 | reporting them to the application in vkEnumerate\*ExtensionProperties. The |
| 217 | pLayerName parameter in these functions are used to select either a single |
| 218 | layer or the Vulkan platform implementation. If pLayerName is NULL, extensions |
| 219 | from Vulkan implementation components (including loader, implicit layers, and |
| 220 | ICDs) are enumerated. If pLayerName is equal to a discovered layer module name |
| 221 | then any extensions from that layer (which may be implicit or explicit) are |
| 222 | enumerated. Duplicate extensions (eg an implicit layer and ICD might report |
| 223 | support for the same extension) are eliminated by the loader. Extensions must |
| 224 | be enabled (in vkCreateInstance or vkCreateDevice) before they can be used. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 225 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 226 | Extension command entry points should be queried via vkGetInstanceProcAddr or |
| 227 | vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device |
| 228 | extension or core device entry points. Device entry points include any command |
| 229 | that uses a VkDevice as the first parameter or a dispatchable object that is a |
| 230 | child of a VkDevice (currently this includes VkQueue and VkCommandBuffer). |
| 231 | vkGetInstanceProcAddr can be used to query either device or instance extension |
| 232 | entry points in addition to all core entry points. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 233 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 234 | VkGetDeviceProcAddr is particularly interesting because it will provide the |
| 235 | most efficient way to call into the ICD. For example, the diagram below shows |
| 236 | what could happen if the application were to use vkGetDeviceProcAddr for the |
| 237 | function “vkGetDeviceQueue” and “vkDestroyDevice” but not “vkAllocateMemory”. |
| 238 | The resulting function pointer (fpGetDeviceQueue) would be the ICD’s entry |
| 239 | point if the loader and any enabled layers do not need to see that call. Even |
| 240 | if an enabled layer intercepts the call (eg vkDestroyDevice) the loader |
| 241 | trampoline code is skipped for function pointers obtained via |
| 242 | vkGetDeviceProcAddr. This also means that function pointers obtained via |
| 243 | vkGetDeviceProcAddr will only work with the specific VkDevice it was created |
| 244 | for, using it with another device has undefined results. For extensions, |
| 245 | Get\*ProcAddr will often be the only way to access extension API features. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 246 | |
Courtney Goeltzenleuchter | ab3a466 | 2016-02-14 10:48:22 -0700 | [diff] [blame] | 247 |  |
| 248 | |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 249 | |
| 250 | Vulkan Installable Client Driver interface with the loader |
| 251 | ---------------------------------------------------------- |
| 252 | |
| 253 | ### ICD discovery |
| 254 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 255 | Vulkan allows multiple drivers each with one or more devices (represented by a |
| 256 | Vulkan VkPhysicalDevice object) to be used collectively. The loader is |
| 257 | responsible for discovering available Vulkan ICDs on the system. Given a list |
| 258 | of available ICDs, the loader can enumerate all the physical devices available |
| 259 | for an application and return this information to the application. The process |
| 260 | in which the loader discovers the available Installable Client Drivers (ICDs) |
| 261 | on a system is platform dependent. Windows, Linux and Android ICD discovery |
| 262 | details are listed below. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 263 | |
| 264 | #### Windows |
| 265 | |
| 266 | ##### Properly-Installed ICDs |
| 267 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 268 | In order to find properly-installed ICDs, the Vulkan loader will scan the |
| 269 | values in the following Windows registry key: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 270 | |
| 271 | HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers |
| 272 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 273 | For each value in this key which has DWORD data set to 0, the loader opens the |
| 274 | JSON format text information file (a.k.a. "manifest file") specified by the |
| 275 | name of the value. Each name must be a full pathname to the text manifest file. |
| 276 | The Vulkan loader will open each manifest file to obtain the name or pathname |
| 277 | of an ICD shared library (".dll") file. For example: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 278 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 279 | ``` |
| 280 | { |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 281 | "file_format_version": "1.0.0", |
| 282 | "ICD": { |
| 283 | "library_path": "path to ICD library", |
Tony Barbour | cd48951 | 2016-02-10 15:59:32 -0700 | [diff] [blame] | 284 | "api_version": "1.0.3" |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 287 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 288 | |
| 289 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 290 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 291 | pathname to an ICD shared library file, which the loader will attempt to load |
| 292 | using LoadLibrary(). If the ICD is specified via a filename, the shared library |
| 293 | lives in the system's DLL search path (e.g. in the "C:\\\\Windows\\\\System32" |
| 294 | folder). If the ICD is specified via a relative pathname, it is relative to the |
| 295 | path of the manifest file. Relative pathnames are those that do not start with |
| 296 | a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\' |
| 297 | character), but do contain at least one directory separator. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 298 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 299 | The "file\_format\_version" specifies a major.minor.patch version number in |
| 300 | case the format of the text information file changes in the future. If the same |
| 301 | ICD shared library supports multiple, incompatible versions of text manifest |
| 302 | file format versions, it must have multiple text info files (all of which may |
| 303 | point to the same shared library). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 304 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 305 | The “api\_version” specifies the major.minor.patch version number of the Vulkan |
| 306 | API that the shared library (referenced by "library\_path") was built with. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 307 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 308 | There are no rules about the name of the text information files (except the |
| 309 | .json suffix). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 310 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 311 | There are no rules about the name of the ICD shared library files. For example, |
| 312 | if the registry contains the following values, |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 313 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 314 | ``` |
| 315 | [HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\] |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 316 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 317 | "C:\vendor a\vk\_vendora.json"=dword:00000000 |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 318 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 319 | "C:\windows\system32\vendorb\_vk.json"=dword:00000000 |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 320 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 321 | "C:\windows\system32\vendorc\_icd.json"=dword:00000000 |
| 322 | ``` |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 323 | then the loader will open the following text information files, with the |
| 324 | specified contents: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 325 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 326 | | Text File Name | Text File Contents | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 327 | |----------------|--------------------| |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 328 | |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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 331 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 332 | Then the loader will open the three files mentioned in the "Text File Contents" |
| 333 | column, and then try to load and use the three shared libraries indicated by |
| 334 | the ICD.library\_path value. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 335 | |
| 336 | ##### Using Pre-Production ICDs |
| 337 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 338 | IHV developers (and sometimes other developers) need to use special, |
| 339 | pre-production ICDs. In some cases, a pre-production ICD may be in an |
| 340 | installable package. In other cases, a pre-production ICD may simply be a |
| 341 | shared library in the developer's build tree. In this latter case, we want to |
| 342 | allow developers to point to such an ICD without modifying the |
| 343 | properly-installed ICD(s) on their system. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 344 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 345 | This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable, |
| 346 | which will override the mechanism used for finding properly-installed ICDs. In |
| 347 | other 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 |
| 349 | text information files (aka manifest files), containing the following: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 350 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 351 | - A full pathname (e.g. "C:\\my\_build\\my\_icd.json") |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 352 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 353 | Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info |
| 354 | file for a developer-built ICD. A semi-colon is only used if more than one ICD |
| 355 | is listed. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 356 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 357 | For example, if a developer wants to refer to one ICD that they built, they |
| 358 | could set the "VK\_ICD\_FILENAMES" environment variable to: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 359 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 360 | C:\\my\_build\\my\_icd.json |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 361 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 362 | If a developer wants to refer to two ICDs, one of which is a properly-installed |
| 363 | ICD, they can use the full pathname of the text file: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 364 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 365 | C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 366 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 367 | Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and |
| 368 | "C:\\my\_build\\my\_icd.json". |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 369 | |
| 370 | #### Linux |
| 371 | |
| 372 | ##### Properly-Installed ICDs |
| 373 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 374 | In order to find properly-installed ICDs, the Vulkan loader will scan the files |
| 375 | in the following Linux directories: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 376 | |
| 377 | /usr/share/vulkan/icd.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 378 | /etc/vulkan/icd.d |
| 379 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 380 | These directories will contain text information files (a.k.a. "manifest |
| 381 | files"), that use a JSON format. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 382 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 383 | The Vulkan loader will open each manifest file found to obtain the name or |
| 384 | pathname of an ICD shared library (".so") file. For example: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 385 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 386 | ``` |
| 387 | { |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 388 | "file_format_version": "1.0.0", |
| 389 | "ICD": { |
| 390 | "library_path": "path to ICD library", |
Tony Barbour | cd48951 | 2016-02-10 15:59:32 -0700 | [diff] [blame] | 391 | "api_version": "1.0.3" |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 394 | ``` |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 395 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 396 | pathname to an ICD shared library file. If the ICD is specified via a filename, |
| 397 | the loader will attempt to open that file as a shared object using dlopen(), |
| 398 | and the file must be in a directory that dlopen is configured to look in (Note: |
| 399 | various distributions are configured differently). A distribution is free to |
| 400 | create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not |
| 401 | required to do so. If the ICD is specified via a relative pathname, it is |
| 402 | relative to the path of the info file. Relative pathnames are those that do not |
| 403 | start with, but do contain at least one directory separator (i.e. the '/' |
| 404 | character). For example, "lib/vendora.so" and "./vendora.so" are examples of |
| 405 | relative pathnames. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 406 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 407 | The "file\_format\_version" provides a major.minor.patch version number in case |
| 408 | the format of the manifest file changes in the future. If the same ICD shared |
| 409 | library supports multiple, incompatible versions of manifest file format |
| 410 | versions, it must have multiple manifest files (all of which may point to the |
| 411 | same shared library). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 412 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 413 | The “api\_version” specifies the major.minor.patch version number of the Vulkan |
| 414 | API that the shared library (referenced by "library\_path") was built with. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 415 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 416 | The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from |
| 417 | Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for |
| 418 | ICDs that are installed from non-Linux-distribution-provided packages. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 419 | |
| 420 | There are no rules about the name of the text files (except the .json suffix). |
| 421 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 422 | There are no rules about the name of the ICD shared library files. For example, |
| 423 | if the "/usr/share/vulkan/icd.d" directory contain the following files, with |
| 424 | the specified contents: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 425 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 426 | | Text File Name | Text File Contents | |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame^] | 427 | |--------------------------------------| |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 428 | |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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 431 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 432 | then the loader will open the three files mentioned in the "Text File Contents" |
| 433 | column, and then try to load and use the three shared libraries indicated by |
| 434 | the ICD.library\_path value. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 435 | |
| 436 | ##### Using Pre-Production ICDs |
| 437 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 438 | IHV developers (and sometimes other developers) need to use special, |
| 439 | pre-production ICDs. In some cases, a pre-production ICD may be in an |
| 440 | installable package. In other cases, a pre-production ICD may simply be a |
| 441 | shared library in the developer's build tree. In this latter case, we want to |
| 442 | allow developers to point to such an ICD without modifying the |
| 443 | properly-installed ICD(s) on their system. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 444 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 445 | This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable, |
| 446 | which will override the mechanism used for finding properly-installed ICDs. In |
| 447 | other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 448 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 449 | The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD |
| 450 | manifest files, containing the following: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 451 | |
| 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 Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 456 | Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info |
| 457 | file for a developer-built ICD. A colon is only used if more than one ICD is |
| 458 | listed. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 459 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 460 | For example, if a developer wants to refer to one ICD that they built, they |
| 461 | could set the "VK\_ICD\_FILENAMES" environment variable to: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 462 | |
| 463 | /my\_build/my\_icd.json |
| 464 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 465 | If a developer wants to refer to two ICDs, one of which is a properly-installed |
| 466 | ICD, they can use the name of the text file in the system directory: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 467 | |
| 468 | vendorc\_vulkan.json:/my\_build/my\_icd.json |
| 469 | |
| 470 | Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json". |
| 471 | |
| 472 | NOTE: this environment variable will be ignored for suid programs. |
| 473 | |
| 474 | #### Android |
| 475 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 476 | The Android loader lives in the system library folder. The location cannot be |
| 477 | changed. The loader will load the driver/ICD via hw_get_module with the ID |
| 478 | of "vulkan". Due to security policies in Android none of this can be modified |
| 479 | under normal use. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 480 | |
| 481 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 482 | ICD interface requirements |
| 483 | ---------------------------------------- |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 484 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 485 | Generally, for all Vulkan commands issued by an application, the loader can be |
| 486 | viewed as a pass through. That is, the loader generally doesn’t modified the |
| 487 | commands or their parameters but simply calls the ICDs entry point for that |
| 488 | command. Thus, the loader to ICD interface requirements will be specified by |
| 489 | covering two areas: 1) Obtaining ICD Vulkan entry points; 2) Specifying |
| 490 | requirements for a given Vulkan command(s) over and above the Vulkan |
| 491 | specification requirements. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 492 | |
| 493 | #### Windows and Linux |
| 494 | |
| 495 | ##### Obtaining ICD entry points |
| 496 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 497 | Currently, two methods of the loader finding ICD entry points are supported on |
| 498 | Linux and Windows: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 499 | |
| 500 | 1) Recommended |
| 501 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 502 | - 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 515 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 516 | - 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 523 | |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame^] | 524 | - Beware of interposing by dynamic OS library loaders if the offical Vulkan names |
| 525 | are used. On Linux, if offical names are used, the ICD library must be linked with -Bsymbolic. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 526 | 2) Deprecated |
| 527 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 528 | - vkGetInstanceProcAddr exported in the ICD library and returns valid function |
| 529 | pointers for all the Vulkan API entrypoints. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 530 | |
| 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 Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 537 | Normally, ICDs handle object creation and destruction for various Vulkan |
| 538 | objects. The WSI surface extensions for Linux and Windows |
| 539 | (VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface, |
| 540 | VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are |
| 541 | handled differently. For these extensions, the VkSurfaceKHR object creation and |
| 542 | destruction is handled by the loader as follows: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 543 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 544 | 1. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR() |
| 545 | functions including creating/destroying the VkSurfaceKHR object. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 546 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 547 | 2. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as |
| 548 | defined in include/vulkan/vk\_icd.h. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 549 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 550 | 3. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate |
| 551 | VkIcdSurface\* structure. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 552 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 553 | 4. 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 557 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 558 | As previously covered, the loader requires dispatch tables to be accessible |
| 559 | within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice, |
| 560 | VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all |
| 561 | dispatchable objects created by ICDs are as follows: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 562 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 563 | - All dispatchable objects created by an ICD can be cast to void \*\* |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 564 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 565 | - 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 567 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 568 | 1. The ICD must return a pointer for the opaque dispatchable object handle. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 569 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 570 | 2. 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 574 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 575 | 3. 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 577 | |
| 578 | ``` |
| 579 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 580 | #include "vk_icd.h" |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 581 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 582 | union _VK_LOADER_DATA { |
| 583 | uintptr loadermagic; |
| 584 | void *loaderData; |
| 585 | } VK_LOADER_DATA; |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 586 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 587 | vkObj alloc_icd_obj() |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 588 | { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 589 | vkObj *newObj = alloc_obj(); |
| 590 | ... |
| 591 | // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 592 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 593 | set_loader_magic_value(newObj); |
| 594 | ... |
| 595 | return newObj; |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 596 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 597 | ``` |
| 598 | |
| 599 | Additional Notes: |
| 600 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 601 | - The loader will filter out extensions requested in vkCreateInstance and |
| 602 | vkCreateDevice before calling into the ICD; Filtering will be of extensions |
| 603 | advertised by entities (eg layers) different from the ICD in question. |
| 604 | - The loader will not call ICD for vkEnumerate\*LayerProperties() as layer |
| 605 | properties 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 |
| 607 | appropriate layer JSON manifest file refer to the ICD library file. |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 608 | - The loader will not call the ICD for |
| 609 | vkEnumerate\*ExtensionProperties(pLayerName != NULL). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 610 | - The ICD may or may not implement a dispatch table. |
| 611 | |
| 612 | #### Android |
| 613 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 614 | The Android loader uses the same protocol for initializing the dispatch |
| 615 | table as described above. The only difference is that the Android |
| 616 | loader queries layer and extension information directly from the |
| 617 | respective libraries and does not use the json manifest files used |
| 618 | by the Windows and Linux loaders. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 619 | |
| 620 | Vulkan layer interface with the loader |
| 621 | -------------------------------------- |
| 622 | |
| 623 | ### Layer discovery |
| 624 | |
| 625 | #### Windows |
| 626 | |
| 627 | ##### Properly-Installed Layers |
| 628 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 629 | In order to find properly-installed layers, the Vulkan loader will use a |
| 630 | similar mechanism as used for ICDs. Text information files (aka manifest |
| 631 | files), that use a JSON format, are read in order to identify the names and |
| 632 | attributes of layers and their extensions. The use of manifest files allows the |
| 633 | loader to avoid loading any shared library files when the application does not |
| 634 | query nor request any extensions. Layers and extensions have additional |
| 635 | complexity, and so their manifest files contain more information than ICD info |
| 636 | files. For example, a layer shared library file may contain multiple |
| 637 | layers/extensions (perhaps even an ICD). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 638 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 639 | In order to find properly-installed layers, the Vulkan loader will scan the |
| 640 | values in the following Windows registry keys: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 641 | |
| 642 | HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers |
| 643 | |
| 644 | HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers |
| 645 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 646 | Explicit layers are those which are enabled by an application (e.g. with the |
| 647 | vkCreateInstance function), or by an environment variable (as mentioned |
| 648 | previously). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 649 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 650 | Implicit layers are those which are enabled by their existence. For example, |
| 651 | certain application environments (e.g. Steam or an automotive infotainment |
| 652 | system) may have layers which they always want enabled for all applications |
| 653 | that they start. Other implicit layers may be for all applications started on a |
| 654 | given system (e.g. layers that overlay frames-per-second). Implicit layers are |
| 655 | enabled automatically, whereas explicit layers must be enabled explicitly. What |
| 656 | distinguishes a layer as implicit or explicit is by which registry key its |
| 657 | layer information file is referenced by. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 658 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 659 | For each value in these keys which has DWORD data set to 0, the loader opens |
| 660 | the JSON manifest file specified by the name of the value. Each name must be a |
| 661 | full pathname to the manifest file. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 662 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 663 | The Vulkan loader will open each info file to obtain information about the |
| 664 | layer, including the name or pathname of a shared library (".dll") file. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 665 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 666 | This manifest file is in the JSON format and contains the following |
| 667 | information: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 668 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 669 | - (required) "file\_format\_version" - same as for ICDs, except that the format |
| 670 | version can vary independently for ICDs and layers. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 671 | |
| 672 | - (required) "name" - layer name |
| 673 | |
| 674 | - (required) "type" - which layer chains should the layer be activated on. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 675 | Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on |
| 676 | both device and instance chains. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 677 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 678 | - (required) "library\_path" - filename / full path / relative path to the |
| 679 | library file |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 680 | |
| 681 | - (required) "api\_version" - same as for ICDs. |
| 682 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 683 | - (required) "implementation\_version" - layer version, a single number |
| 684 | increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 685 | |
| 686 | - (required) "description" - informative description of the layer. |
| 687 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 688 | - (optional) "device\_extensions" or "instance\_extensions" - array of |
| 689 | extension information as follows |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 690 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 691 | - (required) extension "name" - Vulkan registered name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 692 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 693 | - (required) extension "spec\_version" - extension specification version, a |
| 694 | single number, increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 695 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 696 | - (required for device\_extensions with entry points) extension |
| 697 | "entrypoints" - array of device extension entrypoints; not used for instance |
| 698 | extensions |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 699 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 700 | - (sometimes required) "functions" - mapping list of function entry points. If |
| 701 | multiple layers exist within the same shared library (or if a layer is in the |
| 702 | same shared library as an ICD), this must be specified to allow each layer to |
| 703 | have its own vkGet\*ProcAddr entrypoints that can be found by the loader. At |
| 704 | this time, only the following two functions are required: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 705 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 706 | - "vkGetInstanceProcAddr" name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 707 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 708 | - "vkGetDeviceProcAddr" name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 709 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 710 | - (optional for implicit layers) "enable\_environment" requirement(s) - |
| 711 | environment variable and value required to enable an implicit layer. This |
| 712 | environment 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 |
| 714 | layer is not loaded. This is for application environments (e.g. Steam) which |
| 715 | want to enable a layer(s) only for applications that they launch, and allows |
| 716 | for applications run outside of an application environment to not get that |
| 717 | implicit layer(s). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 718 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 719 | - (required for implicit layers) "disable\_environment" requirement(s) - |
| 720 | environment variable and value required to disable an implicit layer. Note: in |
| 721 | rare cases of an application not working with an implicit layer, the |
| 722 | application can set this environment variable (before calling Vulkan functions) |
| 723 | in order to "blacklist" the layer. This environment variable (which should vary |
| 724 | with 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 727 | |
| 728 | For example: |
| 729 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 730 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 731 | { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 732 | "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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 764 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 765 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 766 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 767 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 768 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 769 | pathname to a layer shared library (".dll") file, which the loader will attempt |
| 770 | to load using LoadLibrary(). If the layer is specified via a relative pathname, |
| 771 | it is relative to the path of the info file (e.g. for cases when an application |
| 772 | provides a layer that is in the same folder hierarchy as the rest of the |
| 773 | application files). If the layer is specified via a filename, the shared |
| 774 | library lives in the system's DLL search path (e.g. in the |
| 775 | "C:\\Windows\\System32" folder). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 776 | |
| 777 | There are no rules about the name of the text files (except the .json suffix). |
| 778 | |
| 779 | There are no rules about the name of the layer shared library files. |
| 780 | |
| 781 | ##### Using Pre-Production Layers |
| 782 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 783 | As with ICDs, developers may need to use special, pre-production layers, |
| 784 | without modifying the properly-installed layers. This need is met with the use |
| 785 | of the "VK\_LAYER\_PATH" environment variable, which will override the |
| 786 | mechanism using for finding properly-installed layers. Because many layers may |
| 787 | exist on a system, this environment variable is a semi-colon-separated list of |
| 788 | folders that contain layer info files. Only the folder listed in |
| 789 | "VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated |
| 790 | entry is: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 791 | |
| 792 | - The full pathname of a folder containing layer info files |
| 793 | |
| 794 | #### Linux |
| 795 | |
| 796 | ##### Properly-Installed Layers |
| 797 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 798 | In order to find properly-installed layers, the Vulkan loader will use a |
| 799 | similar mechanism as used for ICDs. Text information files, that use a JSON |
| 800 | format, are read in order to identify the names and attributes of layers and |
| 801 | their extensions. The use of text info files allows the loader to avoid loading |
| 802 | any shared library files when the application does not query nor request any |
| 803 | extensions. Layers and extensions have additional complexity, and so their info |
| 804 | files contain more information than ICD info files. For example, a layer shared |
| 805 | library file may contain multiple layers/extensions (perhaps even an ICD). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 806 | |
| 807 | The Vulkan loader will scan the files in the following Linux directories: |
| 808 | |
| 809 | /usr/share/vulkan/explicit\_layer.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 810 | /usr/share/vulkan/implicit\_layer.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 811 | /etc/vulkan/explicit\_layer.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 812 | /etc/vulkan/implicit\_layer.d |
| 813 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 814 | Explicit layers are those which are enabled by an application (e.g. with the |
| 815 | vkCreateInstance function), or by an environment variable (as mentioned |
| 816 | previously). Implicit layers are those which are enabled by their existence. |
| 817 | For example, certain application environments (e.g. Steam or an automotive |
| 818 | infotainment system) may have layers which they always want enabled for all |
| 819 | applications that they start. Other implicit layers may be for all applications |
| 820 | started on a given system (e.g. layers that overlay frames-per-second). |
| 821 | Implicit layers are enabled automatically, whereas explicit layers must be |
| 822 | enabled explicitly. What distinguishes a layer as implicit or explicit is by |
| 823 | which directory its layer information file exists in. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 824 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 825 | The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are |
| 826 | installed from Linux-distribution-provided packages. The |
| 827 | "/etc/vulkan/\*\_layer.d" directories are for layers that are installed from |
| 828 | non-Linux-distribution-provided packages. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 829 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 830 | The information file is in the JSON format and contains the following |
| 831 | information: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 832 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 833 | - (required) "file\_format\_version" – same as for ICDs, except that the format |
| 834 | version can vary independently for ICDs and layers. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 835 | |
| 836 | - (required) "name" - layer name |
| 837 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 838 | - (required) "type" - which layer chains should the layer be activated on. |
| 839 | Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on |
| 840 | both device and instance chains. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 841 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 842 | - (required) "library\_path" - filename / full path / relative path to the text |
| 843 | file |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 844 | |
| 845 | - (required) "api\_version" – same as for ICDs. |
| 846 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 847 | - (required) "implementation\_version" – layer version, a single number |
| 848 | increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 849 | |
| 850 | - (required) "description" – informative decription of the layer. |
| 851 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 852 | - (optional) "device\_extensions" or "instance\_extensions" - array of |
| 853 | extension information as follows |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 854 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 855 | - (required) extension "name" - Vulkan registered name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 856 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 857 | - (required) extension "spec\_version" - extension specification version, a |
| 858 | single number, increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 859 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 860 | - (required for device extensions with entry points) extension |
| 861 | "entrypoints" - array of device extension entrypoints; not used for instance |
| 862 | extensions |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 863 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 864 | - (sometimes required) "functions" - mapping list of function entry points. If |
| 865 | multiple layers exist within the same shared library (or if a layer is in the |
| 866 | same shared library as an ICD), this must be specified to allow each layer to |
| 867 | have its own vkGet\*ProcAddr entrypoints that can be found by the loader. At |
| 868 | this time, only the following two functions are required: |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 869 | - "vkGetInstanceProcAddr" name |
| 870 | - "vkGetDeviceProcAddr" name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 871 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 872 | - (optional for implicit layers) "enable\_environment" requirement(s) - |
| 873 | environment variable and value required to enable an implicit layer. This |
| 874 | environment 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 |
| 876 | layer is not loaded. This is for application environments (e.g. Steam) which |
| 877 | want to enable a layer(s) only for applications that they launch, and allows |
| 878 | for applications run outside of an application environment to not get that |
| 879 | implicit layer(s). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 880 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 881 | - (required for implicit layers) "disable\_environment" requirement(s) - |
| 882 | environment variable and value required to disable an implicit layer. Note: in |
| 883 | rare cases of an application not working with an implicit layer, the |
| 884 | application can set this environment variable (before calling Vulkan functions) |
| 885 | in order to "blacklist" the layer. This environment variable (which should vary |
| 886 | with 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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 889 | |
| 890 | For example: |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 891 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 892 | { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 893 | "file_format_version" : "1.0.0", |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 894 | "layer": { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 895 | "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 Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 925 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 926 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 927 | ``` |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 928 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 929 | pathname to a layer shared library (".so") file, which the loader will attempt |
| 930 | to load using dlopen(). If the layer is specified via a filename, the loader |
| 931 | will attempt to open that file as a shared object using dlopen(), and the file |
| 932 | must be in a directory that dlopen is configured to look in (Note: various |
| 933 | distributions are configured differently). A distribution is free to create |
| 934 | Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not |
| 935 | required to do so. If the layer is specified via a relative pathname, it is |
| 936 | relative to the path of the info file (e.g. for cases when an application |
| 937 | provides a layer that is in the same directory hierarchy as the rest of the |
| 938 | application files). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 939 | |
| 940 | There are no rules about the name of the text files (except the .json suffix). |
| 941 | |
| 942 | There are no rules about the name of the layer shared library files. |
| 943 | |
| 944 | ##### Using Pre-Production Layers |
| 945 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 946 | As with ICDs, developers may need to use special, pre-production layers, |
| 947 | without modifying the properly-installed layers. This need is met with the use |
| 948 | of the "VK\_LAYER\_PATH" environment variable, which will override the |
| 949 | mechanism using for finding properly-installed layers. Because many layers may |
| 950 | exist on a system, this environment variable is a colon-separated list of |
| 951 | directories that contain layer info files. Only the directories listed in |
| 952 | "VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry |
| 953 | is: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 954 | |
| 955 | - The full pathname of a directory containing layer info files |
| 956 | |
| 957 | NOTE: these environment variables will be ignored for suid programs. |
| 958 | |
| 959 | #### Android |
| 960 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 961 | The recommended way to enable layers is for applications |
| 962 | to programatically enable them. The layers are provided by the application |
| 963 | and must live in the application's library folder. The application |
| 964 | enables the layers at vkCreateInstance and vkCreateDevice as any Vulkan |
| 965 | application would. |
| 966 | An application enabled for debug has more options. It can enumerate and enable |
| 967 | layers located in /data/local/vulkan/debug. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 968 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 969 | Layer interface requirements |
| 970 | ------------------------------------------------------ |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 971 | |
| 972 | #### Architectural interface overview |
| 973 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 974 | There are two key architectural features that drive the loader to layer library |
| 975 | interface: 1) separate and distinct instance and device call chains, and 2) |
| 976 | distributed dispatch. First these architectural features will be described and |
| 977 | then the detailed interface will be specified. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 978 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 979 | Call chains are the links of calls for a given Vulkan command from layer module |
| 980 | to layer module with the loader and or the ICD being the bottom most command. |
| 981 | Call chains are constructed at both the instance level and the device level by |
| 982 | the loader with cooperation from the layer libraries. Instance call chains are |
| 983 | constructed by the loader when layers are enabled at vkCreateInstance. Device |
| 984 | call chains are constructed by the loader when layers are enabled at |
| 985 | CreateDevice. A layer can intercept Vulkan instance commands, device commands |
| 986 | or both. For a layer to intercept instance commands, it must participate in the |
| 987 | instance call chain. For a layer to intercept device commands, it must |
| 988 | participate in the device chain. Layers which participate in intercepting calls |
| 989 | in both the intance and device chains are called global layers. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 990 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 991 | Normally, when a layer intercepts a given Vulkan command, it will call down the |
| 992 | instance or device chain as needed. The loader and all layer libraries that |
| 993 | participate in a call chain cooperate to ensure the correct sequencing of calls |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 994 | from one entity to the next. This group effort for call chain sequencing is |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 995 | hereinafter referred to as disitributed dispatch. In distributed dispatch, |
| 996 | since each layer is responsible for properly calling the next entity in the |
| 997 | device or instance chain, a dispatch mechanism is required for all Vulkan |
| 998 | commands a layer intercepts. For Vulkan commands that are not intercepted by a |
| 999 | layer, or if the layer chooses to terminate a given Vulkman command by not |
| 1000 | calling down the chain, then no dispatch mechanism is needed for that |
| 1001 | particular Vulkan command. Only for those Vulkan commands, which may be a |
| 1002 | subset of all Vulkan commands, that a layer intercepts is a dispatching |
| 1003 | mechanism by the layer needed. The loader is responsible for dispatching all |
| 1004 | core and instance extension Vulkan commands to the first entity in the chain. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1005 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1006 | Instance level Vulkan commands are those that have the disapatchable objects |
| 1007 | VkInstance, or VkPhysicalDevice as the first parameter and alos includes |
| 1008 | vkCreateInstance. |
| 1009 | Device level Vulkan commands are those that use VkDevice, VkQueue or |
| 1010 | VkCommandBuffer as the first parameter and also include vkCreateDevice. Future |
| 1011 | extensions may introduce new instance or device level dispatchable objects, so |
| 1012 | the above lists may be extended in the future. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1013 | |
| 1014 | #### Discovery of layer entrypoints |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1015 | For the layer libraries that have been discovered by the loader, their |
| 1016 | intercepting entry points that will participate in a device or instance call |
| 1017 | chain need to be available to the loader or whatever layer is before them in |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 1018 | the chain. Layers have the following requirements in this area. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1019 | - A layer intercepting instance level Vulkan commands (aka an instance level |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 1020 | layer) must implement a vkGetInstanceProcAddr type of function. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1021 | - This vkGetInstanceProcAddr type function must be exported by the layer |
| 1022 | library. The name of this function is specified in various ways: 1) the layer |
| 1023 | manifest JSON file in the "functions", "vkGetInstanceProcAddr" node |
| 1024 | (Linux/Windows); 2) it is named "vkGetInstanceProcAddr"; 3) it is |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 1025 | "<layerName>GetInstanceProcAddr" (Android). |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1026 | - A layer intercepting device level Vulkan commands (aka a device level layer) |
| 1027 | must implement a vkGetDeviceProcAddr type of function. |
| 1028 | - This vkGetDeviceProcAddr type function must be exported by the layer library. |
| 1029 | The name of this function is specified in various ways: 1) the layer manifest |
| 1030 | JSON file in the "functions", "vkGetDeviceProcAddr" node (Linux/Windows); 2) it |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 1031 | is named "vkGetDeviceProcAddr"; 3) it is "<layerName>GetDeviceProcAddr" |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1032 | (Android). |
| 1033 | - A layer's vkGetInstanceProcAddr function (irregardless of it's name) must |
| 1034 | return the local entry points for all instance level Vulkan commands it |
| 1035 | intercepts. At a minimum, this includes vkGetInstanceProcAddr and |
| 1036 | vkCreateInstance. |
| 1037 | - A layer's vkGetDeviceProcAddr function (irregardless of it's name) must |
| 1038 | return the entry points for all device level Vulkan commands it intercepts. At |
| 1039 | a minimum, this includes vkGetDeviceProcAddr and vkCreateDevice. |
| 1040 | - There are no requirements on the names of the intercepting functions a layer |
| 1041 | implements except those listed above for vkGetInstanceProcAddr and |
| 1042 | vkGetDeviceProcAddr. |
| 1043 | - Currently a layer's VkGetInstanceProcAddr must be able to handle a VkInstance |
| 1044 | parameter equal to NULL for |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1045 | instance level commands it intercepts including vkCreateDevice. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1046 | - Currently a layer's VkGetDeviceProcAddr must be able to handle a VkDevice |
| 1047 | parameter equal to NULL for device level commands it intercepts. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1048 | |
| 1049 | #### Layer intercept requirements |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1050 | - Layers intercept a Vulkan command by defining a C/C++ function with signature |
| 1051 | identical to the Vulkan API for that command. |
| 1052 | - Other than the two vkGet*ProcAddr, all other functions intercepted by a layer |
| 1053 | need NOT be exported by the layer. |
| 1054 | - For any Vulkan command a layer intercepts which has a non-void return value, |
| 1055 | an appropriate value must be returned by the layer intercept function. |
| 1056 | - The layer intercept function must call down the chain to the corresponding |
| 1057 | Vulkan command in the next entity. Undefined results will occur if a layer |
| 1058 | doesn't propagate calls down the chain. The two exceptions to this requirement |
| 1059 | are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the |
| 1060 | chain for Vulkan commands that they do not intercept. |
| 1061 | - Layer intercept functions may insert extra calls to Vulkan commands in |
| 1062 | addition to the intercept. For example, a layer intercepting vkQueueSubmit may |
| 1063 | want to add a call to vkQueueWaitIdle after calling down the chain for |
| 1064 | vkQueueSubmit. Any additional calls inserted by a layer must be on the same |
| 1065 | chain. They should call down the chain. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1066 | |
| 1067 | #### Distributed dispatching requirements |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1068 | - For each entry point a layer intercepts, it must keep track of the entry |
| 1069 | point residing in the next entity in the chain it will call down into. In other |
| 1070 | words, the layer must have a list of pointers to functions of the appropriate |
| 1071 | type to call into the next entity. This can be implemented in various ways but |
| 1072 | for 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 |
| 1076 | dispatch table (see include/vulkan/vk_layer.h). |
| 1077 | - Layers vkGetInstanceProcAddr function uses the next entity's |
| 1078 | vkGetInstanceProcAddr to call down the chain for unknown (ie non-intercepted) |
| 1079 | functions. |
| 1080 | - Layers vkGetDeviceProcAddr function uses the next entity's |
| 1081 | vkGetDeviceProcAddr to call down the chain for unknown (ie non-intercepted) |
| 1082 | functions. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1083 | |
| 1084 | #### Layer dispatch initialization |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1085 | - A layer intializes it's instance dispatch table within it's vkCreateInstance |
| 1086 | function. |
| 1087 | - A layer intializes it's device dispatch table within it's vkCreateDevice |
| 1088 | function. |
| 1089 | - The loader passes a linked list of initialization structures to layers via |
| 1090 | the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures |
| 1091 | for vkCreateInstance and VkCreateDevice respectively. |
| 1092 | - The head node in this linked list is of type VkLayerInstanceCreateInfo for |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 1093 | instance and VkLayerDeviceCreateInfo for device. See file |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1094 | include/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 |
| 1100 | within VkLayer*CreateInfo. The loader will set the "function" field to |
| 1101 | VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or |
| 1102 | VkLayerDeviceLink. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1103 | - The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1104 | - The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used |
| 1105 | by a layer. |
| 1106 | - The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and |
| 1107 | vkGetDeviceProcAddr used by a layer. |
| 1108 | - Given the above structures set up by the loader, layer must initialize their |
| 1109 | dispatch table as follows: |
| 1110 | - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in |
| 1111 | the VkInstanceCreateInfo/VkDeviceCreateInfo structure. |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1112 | - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1113 | - For CreateInstance get the next entity's vkCreateInstance by calling the |
| 1114 | "pfnNextGetInstanceProcAddr": |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1115 | pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance"). |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1116 | - For CreateDevice get the next entity's vkCreateDevice by calling the |
| 1117 | "pfnNextGetInstanceProcAddr": |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1118 | pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice"). |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1119 | - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext. |
| 1120 | - Call down the chain either CreateDevice or CreateInstance |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1121 | - Initialize your layer dispatch table by calling the next entity's |
| 1122 | Get*ProcAddr function once for each Vulkan command needed in your dispatch |
| 1123 | table |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1124 | |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame^] | 1125 | TODO: Example code for CreateInstance. |
| 1126 | |
| 1127 | TODO: Example code for CreateDevice. |
| 1128 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1129 | #### Special Considerations |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame^] | 1130 | A layer may want to associate it's own private data with one or more Vulkan objects. |
| 1131 | Two common methods to do this are hash maps and object wrapping. The loader |
| 1132 | supports layers wrapping any Vulkan object including dispatchable objects. |
| 1133 | Layers which wrap objects should ensure they always unwrap objects before |
| 1134 | passing them down the chain. This implies the layer must intercept every Vulkan |
| 1135 | command which uses the object in question. Layers above the object wrapping |
| 1136 | layer will see the wrapped object. |
| 1137 | |
| 1138 | Alternatively, a layer may want to use a hash map to associate data with a given object. |
| 1139 | The key to the map could be the object. Alternatively, for dispatchable objects |
| 1140 | at 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 |
| 1141 | dispatchable objects for a given VkInstance or VkDevice, the VkDevice or |
| 1142 | VkInstance object is not a great map key. Instead the layer should use the |
| 1143 | dispatch table pointer withbin the VkDevice or VkInstance since that will be |
| 1144 | unique for a given VkInstance or VkDevice. |
| 1145 | |
| 1146 | Layers which create dispatchable objects take special care. Remember that loader |
| 1147 | trampoline code normally fills in the dispatch table pointer in the newly |
| 1148 | created object. Thus, the layer must fill in the dispatch table pointer if the |
| 1149 | loader trampoline will not do so. Common cases a layer may create a dispatchable |
| 1150 | object 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 |
| 1154 | intercept from the application |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1155 | |