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