// Copyright (c) 2015-2017 Khronos Group. This work is licensed under a // Creative Commons Attribution 4.0 International License; see // http://creativecommons.org/licenses/by/4.0/ [[devsandqueues]] = Devices and Queues Once Vulkan is initialized, devices and queues are the primary objects used to interact with a Vulkan implementation. [open,refpage='VkPhysicalDevice',desc='Opaque handle to a physical device object',type='handles'] -- Vulkan separates the concept of _physical_ and _logical_ devices. A physical device usually represents a single device in a system (perhaps made up of several individual hardware devices working together), of which there are a finite number. A logical device represents an application's view of the device. Physical devices are represented by sname:VkPhysicalDevice handles: include::../api/handles/VkPhysicalDevice.txt[] -- [[devsandqueues-physical-device-enumeration]] == Physical Devices [open,refpage='vkEnumeratePhysicalDevices',desc='Enumerates the physical devices accessible to a Vulkan instance',type='protos'] -- To retrieve a list of physical device objects representing the physical devices installed in the system, call: include::../api/protos/vkEnumeratePhysicalDevices.txt[] * pname:instance is a handle to a Vulkan instance previously created with flink:vkCreateInstance. * pname:pPhysicalDeviceCount is a pointer to an integer related to the number of physical devices available or queried, as described below. * pname:pPhysicalDevices is either `NULL` or a pointer to an array of sname:VkPhysicalDevice handles. If pname:pPhysicalDevices is `NULL`, then the number of physical devices available is returned in pname:pPhysicalDeviceCount. Otherwise, pname:pPhysicalDeviceCount must: point to a variable set by the user to the number of elements in the pname:pPhysicalDevices array, and on return the variable is overwritten with the number of handles actually written to pname:pPhysicalDevices. If pname:pPhysicalDeviceCount is less than the number of physical devices available, at most pname:pPhysicalDeviceCount structures will be written. If pname:pPhysicalDeviceCount is smaller than the number of physical devices available, ename:VK_INCOMPLETE will be returned instead of ename:VK_SUCCESS, to indicate that not all the available physical devices were returned. include::../validity/protos/vkEnumeratePhysicalDevices.txt[] -- [open,refpage='vkGetPhysicalDeviceProperties',desc='Returns properties of a physical device',type='protos'] -- To query general properties of physical devices once enumerated, call: include::../api/protos/vkGetPhysicalDeviceProperties.txt[] * pname:physicalDevice is the handle to the physical device whose properties will be queried. * pname:pProperties points to an instance of the slink:VkPhysicalDeviceProperties structure, that will be filled with returned information. include::../validity/protos/vkGetPhysicalDeviceProperties.txt[] -- [open,refpage='VkPhysicalDeviceProperties',desc='Structure specifying physical device properties',type='structs'] -- The sname:VkPhysicalDeviceProperties structure is defined as: include::../api/structs/VkPhysicalDeviceProperties.txt[] * pname:apiVersion is the version of Vulkan supported by the device, encoded as described in the <> section. * pname:driverVersion is the vendor-specified version of the driver. * pname:vendorID is a unique identifier for the _vendor_ (see below) of the physical device. * pname:deviceID is a unique identifier for the physical device among devices available from the vendor. * pname:deviceType is a elink:VkPhysicalDeviceType specifying the type of device. * pname:deviceName is a null-terminated UTF-8 string containing the name of the device. * pname:pipelineCacheUUID is an array of size ename:VK_UUID_SIZE, containing 8-bit values that represent a universally unique identifier for the device. * pname:limits is the slink:VkPhysicalDeviceLimits structure which specifies device-specific limits of the physical device. See <> for details. * pname:sparseProperties is the slink:VkPhysicalDeviceSparseProperties structure which specifies various sparse related properties of the physical device. See <> for details. The pname:vendorID and pname:deviceID fields are provided to allow applications to adapt to device characteristics that are not adequately exposed by other Vulkan queries. These may: include performance profiles, hardware errata, or other characteristics. In PCI-based implementations, the low sixteen bits of pname:vendorID and pname:deviceID must: contain (respectively) the PCI vendor and device IDs associated with the hardware device, and the remaining bits must: be set to zero. In non-PCI implementations, the choice of what values to return may: be dictated by operating system or platform policies. It is otherwise at the discretion of the implementer, subject to the following constraints and guidelines: * For purposes of physical device identification, the _vendor_ of a physical device is the entity responsible for the most salient characteristics of the hardware represented by the physical device handle. In the case of a discrete GPU, this should: be the GPU chipset vendor. In the case of a GPU or other accelerator integrated into a system-on-chip (SoC), this should: be the supplier of the silicon IP used to create the GPU or other accelerator. * If the vendor of the physical device has a valid PCI vendor ID issued by https://pcisig.com/[PCI-SIG], that ID should: be used to construct pname:vendorID as described above for PCI-based implementations. Implementations that do not return a PCI vendor ID in pname:vendorID must: return a valid Khronos vendor ID, obtained as described in the <> document in the section "`Registering a Vendor ID with Khronos`". Khronos vendor IDs are allocated starting at 0x10000, to distinguish them from the PCI vendor ID namespace. * The vendor of the physical device is responsible for selecting pname:deviceID. The value selected should: uniquely identify both the device version and any major configuration options (for example, core count in the case of multicore devices). The same device ID should: be used for all physical implementations of that device version and configuration. For example, all uses of a specific silicon IP GPU version and configuration should: use the same device ID, even if those uses occur in different SoCs. include::../validity/structs/VkPhysicalDeviceProperties.txt[] -- [open,refpage='VkPhysicalDeviceType',desc='Supported physical device types',type='enums'] -- The physical device types which may: be returned in slink:VkPhysicalDeviceProperties::pname:deviceType are: include::../api/enums/VkPhysicalDeviceType.txt[] * ename:VK_PHYSICAL_DEVICE_TYPE_OTHER - the device does not match any other available types. * ename:VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU - the device is typically one embedded in or tightly coupled with the host. * ename:VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU - the device is typically a separate processor connected to the host via an interlink. * ename:VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU - the device is typically a virtual node in a virtualization environment. * ename:VK_PHYSICAL_DEVICE_TYPE_CPU - the device is typically running on the same processors as the host. The physical device type is advertised for informational purposes only, and does not directly affect the operation of the system. However, the device type may: correlate with other advertised properties or capabilities of the system, such as how many memory heaps there are. -- ifdef::VK_KHR_get_physical_device_properties2[] [open,refpage='vkGetPhysicalDeviceProperties2KHR',desc='Returns properties of a physical device',type='protos'] -- To query general properties of physical devices once enumerated, call: include::../api/protos/vkGetPhysicalDeviceProperties2KHR.txt[] * pname:physicalDevice is the handle to the physical device whose properties will be queried. * pname:pProperties points to an instance of the slink:VkPhysicalDeviceProperties2KHR structure, that will be filled with returned information. Each structure in pname:pProperties and its pname:pNext chain contain members corresponding to properties or implementation-dependent limits. fname:vkGetPhysicalDeviceProperties2KHR writes each member to a value indicating the value of that property or limit. include::../validity/protos/vkGetPhysicalDeviceProperties2KHR.txt[] -- [open,refpage='VkPhysicalDeviceProperties2KHR',desc='Structure specifying physical device properties',type='structs'] -- The sname:VkPhysicalDeviceProperties2KHR structure is defined as: include::../api/structs/VkPhysicalDeviceProperties2KHR.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:properties is a structure of type slink:VkPhysicalDeviceProperties describing the properties of the physical device. This structure is written with the same values as if it were written by flink:vkGetPhysicalDeviceProperties. The pname:pNext chain of this structure is used to extend the structure with properties defined by extensions. include::../validity/structs/VkPhysicalDeviceProperties2KHR.txt[] -- ifdef::VK_KHR_external_memory_capabilities,VK_KHR_external_semaphore_capabilities,VK_KHR_external_fence_capabilities[] [open,refpage='VkPhysicalDeviceIDPropertiesKHR',desc='Structure specifying IDs related to the physical device',type='structs'] -- To query the UUID and LUID of a device, add slink:VkPhysicalDeviceIDPropertiesKHR to the pname:pNext chain of the slink:VkPhysicalDeviceProperties2KHR structure. The sname:VkPhysicalDeviceIDPropertiesKHR structure is defined as: include::../api/structs/VkPhysicalDeviceIDPropertiesKHR.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:deviceUUID is an array of size ename:VK_UUID_SIZE, containing 8-bit values that represent a universally unique identifier for the device. * pname:driverUUID is an array of size ename:VK_UUID_SIZE, containing 8-bit values that represent a universally unique identifier for the driver build in use by the device. * pname:deviceLUID is an array of size ename:VK_LUID_SIZE_KHR, containing 8-bit values that represent a locally unique identifier for the device. * pname:deviceNodeMask is a bitfield identifying the node within a linked device adapter corresponding to the device. * pname:deviceLUIDValid is a boolean value that will be ename:VK_TRUE if pname:deviceLUID contains a valid LUID and pname:deviceNodeMask contains a valid node mask, and ename:VK_FALSE if they do not. pname:deviceUUID must: be immutable for a given device across instances, processes, driver APIs, driver versions, and system reboots. Applications can: compare the pname:driverUUID value across instance and process boundaries, and can: make similar queries in external APIs to determine whether they are capable of sharing memory objects and resources using them with the device. pname:deviceUUID and/or pname:driverUUID must: be used to determine whether a particular external object can be shared between driver components, where such a restriction exists as defined in the compatibility table for the particular object type: ifdef::VK_KHR_external_memory_capabilities[] * <> endif::VK_KHR_external_memory_capabilities[] ifdef::VK_KHR_external_semaphore_capabilities[] * <> endif::VK_KHR_external_semaphore_capabilities[] ifdef::VK_KHR_external_fence_capabilities[] * <> endif::VK_KHR_external_fence_capabilities[] If pname:deviceLUIDValid is ename:VK_FALSE, the contents of pname:deviceLUID and pname:deviceNodeMask are undefined. If pname:deviceLUIDValid is ename:VK_TRUE and Vulkan is running on the Windows operating system, the contents of pname:deviceLUID can: be cast to an sname:LUID object and must: be equal to the locally unique identifier of a sname:IDXGIAdapter1 object that corresponds to pname:physicalDevice. If pname:deviceLUIDValid is ename:VK_TRUE, pname:deviceNodeMask must: contain exactly one bit. If Vulkan is running on an operating system that supports the Direct3D 12 API and pname:physicalDevice corresponds to an individual device in a linked device adapter, pname:deviceNodeMask identifies the Direct3D 12 node corresponding to pname:physicalDevice. Otherwise, pname:deviceNodeMask must: be `1`. [NOTE] .Note ==== Although they have identical descriptions, slink:VkPhysicalDeviceIDPropertiesKHR::pname:deviceUUID may differ from slink:VkPhysicalDeviceProperties2KHR::pname:pipelineCacheUUID. The former is intended to identify and correlate devices across API and driver boundaries, while the latter is used to identify a compatible device and driver combination to use when serializing and de-serializing pipeline state. ==== [NOTE] .Note ==== While slink:VkPhysicalDeviceIDPropertiesKHR::pname:deviceUUID is specified to remain consistent across driver versions and system reboots, it is not intended to be usable as a serializable persistent identifier for a device. It may change when a device is physically added to, removed from, or moved to a different connector in a system while that system is powered down. Further, there is no reasonable way to verify with conformance testing that a given device retains the same UUID in a given system across all driver versions supported in that system. While implementations should make every effort to report consistent device UUIDs across driver versions, applications should avoid relying on the persistence of this value for uses other than identifying compatible devices for external object sharing purposes. ==== include::../validity/structs/VkPhysicalDeviceIDPropertiesKHR.txt[] -- endif::VK_KHR_external_memory_capabilities,VK_KHR_external_semaphore_capabilities,VK_KHR_external_fence_capabilities[] endif::VK_KHR_get_physical_device_properties2[] [open,refpage='vkGetPhysicalDeviceQueueFamilyProperties',desc='Reports properties of the queues of the specified physical device',type='protos'] -- To query properties of queues available on a physical device, call: include::../api/protos/vkGetPhysicalDeviceQueueFamilyProperties.txt[] * pname:physicalDevice is the handle to the physical device whose properties will be queried. * pname:pQueueFamilyPropertyCount is a pointer to an integer related to the number of queue families available or queried, as described below. * pname:pQueueFamilyProperties is either `NULL` or a pointer to an array of slink:VkQueueFamilyProperties structures. If pname:pQueueFamilyProperties is `NULL`, then the number of queue families available is returned in pname:pQueueFamilyPropertyCount. Otherwise, pname:pQueueFamilyPropertyCount must: point to a variable set by the user to the number of elements in the pname:pQueueFamilyProperties array, and on return the variable is overwritten with the number of structures actually written to pname:pQueueFamilyProperties. If pname:pQueueFamilyPropertyCount is less than the number of queue families available, at most pname:pQueueFamilyPropertyCount structures will be written. include::../validity/protos/vkGetPhysicalDeviceQueueFamilyProperties.txt[] -- [open,refpage='VkQueueFamilyProperties',desc='Structure providing information about a queue family',type='structs'] -- The sname:VkQueueFamilyProperties structure is defined as: include::../api/structs/VkQueueFamilyProperties.txt[] * pname:queueFlags is a bitmask of elink:VkQueueFlagBits indicating capabilities of the queues in this queue family. * pname:queueCount is the unsigned integer count of queues in this queue family. * pname:timestampValidBits is the unsigned integer count of meaningful bits in the timestamps written via fname:vkCmdWriteTimestamp. The valid range for the count is 36..64 bits, or a value of 0, indicating no support for timestamps. Bits outside the valid range are guaranteed to be zeros. * pname:minImageTransferGranularity is the minimum granularity supported for image transfer operations on the queues in this queue family. The value returned in pname:minImageTransferGranularity has a unit of compressed texel blocks for images having a block-compressed format, and a unit of texels otherwise. Possible values of pname:minImageTransferGranularity are: * [eq]#(0,0,0)# which indicates that only whole mip levels must: be transferred using the image transfer operations on the corresponding queues. In this case, the following restrictions apply to all offset and extent parameters of image transfer operations: ** The pname:x, pname:y, and pname:z members of a slink:VkOffset3D parameter must: always be zero. ** The pname:width, pname:height, and pname:depth members of a slink:VkExtent3D parameter must: always match the width, height, and depth of the image subresource corresponding to the parameter, respectively. * [eq]#(A~x~, A~y~, A~z~)# where [eq]#A~x~#, [eq]#A~y~#, and [eq]#A~z~# are all integer powers of two. In this case the following restrictions apply to all image transfer operations: ** pname:x, pname:y, and pname:z of a slink:VkOffset3D parameter must: be integer multiples of [eq]#A~x~#, [eq]#A~y~#, and [eq]#A~z~#, respectively. ** pname:width of a slink:VkExtent3D parameter must: be an integer multiple of [eq]#A~x~#, or else [eq]#pname:x {plus} pname:width# must: equal the width of the image subresource corresponding to the parameter. ** pname:height of a slink:VkExtent3D parameter must: be an integer multiple of [eq]#A~y~#, or else [eq]#pname:y {plus} pname:height# must: equal the height of the image subresource corresponding to the parameter. ** pname:depth of a slink:VkExtent3D parameter must: be an integer multiple of [eq]#A~z~#, or else [eq]#pname:z {plus} pname:depth# must: equal the depth of the image subresource corresponding to the parameter. ** If the format of the image corresponding to the parameters is one of the block-compressed formats then for the purposes of the above calculations the granularity must: be scaled up by the compressed texel block dimensions. Queues supporting graphics and/or compute operations must: report [eq]#(1,1,1)# in pname:minImageTransferGranularity, meaning that there are no additional restrictions on the granularity of image transfer operations for these queues. Other queues supporting image transfer operations are only required: to support whole mip level transfers, thus pname:minImageTransferGranularity for queues belonging to such queue families may: be [eq]#(0,0,0)#. The <> section describes memory properties queried from the physical device. For physical device feature queries see the <> chapter. include::../validity/structs/VkQueueFamilyProperties.txt[] -- [open,refpage='VkQueueFlagBits',desc='Bitmask specifying capabilities of queues in a queue family',type='enums'] -- Bits which may: be set in slink:VkQueueFamilyProperties::pname:queueFlags indicating capabilities of queues in a queue family are: include::../api/enums/VkQueueFlagBits.txt[] * ename:VK_QUEUE_GRAPHICS_BIT indicates that queues in this queue family support graphics operations. * ename:VK_QUEUE_COMPUTE_BIT indicates that queues in this queue family support compute operations. * ename:VK_QUEUE_TRANSFER_BIT indicates that queues in this queue family support transfer operations. * ename:VK_QUEUE_SPARSE_BINDING_BIT indicates that queues in this queue family support sparse memory management operations (see <>). If any of the sparse resource features are enabled, then at least one queue family must: support this bit. If an implementation exposes any queue family that supports graphics operations, at least one queue family of at least one physical device exposed by the implementation must: support both graphics and compute operations. [NOTE] .Note ==== All commands that are allowed on a queue that supports transfer operations are also allowed on a queue that supports either graphics or compute operations. Thus, if the capabilities of a queue family include ename:VK_QUEUE_GRAPHICS_BIT or ename:VK_QUEUE_COMPUTE_BIT, then reporting the ename:VK_QUEUE_TRANSFER_BIT capability separately for that queue family is optional:. ==== For further details see <>. -- ifdef::VK_KHR_get_physical_device_properties2[] [open,refpage='vkGetPhysicalDeviceQueueFamilyProperties2KHR',desc='Reports properties of the queues of the specified physical device',type='protos'] -- To query properties of queues available on a physical device, call: include::../api/protos/vkGetPhysicalDeviceQueueFamilyProperties2KHR.txt[] * pname:physicalDevice is the handle to the physical device whose properties will be queried. * pname:pQueueFamilyPropertyCount is a pointer to an integer related to the number of queue families available or queried, as described in flink:vkGetPhysicalDeviceQueueFamilyProperties. * pname:pQueueFamilyProperties is either `NULL` or a pointer to an array of slink:VkQueueFamilyProperties2KHR structures. fname:vkGetPhysicalDeviceQueueFamilyProperties2KHR behaves similarly to flink:vkGetPhysicalDeviceQueueFamilyProperties, with the ability to return extended information in a pname:pNext chain of output structures. include::../validity/protos/vkGetPhysicalDeviceQueueFamilyProperties2KHR.txt[] -- [open,refpage='VkQueueFamilyProperties2KHR',desc='Structure providing information about a queue family',type='structs'] -- The sname:VkQueueFamilyProperties2KHR structure is defined as: include::../api/structs/VkQueueFamilyProperties2KHR.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:queueFamilyProperties is a structure of type slink:VkQueueFamilyProperties which is populated with the same values as in flink:vkGetPhysicalDeviceQueueFamilyProperties. include::../validity/structs/VkQueueFamilyProperties2KHR.txt[] -- endif::VK_KHR_get_physical_device_properties2[] [[devsandqueues-devices]] == Devices Device objects represent logical connections to physical devices. Each device exposes a number of _queue families_ each having one or more _queues_. All queues in a queue family support the same operations. As described in <>, a Vulkan application will first query for all physical devices in a system. Each physical device can: then be queried for its capabilities, including its queue and queue family properties. Once an acceptable physical device is identified, an application will create a corresponding logical device. An application must: create a separate logical device for each physical device it will use. The created logical device is then the primary interface to the physical device. How to enumerate the physical devices in a system and query those physical devices for their queue family properties is described in the <> section above. ifdef::VK_KHX_device_group_creation[] A single logical device can: also be created from multiple physical devices, if those physical devices belong to the same device group. A _device group_ is a set of physical devices that support accessing each other's memory and recording a single command buffer that can: be executed on all the physical devices. Device groups are enumerated by calling flink:vkEnumeratePhysicalDeviceGroupsKHX, and a logical device is created from a subset of the physical devices in a device group by passing the physical devices through slink:VkDeviceGroupDeviceCreateInfoKHX. [open,refpage='vkEnumeratePhysicalDeviceGroupsKHX',desc='Enumerates groups of physical devices that can be used to create a single logical device',type='protos'] -- To retrieve a list of the device groups present in the system, call: include::../api/protos/vkEnumeratePhysicalDeviceGroupsKHX.txt[] * pname:instance is a handle to a Vulkan instance previously created with flink:vkCreateInstance. * pname:pPhysicalDeviceGroupCount is a pointer to an integer related to the number of device groups available or queried, as described below. * pname:pPhysicalDeviceGroupProperties is either `NULL` or a pointer to an array of slink:VkPhysicalDeviceGroupPropertiesKHX structures. If pname:pPhysicalDeviceGroupProperties is `NULL`, then the number of device groups available is returned in pname:pPhysicalDeviceGroupCount. Otherwise, pname:pPhysicalDeviceGroupCount must: point to a variable set by the user to the number of elements in the pname:pPhysicalDeviceGroupProperties array, and on return the variable is overwritten with the number of structures actually written to pname:pPhysicalDeviceGroupProperties. If pname:pPhysicalDeviceGroupCount is less than the number of device groups available, at most pname:pPhysicalDeviceGroupCount structures will be written. If pname:pPhysicalDeviceGroupCount is smaller than the number of device groups available, ename:VK_INCOMPLETE will be returned instead of ename:VK_SUCCESS, to indicate that not all the available device groups were returned. Every physical device must: be in exactly one device group. include::../validity/protos/vkEnumeratePhysicalDeviceGroupsKHX.txt[] -- [open,refpage='VkPhysicalDeviceGroupPropertiesKHX',desc='Structure specifying physical device group properties',type='structs'] -- The sname:VkPhysicalDeviceGroupPropertiesKHX structure is defined as: include::../api/structs/VkPhysicalDeviceGroupPropertiesKHX.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:physicalDeviceCount is the number of physical devices in the group. * pname:physicalDevices is an array of physical device handles representing all physical devices in the group. The first pname:physicalDeviceCount elements of the array will be valid. * pname:subsetAllocation indicates whether logical devices created from the group support allocating device memory on a subset of devices, via the pname:deviceMask member of the slink:VkMemoryAllocateFlagsInfoKHX. If this is ename:VK_FALSE, then all device memory allocations are made across all physical devices in the group. If pname:physicalDeviceCount is `1`, then pname:subsetAllocation must: be ename:VK_FALSE. -- endif::VK_KHX_device_group_creation[] [[devsandqueues-device-creation]] === Device Creation [open,refpage='VkDevice',desc='Opaque handle to a device object',type='handles'] -- Logical devices are represented by sname:VkDevice handles: include::../api/handles/VkDevice.txt[] -- [open,refpage='vkCreateDevice',desc='Create a new device instance',type='protos'] -- A logical device is created as a _connection_ to a physical device. To create a logical device, call: include::../api/protos/vkCreateDevice.txt[] * pname:physicalDevice must: be one of the device handles returned from a call to fname:vkEnumeratePhysicalDevices (see <>). * pname:pCreateInfo is a pointer to a slink:VkDeviceCreateInfo structure containing information about how to create the device. * pname:pAllocator controls host memory allocation as described in the <> chapter. * pname:pDevice points to a handle in which the created sname:VkDevice is returned. fname:vkCreateDevice verifies that extensions and features requested in the pname:ppEnabledExtensionNames and pname:pEnabledFeatures members of pname:pCreateInfo, respectively, are supported by the implementation. If any requested extension is not supported, fname:vkCreateDevice must: return ename:VK_ERROR_EXTENSION_NOT_PRESENT. If any requested feature is not supported, fname:vkCreateDevice must: return ename:VK_ERROR_FEATURE_NOT_PRESENT. Support for extensions can: be checked before creating a device by querying flink:vkEnumerateDeviceExtensionProperties. Support for features can: similarly be checked by querying flink:vkGetPhysicalDeviceFeatures. After verifying and enabling the extensions the sname:VkDevice object is created and returned to the application. If a requested extension is only supported by a layer, both the layer and the extension need to be specified at fname:vkCreateInstance time for the creation to succeed. Multiple logical devices can: be created from the same physical device. Logical device creation may: fail due to lack of device-specific resources (in addition to the other errors). If that occurs, fname:vkCreateDevice will return ename:VK_ERROR_TOO_MANY_OBJECTS. .Valid Usage **** * [[VUID-vkCreateDevice-ppEnabledExtensionNames-01387]] All <> for each extension in the slink:VkDeviceCreateInfo::pname:ppEnabledExtensionNames list must: also be present in that list. **** include::../validity/protos/vkCreateDevice.txt[] -- [open,refpage='VkDeviceCreateInfo',desc='Structure specifying parameters of a newly created device',type='structs'] -- The sname:VkDeviceCreateInfo structure is defined as: include::../api/structs/VkDeviceCreateInfo.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:flags is reserved for future use. * pname:queueCreateInfoCount is the unsigned integer size of the pname:pQueueCreateInfos array. Refer to the <> section below for further details. * pname:pQueueCreateInfos is a pointer to an array of slink:VkDeviceQueueCreateInfo structures describing the queues that are requested to be created along with the logical device. Refer to the <> section below for further details. * pname:enabledLayerCount is deprecated and ignored. * pname:ppEnabledLayerNames is deprecated and ignored. See <>. * pname:enabledExtensionCount is the number of device extensions to enable. * pname:ppEnabledExtensionNames is a pointer to an array of pname:enabledExtensionCount null-terminated UTF-8 strings containing the names of extensions to enable for the created device. See the <> section for further details. * pname:pEnabledFeatures is `NULL` or a pointer to a slink:VkPhysicalDeviceFeatures structure that contains boolean indicators of all the features to be enabled. Refer to the <> section for further details. .Valid Usage **** * [[VUID-VkDeviceCreateInfo-queueFamilyIndex-00372]] The pname:queueFamilyIndex member of each element of pname:pQueueCreateInfos must: be unique within pname:pQueueCreateInfos ifdef::VK_KHR_get_physical_device_properties2[] * [[VUID-VkDeviceCreateInfo-pNext-00373]] If the pname:pNext chain includes a slink:VkPhysicalDeviceFeatures2KHR structure, then pname:pEnabledFeatures must: be `NULL` endif::VK_KHR_get_physical_device_properties2[] ifdef::VK_KHR_maintenance1[] ifdef::VK_AMD_negative_viewport_height[] * [[VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-00374]] pname:ppEnabledExtensionNames must: not contain both code:VK_KHR_maintenance1 and code:VK_AMD_negative_viewport_height endif::VK_AMD_negative_viewport_height[] endif::VK_KHR_maintenance1[] **** include::../validity/structs/VkDeviceCreateInfo.txt[] -- ifdef::VK_KHX_device_group_creation[] [open,refpage='VkDeviceGroupDeviceCreateInfoKHX',desc='Create a logical device from multiple physical devices',type='structs'] -- A logical device can: be created that connects to one or more physical devices by including a sname:VkDeviceGroupDeviceCreateInfoKHX structure in the pname:pNext chain of slink:VkDeviceCreateInfo. The sname:VkDeviceGroupDeviceCreateInfoKHX structure is defined as: include::../api/structs/VkDeviceGroupDeviceCreateInfoKHX.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:physicalDeviceCount is the number of elements in the pname:pPhysicalDevices array. * pname:pPhysicalDevices is an array of physical device handles belonging to the same device group. The elements of the pname:pPhysicalDevices array are an ordered list of the physical devices that the logical device represents. These must: be a subset of a single device group, and need not be in the same order as they were enumerated. The order of the physical devices in the pname:pPhysicalDevices array determines the _device index_ of each physical device, with element [eq]#i# being assigned a device index of [eq]#i#. Certain commands and structures refer to one or more physical devices by using device indices or _device masks_ formed using device indices. A logical device created without using sname:VkDeviceGroupDeviceCreateInfoKHX, or with pname:physicalDeviceCount equal to zero, is equivalent to a pname:physicalDeviceCount of one and pname:pPhysicalDevices pointing to the pname:physicalDevice parameter to flink:vkCreateDevice. In particular, the device index of that physical device is zero. .Valid Usage **** * [[VUID-VkDeviceGroupDeviceCreateInfoKHX-pPhysicalDevices-00375]] Each element of pname:pPhysicalDevices must: be unique * [[VUID-VkDeviceGroupDeviceCreateInfoKHX-pPhysicalDevices-00376]] All elements of pname:pPhysicalDevices must: be in the same device group as enumerated by flink:vkEnumeratePhysicalDeviceGroupsKHX * [[VUID-VkDeviceGroupDeviceCreateInfoKHX-physicalDeviceCount-00377]] If pname:physicalDeviceCount is not `0`, the pname:physicalDevice parameter of flink:vkCreateDevice must: be an element of pname:pPhysicalDevices. **** include::../validity/structs/VkDeviceGroupDeviceCreateInfoKHX.txt[] -- endif::VK_KHX_device_group_creation[] [[devsandqueues-use]] === Device Use The following is a high-level list of sname:VkDevice uses along with references on where to find more information: * Creation of queues. See the <> section below for further details. * Creation and tracking of various synchronization constructs. See <> for further details. * Allocating, freeing, and managing memory. See <> and <> for further details. * Creation and destruction of command buffers and command buffer pools. See <> for further details. * Creation, destruction, and management of graphics state. See <> and <>, among others, for further details. [[devsandqueues-lost-device]] === Lost Device A logical device may: become _lost_ because of hardware errors, execution timeouts, power management events and/or platform-specific events. This may: cause pending and future command execution to fail and cause hardware resources to be corrupted. When this happens, certain commands will return ename:VK_ERROR_DEVICE_LOST (see <> for a list of such commands). After any such event, the logical device is considered _lost_. It is not possible to reset the logical device to a non-lost state, however the lost state is specific to a logical device (sname:VkDevice), and the corresponding physical device (sname:VkPhysicalDevice) may: be otherwise unaffected. In some cases, the physical device may: also be lost, and attempting to create a new logical device will fail, returning ename:VK_ERROR_DEVICE_LOST. This is usually indicative of a problem with the underlying hardware, or its connection to the host. If the physical device has not been lost, and a new logical device is successfully created from that physical device, it must: be in the non-lost state. [NOTE] .Note ==== Whilst logical device loss may: be recoverable, in the case of physical device loss, it is unlikely that an application will be able to recover unless additional, unaffected physical devices exist on the system. The error is largely informational and intended only to inform the user that their hardware has probably developed a fault or become physically disconnected, and should: be investigated further. In many cases, physical device loss may: cause other more serious issues such as the operating system crashing; in which case it may: not be reported via the Vulkan API. ==== [NOTE] .Note ==== Undefined behavior caused by an application error may: cause a device to become lost. However, such undefined behavior may: also cause unrecoverable damage to the process, and it is then not guaranteed that the API objects, including the sname:VkPhysicalDevice or the sname:VkInstance are still valid or that the error is recoverable. ==== When a device is lost, its child objects are not implicitly destroyed and their handles are still valid. Those objects must: still be destroyed before their parents or the device can: be destroyed (see the <> section). The host address space corresponding to device memory mapped using flink:vkMapMemory is still valid, and host memory accesses to these mapped regions are still valid, but the contents are undefined. It is still legal to call any API command on the device and child objects. Once a device is lost, command execution may: fail, and commands that return a elink:VkResult may: return ename:VK_ERROR_DEVICE_LOST. Commands that do not allow run-time errors must: still operate correctly for valid usage and, if applicable, return valid data. Commands that wait indefinitely for device execution (namely flink:vkDeviceWaitIdle, flink:vkQueueWaitIdle, flink:vkWaitForFences ifdef::VK_KHR_swapchain[] or flink:vkAcquireNextImageKHR endif::VK_KHR_swapchain[] with a maximum pname:timeout, and flink:vkGetQueryPoolResults with the ename:VK_QUERY_RESULT_WAIT_BIT bit set in pname:flags) must: return in finite time even in the case of a lost device, and return either ename:VK_SUCCESS or ename:VK_ERROR_DEVICE_LOST. For any command that may: return ename:VK_ERROR_DEVICE_LOST, for the purpose of determining whether a command buffer is in the <>, or whether resources are considered in-use by the device, a return value of ename:VK_ERROR_DEVICE_LOST is equivalent to ename:VK_SUCCESS. ifdef::VK_KHR_external_memory[] The content of any external memory objects that have been exported from or imported to a lost device become undefined. Objects on other logical devices or in other APIs which are associated with the same underlying memory resource as the external memory objects on the lost device are unaffected other than their content becoming undefined. The layout of subresources of images on other logical devices that are bound to sname:VkDeviceMemory objects associated with the same underlying memory resources as external memory objects on the lost device becomes ename:VK_IMAGE_LAYOUT_UNDEFINED. endif::VK_KHR_external_memory[] ifdef::VK_KHR_external_semaphore[] The state of sname:VkSemaphore objects on other logical devices created by <> with temporary permanence which was exported from the lost device is undefined. The state of sname:VkSemaphore objects on other logical devices that permanently share a semaphore payload with a sname:VkSemaphore object on the lost device is undefined, and remains undefined following any subsequent signal operations. Implementations must: ensure pending and subsequently submitted wait operations on such semaphores behave as defined in <> for external semaphores not in a valid state for a wait operation. endif::VK_KHR_external_semaphore[] ifdef::editing-notes[] [NOTE] .editing-note ==== TODO (piman) - I do not think we are very clear about what "`in-use by the device`" means. ==== endif::editing-notes[] [[devsandqueues-destruction]] === Device Destruction [open,refpage='vkDestroyDevice',desc='Destroy a logical device',type='protos'] -- To destroy a device, call: include::../api/protos/vkDestroyDevice.txt[] * pname:device is the logical device to destroy. * pname:pAllocator controls host memory allocation as described in the <> chapter. To ensure that no work is active on the device, flink:vkDeviceWaitIdle can: be used to gate the destruction of the device. Prior to destroying a device, an application is responsible for destroying/freeing any Vulkan objects that were created using that device as the first parameter of the corresponding ftext:vkCreate* or ftext:vkAllocate* command. [NOTE] .Note ==== The lifetime of each of these objects is bound by the lifetime of the sname:VkDevice object. Therefore, to avoid resource leaks, it is critical that an application explicitly free all of these resources prior to calling fname:vkDestroyDevice. ==== .Valid Usage **** * [[VUID-vkDestroyDevice-device-00378]] All child objects created on pname:device must: have been destroyed prior to destroying pname:device * [[VUID-vkDestroyDevice-device-00379]] If sname:VkAllocationCallbacks were provided when pname:device was created, a compatible set of callbacks must: be provided here * [[VUID-vkDestroyDevice-device-00380]] If no sname:VkAllocationCallbacks were provided when pname:device was created, pname:pAllocator must: be `NULL` **** include::../validity/protos/vkDestroyDevice.txt[] -- [[devsandqueues-queues]] == Queues [[devsandqueues-queueprops]] === Queue Family Properties As discussed in the <> section above, the flink:vkGetPhysicalDeviceQueueFamilyProperties command is used to retrieve details about the queue families and queues supported by a device. Each index in the pname:pQueueFamilyProperties array returned by flink:vkGetPhysicalDeviceQueueFamilyProperties describes a unique queue family on that physical device. These indices are used when creating queues, and they correspond directly with the pname:queueFamilyIndex that is passed to the flink:vkCreateDevice command via the slink:VkDeviceQueueCreateInfo structure as described in the <> section below. Grouping of queue families within a physical device is implementation-dependent. [NOTE] .Note ==== The general expectation is that a physical device groups all queues of matching capabilities into a single family. However, while implementations should: do this, it is possible that a physical device may: return two separate queue families with the same capabilities. ==== Once an application has identified a physical device with the queue(s) that it desires to use, it will create those queues in conjunction with a logical device. This is described in the following section. [[devsandqueues-queue-creation]] === Queue Creation [open,refpage='VkQueue',desc='Opaque handle to a queue object',type='handles'] -- Creating a logical device also creates the queues associated with that device. The queues to create are described by a set of slink:VkDeviceQueueCreateInfo structures that are passed to flink:vkCreateDevice in pname:pQueueCreateInfos. Queues are represented by sname:VkQueue handles: include::../api/handles/VkQueue.txt[] -- [open,refpage='VkDeviceQueueCreateInfo',desc='Structure specifying parameters of a newly created device queue',type='structs'] -- The sname:VkDeviceQueueCreateInfo structure is defined as: include::../api/structs/VkDeviceQueueCreateInfo.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:flags is reserved for future use. * pname:queueFamilyIndex is an unsigned integer indicating the index of the queue family to create on this device. This index corresponds to the index of an element of the pname:pQueueFamilyProperties array that was returned by fname:vkGetPhysicalDeviceQueueFamilyProperties. * pname:queueCount is an unsigned integer specifying the number of queues to create in the queue family indicated by pname:queueFamilyIndex. * pname:pQueuePriorities is an array of pname:queueCount normalized floating point values, specifying priorities of work that will be submitted to each created queue. See <> for more information. .Valid Usage **** * [[VUID-VkDeviceQueueCreateInfo-queueFamilyIndex-00381]] pname:queueFamilyIndex must: be less than pname:pQueueFamilyPropertyCount returned by fname:vkGetPhysicalDeviceQueueFamilyProperties * [[VUID-VkDeviceQueueCreateInfo-queueCount-00382]] pname:queueCount must: be less than or equal to the pname:queueCount member of the sname:VkQueueFamilyProperties structure, as returned by fname:vkGetPhysicalDeviceQueueFamilyProperties in the pname:pQueueFamilyProperties[pname:queueFamilyIndex] * [[VUID-VkDeviceQueueCreateInfo-pQueuePriorities-00383]] Each element of pname:pQueuePriorities must: be between `0.0` and `1.0` inclusive **** include::../validity/structs/VkDeviceQueueCreateInfo.txt[] -- ifdef::VK_EXT_global_priority[] [open,refpage='VkDeviceQueueGlobalPriorityCreateInfoEXT',desc='Specify a system wide priority',type='structs'] -- A queue can: be created with a system-wide priority by including a sname:VkDeviceQueueGlobalPriorityCreateInfoEXT structure in the pname:pNext chain of slink:VkDeviceQueueCreateInfo. The sname:VkDeviceQueueGlobalPriorityCreateInfoEXT structure is defined as: include::../api/structs/VkDeviceQueueGlobalPriorityCreateInfoEXT.txt[] * pname:sType is the type of this structure. * pname:pNext is `NULL` or a pointer to an extension-specific structure. * pname:globalPriority is the system-wide priority associated to this queue as specified by elink:VkQueueGlobalPriorityEXT A queue created without specifying sname:VkDeviceQueueGlobalPriorityCreateInfoEXT will default to ename:VK_QUEUE_GLOBAL_PRIORITY_MEDIUM. include::../validity/structs/VkDeviceQueueGlobalPriorityCreateInfoEXT.txt[] -- [open,refpage='VkQueueGlobalPriorityEXT',desc='Values specifying a system-wide queue priority',type='enums'] -- Possible values of slink:VkDeviceQueueGlobalPriorityCreateInfoEXT::pname:globalPriority, specifying a system-wide priority level are: include::../api/enums/VkQueueGlobalPriorityEXT.txt[] Priority values are sorted in ascending order. A comparison operation on the enum values can be used to determine the priority order. * ename:VK_QUEUE_GLOBAL_PRIORITY_LOW is below the system default. Useful for non-interactive tasks. * ename:VK_QUEUE_GLOBAL_PRIORITY_MEDIUM is the system default priority. * ename:VK_QUEUE_GLOBAL_PRIORITY_HIGH is above the system default. * ename:VK_QUEUE_GLOBAL_PRIORITY_REALTIME is the highest priority. Useful for critical tasks. -- Queues with higher system priority may: be allotted more processing time than queues with lower priority. An implementation may: allow a higher-priority queue to starve a lower-priority queue until the higher-priority queue has no further commands to execute. Priorities imply no ordering or scheduling constraints. No specific guarantees are made about higher priority queues receiving more processing time or better quality of service than lower priority queues. The global priority level of a queue takes precedence over the per-process queue priority (sname:VkDeviceQueueCreateInfo::pname:pQueuePriorities). Abuse of this feature may result in starving the rest of the system from hardware resources. Therefore, the driver implementation may: deny requests to acquire a priority above the default priority (elink:VK_QUEUE_GLOBAL_PRIORITY_MEDIUM) if the caller does not have sufficient privileges. In this scenario elink:VK_ERROR_NOT_PERMITTED_EXT is returned. The driver implementation may: fail the queue allocation request if resources required to complete the operation have been exhausted (either by the same process or a different process). In this scenario elink:VK_ERROR_INITIALIZATION_FAILED is returned. endif::VK_EXT_global_priority[] [open,refpage='vkGetDeviceQueue',desc='Get a queue handle from a device',type='protos'] -- To retrieve a handle to a VkQueue object, call: include::../api/protos/vkGetDeviceQueue.txt[] * pname:device is the logical device that owns the queue. * pname:queueFamilyIndex is the index of the queue family to which the queue belongs. * pname:queueIndex is the index within this queue family of the queue to retrieve. * pname:pQueue is a pointer to a sname:VkQueue object that will be filled with the handle for the requested queue. .Valid Usage **** * [[VUID-vkGetDeviceQueue-queueFamilyIndex-00384]] pname:queueFamilyIndex must: be one of the queue family indices specified when pname:device was created, via the sname:VkDeviceQueueCreateInfo structure * [[VUID-vkGetDeviceQueue-queueIndex-00385]] pname:queueIndex must: be less than the number of queues created for the specified queue family index when pname:device was created, via the pname:queueCount member of the sname:VkDeviceQueueCreateInfo structure **** include::../validity/protos/vkGetDeviceQueue.txt[] -- [[devsandqueues-index]] === Queue Family Index The queue family index is used in multiple places in Vulkan in order to tie operations to a specific family of queues. When retrieving a handle to the queue via fname:vkGetDeviceQueue, the queue family index is used to select which queue family to retrieve the sname:VkQueue handle from as described in the previous section. When creating a sname:VkCommandPool object (see <>), a queue family index is specified in the slink:VkCommandPoolCreateInfo structure. Command buffers from this pool can: only be submitted on queues corresponding to this queue family. When creating sname:VkImage (see <>) and sname:VkBuffer (see <>) resources, a set of queue families is included in the slink:VkImageCreateInfo and slink:VkBufferCreateInfo structures to specify the queue families that can: access the resource. When inserting a slink:VkBufferMemoryBarrier or slink:VkImageMemoryBarrier (see <>) a source and destination queue family index is specified to allow the ownership of a buffer or image to be transferred from one queue family to another. See the <> section for details. [[devsandqueues-priority]] === Queue Priority Each queue is assigned a priority, as set in the slink:VkDeviceQueueCreateInfo structures when creating the device. The priority of each queue is a normalized floating point value between 0.0 and 1.0, which is then translated to a discrete priority level by the implementation. Higher values indicate a higher priority, with 0.0 being the lowest priority and 1.0 being the highest. Within the same device, queues with higher priority may: be allotted more processing time than queues with lower priority. The implementation makes no guarantees with regards to ordering or scheduling among queues with the same priority, other than the constraints defined by any <>. The implementation make no guarantees with regards to queues across different devices. An implementation may: allow a higher-priority queue to starve a lower-priority queue on the same sname:VkDevice until the higher-priority queue has no further commands to execute. The relationship of queue priorities must: not cause queues on one VkDevice to starve queues on another sname:VkDevice. No specific guarantees are made about higher priority queues receiving more processing time or better quality of service than lower priority queues. [[devsandqueues-submission]] === Queue Submission Work is submitted to a queue via _queue submission_ commands such as flink:vkQueueSubmit. Queue submission commands define a set of _queue operations_ to be executed by the underlying physical device, including synchronization with semaphores and fences. Submission commands take as parameters a target queue, zero or more _batches_ of work, and an optional: fence to signal upon completion. Each batch consists of three distinct parts: . Zero or more semaphores to wait on before execution of the rest of the batch. ** If present, these describe a <>. . Zero or more work items to execute. ** If present, these describe a _queue operation_ matching the work described. . Zero or more semaphores to signal upon completion of the work items. ** If present, these describe a <>. If a fence is present in a queue submission, it describes a <>. All work described by a queue submission command must: be submitted to the queue before the command returns. [[devsandqueues-sparsebinding]] ==== Sparse Memory Binding In Vulkan it is possible to sparsely bind memory to buffers and images as described in the <> chapter. Sparse memory binding is a queue operation. A queue whose flags include the ename:VK_QUEUE_SPARSE_BINDING_BIT must: be able to support the mapping of a virtual address to a physical address on the device. This causes an update to the page table mappings on the device. This update must: be synchronized on a queue to avoid corrupting page table mappings during execution of graphics commands. By binding the sparse memory resources on queues, all commands that are dependent on the updated bindings are synchronized to only execute after the binding is updated. See the <> chapter for how this synchronization is accomplished. [[devsandqueues-queuedestruction]] === Queue Destruction Queues are created along with a logical device during fname:vkCreateDevice. All queues associated with a logical device are destroyed when fname:vkDestroyDevice is called on that device.