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. |
Jon Ashburn | c250556 | 2016-02-15 10:19:26 -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. |
Jon Ashburn | c250556 | 2016-02-15 10:19:26 -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 |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 120 | an application to fail gracefully if the loader cannot be found, and it |
| 121 | provides the fastest mechanism for the application to call Vulkan functions. An |
| 122 | application will only need to query (via system calls such as dlsym()) the |
| 123 | address of vkGetInstanceProcAddr from the loader library. Using |
| 124 | vkGetInstanceProcAddr the application can then discover the address of all |
| 125 | instance and global functions and extensions, such as vkCreateInstance, |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 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 |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 134 | guaranteed for all versions with the same major number (e.g. 1.0 and 1.1). On |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 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 |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 137 | given system. The Vulkan loader library file name is “vulkan-<ABI |
| 138 | version>.dll”. For example, for Vulkan version 1.X on Windows the library |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 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 |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 146 | also be linked to by applications (e.g. 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 |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 153 | application. Thus, eliminating the overhead of validating the application's |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 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 | ``` |
Mark Lobodzinski | 739391a | 2016-03-17 15:08:18 -0600 | [diff] [blame] | 186 | > $ export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_parameter_validation |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 187 | |
Mark Lobodzinski | 739391a | 2016-03-17 15:08:18 -0600 | [diff] [blame] | 188 | > $ export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_parameter_validation |
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 |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 217 | pLayerName parameter in these functions is used to select either a single layer |
| 218 | or the Vulkan platform implementation. If pLayerName is NULL, extensions from |
| 219 | Vulkan implementation components (including loader, implicit layers, and ICDs) |
| 220 | are enumerated. If pLayerName is equal to a discovered layer module name then |
| 221 | any extensions from that layer (which may be implicit or explicit) are |
| 222 | enumerated. Duplicate extensions (e.g. an implicit layer and ICD might report |
Jon Ashburn | 859c7fb | 2016-03-02 17:26:31 -0700 | [diff] [blame] | 223 | support for the same extension) are eliminated by the loader. For duplicates, the |
| 224 | ICD version is reported and the layer version is culled. Extensions must |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 225 | be enabled (in vkCreateInstance or vkCreateDevice) before they can be used. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 226 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 227 | Extension command entry points should be queried via vkGetInstanceProcAddr or |
| 228 | vkGetDeviceProcAddr. vkGetDeviceProcAddr can only be used to query for device |
| 229 | extension or core device entry points. Device entry points include any command |
| 230 | that uses a VkDevice as the first parameter or a dispatchable object that is a |
| 231 | child of a VkDevice (currently this includes VkQueue and VkCommandBuffer). |
| 232 | vkGetInstanceProcAddr can be used to query either device or instance extension |
| 233 | entry points in addition to all core entry points. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 234 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 235 | VkGetDeviceProcAddr is particularly interesting because it will provide the |
| 236 | most efficient way to call into the ICD. For example, the diagram below shows |
| 237 | what could happen if the application were to use vkGetDeviceProcAddr for the |
| 238 | function “vkGetDeviceQueue” and “vkDestroyDevice” but not “vkAllocateMemory”. |
| 239 | The resulting function pointer (fpGetDeviceQueue) would be the ICD’s entry |
| 240 | point if the loader and any enabled layers do not need to see that call. Even |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 241 | if an enabled layer intercepts the call (e.g. vkDestroyDevice) the loader |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 242 | trampoline code is skipped for function pointers obtained via |
| 243 | vkGetDeviceProcAddr. This also means that function pointers obtained via |
| 244 | vkGetDeviceProcAddr will only work with the specific VkDevice it was created |
| 245 | for, using it with another device has undefined results. For extensions, |
| 246 | 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] | 247 | |
Jon Ashburn | c250556 | 2016-02-15 10:19:26 -0700 | [diff] [blame] | 248 |  |
Courtney Goeltzenleuchter | ab3a466 | 2016-02-14 10:48:22 -0700 | [diff] [blame] | 249 | |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 250 | |
| 251 | Vulkan Installable Client Driver interface with the loader |
| 252 | ---------------------------------------------------------- |
| 253 | |
| 254 | ### ICD discovery |
| 255 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 256 | Vulkan allows multiple drivers each with one or more devices (represented by a |
| 257 | Vulkan VkPhysicalDevice object) to be used collectively. The loader is |
| 258 | responsible for discovering available Vulkan ICDs on the system. Given a list |
| 259 | of available ICDs, the loader can enumerate all the physical devices available |
| 260 | for an application and return this information to the application. The process |
| 261 | in which the loader discovers the available Installable Client Drivers (ICDs) |
| 262 | on a system is platform dependent. Windows, Linux and Android ICD discovery |
| 263 | details are listed below. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 264 | |
| 265 | #### Windows |
| 266 | |
| 267 | ##### Properly-Installed ICDs |
| 268 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 269 | In order to find properly-installed ICDs, the Vulkan loader will scan the |
| 270 | values in the following Windows registry key: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 271 | |
| 272 | HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\Drivers |
| 273 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 274 | For each value in this key which has DWORD data set to 0, the loader opens the |
| 275 | JSON format text information file (a.k.a. "manifest file") specified by the |
| 276 | name of the value. Each name must be a full pathname to the text manifest file. |
| 277 | The Vulkan loader will open each manifest file to obtain the name or pathname |
| 278 | of an ICD shared library (".dll") file. For example: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 279 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 280 | ``` |
| 281 | { |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 282 | "file_format_version": "1.0.0", |
| 283 | "ICD": { |
| 284 | "library_path": "path to ICD library", |
Tony Barbour | d83f06c | 2016-03-08 14:50:03 -0700 | [diff] [blame] | 285 | "api_version": "1.0.5" |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 286 | } |
| 287 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 288 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 289 | |
| 290 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 291 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 292 | pathname to an ICD shared library file, which the loader will attempt to load |
| 293 | using LoadLibrary(). If the ICD is specified via a filename, the shared library |
David Pinedo | 3e163ee | 2016-04-18 16:59:59 -0600 | [diff] [blame] | 294 | lives in the system's DLL search path (e.g. in the "C:\Windows\System32" |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 295 | folder). If the ICD is specified via a relative pathname, it is relative to the |
| 296 | path of the manifest file. Relative pathnames are those that do not start with |
| 297 | a drive specifier (e.g. "C:"), nor with a directory separator (i.e. the '\\' |
| 298 | character), but do contain at least one directory separator. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 299 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 300 | The "file\_format\_version" specifies a major.minor.patch version number in |
| 301 | case the format of the text information file changes in the future. If the same |
| 302 | ICD shared library supports multiple, incompatible versions of text manifest |
| 303 | file format versions, it must have multiple text info files (all of which may |
| 304 | point to the same shared library). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 305 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 306 | The “api\_version” specifies the major.minor.patch version number of the Vulkan |
| 307 | API that the shared library (referenced by "library\_path") was built with. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 308 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 309 | There are no rules about the name of the text information files (except the |
| 310 | .json suffix). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 311 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 312 | There are no rules about the name of the ICD shared library files. For example, |
| 313 | if the registry contains the following values, |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 314 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 315 | ``` |
| 316 | [HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers\] |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 317 | |
David Pinedo | 3e163ee | 2016-04-18 16:59:59 -0600 | [diff] [blame] | 318 | "C:\vendor a\vk_vendora.json"=dword:00000000 |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 319 | |
David Pinedo | 3e163ee | 2016-04-18 16:59:59 -0600 | [diff] [blame] | 320 | "C:\windows\system32\vendorb_vk.json"=dword:00000000 |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 321 | |
David Pinedo | 3e163ee | 2016-04-18 16:59:59 -0600 | [diff] [blame] | 322 | "C:\windows\system32\vendorc_icd.json"=dword:00000000 |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 323 | ``` |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 324 | then the loader will open the following text information files, with the |
| 325 | specified contents: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 326 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 327 | | Text File Name | Text File Contents | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 328 | |----------------|--------------------| |
David Pinedo | 3e163ee | 2016-04-18 16:59:59 -0600 | [diff] [blame] | 329 | |vk\_vendora.json | "ICD": { "library\_path": "C:\VENDOR A\vk_vendora.dll", "api_version": "1.0.5" } | |
Tony Barbour | d83f06c | 2016-03-08 14:50:03 -0700 | [diff] [blame] | 330 | | vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vk.dll", "api_version": "1.0.5" } | |
| 331 | |vendorc\_icd.json | "ICD": { "library\_path": "vedorc\_icd.dll", "api_version": "1.0.5" }| |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 332 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 333 | Then the loader will open the three files mentioned in the "Text File Contents" |
| 334 | column, and then try to load and use the three shared libraries indicated by |
| 335 | the ICD.library\_path value. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 336 | |
| 337 | ##### Using Pre-Production ICDs |
| 338 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 339 | IHV developers (and sometimes other developers) need to use special, |
| 340 | pre-production ICDs. In some cases, a pre-production ICD may be in an |
| 341 | installable package. In other cases, a pre-production ICD may simply be a |
| 342 | shared library in the developer's build tree. In this latter case, we want to |
| 343 | allow developers to point to such an ICD without modifying the |
| 344 | properly-installed ICD(s) on their system. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 345 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 346 | This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable, |
| 347 | which will override the mechanism used for finding properly-installed ICDs. In |
| 348 | other words, only the ICDs listed in "VK\_ICD\_FILENAMES" will be used. The |
| 349 | "VK\_ICD\_FILENAMES" environment variable is a semi-colon-separated list of ICD |
| 350 | text information files (aka manifest files), containing the following: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 351 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 352 | - A full pathname (e.g. "C:\\my\_build\\my\_icd.json") |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 353 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 354 | Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info |
| 355 | file for a developer-built ICD. A semi-colon is only used if more than one ICD |
| 356 | is listed. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 357 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 358 | For example, if a developer wants to refer to one ICD that they built, they |
| 359 | could set the "VK\_ICD\_FILENAMES" environment variable to: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 360 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 361 | C:\\my\_build\\my\_icd.json |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 362 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 363 | If a developer wants to refer to two ICDs, one of which is a properly-installed |
| 364 | ICD, they can use the full pathname of the text file: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 365 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 366 | C:\\Windows\\System32\\vendorc\_icd.json;C:\\my\_build\\my\_icd.json |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 367 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 368 | Notice the semi-colon between "C:\\Windows\\System32\\vendorc\_icd.json" and |
| 369 | "C:\\my\_build\\my\_icd.json". |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 370 | |
| 371 | #### Linux |
| 372 | |
| 373 | ##### Properly-Installed ICDs |
| 374 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 375 | In order to find properly-installed ICDs, the Vulkan loader will scan the files |
| 376 | in the following Linux directories: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 377 | |
| 378 | /usr/share/vulkan/icd.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 379 | /etc/vulkan/icd.d |
Jon Ashburn | 7f00ca8 | 2016-02-24 12:00:55 -0700 | [diff] [blame] | 380 | $HOME/.local/share/vulkan/icd.d |
| 381 | |
| 382 | Where $HOME is the current home directory of the application's user id; this |
| 383 | path will be ignored for suid programs. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 384 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 385 | These directories will contain text information files (a.k.a. "manifest |
| 386 | files"), that use a JSON format. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 387 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 388 | The Vulkan loader will open each manifest file found to obtain the name or |
| 389 | pathname of an ICD shared library (".so") file. For example: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 390 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 391 | ``` |
| 392 | { |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 393 | "file_format_version": "1.0.0", |
| 394 | "ICD": { |
| 395 | "library_path": "path to ICD library", |
Tony Barbour | d83f06c | 2016-03-08 14:50:03 -0700 | [diff] [blame] | 396 | "api_version": "1.0.5" |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 397 | } |
| 398 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 399 | ``` |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 400 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 401 | pathname to an ICD shared library file. If the ICD is specified via a filename, |
| 402 | the loader will attempt to open that file as a shared object using dlopen(), |
| 403 | and the file must be in a directory that dlopen is configured to look in (Note: |
| 404 | various distributions are configured differently). A distribution is free to |
| 405 | create Vulkan-specific system directories (e.g. ".../vulkan/icd"), but is not |
| 406 | required to do so. If the ICD is specified via a relative pathname, it is |
| 407 | relative to the path of the info file. Relative pathnames are those that do not |
| 408 | start with, but do contain at least one directory separator (i.e. the '/' |
| 409 | character). For example, "lib/vendora.so" and "./vendora.so" are examples of |
| 410 | relative pathnames. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 411 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 412 | The "file\_format\_version" provides a major.minor.patch version number in case |
| 413 | the format of the manifest file changes in the future. If the same ICD shared |
| 414 | library supports multiple, incompatible versions of manifest file format |
| 415 | versions, it must have multiple manifest files (all of which may point to the |
| 416 | same shared library). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 417 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 418 | The “api\_version” specifies the major.minor.patch version number of the Vulkan |
| 419 | API that the shared library (referenced by "library\_path") was built with. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 420 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 421 | The "/usr/share/vulkan/icd.d" directory is for ICDs that are installed from |
| 422 | Linux-distribution-provided packages. The "/etc/vulkan/icd.d" directory is for |
| 423 | ICDs that are installed from non-Linux-distribution-provided packages. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 424 | |
| 425 | There are no rules about the name of the text files (except the .json suffix). |
| 426 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 427 | There are no rules about the name of the ICD shared library files. For example, |
| 428 | if the "/usr/share/vulkan/icd.d" directory contain the following files, with |
| 429 | the specified contents: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 430 | |
Jon Ashburn | 26ed3f3 | 2016-02-14 21:54:52 -0700 | [diff] [blame] | 431 | | Text File Name | Text File Contents | |
| 432 | |-------------------|------------------------| |
Tony Barbour | d83f06c | 2016-03-08 14:50:03 -0700 | [diff] [blame] | 433 | | vk\_vendora.json | "ICD": { "library\_path": "vendora.so", "api_version": "1.0.5" } | |
| 434 | | vendorb\_vk.json | "ICD": { "library\_path": "vendorb\_vulkan\_icd.so", "api_version": "1.0.5" } | |
| 435 | | vendorc\_icd.json | "ICD": { "library\_path": "/usr/lib/VENDORC/icd.so", "api_version": "1.0.5" } | |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 436 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 437 | then the loader will open the three files mentioned in the "Text File Contents" |
| 438 | column, and then try to load and use the three shared libraries indicated by |
| 439 | the ICD.library\_path value. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 440 | |
| 441 | ##### Using Pre-Production ICDs |
| 442 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 443 | IHV developers (and sometimes other developers) need to use special, |
| 444 | pre-production ICDs. In some cases, a pre-production ICD may be in an |
| 445 | installable package. In other cases, a pre-production ICD may simply be a |
| 446 | shared library in the developer's build tree. In this latter case, we want to |
| 447 | allow developers to point to such an ICD without modifying the |
| 448 | properly-installed ICD(s) on their system. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 449 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 450 | This need is met with the use of the "VK\_ICD\_FILENAMES" environment variable, |
| 451 | which will override the mechanism used for finding properly-installed ICDs. In |
| 452 | 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] | 453 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 454 | The "VK\_ICD\_FILENAMES" environment variable is a colon-separated list of ICD |
| 455 | manifest files, containing the following: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 456 | |
Jon Ashburn | 7f00ca8 | 2016-02-24 12:00:55 -0700 | [diff] [blame] | 457 | - A filename (e.g. "libvkicd.json") in the "/usr/share/vulkan/icd.d", "/etc/vulkan/icd.d" "$HOME/.local/share/vulkan/icd.d" directories |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 458 | |
| 459 | - A full pathname (e.g. "/my\_build/my\_icd.json") |
| 460 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 461 | Typically, "VK\_ICD\_FILENAMES" will only contain a full pathname to one info |
| 462 | file for a developer-built ICD. A colon is only used if more than one ICD is |
| 463 | listed. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 464 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 465 | For example, if a developer wants to refer to one ICD that they built, they |
| 466 | could set the "VK\_ICD\_FILENAMES" environment variable to: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 467 | |
| 468 | /my\_build/my\_icd.json |
| 469 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 470 | If a developer wants to refer to two ICDs, one of which is a properly-installed |
| 471 | 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] | 472 | |
| 473 | vendorc\_vulkan.json:/my\_build/my\_icd.json |
| 474 | |
| 475 | Notice the colon between "vendorc\_vulkan.json" and "/my\_build/my\_icd.json". |
| 476 | |
| 477 | NOTE: this environment variable will be ignored for suid programs. |
| 478 | |
| 479 | #### Android |
| 480 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 481 | The Android loader lives in the system library folder. The location cannot be |
| 482 | changed. The loader will load the driver/ICD via hw_get_module with the ID |
| 483 | of "vulkan". Due to security policies in Android none of this can be modified |
| 484 | under normal use. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 485 | |
| 486 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 487 | ICD interface requirements |
| 488 | ---------------------------------------- |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 489 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 490 | Generally, for all Vulkan commands issued by an application, the loader can be |
| 491 | viewed as a pass through. That is, the loader generally doesn’t modified the |
| 492 | commands or their parameters but simply calls the ICDs entry point for that |
| 493 | command. Thus, the loader to ICD interface requirements will be specified by |
| 494 | covering two areas: 1) Obtaining ICD Vulkan entry points; 2) Specifying |
| 495 | requirements for a given Vulkan command(s) over and above the Vulkan |
| 496 | specification requirements. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 497 | |
| 498 | #### Windows and Linux |
| 499 | |
| 500 | ##### Obtaining ICD entry points |
| 501 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 502 | Currently, two methods of the loader finding ICD entry points are supported on |
| 503 | Linux and Windows: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 504 | |
| 505 | 1) Recommended |
| 506 | |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 507 | - vk\_icdGetInstanceProcAddr is exported by the ICD library and it returns |
| 508 | valid function pointers for all the global level and instance level Vulkan |
| 509 | commands, and also for vkGetDeviceProcAddr. Global level commands are those |
| 510 | which contain no dispatchable object as the first parameter, such as |
| 511 | vkCreateInstance and vkEnumerateInstanceExtensionProperties. The ICD must |
| 512 | support querying global level entry points by calling |
| 513 | vk\_icdGetInstanceProcAddr with a NULL VkInstance parameter. Instance level |
| 514 | commands are those that have either VkInstance, or VkPhysicalDevice as the |
| 515 | first parameter dispatchable object. Both core entry points and any instance |
| 516 | extension entry points the ICD supports should be available via |
| 517 | vk\_icdGetInstanceProcAddr. Future Vulkan instance extensions may define and |
| 518 | use new instance level dispatchable objects other than VkInstance and |
| 519 | VkPhysicalDevice, in which case extension entry points using these newly |
| 520 | defined dispatchable objects must be queryable via |
| 521 | vk\_icdGetInstanceProcAddr. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 522 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 523 | - All other Vulkan entry points must either NOT be exported from the ICD |
| 524 | library or else NOT use the official Vulkan function names if they are |
| 525 | exported. This requirement is for ICD libraries that include other |
| 526 | functionality (such as OpenGL library) and thus could be loaded by the |
| 527 | application prior to when the Vulkan loader library is loaded by the |
| 528 | application. In other words, the ICD library exported Vulkan symbols must not |
| 529 | clash with the loader's exported Vulkan symbols. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 530 | |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 531 | - Beware of interposing by dynamic OS library loaders if the official Vulkan |
| 532 | names are used. On Linux, if official names are used, the ICD library must be |
| 533 | linked with -Bsymbolic. |
| 534 | |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 535 | 2) Deprecated |
| 536 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 537 | - vkGetInstanceProcAddr exported in the ICD library and returns valid function |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 538 | pointers for all the Vulkan API entry points. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 539 | |
| 540 | - vkCreateInstance exported in the ICD library; |
| 541 | |
| 542 | - vkEnumerateInstanceExtensionProperties exported in the ICD library; |
| 543 | |
| 544 | ##### Loader specific requirements for Vulkan commands |
| 545 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 546 | Normally, ICDs handle object creation and destruction for various Vulkan |
| 547 | objects. The WSI surface extensions for Linux and Windows |
| 548 | (VK\_KHR\_win32\_surface, VK\_KHR\_xcb\_surface, VK\_KHR\_xlib\_surface, |
| 549 | VK\_KHR\_mir\_surface, VK\_KHR\_wayland\_surface, and VK\_KHR\_surface) are |
| 550 | handled differently. For these extensions, the VkSurfaceKHR object creation and |
| 551 | destruction is handled by the loader as follows: |
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 | 1. Loader handles the vkCreate\*SurfaceKHR() and vkDestroySurfaceKHR() |
| 554 | functions including creating/destroying the VkSurfaceKHR object. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 555 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 556 | 2. VkSurfaceKHR objects have the underlying structure (VkIcdSurface\*) as |
| 557 | defined in include/vulkan/vk\_icd.h. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 558 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 559 | 3. ICDs can cast any VkSurfaceKHR object to a pointer to the appropriate |
| 560 | VkIcdSurface\* structure. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 561 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 562 | 4. VkIcdSurface\* structures include VkIcdSurfaceWin32, VkIcdSurfaceXcb, |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 563 | VkIcdSurfaceXlib, VkIcdSurfaceMir, and VkIcdSurfaceWayland. The first field |
| 564 | in the structure is a VkIcdSurfaceBase enumerant that indicates whether the |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 565 | surface object is Win32, Xcb, Xlib, Mir, or Wayland. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 566 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 567 | As previously covered, the loader requires dispatch tables to be accessible |
| 568 | within Vulkan dispatchable objects, which include VkInstance, VkPhysicalDevice, |
| 569 | VkDevice, VkQueue, and VkCommandBuffer. The specific requirements on all |
| 570 | dispatchable objects created by ICDs are as follows: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 571 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 572 | - All dispatchable objects created by an ICD can be cast to void \*\* |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 573 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 574 | - The loader will replace the first entry with a pointer to the dispatch table |
| 575 | 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] | 576 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 577 | 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] | 578 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 579 | 2. This pointer points to a regular C structure with the first entry being a |
| 580 | pointer. Note: for any C\++ ICD's that implement VK objects directly as C\++ |
| 581 | classes. The C\++ compiler may put a vtable at offset zero if your class is |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 582 | non-POD due to the use of a virtual function. In this case use a regular C |
| 583 | structure (see below). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 584 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 585 | 3. The loader checks for a magic value (ICD\_LOADER\_MAGIC) in all the created |
| 586 | dispatchable objects, as follows (see include/vulkan/vk\_icd.h): |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 587 | |
| 588 | ``` |
| 589 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 590 | #include "vk_icd.h" |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 591 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 592 | union _VK_LOADER_DATA { |
| 593 | uintptr loadermagic; |
| 594 | void *loaderData; |
| 595 | } VK_LOADER_DATA; |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 596 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 597 | vkObj alloc_icd_obj() |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 598 | { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 599 | vkObj *newObj = alloc_obj(); |
| 600 | ... |
| 601 | // Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 602 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 603 | set_loader_magic_value(newObj); |
| 604 | ... |
| 605 | return newObj; |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 606 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 607 | ``` |
| 608 | |
| 609 | Additional Notes: |
| 610 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 611 | - The loader will filter out extensions requested in vkCreateInstance and |
| 612 | vkCreateDevice before calling into the ICD; Filtering will be of extensions |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 613 | advertised by entities (e.g. layers) different from the ICD in question. |
| 614 | - The loader will not call the ICD for vkEnumerate\*LayerProperties() as layer |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 615 | properties are obtained from the layer libraries and layer JSON files. |
| 616 | - If an ICD library wants to implement a layer it can do so by having the |
| 617 | appropriate layer JSON manifest file refer to the ICD library file. |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 618 | - The loader will not call the ICD for |
| 619 | vkEnumerate\*ExtensionProperties(pLayerName != NULL). |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 620 | - ICDs creating new dispatchable objects via device extensions need to initialize |
| 621 | the created disaptchable object. The loader has generic trampoline code for unknown |
| 622 | device extensions. This generic trampoline code doesn't initialize the dispatch table within |
| 623 | the newly created object. See the section [layer link](#creating-new-dispatchable-objects) |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 624 | |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 625 | #### Android |
| 626 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 627 | The Android loader uses the same protocol for initializing the dispatch |
| 628 | table as described above. The only difference is that the Android |
| 629 | loader queries layer and extension information directly from the |
| 630 | respective libraries and does not use the json manifest files used |
| 631 | by the Windows and Linux loaders. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 632 | |
| 633 | Vulkan layer interface with the loader |
| 634 | -------------------------------------- |
| 635 | |
| 636 | ### Layer discovery |
| 637 | |
| 638 | #### Windows |
| 639 | |
| 640 | ##### Properly-Installed Layers |
| 641 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 642 | In order to find properly-installed layers, the Vulkan loader will use a |
| 643 | similar mechanism as used for ICDs. Text information files (aka manifest |
| 644 | files), that use a JSON format, are read in order to identify the names and |
| 645 | attributes of layers and their extensions. The use of manifest files allows the |
| 646 | loader to avoid loading any shared library files when the application does not |
| 647 | query nor request any extensions. Layers and extensions have additional |
| 648 | complexity, and so their manifest files contain more information than ICD info |
| 649 | files. For example, a layer shared library file may contain multiple |
| 650 | layers/extensions (perhaps even an ICD). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 651 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 652 | In order to find properly-installed layers, the Vulkan loader will scan the |
| 653 | values in the following Windows registry keys: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 654 | |
| 655 | HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers |
| 656 | |
| 657 | HKEY\_LOCAL\_MACHINE\\SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers |
| 658 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 659 | Explicit layers are those which are enabled by an application (e.g. with the |
| 660 | vkCreateInstance function), or by an environment variable (as mentioned |
| 661 | previously). |
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 | Implicit layers are those which are enabled by their existence. For example, |
| 664 | certain application environments (e.g. Steam or an automotive infotainment |
| 665 | system) may have layers which they always want enabled for all applications |
| 666 | that they start. Other implicit layers may be for all applications started on a |
| 667 | given system (e.g. layers that overlay frames-per-second). Implicit layers are |
| 668 | enabled automatically, whereas explicit layers must be enabled explicitly. What |
| 669 | distinguishes a layer as implicit or explicit is by which registry key its |
| 670 | layer information file is referenced by. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 671 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 672 | For each value in these keys which has DWORD data set to 0, the loader opens |
| 673 | the JSON manifest file specified by the name of the value. Each name must be a |
| 674 | full pathname to the manifest file. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 675 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 676 | The Vulkan loader will open each info file to obtain information about the |
| 677 | layer, including the name or pathname of a shared library (".dll") file. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 678 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 679 | This manifest file is in the JSON format and contains the following |
| 680 | information: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 681 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 682 | - (required) "file\_format\_version" - same as for ICDs, except that the format |
| 683 | version can vary independently for ICDs and layers. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 684 | |
| 685 | - (required) "name" - layer name |
| 686 | |
| 687 | - (required) "type" - which layer chains should the layer be activated on. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 688 | Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on |
| 689 | both device and instance chains. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 690 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 691 | - (required) "library\_path" - filename / full path / relative path to the |
| 692 | library file |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 693 | |
| 694 | - (required) "api\_version" - same as for ICDs. |
| 695 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 696 | - (required) "implementation\_version" - layer version, a single number |
| 697 | increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 698 | |
| 699 | - (required) "description" - informative description of the layer. |
| 700 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 701 | - (optional) "device\_extensions" or "instance\_extensions" - array of |
| 702 | extension information as follows |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 703 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 704 | - (required) extension "name" - Vulkan registered name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 705 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 706 | - (required) extension "spec\_version" - extension specification version, a |
| 707 | single number, increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 708 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 709 | - (required for device\_extensions with entry points) extension |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 710 | "entrypoints" - array of device extension entry points; not used for instance |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 711 | extensions |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 712 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 713 | - (sometimes required) "functions" - mapping list of function entry points. If |
| 714 | multiple layers exist within the same shared library (or if a layer is in the |
| 715 | same shared library as an ICD), this must be specified to allow each layer to |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 716 | have its own vkGet\*ProcAddr entry points that can be found by the loader. At |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 717 | this time, only the following two functions are required: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 718 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 719 | - "vkGetInstanceProcAddr" name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 720 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 721 | - "vkGetDeviceProcAddr" name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 722 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 723 | - (optional for implicit layers) "enable\_environment" requirement(s) - |
| 724 | environment variable and value required to enable an implicit layer. This |
| 725 | environment variable (which should vary with each "version" of the layer, as in |
| 726 | "ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit |
| 727 | layer is not loaded. This is for application environments (e.g. Steam) which |
| 728 | want to enable a layer(s) only for applications that they launch, and allows |
| 729 | for applications run outside of an application environment to not get that |
| 730 | implicit layer(s). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 731 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 732 | - (required for implicit layers) "disable\_environment" requirement(s) - |
| 733 | environment variable and value required to disable an implicit layer. Note: in |
| 734 | rare cases of an application not working with an implicit layer, the |
| 735 | application can set this environment variable (before calling Vulkan functions) |
| 736 | in order to "blacklist" the layer. This environment variable (which should vary |
| 737 | with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set |
| 738 | (not particularly to any value). If both the "enable\_environment" and |
| 739 | "disable\_environment" variables are set, the implicit layer is disabled. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 740 | |
| 741 | For example: |
| 742 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 743 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 744 | { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 745 | "file_format_version" : "1.0.0", |
| 746 | "layer": { |
| 747 | "name": "VK_LAYER_LUNARG_OverlayLayer", |
| 748 | "type": "DEVICE", |
| 749 | "library_path": "vkOverlayLayer.dll" |
Tony Barbour | d83f06c | 2016-03-08 14:50:03 -0700 | [diff] [blame] | 750 | "api_version" : "1.0.5", |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 751 | "implementation_version" : "2", |
| 752 | "description" : "LunarG HUD layer", |
| 753 | "functions": { |
| 754 | "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr", |
| 755 | "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr" |
| 756 | }, |
Jon Ashburn | 26ed3f3 | 2016-02-14 21:54:52 -0700 | [diff] [blame] | 757 | "instance_extensions": [ |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 758 | { |
| 759 | "name": "VK_debug_report_EXT", |
| 760 | "spec_version": "1" |
| 761 | }, |
| 762 | { |
| 763 | "name": "VK_VENDOR_DEBUG_X", |
| 764 | "spec_version": "3" |
| 765 | } |
| 766 | ], |
Courtney Goeltzenleuchter | 84a75ce | 2016-02-15 15:07:54 -0700 | [diff] [blame] | 767 | "device_extensions": [ |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 768 | { |
Jon Ashburn | 58048d0 | 2016-03-03 12:03:58 -0700 | [diff] [blame] | 769 | "name": "VK_DEBUG_MARKER_EXT", |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 770 | "spec_version": "1", |
| 771 | "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"] |
| 772 | } |
| 773 | ], |
| 774 | "disable_environment": { |
| 775 | "DISABLE_LAYER_OVERLAY_1": "" |
| 776 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 777 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 778 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 779 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 780 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 781 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 782 | pathname to a layer shared library (".dll") file, which the loader will attempt |
| 783 | to load using LoadLibrary(). If the layer is specified via a relative pathname, |
| 784 | it is relative to the path of the info file (e.g. for cases when an application |
| 785 | provides a layer that is in the same folder hierarchy as the rest of the |
| 786 | application files). If the layer is specified via a filename, the shared |
| 787 | library lives in the system's DLL search path (e.g. in the |
| 788 | "C:\\Windows\\System32" folder). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 789 | |
| 790 | There are no rules about the name of the text files (except the .json suffix). |
| 791 | |
| 792 | There are no rules about the name of the layer shared library files. |
| 793 | |
| 794 | ##### Using Pre-Production Layers |
| 795 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 796 | As with ICDs, developers may need to use special, pre-production layers, |
| 797 | without modifying the properly-installed layers. This need is met with the use |
| 798 | of the "VK\_LAYER\_PATH" environment variable, which will override the |
| 799 | mechanism using for finding properly-installed layers. Because many layers may |
| 800 | exist on a system, this environment variable is a semi-colon-separated list of |
| 801 | folders that contain layer info files. Only the folder listed in |
| 802 | "VK\_LAYER\_PATH" will be scanned for info files. Each semi-colon-separated |
| 803 | entry is: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 804 | |
| 805 | - The full pathname of a folder containing layer info files |
| 806 | |
| 807 | #### Linux |
| 808 | |
| 809 | ##### Properly-Installed Layers |
| 810 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 811 | In order to find properly-installed layers, the Vulkan loader will use a |
| 812 | similar mechanism as used for ICDs. Text information files, that use a JSON |
| 813 | format, are read in order to identify the names and attributes of layers and |
| 814 | their extensions. The use of text info files allows the loader to avoid loading |
| 815 | any shared library files when the application does not query nor request any |
| 816 | extensions. Layers and extensions have additional complexity, and so their info |
| 817 | files contain more information than ICD info files. For example, a layer shared |
| 818 | library file may contain multiple layers/extensions (perhaps even an ICD). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 819 | |
| 820 | The Vulkan loader will scan the files in the following Linux directories: |
| 821 | |
| 822 | /usr/share/vulkan/explicit\_layer.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 823 | /usr/share/vulkan/implicit\_layer.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 824 | /etc/vulkan/explicit\_layer.d |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 825 | /etc/vulkan/implicit\_layer.d |
David Pinedo | 3e163ee | 2016-04-18 16:59:59 -0600 | [diff] [blame] | 826 | \$HOME/.local/share/vulkan/explicit\_layer.d |
| 827 | \$HOME/.local/share/vulkan/implicit\_layer.d |
Jon Ashburn | 7f00ca8 | 2016-02-24 12:00:55 -0700 | [diff] [blame] | 828 | |
| 829 | Where $HOME is the current home directory of the application's user id; this |
| 830 | path will be ignored for suid programs. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 831 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 832 | Explicit layers are those which are enabled by an application (e.g. with the |
| 833 | vkCreateInstance function), or by an environment variable (as mentioned |
| 834 | previously). Implicit layers are those which are enabled by their existence. |
| 835 | For example, certain application environments (e.g. Steam or an automotive |
| 836 | infotainment system) may have layers which they always want enabled for all |
| 837 | applications that they start. Other implicit layers may be for all applications |
| 838 | started on a given system (e.g. layers that overlay frames-per-second). |
| 839 | Implicit layers are enabled automatically, whereas explicit layers must be |
| 840 | enabled explicitly. What distinguishes a layer as implicit or explicit is by |
| 841 | which directory its layer information file exists in. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 842 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 843 | The "/usr/share/vulkan/\*\_layer.d" directories are for layers that are |
| 844 | installed from Linux-distribution-provided packages. The |
| 845 | "/etc/vulkan/\*\_layer.d" directories are for layers that are installed from |
| 846 | non-Linux-distribution-provided packages. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 847 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 848 | The information file is in the JSON format and contains the following |
| 849 | information: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 850 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 851 | - (required) "file\_format\_version" – same as for ICDs, except that the format |
| 852 | version can vary independently for ICDs and layers. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 853 | |
| 854 | - (required) "name" - layer name |
| 855 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 856 | - (required) "type" - which layer chains should the layer be activated on. |
| 857 | Allowable values are "INSTANCE", "DEVICE", "GLOBAL". Global means activate on |
| 858 | both device and instance chains. |
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) "library\_path" - filename / full path / relative path to the text |
| 861 | file |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 862 | |
| 863 | - (required) "api\_version" – same as for ICDs. |
| 864 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 865 | - (required) "implementation\_version" – layer version, a single number |
| 866 | increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 867 | |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 868 | - (required) "description" – informative description of the layer. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 869 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 870 | - (optional) "device\_extensions" or "instance\_extensions" - array of |
| 871 | extension information as follows |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 872 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 873 | - (required) extension "name" - Vulkan registered name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 874 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 875 | - (required) extension "spec\_version" - extension specification version, a |
| 876 | single number, increasing with backward compatible changes. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 877 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 878 | - (required for device extensions with entry points) extension |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 879 | "entrypoints" - array of device extension entry points; not used for instance |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 880 | extensions |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 881 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 882 | - (sometimes required) "functions" - mapping list of function entry points. If |
| 883 | multiple layers exist within the same shared library (or if a layer is in the |
| 884 | same shared library as an ICD), this must be specified to allow each layer to |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 885 | have its own vkGet\*ProcAddr entry points that can be found by the loader. At |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 886 | this time, only the following two functions are required: |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 887 | - "vkGetInstanceProcAddr" name |
| 888 | - "vkGetDeviceProcAddr" name |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 889 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 890 | - (optional for implicit layers) "enable\_environment" requirement(s) - |
| 891 | environment variable and value required to enable an implicit layer. This |
| 892 | environment variable (which should vary with each "version" of the layer, as in |
| 893 | "ENABLE\_LAYER\_FOO\_1") must be set to the given value or else the implicit |
| 894 | layer is not loaded. This is for application environments (e.g. Steam) which |
| 895 | want to enable a layer(s) only for applications that they launch, and allows |
| 896 | for applications run outside of an application environment to not get that |
| 897 | implicit layer(s). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 898 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 899 | - (required for implicit layers) "disable\_environment" requirement(s) - |
| 900 | environment variable and value required to disable an implicit layer. Note: in |
| 901 | rare cases of an application not working with an implicit layer, the |
| 902 | application can set this environment variable (before calling Vulkan functions) |
| 903 | in order to "blacklist" the layer. This environment variable (which should vary |
| 904 | with each "version" of the layer, as in "DISABLE\_LAYER\_FOO\_1") must be set |
| 905 | (not particularly to any value). If both the "enable\_environment" and |
| 906 | "disable\_environment" variables are set, the implicit layer is disabled. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 907 | |
| 908 | For example: |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 909 | ``` |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 910 | { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 911 | "file_format_version" : "1.0.0", |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 912 | "layer": { |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 913 | "name": "VK_LAYER_LUNARG_OverlayLayer", |
| 914 | "type": "DEVICE", |
| 915 | "library_path": "vkOverlayLayer.dll" |
Tony Barbour | d83f06c | 2016-03-08 14:50:03 -0700 | [diff] [blame] | 916 | "api_version" : "1.0.5", |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 917 | "implementation_version" : "2", |
| 918 | "description" : "LunarG HUD layer", |
| 919 | "functions": { |
| 920 | "vkGetInstanceProcAddr": "OverlayLayer_GetInstanceProcAddr", |
| 921 | "vkGetDeviceProcAddr": "OverlayLayer_GetDeviceProcAddr" |
| 922 | }, |
Jon Ashburn | 26ed3f3 | 2016-02-14 21:54:52 -0700 | [diff] [blame] | 923 | "instance_extensions": [ |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 924 | { |
| 925 | "name": "VK_debug_report_EXT", |
| 926 | "spec_version": "1" |
| 927 | }, |
| 928 | { |
| 929 | "name": "VK_VENDOR_DEBUG_X", |
| 930 | "spec_version": "3" |
| 931 | } |
| 932 | ], |
Courtney Goeltzenleuchter | 84a75ce | 2016-02-15 15:07:54 -0700 | [diff] [blame] | 933 | "device_extensions": [ |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 934 | { |
Jon Ashburn | 58048d0 | 2016-03-03 12:03:58 -0700 | [diff] [blame] | 935 | "name": "VK_DEBUG_MARKER_EXT", |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 936 | "spec_version": "1", |
| 937 | "entrypoints": ["vkCmdDbgMarkerBegin", "vkCmdDbgMarkerEnd"] |
| 938 | } |
| 939 | ], |
| 940 | "disable_environment": { |
| 941 | "DISABLE_LAYER_OVERLAY_1": "" |
| 942 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 943 | } |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 944 | } |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 945 | ``` |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 946 | The "library\_path" specifies either a filename, a relative pathname, or a full |
| 947 | pathname to a layer shared library (".so") file, which the loader will attempt |
| 948 | to load using dlopen(). If the layer is specified via a filename, the loader |
| 949 | will attempt to open that file as a shared object using dlopen(), and the file |
| 950 | must be in a directory that dlopen is configured to look in (Note: various |
| 951 | distributions are configured differently). A distribution is free to create |
| 952 | Vulkan-specific system directories (e.g. ".../vulkan/layers"), but is not |
| 953 | required to do so. If the layer is specified via a relative pathname, it is |
| 954 | relative to the path of the info file (e.g. for cases when an application |
| 955 | provides a layer that is in the same directory hierarchy as the rest of the |
| 956 | application files). |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 957 | |
| 958 | There are no rules about the name of the text files (except the .json suffix). |
| 959 | |
| 960 | There are no rules about the name of the layer shared library files. |
| 961 | |
| 962 | ##### Using Pre-Production Layers |
| 963 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 964 | As with ICDs, developers may need to use special, pre-production layers, |
| 965 | without modifying the properly-installed layers. This need is met with the use |
| 966 | of the "VK\_LAYER\_PATH" environment variable, which will override the |
| 967 | mechanism using for finding properly-installed layers. Because many layers may |
| 968 | exist on a system, this environment variable is a colon-separated list of |
| 969 | directories that contain layer info files. Only the directories listed in |
| 970 | "VK\_LAYER\_PATH" will be scanned for info files. Each colon-separated entry |
| 971 | is: |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 972 | |
| 973 | - The full pathname of a directory containing layer info files |
| 974 | |
| 975 | NOTE: these environment variables will be ignored for suid programs. |
| 976 | |
| 977 | #### Android |
| 978 | |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 979 | The recommended way to enable layers is for applications |
| 980 | to programatically enable them. The layers are provided by the application |
| 981 | and must live in the application's library folder. The application |
| 982 | enables the layers at vkCreateInstance and vkCreateDevice as any Vulkan |
| 983 | application would. |
| 984 | An application enabled for debug has more options. It can enumerate and enable |
| 985 | layers located in /data/local/vulkan/debug. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 986 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 987 | Layer interface requirements |
| 988 | ------------------------------------------------------ |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 989 | |
| 990 | #### Architectural interface overview |
| 991 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 992 | There are two key architectural features that drive the loader to layer library |
| 993 | interface: 1) separate and distinct instance and device call chains, and 2) |
| 994 | distributed dispatch. First these architectural features will be described and |
| 995 | then the detailed interface will be specified. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 996 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 997 | Call chains are the links of calls for a given Vulkan command from layer module |
| 998 | to layer module with the loader and or the ICD being the bottom most command. |
| 999 | Call chains are constructed at both the instance level and the device level by |
| 1000 | the loader with cooperation from the layer libraries. Instance call chains are |
| 1001 | constructed by the loader when layers are enabled at vkCreateInstance. Device |
| 1002 | call chains are constructed by the loader when layers are enabled at |
ttyio | 0811cec | 2016-04-10 22:09:44 +0800 | [diff] [blame] | 1003 | vkCreateDevice. A layer can intercept Vulkan instance commands, device commands |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1004 | or both. For a layer to intercept instance commands, it must participate in the |
| 1005 | instance call chain. For a layer to intercept device commands, it must |
| 1006 | participate in the device chain. Layers which participate in intercepting calls |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1007 | in both the instance and device chains are called global layers. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1008 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1009 | Normally, when a layer intercepts a given Vulkan command, it will call down the |
| 1010 | instance or device chain as needed. The loader and all layer libraries that |
| 1011 | 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] | 1012 | from one entity to the next. This group effort for call chain sequencing is |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1013 | hereinafter referred to as distributed dispatch. In distributed dispatch, since |
| 1014 | each layer is responsible for properly calling the next entity in the device or |
| 1015 | instance chain, a dispatch mechanism is required for all Vulkan commands a |
| 1016 | layer intercepts. For Vulkan commands that are not intercepted by a layer, or |
| 1017 | if the layer chooses to terminate a given Vulkan command by not calling down |
| 1018 | the chain, then no dispatch mechanism is needed for that particular Vulkan |
| 1019 | command. Only for those Vulkan commands, which may be a subset of all Vulkan |
| 1020 | commands, that a layer intercepts is a dispatching mechanism by the layer |
| 1021 | needed. The loader is responsible for dispatching all core and instance |
| 1022 | extension Vulkan commands to the first entity in the chain. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1023 | |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1024 | Instance level Vulkan commands are those that have the dispatchable objects |
| 1025 | VkInstance, or VkPhysicalDevice as the first parameter and also includes |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1026 | vkCreateInstance. |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1027 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1028 | Device level Vulkan commands are those that use VkDevice, VkQueue or |
| 1029 | VkCommandBuffer as the first parameter and also include vkCreateDevice. Future |
| 1030 | extensions may introduce new instance or device level dispatchable objects, so |
| 1031 | the above lists may be extended in the future. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1032 | |
Chia-I Wu | cb24fec | 2016-04-20 06:23:24 +0800 | [diff] [blame^] | 1033 | #### Layer Library Interface |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1034 | |
Chia-I Wu | cb24fec | 2016-04-20 06:23:24 +0800 | [diff] [blame^] | 1035 | A layer library is a container of layers. This section defines an extensible |
| 1036 | programming interface to discover layers contained in layer libraries. It |
| 1037 | also specifies the minimal conventions and rules a layer must follow. |
| 1038 | |
| 1039 | Other sections might have other guidelines that layers, at least validation |
| 1040 | layers, should follow. |
| 1041 | |
| 1042 | ##### Layer Conventions and Rules |
| 1043 | |
| 1044 | A layer, when inserted into an otherwise compliant Vulkan implementation, must |
| 1045 | still result in a compliant Vulkan implementation[\*]. It must additionally |
| 1046 | follow some conventions and rules. |
| 1047 | |
| 1048 | A layer is always chained with other layers. It must not make invalid calls |
| 1049 | to or rely on undefined behaviors of its lower layers. When it changes the |
| 1050 | behavior of a command, it must make sure its upper layers do not make invalid |
| 1051 | calls to or rely on undefined behaviors of its lower layers because of the |
| 1052 | changed behavior. For example, when a layer intercepts an object creation |
| 1053 | command to wrap the objects created by its lower layers, it must make sure its |
| 1054 | lower layers never see the wrapping objects, directly from itself or |
| 1055 | indirectly from its upper layers. |
| 1056 | |
| 1057 | When a layer requires host memory, it is free to scope the allocations to |
| 1058 | itself, bypassing the provided allocators entirely. |
| 1059 | |
| 1060 | `vkEnumerateInstanceLayerProperties` must always fail with |
| 1061 | `VK_ERROR_LAYER_NOT_PRESENT`. |
| 1062 | |
| 1063 | `vkEnumerateInstanceExtensionProperties` must always fail with |
| 1064 | `VK_ERROR_LAYER_NOT_PRESENT`, including when `pLayerName` is `NULL`. |
| 1065 | |
| 1066 | `vkEnumerateDeviceLayerProperties` must always fail with |
| 1067 | `VK_ERROR_LAYER_NOT_PRESENT`. |
| 1068 | |
| 1069 | `vkEnumerateDeviceExtensionProperties` must always fail with |
| 1070 | `VK_ERROR_LAYER_NOT_PRESENT`, except when `pLayerName` is `NULL`. It must |
| 1071 | handle the case where `pLayerName` is `NULL`, usually by chaining to other |
| 1072 | layers. |
| 1073 | |
| 1074 | `vkGetInstanceProcAddr` can intercept a command by returning a function |
| 1075 | pointer different from what would be returned through chaining. |
| 1076 | |
| 1077 | `vkGetDeviceProcAddr` can intercept a command by returning a function pointer |
| 1078 | different from what would be returned through chaining. |
| 1079 | |
| 1080 | `vkCreateInstance` must not generate an error for unrecognized layer names, |
| 1081 | extension names, and `pNext` structs. It may assume the layer names and |
| 1082 | extension names have been validated. |
| 1083 | |
| 1084 | `vkCreateDevice` must not generate an error for unrecognized layer names, |
| 1085 | extension names, and `pNext` structs. It may assume the layer names and |
| 1086 | extension names have been validated. |
| 1087 | |
| 1088 | [\*]: The intention is for layers to have a well-defined baseline behavior. |
| 1089 | Some of the conventions or rules, for example, may be considered abuses of the |
| 1090 | specification. |
| 1091 | |
| 1092 | ###### Layer Library Interface Version 0 |
| 1093 | |
| 1094 | A layer library supporting interface version 0 must define and export these |
| 1095 | functions, unrelated to any Vulkan command despite the names, signatures, and |
| 1096 | other similarities: |
| 1097 | |
| 1098 | - `vkEnumerateInstanceLayerProperties` enumerates all instance layers in a |
| 1099 | layer library. This function never fails. |
| 1100 | |
| 1101 | - `vkEnumerateInstanceExtensionProperties` enumerates instance extensions of |
| 1102 | instance layers in a layer library. `pLayerName` is always a valid |
| 1103 | instance layer name. This function never fails. |
| 1104 | |
| 1105 | - `vkEnumerateDeviceLayerProperties` enumerates all device layers in a layer |
| 1106 | library. `physicalDevice` is always `VK_NULL_HANDLE`. This function never |
| 1107 | fails. |
| 1108 | |
| 1109 | - `vkEnumerateDeviceExtensionProperties` enumerates device extensions of |
| 1110 | device layers in a layer library. `physicalDevice` is always |
| 1111 | `VK_NULL_HANDLE`. `pLayerName` is always a valid device layer name. This |
| 1112 | function never fails. |
| 1113 | |
| 1114 | - `<layerName>GetInstanceProcAddr` behaves as if `<layerName>`'s |
| 1115 | `vkGetInstanceProcAddr` is called, except |
| 1116 | |
| 1117 | - when `pName` is `vkEnumerateInstanceLayerProperties`, |
| 1118 | `vkEnumerateInstanceExtensionProperties`, or |
| 1119 | `vkEnumerateDeviceLayerProperties` (but _not_ |
| 1120 | `vkEnumerateDeviceExtensionProperties`), it returns a function pointer to |
| 1121 | the function of the same name defined by this interface. |
| 1122 | - when `pName` is `vkGetInstanceProcAddr`, it returns a function pointer |
| 1123 | to itself. |
| 1124 | - when `pName` is `vkCreateDevice`, it ignores `instance`. |
| 1125 | - when `pName` is a device command defined by Vulkan 1.0 or |
| 1126 | `VK_KHR_swapchain` (but _not_ other device commands), it may chain to |
| 1127 | other layers without intercepting. A loader should avoid querying such |
| 1128 | device commands. |
| 1129 | |
| 1130 | When a layer library contains only one layer, this function may |
| 1131 | alternatively be named `vkGetInstanceProcAddr`. |
| 1132 | |
| 1133 | - `<layerName>GetDeviceProcAddr` behaves as if `<layerName>`'s |
| 1134 | `vkGetDeviceProcAddr` is called. |
| 1135 | |
| 1136 | When a layer library contains only one layer, this function may |
| 1137 | alternatively be named `vkGetDeviceProcAddr`. |
| 1138 | |
| 1139 | All contained layers must support [`vk_layer.h`][]. They do not need to |
| 1140 | implement commands that are not queryable. They are recommended not to export |
| 1141 | any command. |
| 1142 | |
| 1143 | [`vk_layer.h`]: ../include/vulkan/vk_layer.h |
| 1144 | |
| 1145 | #### Layer Libraries and Manifest Files |
| 1146 | |
| 1147 | The layer libraries and the manifest files must be kept in sync. On Windows |
| 1148 | and Linux, the loader uses manifest files to discover layer libraries and |
| 1149 | layers. On Android, the loader inspects the layer libraries directly. |
| 1150 | |
| 1151 | The manifest file specifies in its "functions", "vkGetInstanceProcAddr" node |
| 1152 | the function name the loader will use to discover |
| 1153 | <layerName>GetInstanceProcAddr. When the layer library exports |
| 1154 | <layerName>GetInstanceProcAddr, the JSON node must explicitly specify that |
| 1155 | function name. When the layer library exports vkGetInstanceProcAddr, the JSON |
| 1156 | node may be omitted. The layer library may additionally export another alias |
| 1157 | and specify that in the JSON node. |
| 1158 | |
| 1159 | Similarly, the manifest file specifies in its "functions", |
| 1160 | "vkGetDeviceProcAddr" node the function name the loader will use to discover |
| 1161 | <layerName>GetDeviceProcAddr. When the layer library exports |
| 1162 | <layerName>GetDeviceProcAddr, the JSON node must explicitly specify that |
| 1163 | function name. When the layer library exports vkGetDeviceProcAddr, the JSON |
| 1164 | node may be omitted. The layer library may additionally export another alias |
| 1165 | and specify that in the JSON node. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1166 | |
| 1167 | #### Layer intercept requirements |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1168 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1169 | - Layers intercept a Vulkan command by defining a C/C++ function with signature |
| 1170 | identical to the Vulkan API for that command. |
Chia-I Wu | cb24fec | 2016-04-20 06:23:24 +0800 | [diff] [blame^] | 1171 | - An instance layer must intercept at least vkGetInstanceProcAddr and |
| 1172 | vkCreateInstance. A device layer must intercept at least vkGetDeviceProcAddr |
| 1173 | and vkCreateDevice. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1174 | - Other than the two vkGet*ProcAddr, all other functions intercepted by a layer |
| 1175 | need NOT be exported by the layer. |
| 1176 | - For any Vulkan command a layer intercepts which has a non-void return value, |
| 1177 | an appropriate value must be returned by the layer intercept function. |
| 1178 | - The layer intercept function must call down the chain to the corresponding |
| 1179 | Vulkan command in the next entity. Undefined results will occur if a layer |
| 1180 | doesn't propagate calls down the chain. The two exceptions to this requirement |
| 1181 | are vkGetInstanceProcAddr and vkGetDeviceProcAddr which only call down the |
| 1182 | chain for Vulkan commands that they do not intercept. |
| 1183 | - Layer intercept functions may insert extra calls to Vulkan commands in |
| 1184 | addition to the intercept. For example, a layer intercepting vkQueueSubmit may |
| 1185 | want to add a call to vkQueueWaitIdle after calling down the chain for |
| 1186 | vkQueueSubmit. Any additional calls inserted by a layer must be on the same |
| 1187 | chain. They should call down the chain. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1188 | |
| 1189 | #### Distributed dispatching requirements |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1190 | |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1191 | - For each entry point a layer intercepts, it must keep track of the entry |
| 1192 | point residing in the next entity in the chain it will call down into. In other |
| 1193 | words, the layer must have a list of pointers to functions of the appropriate |
| 1194 | type to call into the next entity. This can be implemented in various ways but |
| 1195 | for clarity will be referred to as a dispatch table. |
| 1196 | - A layer can use the VkLayerDispatchTable structure as a device dispatch table |
| 1197 | (see include/vulkan/vk_layer.h). |
| 1198 | - A layer can use the VkLayerInstanceDispatchTable structure as a instance |
| 1199 | dispatch table (see include/vulkan/vk_layer.h). |
| 1200 | - Layers vkGetInstanceProcAddr function uses the next entity's |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1201 | vkGetInstanceProcAddr to call down the chain for unknown (i.e. non-intercepted) |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1202 | functions. |
| 1203 | - Layers vkGetDeviceProcAddr function uses the next entity's |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1204 | vkGetDeviceProcAddr to call down the chain for unknown (i.e. non-intercepted) |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1205 | functions. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1206 | |
| 1207 | #### Layer dispatch initialization |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1208 | |
| 1209 | - A layer initializes its instance dispatch table within its vkCreateInstance |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1210 | function. |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1211 | - A layer initializes its device dispatch table within its vkCreateDevice |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1212 | function. |
| 1213 | - The loader passes a linked list of initialization structures to layers via |
| 1214 | the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo structures |
| 1215 | for vkCreateInstance and VkCreateDevice respectively. |
| 1216 | - The head node in this linked list is of type VkLayerInstanceCreateInfo for |
Courtney Goeltzenleuchter | 42c4cdb | 2016-02-14 11:42:24 -0700 | [diff] [blame] | 1217 | instance and VkLayerDeviceCreateInfo for device. See file |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1218 | include/vulkan/vk_layer.h for details. |
| 1219 | - A VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO is used by the loader for the |
| 1220 | "sType" field in VkLayerInstanceCreateInfo. |
| 1221 | - A VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO is used by the loader for the |
| 1222 | "sType" field in VkLayerDeviceCreateInfo. |
| 1223 | - The "function" field indicates how the union field "u" should be interpreted |
| 1224 | within VkLayer*CreateInfo. The loader will set the "function" field to |
| 1225 | VK_LAYER_LINK_INFO. This indicates "u" field should be VkLayerInstanceLink or |
| 1226 | VkLayerDeviceLink. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1227 | - The VkLayerInstanceLink and VkLayerDeviceLink structures are the list nodes. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1228 | - The VkLayerInstanceLink contains the next entity's vkGetInstanceProcAddr used |
| 1229 | by a layer. |
| 1230 | - The VkLayerDeviceLink contains the next entity's vkGetInstanceProcAddr and |
| 1231 | vkGetDeviceProcAddr used by a layer. |
| 1232 | - Given the above structures set up by the loader, layer must initialize their |
| 1233 | dispatch table as follows: |
| 1234 | - Find the VkLayerInstanceCreateInfo/VkLayerDeviceCreateInfo structure in |
| 1235 | the VkInstanceCreateInfo/VkDeviceCreateInfo structure. |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1236 | - Get the next entity's vkGet*ProcAddr from the "pLayerInfo" field. |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1237 | - For CreateInstance get the next entity's vkCreateInstance by calling the |
| 1238 | "pfnNextGetInstanceProcAddr": |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1239 | pfnNextGetInstanceProcAddr(NULL, "vkCreateInstance"). |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1240 | - For CreateDevice get the next entity's vkCreateDevice by calling the |
| 1241 | "pfnNextGetInstanceProcAddr": |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1242 | pfnNextGetInstanceProcAddr(NULL, "vkCreateDevice"). |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1243 | - Advanced the linked list to the next node: pLayerInfo = pLayerInfo->pNext. |
| 1244 | - Call down the chain either CreateDevice or CreateInstance |
Courtney Goeltzenleuchter | a147376 | 2016-02-14 09:31:24 -0700 | [diff] [blame] | 1245 | - Initialize your layer dispatch table by calling the next entity's |
| 1246 | Get*ProcAddr function once for each Vulkan command needed in your dispatch |
| 1247 | table |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1248 | |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1249 | #### Example code for CreateInstance |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame] | 1250 | |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1251 | ```cpp |
| 1252 | VkResult vkCreateInstance( |
| 1253 | const VkInstanceCreateInfo *pCreateInfo, |
| 1254 | const VkAllocationCallbacks *pAllocator, |
| 1255 | VkInstance *pInstance) |
| 1256 | { |
| 1257 | VkLayerInstanceCreateInfo *chain_info = |
| 1258 | get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 1259 | |
| 1260 | assert(chain_info->u.pLayerInfo); |
| 1261 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = |
| 1262 | chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 1263 | PFN_vkCreateInstance fpCreateInstance = |
| 1264 | (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
| 1265 | if (fpCreateInstance == NULL) { |
| 1266 | return VK_ERROR_INITIALIZATION_FAILED; |
| 1267 | } |
| 1268 | |
| 1269 | // Advance the link info for the next element of the chain |
| 1270 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 1271 | |
| 1272 | // Continue call down the chain |
| 1273 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 1274 | if (result != VK_SUCCESS) |
| 1275 | return result; |
| 1276 | |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1277 | // Init layer's dispatch table using GetInstanceProcAddr of |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1278 | // next layer in the chain. |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1279 | instance_dispatch_table = new VkLayerInstanceDispatchTable; |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1280 | layer_init_instance_dispatch_table( |
| 1281 | *pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
| 1282 | |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1283 | // Other layer initialization |
| 1284 | ... |
| 1285 | |
| 1286 | return VK_SUCCESS; |
| 1287 | } |
| 1288 | ``` |
| 1289 | |
| 1290 | #### Example code for CreateDevice |
| 1291 | |
| 1292 | ```cpp |
| 1293 | VkResult |
| 1294 | vkCreateDevice( |
| 1295 | VkPhysicalDevice gpu, |
| 1296 | const VkDeviceCreateInfo *pCreateInfo, |
| 1297 | const VkAllocationCallbacks *pAllocator, |
| 1298 | VkDevice *pDevice) |
| 1299 | { |
| 1300 | VkLayerDeviceCreateInfo *chain_info = |
| 1301 | get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 1302 | |
| 1303 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = |
| 1304 | chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 1305 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = |
| 1306 | chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
| 1307 | PFN_vkCreateDevice fpCreateDevice = |
| 1308 | (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice"); |
| 1309 | if (fpCreateDevice == NULL) { |
| 1310 | return VK_ERROR_INITIALIZATION_FAILED; |
| 1311 | } |
| 1312 | |
| 1313 | // Advance the link info for the next element on the chain |
| 1314 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 1315 | |
| 1316 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 1317 | if (result != VK_SUCCESS) { |
| 1318 | return result; |
| 1319 | } |
| 1320 | |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1321 | // initialize layer's dispatch table |
| 1322 | device_dispatch_table = new VkLayerDispatchTable; |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1323 | layer_init_device_dispatch_table( |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1324 | *pDevice, device_dispatch_table, fpGetDeviceProcAddr); |
Courtney Goeltzenleuchter | f6abc20 | 2016-02-15 15:05:16 -0700 | [diff] [blame] | 1325 | |
| 1326 | // Other layer initialization |
| 1327 | ... |
| 1328 | |
| 1329 | return VK_SUCCESS; |
| 1330 | } |
| 1331 | ``` |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame] | 1332 | |
Jon Ashburn | cc300a2 | 2016-02-11 14:57:30 -0700 | [diff] [blame] | 1333 | #### Special Considerations |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1334 | ##### Associating private data with Vulkan objects within a layer |
Courtney Goeltzenleuchter | 7221a5a | 2016-02-15 14:59:37 -0700 | [diff] [blame] | 1335 | A layer may want to associate it's own private data with one or more Vulkan |
| 1336 | objects. |
| 1337 | Two common methods to do this are hash maps and object wrapping. The loader |
| 1338 | supports layers wrapping any Vulkan object including dispatchable objects. |
| 1339 | Layers which wrap objects should ensure they always unwrap objects before |
| 1340 | passing them down the chain. This implies the layer must intercept every Vulkan |
| 1341 | command which uses the object in question. Layers above the object wrapping |
Jon Ashburn | 859c7fb | 2016-03-02 17:26:31 -0700 | [diff] [blame] | 1342 | layer will see the wrapped object. Layers which wrap dispatchable objects must |
| 1343 | ensure that the first field in the wrapping structure is a pointer to a dispatch table |
| 1344 | as defined in vk_layer.h. Specifically, an instance wrapped dispatchable object |
| 1345 | could be as follows: |
| 1346 | ``` |
| 1347 | struct my_wrapped_instance_obj_ { |
| 1348 | VkLayerInstanceDispatchTable *disp; |
| 1349 | // whatever data layer wants to add to this object |
| 1350 | }; |
| 1351 | ``` |
| 1352 | A device wrapped dispatchable object could be as follows: |
| 1353 | ``` |
| 1354 | struct my_wrapped_instance_obj_ { |
| 1355 | VkLayerDispatchTable *disp; |
| 1356 | // whatever data layer wants to add to this object |
| 1357 | }; |
| 1358 | ``` |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1359 | |
| 1360 | Alternatively, a layer may want to use a hash map to associate data with a |
Courtney Goeltzenleuchter | 7221a5a | 2016-02-15 14:59:37 -0700 | [diff] [blame] | 1361 | given object. The key to the map could be the object. Alternatively, for |
| 1362 | dispatchable objects at a given level (eg device or instance) the layer may |
| 1363 | want data associated with the VkDevice or VkInstance objects. Since |
Jeff Juliano | f161987 | 2016-02-17 17:25:42 -0500 | [diff] [blame] | 1364 | there are multiple dispatchable objects for a given VkInstance or VkDevice, the |
| 1365 | VkDevice or VkInstance object is not a great map key. Instead the layer should |
| 1366 | use the dispatch table pointer within the VkDevice or VkInstance since that |
| 1367 | will be unique for a given VkInstance or VkDevice. |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame] | 1368 | |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1369 | ##### Creating new dispatchable objects |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame] | 1370 | Layers which create dispatchable objects take special care. Remember that loader |
| 1371 | trampoline code normally fills in the dispatch table pointer in the newly |
| 1372 | created object. Thus, the layer must fill in the dispatch table pointer if the |
Jon Ashburn | 859c7fb | 2016-03-02 17:26:31 -0700 | [diff] [blame] | 1373 | loader trampoline will not do so. Common cases where a layer (or ICD) may create a |
Courtney Goeltzenleuchter | 7221a5a | 2016-02-15 14:59:37 -0700 | [diff] [blame] | 1374 | dispatchable object without loader trampoline code is as follows: |
Jon Ashburn | fe630fb | 2016-02-14 21:40:34 -0700 | [diff] [blame] | 1375 | - object wrapping layers that wrap dispatchable objects |
| 1376 | - layers which add extensions that create dispatchable objects |
| 1377 | - layers which insert extra Vulkan commands in the stream of commands they |
| 1378 | intercept from the application |
Jon Ashburn | 859c7fb | 2016-03-02 17:26:31 -0700 | [diff] [blame] | 1379 | - ICDs which add extensions that create dispatchable objects |
| 1380 | |
Jon Ashburn | 2b2f618 | 2016-04-04 16:37:37 -0600 | [diff] [blame] | 1381 | The Windows/Linux loader provides a callback that can be used for initializing |
| 1382 | a dispatchable object. The callback is passed as an extension structure via the |
| 1383 | pNext field in VkInstanceCreateInfo and VkDeviceCreateInfo. The callback prototype |
| 1384 | is defined as follows for instance and device callbacks respectively (see vk_layer.h): |
| 1385 | ``` |
| 1386 | VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceLoaderData(VkInstance instance, void *object); |
| 1387 | VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceLoaderData)(VkDevice device, void *object); |
| 1388 | ``` |
| 1389 | To obtain these callbacks the layer must search through the list of structures |
| 1390 | pointed to by the "pNext" field in the VkInstanceCreateInfo and VkDeviceCreateInfo parameters to find any callback structures inserted by the loader. The salient details are as follows: |
| 1391 | - For CreateInstance the callback structure pointed to by "pNext" is VkLayerInstanceCreateInfo as defined in vk_layer.h. |
| 1392 | - A "sType" field in of VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO within VkInstanceCreateInfo parameter indicates a loader structure. |
| 1393 | - Within VkLayerInstanceCreateInfo, the "function" field indicates how the union field "u" should be interpreted. |
| 1394 | - A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetInstanceLoaderData". |
| 1395 | - For CreateDevice the callback structure pointed to by "pNext" is VkLayerDeviceCreateInfo as defined in include/vulkan/vk_layer.h. |
| 1396 | - A "sType" field in of VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO within VkDeviceCreateInfo parameter indicates a loader structure. |
| 1397 | - Within VkLayerDeviceCreateInfo, the "function" field indicates how the union field "u" should be interpreted. |
| 1398 | - A "function" equal to VK_LOADER_DATA_CALLBACK indicates the "u" field will contain the callback in "pfnSetDeviceLoaderData". |
| 1399 | |
| 1400 | Alternatively, if an older loader is being used that doesn't provide these callbacks, the layer may manually initialize the newly created dispatchable object. |
Jon Ashburn | 859c7fb | 2016-03-02 17:26:31 -0700 | [diff] [blame] | 1401 | To fill in the dispatch table pointer in newly created dispatchable object, |
| 1402 | the layer should copy the dispatch pointer, which is always the first entry in the structure, from an existing parent object of the same level (instance versus |
| 1403 | device). For example, if there is a newly created VkCommandBuffer object, then the dispatch pointer from the VkDevice object, which is the parent of the VkCommandBuffer object, should be copied into the newly created object. |
Jon Ashburn | c297268 | 2016-02-08 15:42:01 -0700 | [diff] [blame] | 1404 | |