1// Copyright (c) 2015-2018 Khronos Group. This work is licensed under a 2// Creative Commons Attribution 4.0 International License; see 3// http://creativecommons.org/licenses/by/4.0/ 4 5[[extended-functionality]] 6= Extended Functionality 7 8Additional functionality may: be provided by layers or extensions. 9A layer cannot: add or modify Vulkan commands, while an extension may: do 10so. 11 12The set of layers to enable is specified when creating an instance, and 13those layers are able to intercept any Vulkan command dispatched to that 14instance or any of its child objects. 15 16Extensions can operate at either the instance or device _extension scope_. 17Enabled instance extensions are able to affect the operation of the instance 18and any of its child objects, while device extensions may: only be available 19on a subset of physical devices, must: be individually enabled per-device, 20and only affect the operation of the devices where they are enabled. 21 22[NOTE] 23.Note 24==== 25Examples of these might be: 26 27 * Whole API validation is an example of a layer. 28 * Debug capabilities might make a good instance extension. 29 * A layer that provides implementation-specific performance telemetry and 30 analysis could be a layer that is only active for devices created from 31 compatible physical devices. 32 * Functions to allow an application to use additional implementation 33 features beyond the core would be a good candidate for a device 34 extension. 35==== 36 37[[extended-functionality-layers]] 38== Layers 39 40When a layer is enabled, it inserts itself into the call chain for Vulkan 41commands the layer is interested in. 42A common use of layers is to validate application behavior during 43development. 44For example, the implementation will not check that Vulkan enums used by the 45application fall within allowed ranges. 46Instead, a validation layer would do those checks and flag issues. 47This avoids a performance penalty during production use of the application 48because those layers would not be enabled in production. 49 50Vulkan layers may: wrap object handles (i.e. return a different handle value 51to the application than that generated by the implementation). 52This is generally discouraged, as it increases the probability of 53incompatibilities with new extensions. 54The validation layers wrap handles in order to track the proper use and 55destruction of each object. 56See the <<LoaderAndLayerInterface, "`Vulkan Loader Specification and 57Architecture Overview`">> document for additional information. 58 59[open,refpage='vkEnumerateInstanceLayerProperties',desc='Returns up to requested number of global layer properties',type='protos'] 60-- 61 62To query the available layers, call: 63 64include::../api/protos/vkEnumerateInstanceLayerProperties.txt[] 65 66 * pname:pPropertyCount is a pointer to an integer related to the number of 67 layer properties available or queried, as described below. 68 * pname:pProperties is either `NULL` or a pointer to an array of 69 slink:VkLayerProperties structures. 70 71If pname:pProperties is `NULL`, then the number of layer properties 72available is returned in pname:pPropertyCount. 73Otherwise, pname:pPropertyCount must: point to a variable set by the user to 74the number of elements in the pname:pProperties array, and on return the 75variable is overwritten with the number of structures actually written to 76pname:pProperties. 77If pname:pPropertyCount is less than the number of layer properties 78available, at most pname:pPropertyCount structures will be written. 79If pname:pPropertyCount is smaller than the number of layers available, 80ename:VK_INCOMPLETE will be returned instead of ename:VK_SUCCESS, to 81indicate that not all the available layer properties were returned. 82 83The list of available layers may change at any time due to actions outside 84of the Vulkan implementation, so two calls to 85fname:vkEnumerateInstanceLayerProperties with the same parameters may: 86return different results, or retrieve different pname:pPropertyCount values 87or pname:pProperties contents. 88Once an instance has been created, the layers enabled for that instance will 89continue to be enabled and valid for the lifetime of that instance, even if 90some of them become unavailable for future instances. 91 92include::../validity/protos/vkEnumerateInstanceLayerProperties.txt[] 93-- 94 95[open,refpage='VkLayerProperties',desc='Structure specifying layer properties',type='structs'] 96-- 97 98The sname:VkLayerProperties structure is defined as: 99 100include::../api/structs/VkLayerProperties.txt[] 101 102 * pname:layerName is a null-terminated UTF-8 string specifying the name of 103 the layer. 104 Use this name in the pname:ppEnabledLayerNames array passed in the 105 slink:VkInstanceCreateInfo structure to enable this layer for an 106 instance. 107 * pname:specVersion is the Vulkan version the layer was written to, 108 encoded as described in the <<fundamentals-versionnum,API Version 109 Numbers and Semantics>> section. 110 * pname:implementationVersion is the version of this layer. 111 It is an integer, increasing with backward compatible changes. 112 * pname:description is a null-terminated UTF-8 string providing additional 113 details that can: be used by the application to identify the layer. 114 115include::../validity/structs/VkLayerProperties.txt[] 116-- 117 118To enable a layer, the name of the layer should: be added to the 119pname:ppEnabledLayerNames member of slink:VkInstanceCreateInfo when creating 120a sname:VkInstance. 121 122Loader implementations may: provide mechanisms outside the Vulkan API for 123enabling specific layers. 124Layers enabled through such a mechanism are _implicitly enabled_, while 125layers enabled by including the layer name in the pname:ppEnabledLayerNames 126member of slink:VkInstanceCreateInfo are _explicitly enabled_. 127Except where otherwise specified, implicitly enabled and explicitly enabled 128layers differ only in the way they are enabled. 129Explicitly enabling a layer that is implicitly enabled has no additional 130effect. 131 132 133[[extended-functionality-device-layer-deprecation]] 134=== Device Layer Deprecation 135 136Previous versions of this specification distinguished between instance and 137device layers. 138Instance layers were only able to intercept commands that operate on 139sname:VkInstance and sname:VkPhysicalDevice, except they were not able to 140intercept flink:vkCreateDevice. 141Device layers were enabled for individual devices when they were created, 142and could only intercept commands operating on that device or its child 143objects. 144 145Device-only layers are now deprecated, and this specification no longer 146distinguishes between instance and device layers. 147Layers are enabled during instance creation, and are able to intercept all 148commands operating on that instance or any of its child objects. 149At the time of deprecation there were no known device-only layers and no 150compelling reason to create one. 151 152In order to maintain compatibility with implementations released prior to 153device-layer deprecation, applications should: still enumerate and enable 154device layers. 155The behavior of fname:vkEnumerateDeviceLayerProperties and valid usage of 156the pname:ppEnabledLayerNames member of sname:VkDeviceCreateInfo maximizes 157compatibility with applications written to work with the previous 158requirements. 159 160[open,refpage='vkEnumerateDeviceLayerProperties',desc='Returns properties of available physical device layers',type='protos'] 161-- 162 163To enumerate device layers, call: 164 165include::../api/protos/vkEnumerateDeviceLayerProperties.txt[] 166 167 * pname:pPropertyCount is a pointer to an integer related to the number of 168 layer properties available or queried. 169 * pname:pProperties is either `NULL` or a pointer to an array of 170 slink:VkLayerProperties structures. 171 172If pname:pProperties is `NULL`, then the number of layer properties 173available is returned in pname:pPropertyCount. 174Otherwise, pname:pPropertyCount must: point to a variable set by the user to 175the number of elements in the pname:pProperties array, and on return the 176variable is overwritten with the number of structures actually written to 177pname:pProperties. 178If pname:pPropertyCount is less than the number of layer properties 179available, at most pname:pPropertyCount structures will be written. 180If pname:pPropertyCount is smaller than the number of layers available, 181ename:VK_INCOMPLETE will be returned instead of ename:VK_SUCCESS, to 182indicate that not all the available layer properties were returned. 183 184The list of layers enumerated by fname:vkEnumerateDeviceLayerProperties 185must: be exactly the sequence of layers enabled for the instance. 186The members of sname:VkLayerProperties for each enumerated layer must: be 187the same as the properties when the layer was enumerated by 188fname:vkEnumerateInstanceLayerProperties. 189 190include::../validity/protos/vkEnumerateDeviceLayerProperties.txt[] 191-- 192 193The pname:ppEnabledLayerNames and pname:enabledLayerCount members of 194sname:VkDeviceCreateInfo are deprecated and their values must: be ignored by 195implementations. 196However, for compatibility, only an empty list of layers or a list that 197exactly matches the sequence enabled at instance creation time are valid, 198and validation layers should: issue diagnostics for other cases. 199 200Regardless of the enabled layer list provided in sname:VkDeviceCreateInfo, 201the sequence of layers active for a device will be exactly the sequence of 202layers enabled when the parent instance was created. 203 204 205[[extended-functionality-extensions]] 206== Extensions 207 208Extensions may: define new Vulkan commands, structures, and enumerants. 209For compilation purposes, the interfaces defined by registered extensions, 210including new structures and enumerants as well as function pointer types 211for new commands, are defined in the Khronos-supplied `vulkan_core.h` 212together with the core API. 213However, commands defined by extensions may: not be available for static 214linking - in which case function pointers to these commands should: be 215queried at runtime as described in <<initialization-functionpointers>>. 216Extensions may: be provided by layers as well as by a Vulkan implementation. 217 218Because extensions may: extend or change the behavior of the Vulkan API, 219extension authors should: add support for their extensions to the Khronos 220validation layers. 221This is especially important for new commands whose parameters have been 222wrapped by the validation layers. 223See the <<LoaderAndLayerInterface, "`Vulkan Loader Specification and 224Architecture Overview`">> document for additional information. 225 226[NOTE] 227.Note 228==== 229Valid Usage sections for individual commands and structures do not currently 230contain which extensions have to be enabled in order to make their use 231valid, although it might do so in the future. 232It is defined only in the <<fundamentals-validusage-extensions>> section. 233==== 234 235[open,refpage='vkEnumerateInstanceExtensionProperties',desc='Returns up to requested number of global extension properties',type='protos'] 236-- 237 238To query the available instance extensions, call: 239 240include::../api/protos/vkEnumerateInstanceExtensionProperties.txt[] 241 242 * pname:pLayerName is either `NULL` or a pointer to a null-terminated 243 UTF-8 string naming the layer to retrieve extensions from. 244 * pname:pPropertyCount is a pointer to an integer related to the number of 245 extension properties available or queried, as described below. 246 * pname:pProperties is either `NULL` or a pointer to an array of 247 slink:VkExtensionProperties structures. 248 249When pname:pLayerName parameter is `NULL`, only extensions provided by the 250Vulkan implementation or by implicitly enabled layers are returned. 251When pname:pLayerName is the name of a layer, the instance extensions 252provided by that layer are returned. 253 254If pname:pProperties is `NULL`, then the number of extensions properties 255available is returned in pname:pPropertyCount. 256Otherwise, pname:pPropertyCount must: point to a variable set by the user to 257the number of elements in the pname:pProperties array, and on return the 258variable is overwritten with the number of structures actually written to 259pname:pProperties. 260If pname:pPropertyCount is less than the number of extension properties 261available, at most pname:pPropertyCount structures will be written. 262If pname:pPropertyCount is smaller than the number of extensions available, 263ename:VK_INCOMPLETE will be returned instead of ename:VK_SUCCESS, to 264indicate that not all the available properties were returned. 265 266Because the list of available layers may change externally between calls to 267pname:vkEnumerateInstanceExtensionProperties, two calls may retrieve 268different results if a pname:pLayerName is available in one call but not in 269another. 270The extensions supported by a layer may also change between two calls, e.g. 271if the layer implementation is replaced by a different version between those 272calls. 273 274include::../validity/protos/vkEnumerateInstanceExtensionProperties.txt[] 275-- 276 277To enable an instance extension, the name of the extension should: be added 278to the pname:ppEnabledExtensionNames member of slink:VkInstanceCreateInfo 279when creating a sname:VkInstance. 280 281Enabling an extension does not change behavior of functionality exposed by 282the core Vulkan API or any other extension, other than making valid the use 283of the commands, enums and structures defined by that extension. 284 285[open,refpage='vkEnumerateDeviceExtensionProperties',desc='Returns properties of available physical device extensions',type='protos'] 286-- 287 288To query the extensions available to a given physical device, call: 289 290include::../api/protos/vkEnumerateDeviceExtensionProperties.txt[] 291 292 * pname:physicalDevice is the physical device that will be queried. 293 * pname:pLayerName is either `NULL` or a pointer to a null-terminated 294 UTF-8 string naming the layer to retrieve extensions from. 295 * pname:pPropertyCount is a pointer to an integer related to the number of 296 extension properties available or queried, and is treated in the same 297 fashion as the 298 flink:vkEnumerateInstanceExtensionProperties::pname:pPropertyCount 299 parameter. 300 * pname:pProperties is either `NULL` or a pointer to an array of 301 slink:VkExtensionProperties structures. 302 303When pname:pLayerName parameter is `NULL`, only extensions provided by the 304Vulkan implementation or by implicitly enabled layers are returned. 305When pname:pLayerName is the name of a layer, the device extensions provided 306by that layer are returned. 307 308include::../validity/protos/vkEnumerateDeviceExtensionProperties.txt[] 309-- 310 311[open,refpage='VkExtensionProperties',desc='Structure specifying an extension properties',type='structs'] 312-- 313 314The sname:VkExtensionProperties structure is defined as: 315 316include::../api/structs/VkExtensionProperties.txt[] 317 318 * pname:extensionName is a null-terminated string specifying the name of 319 the extension. 320 * pname:specVersion is the version of this extension. 321 It is an integer, incremented with backward compatible changes. 322 323include::../validity/structs/VkExtensionProperties.txt[] 324-- 325 326 327[[extended-functionality-instance-extensions-and-devices]] 328=== Instance Extensions and Device Extensions 329 330This section provides some guidelines and rules for when to expose new 331functionality as an instance extension, as a device extension, or as both. 332The decision depends on the scope of the new functionality; such as whether 333it extends instance-level or device-level functionality. 334All Vulkan commands, structures, and enumerants are considered either 335instance-level, physical-device-level, or device-level. 336 337New instance-level extension functionality must: be structured within an 338instance extension. 339New device-level extension functionality may: be structured within a device 340extension. 341Vulkan 1.0 initially required all new physical-device-level extension 342functionality to be structured within an instance extension. 343ifdef::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[] 344In order to avoid using an instance extension, which often requires loader 345support, physical-device-level extension functionality may: be implemented 346within device extensions (which must: depend on the 347`<<VK_KHR_get_physical_device_properties2>>` extension, or on Vulkan 1.1 or 348later). 349endif::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[] 350 351 352[[extended-functionality-extensions-dependencies]] 353== Extension Dependencies 354 355Some extensions are dependent on other extensions to function. 356To enable extensions with dependencies, such _required extensions_ must: 357also be enabled through the same API mechanisms when creating an instance 358with flink:vkCreateInstance or a device with flink:vkCreateDevice. 359Each extension which has such dependencies documents them in the 360<<extensions, appendix summarizing that extension>>. 361 362If an extension is supported (as queried by 363flink:vkEnumerateInstanceExtensionProperties or 364flink:vkEnumerateDeviceExtensionProperties), then _required extensions_ of 365that extension must: also be supported for the same instance or physical 366device. 367 368Any device extension that has an instance extension dependency that is not 369enabled by flink:vkCreateInstance is considered to be unsupported, hence it 370must: not be returned by flink:vkEnumerateDeviceExtensionProperties for any 371slink:VkPhysicalDevice child of the instance. 372 373 374[[extended-functionality-extensions-compatibility]] 375== Extension Compatibility 376 377By default, all extensions are considered compatible with each other and any 378core API version, unless otherwise stated. 379Thus enabling such extensions does not otherwise alter the behavior of the 380application. 381 382Each extension that is mutually exclusive or otherwise incompatible with 383another extension or set of extensions documents them in the <<extensions, 384appendix summarizing that extension>> and has a corresponding Valid Usage 385statement disallowing enabling such an incompatible combination of 386extensions at sname:VkInstance creation time or sname:VkDevice creation 387time, depending on the type of extensions participating in the interaction. 388