Skip to content

Latest commit

 

History

History
6595 lines (5870 loc) · 308 KB

descriptorsets.adoc

File metadata and controls

6595 lines (5870 loc) · 308 KB

Resource Descriptors

A descriptor is an opaque data structure representing a shader resource such as a buffer, buffer view, image view, sampler, or combined image sampler. Descriptors are organized into descriptor sets, which are bound during command recording for use in subsequent drawing commands. The arrangement of content in each descriptor set is determined by a descriptor set layout, which determines what descriptors can be stored within it. The sequence of descriptor set layouts that can: be used by a pipeline is specified in a pipeline layout. Each pipeline object can: use up to pname:maxBoundDescriptorSets (see Limits) descriptor sets.

Shaders access resources via variables decorated with a descriptor set and binding number that link them to a descriptor in a descriptor set. The shader interface mapping to bound descriptor sets is described in the Shader Resource Interface section.

Descriptor Types

There are a number of different types of descriptor supported by Vulkan, corresponding to different resources or usage. The following sections describe the API definitions of each descriptor type. The mapping of each type to SPIR-V is listed in the Shader Resource and Descriptor Type Correspondence and Shader Resource and Storage Class Correspondence tables in the Shader Interfaces chapter.

Storage Image

A storage image (ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) is a descriptor type associated with an image resource via an image view that load, store, and atomic operations can: be performed on.

Storage image loads are supported in all shader stages for image views whose format features contain ename:VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT.

Stores to storage images are supported in compute shaders for image views whose format features contain ename:VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT.

Atomic operations on storage images are supported in compute shaders for image views whose format features contain ename:VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT.

When the pname:fragmentStoresAndAtomics feature is enabled, stores and atomic operations are also supported for storage images in fragment shaders with the same set of image formats as supported in compute shaders. When the pname:vertexPipelineStoresAndAtomics feature is enabled, stores and atomic operations are also supported in vertex, tessellation, and geometry shaders with the same set of image formats as supported in compute shaders.

The image subresources for a storage image must: be in the ename:VK_IMAGE_LAYOUT_GENERAL layout in order to access its data in a shader.

Sampler

A sampler descriptor (ename:VK_DESCRIPTOR_TYPE_SAMPLER) is a descriptor type associated with a sampler object, used to control the behavior of sampling operations performed on a sampled image.

Sampled Image

A sampled image (ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) is a descriptor type associated with an image resource via an image view that sampling operations can: be performed on.

Shaders combine a sampled image variable and a sampler variable to perform sampling operations.

Sampled images are supported in all shader stages for image views whose format features contain ename:VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT.

An image subresources for a sampled image must: be in one of the following layouts:

  • ename:VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL

  • ename:VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

  • ename:VK_IMAGE_LAYOUT_GENERAL

Combined Image Sampler

A combined image sampler (ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) is a single descriptor type associated with both a sampler and an image resource, combining both a sampler and sampled image descriptor into a single descriptor.

The sampler and image in this type of descriptor can: be used freely with any other samplers and images.

An image subresources for a combined image sampler must: be in one of the following layouts:

  • ename:VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL

  • ename:VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

  • ename:VK_IMAGE_LAYOUT_GENERAL

Note
Note

On some implementations, it may: be more efficient to sample from an image using a combination of sampler and sampled image that are stored together in the descriptor set in a combined descriptor.

Uniform Texel Buffer

A uniform texel buffer (ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) is a descriptor type associated with a buffer resource via a buffer view that image sampling operations can: be performed on.

Uniform texel buffers define a tightly-packed 1-dimensional linear array of texels, with texels going through format conversion when read in a shader in the same way as they are for an image.

Load operations from uniform texel buffers are supported in all shader stages for image formats which report support for the ename:VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT feature bit via flink:vkGetPhysicalDeviceFormatProperties in slink:VkFormatProperties::pname:bufferFeatures.

Storage Texel Buffer

A storage texel buffer (ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) is a descriptor type associated with a buffer resource via a buffer view that image load, store, and atomic operations can: be performed on.

Storage texel buffers define a tightly-packed 1-dimensional linear array of texels, with texels going through format conversion when read in a shader in the same way as they are for an image. Unlike uniform texel buffers, these buffers can also be written to in the same way as for storage images.

Storage texel buffer loads are supported in all shader stages for texel buffer formats which report support for the ename:VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT feature bit via flink:vkGetPhysicalDeviceFormatProperties in slink:VkFormatProperties::pname:bufferFeatures.

Stores to storage texel buffers are supported in compute shaders for texel buffer formats which report support for the ename:VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT feature via flink:vkGetPhysicalDeviceFormatProperties in slink:VkFormatProperties::pname:bufferFeatures.

Atomic operations on storage texel buffers are supported in compute shaders for texel buffer formats which report support for the ename:VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT feature via flink:vkGetPhysicalDeviceFormatProperties in slink:VkFormatProperties::pname:bufferFeatures.

When the pname:fragmentStoresAndAtomics feature is enabled, stores and atomic operations are also supported for storage texel buffers in fragment shaders with the same set of texel buffer formats as supported in compute shaders. When the pname:vertexPipelineStoresAndAtomics feature is enabled, stores and atomic operations are also supported in vertex, tessellation, and geometry shaders with the same set of texel buffer formats as supported in compute shaders.

Storage Buffer

A storage buffer (ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) is a descriptor type associated with a buffer resource directly, described in a shader as a structure with various members that load, store, and atomic operations can: be performed on.

Note
Note

Atomic operations can: only be performed on members of certain types as defined in the SPIR-V environment appendix.

Uniform Buffer

A uniform buffer (ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) is a descriptor type associated with a buffer resource directly, described in a shader as a structure with various members that load operations can: be performed on.

Dynamic Uniform Buffer

A dynamic uniform buffer (ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) is almost identical to a uniform buffer, and differs only in how the offset into the buffer is specified. The base offset calculated by the slink:VkDescriptorBufferInfo when initially updating the descriptor set is added to a dynamic offset when binding the descriptor set.

Dynamic Storage Buffer

A dynamic storage buffer (ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) is almost identical to a storage buffer, and differs only in how the offset into the buffer is specified. The base offset calculated by the slink:VkDescriptorBufferInfo when initially updating the descriptor set is added to a dynamic offset when binding the descriptor set.

Input Attachment

An input attachment (ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) is a descriptor type associated with an image resource via an image view that can: be used for framebuffer local load operations in fragment shaders.

All image formats that are supported for color attachments (ename:VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT ) or depth/stencil attachments (ename:VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) for a given image tiling mode are also supported for input attachments.

An image view used as an input attachment must: be in one of the following layouts:

  • ename:VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL

  • ename:VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

  • ename:VK_IMAGE_LAYOUT_GENERAL

Descriptor Sets

Descriptors are grouped together into descriptor set objects. A descriptor set object is an opaque object containing storage for a set of descriptors, where the types and number of descriptors is defined by a descriptor set layout. The layout object may: be used to define the association of each descriptor binding with memory or other implementation resources. The layout is used both for determining the resources that need to be associated with the descriptor set, and determining the interface between shader stages and shader resources.

Descriptor Set Layout

A descriptor set layout object is defined by an array of zero or more descriptor bindings. Each individual descriptor binding is specified by a descriptor type, a count (array size) of the number of descriptors in the binding, a set of shader stages that can: access the binding, and (if using immutable samplers) an array of sampler descriptors.

Descriptor set layout objects are represented by sname:VkDescriptorSetLayout handles:

To create descriptor set layout objects, call:

  • pname:device is the logical device that creates the descriptor set layout.

  • pname:pCreateInfo is a pointer to a slink:VkDescriptorSetLayoutCreateInfo structure specifying the state of the descriptor set layout object.

  • pname:pAllocator controls host memory allocation as described in the Memory Allocation chapter.

  • pname:pSetLayout is a pointer to a slink:VkDescriptorSetLayout handle in which the resulting descriptor set layout object is returned.

Information about the descriptor set layout is passed in a sname:VkDescriptorSetLayoutCreateInfo structure:

  • pname:sType is the type of this structure.

  • pname:pNext is NULL or a pointer to a structure extending this structure.

  • pname:flags is a bitmask specifying options for descriptor set layout creation.

  • pname:bindingCount is the number of elements in pname:pBindings.

  • pname:pBindings is a pointer to an array of slink:VkDescriptorSetLayoutBinding structures.

Valid Usage
  • The slink:VkDescriptorSetLayoutBinding::pname:binding members of the elements of the pname:pBindings array must: each have different values

Bits which can: be set in slink:VkDescriptorSetLayoutCreateInfo::pname:flags, specifying options for descriptor set layout, are:

Note
Note

All bits for this type are defined by extensions, and none of those extensions are enabled in this build of the specification.

tname:VkDescriptorSetLayoutCreateFlags is a bitmask type for setting a mask of zero or more elink:VkDescriptorSetLayoutCreateFlagBits.

The sname:VkDescriptorSetLayoutBinding structure is defined as:

  • pname:binding is the binding number of this entry and corresponds to a resource of the same binding number in the shader stages.

  • pname:descriptorType is a elink:VkDescriptorType specifying which type of resource descriptors are used for this binding.

  • pname:descriptorCount is the number of descriptors contained in the binding, accessed in a shader as an array. If pname:descriptorCount is zero this binding entry is reserved and the resource must: not be accessed from any stage via this binding within any pipeline using the set layout.

  • pname:stageFlags member is a bitmask of elink:VkShaderStageFlagBits specifying which pipeline shader stages can: access a resource for this binding. ename:VK_SHADER_STAGE_ALL is a shorthand specifying that all defined shader stages, including any additional stages defined by extensions, can: access the resource.

    If a shader stage is not included in pname:stageFlags, then a resource must: not be accessed from that stage via this binding within any pipeline using the set layout. Other than input attachments which are limited to the fragment shader, there are no limitations on what combinations of stages can: use a descriptor binding, and in particular a binding can: be used by both graphics stages and the compute stage.

  • pname:pImmutableSamplers affects initialization of samplers. If pname:descriptorType specifies a ename:VK_DESCRIPTOR_TYPE_SAMPLER or ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER type descriptor, then pname:pImmutableSamplers can: be used to initialize a set of immutable samplers. Immutable samplers are permanently bound into the set layout and must: not be changed; updating a ename:VK_DESCRIPTOR_TYPE_SAMPLER descriptor with immutable samplers is not allowed and updates to a ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptor with immutable samplers does not modify the samplers (the image views are updated, but the sampler updates are ignored). If pname:pImmutableSamplers is not NULL, then it is a pointer to an array of sampler handles that will be copied into the set layout and used for the corresponding binding. Only the sampler handles are copied; the sampler objects must: not be destroyed before the final use of the set layout and any descriptor pools and sets created using it. If pname:pImmutableSamplers is NULL, then the sampler slots are dynamic and sampler handles must: be bound into descriptor sets using this layout. If pname:descriptorType is not one of these descriptor types, then pname:pImmutableSamplers is ignored.

The above layout definition allows the descriptor bindings to be specified sparsely such that not all binding numbers between 0 and the maximum binding number need to be specified in the pname:pBindings array. Bindings that are not specified have a pname:descriptorCount and pname:stageFlags of zero, and the value of pname:descriptorType is undefined:. However, all binding numbers between 0 and the maximum binding number in the slink:VkDescriptorSetLayoutCreateInfo::pname:pBindings array may: consume memory in the descriptor set layout even if not all descriptor bindings are used, though it should: not consume additional memory from the descriptor pool.

Note
Note

The maximum binding number specified should: be as compact as possible to avoid wasted memory.

Valid Usage
  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLER or ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and pname:descriptorCount is not 0 and pname:pImmutableSamplers is not NULL, pname:pImmutableSamplers must: be a valid pointer to an array of pname:descriptorCount valid sname:VkSampler handles

  • If pname:descriptorCount is not 0, pname:stageFlags must: be a valid combination of elink:VkShaderStageFlagBits values

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT and pname:descriptorCount is not 0, then pname:stageFlags must: be 0 or ename:VK_SHADER_STAGE_FRAGMENT_BIT

The following examples show a shader snippet using two descriptor sets, and application code that creates corresponding descriptor set layouts.

GLSL example
//
// binding to a single sampled image descriptor in set 0
//
layout (set=0, binding=0) uniform texture2D mySampledImage;

//
// binding to an array of sampled image descriptors in set 0
//
layout (set=0, binding=1) uniform texture2D myArrayOfSampledImages[12];

//
// binding to a single uniform buffer descriptor in set 1
//
layout (set=1, binding=0) uniform myUniformBuffer
{
    vec4 myElement[32];
};
SPIR-V example
               ...
          %1 = OpExtInstImport "GLSL.std.450"
               ...
               OpName %9 "mySampledImage"
               OpName %14 "myArrayOfSampledImages"
               OpName %18 "myUniformBuffer"
               OpMemberName %18 0 "myElement"
               OpName %20 ""
               OpDecorate %9 DescriptorSet 0
               OpDecorate %9 Binding 0
               OpDecorate %14 DescriptorSet 0
               OpDecorate %14 Binding 1
               OpDecorate %17 ArrayStride 16
               OpMemberDecorate %18 0 Offset 0
               OpDecorate %18 Block
               OpDecorate %20 DescriptorSet 1
               OpDecorate %20 Binding 0
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
          %6 = OpTypeFloat 32
          %7 = OpTypeImage %6 2D 0 0 0 1 Unknown
          %8 = OpTypePointer UniformConstant %7
          %9 = OpVariable %8 UniformConstant
         %10 = OpTypeInt 32 0
         %11 = OpConstant %10 12
         %12 = OpTypeArray %7 %11
         %13 = OpTypePointer UniformConstant %12
         %14 = OpVariable %13 UniformConstant
         %15 = OpTypeVector %6 4
         %16 = OpConstant %10 32
         %17 = OpTypeArray %15 %16
         %18 = OpTypeStruct %17
         %19 = OpTypePointer Uniform %18
         %20 = OpVariable %19 Uniform
               ...
API example
VkResult myResult;

const VkDescriptorSetLayoutBinding myDescriptorSetLayoutBinding[] =
{
    // binding to a single image descriptor
    {
        0,                                      // binding
        VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,       // descriptorType
        1,                                      // descriptorCount
        VK_SHADER_STAGE_FRAGMENT_BIT,           // stageFlags
        NULL                                    // pImmutableSamplers
    },

    // binding to an array of image descriptors
    {
        1,                                      // binding
        VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,       // descriptorType
        12,                                     // descriptorCount
        VK_SHADER_STAGE_FRAGMENT_BIT,           // stageFlags
        NULL                                    // pImmutableSamplers
    },

    // binding to a single uniform buffer descriptor
    {
        0,                                      // binding
        VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,      // descriptorType
        1,                                      // descriptorCount
        VK_SHADER_STAGE_FRAGMENT_BIT,           // stageFlags
        NULL                                    // pImmutableSamplers
    }
};

const VkDescriptorSetLayoutCreateInfo myDescriptorSetLayoutCreateInfo[] =
{
    // Information for first descriptor set with two descriptor bindings
    {
        VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,    // sType
        NULL,                                                   // pNext
        0,                                                      // flags
        2,                                                      // bindingCount
        &myDescriptorSetLayoutBinding[0]                        // pBindings
    },

    // Information for second descriptor set with one descriptor binding
    {
        VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,    // sType
        NULL,                                                   // pNext
        0,                                                      // flags
        1,                                                      // bindingCount
        &myDescriptorSetLayoutBinding[2]                        // pBindings
    }
};

VkDescriptorSetLayout myDescriptorSetLayout[2];

//
// Create first descriptor set layout
//
myResult = vkCreateDescriptorSetLayout(
    myDevice,
    &myDescriptorSetLayoutCreateInfo[0],
    NULL,
    &myDescriptorSetLayout[0]);

//
// Create second descriptor set layout
//
myResult = vkCreateDescriptorSetLayout(
    myDevice,
    &myDescriptorSetLayoutCreateInfo[1],
    NULL,
    &myDescriptorSetLayout[1]);

To destroy a descriptor set layout, call:

  • pname:device is the logical device that destroys the descriptor set layout.

  • pname:descriptorSetLayout is the descriptor set layout to destroy.

  • pname:pAllocator controls host memory allocation as described in the Memory Allocation chapter.

Valid Usage
  • If sname:VkAllocationCallbacks were provided when pname:descriptorSetLayout was created, a compatible set of callbacks must: be provided here

  • If no sname:VkAllocationCallbacks were provided when pname:descriptorSetLayout was created, pname:pAllocator must: be NULL

Pipeline Layouts

Access to descriptor sets from a pipeline is accomplished through a pipeline layout. Zero or more descriptor set layouts and zero or more push constant ranges are combined to form a pipeline layout object describing the complete set of resources that can: be accessed by a pipeline. The pipeline layout represents a sequence of descriptor sets with each having a specific layout. This sequence of layouts is used to determine the interface between shader stages and shader resources. Each pipeline is created using a pipeline layout.

Pipeline layout objects are represented by sname:VkPipelineLayout handles:

To create a pipeline layout, call:

  • pname:device is the logical device that creates the pipeline layout.

  • pname:pCreateInfo is a pointer to a slink:VkPipelineLayoutCreateInfo structure specifying the state of the pipeline layout object.

  • pname:pAllocator controls host memory allocation as described in the Memory Allocation chapter.

  • pname:pPipelineLayout is a pointer to a slink:VkPipelineLayout handle in which the resulting pipeline layout object is returned.

The slink:VkPipelineLayoutCreateInfo structure is defined as:

  • pname:sType is the type of this structure.

  • pname:pNext is NULL or a pointer to a structure extending this structure.

  • pname:flags is a bitmask of elink:VkPipelineLayoutCreateFlagBits specifying options for pipeline layout creation.

  • pname:setLayoutCount is the number of descriptor sets included in the pipeline layout.

  • pname:pSetLayouts is a pointer to an array of sname:VkDescriptorSetLayout objects.

  • pname:pushConstantRangeCount is the number of push constant ranges included in the pipeline layout.

  • pname:pPushConstantRanges is a pointer to an array of sname:VkPushConstantRange structures defining a set of push constant ranges for use in a single pipeline layout. In addition to descriptor set layouts, a pipeline layout also describes how many push constants can: be accessed by each stage of the pipeline.

    Note
    Note

    Push constants represent a high speed path to modify constant data in pipelines that is expected to outperform memory-backed resource updates.

Valid Usage
  • pname:setLayoutCount must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxBoundDescriptorSets

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_SAMPLER and ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER accessible to any shader stage across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPerStageDescriptorSamplers

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER and ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC accessible to any shader stage across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPerStageDescriptorUniformBuffers

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER and ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC accessible to any shader stage across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPerStageDescriptorStorageBuffers

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, and ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER accessible to any shader stage across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPerStageDescriptorSampledImages

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, and ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER accessible to any shader stage across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPerStageDescriptorStorageImages

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT accessible to any given shader stage across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPerStageDescriptorInputAttachments

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_SAMPLER and ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetSamplers

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetUniformBuffers

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetUniformBuffersDynamic

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetStorageBuffers

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetStorageBuffersDynamic

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, and ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetSampledImages

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, and ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetStorageImages

  • The total number of descriptors of the type ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT accessible across all shader stages and across all elements of pname:pSetLayouts must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxDescriptorSetInputAttachments

  • Any two elements of pname:pPushConstantRanges must: not include the same stage in pname:stageFlags

  • Elements of pname:pSetLayouts must: be valid slink:VkDescriptorSetLayout objects

All values for this enum are defined by extensions.

tname:VkPipelineLayoutCreateFlags is a bitmask type for setting a mask of elink:VkPipelineLayoutCreateFlagBits.

The sname:VkPushConstantRange structure is defined as:

  • pname:stageFlags is a set of stage flags describing the shader stages that will access a range of push constants. If a particular stage is not included in the range, then accessing members of that range of push constants from the corresponding shader stage will return undefined: values.

  • pname:offset and pname:size are the start offset and size, respectively, consumed by the range. Both pname:offset and pname:size are in units of bytes and must: be a multiple of 4. The layout of the push constant variables is specified in the shader.

Valid Usage
  • pname:offset must: be less than sname:VkPhysicalDeviceLimits::pname:maxPushConstantsSize

  • pname:offset must: be a multiple of 4

  • pname:size must: be greater than 0

  • pname:size must: be a multiple of 4

  • pname:size must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPushConstantsSize minus pname:offset

Once created, pipeline layouts are used as part of pipeline creation (see Pipelines), as part of binding descriptor sets (see Descriptor Set Binding), and as part of setting push constants (see Push Constant Updates). Pipeline creation accepts a pipeline layout as input, and the layout may: be used to map (set, binding, arrayElement) tuples to implementation resources or memory locations within a descriptor set. The assignment of implementation resources depends only on the bindings defined in the descriptor sets that comprise the pipeline layout, and not on any shader source.

All resource variables statically used in all shaders in a pipeline must: be declared with a (set, binding, arrayElement) that exists in the corresponding descriptor set layout and is of an appropriate descriptor type and includes the set of shader stages it is used by in pname:stageFlags. The pipeline layout can: include entries that are not used by a particular pipeline, or that are dead-code eliminated from any of the shaders. The pipeline layout allows the application to provide a consistent set of bindings across multiple pipeline compiles, which enables those pipelines to be compiled in a way that the implementation may: cheaply switch pipelines without reprogramming the bindings.

Similarly, the push constant block declared in each shader (if present) must: only place variables at offsets that are each included in a push constant range with pname:stageFlags including the bit corresponding to the shader stage that uses it. The pipeline layout can: include ranges or portions of ranges that are not used by a particular pipeline, or for which the variables have been dead-code eliminated from any of the shaders.

There is a limit on the total number of resources of each type that can: be included in bindings in all descriptor set layouts in a pipeline layout as shown in Pipeline Layout Resource Limits. The “Total Resources Available” column gives the limit on the number of each type of resource that can: be included in bindings in all descriptor sets in the pipeline layout. Some resource types count against multiple limits. Additionally, there are limits on the total number of each type of resource that can: be used in any pipeline stage as described in Shader Resource Limits.

Table 1. Pipeline Layout Resource Limits
Total Resources Available Resource Types

pname:maxDescriptorSetSamplers

sampler

combined image sampler

pname:maxDescriptorSetSampledImages

sampled image

combined image sampler

uniform texel buffer

pname:maxDescriptorSetStorageImages

storage image

storage texel buffer

pname:maxDescriptorSetUniformBuffers

uniform buffer

uniform buffer dynamic

pname:maxDescriptorSetUniformBuffersDynamic

uniform buffer dynamic

pname:maxDescriptorSetStorageBuffers

storage buffer

storage buffer dynamic

pname:maxDescriptorSetStorageBuffersDynamic

storage buffer dynamic

pname:maxDescriptorSetInputAttachments

input attachment

To destroy a pipeline layout, call:

  • pname:device is the logical device that destroys the pipeline layout.

  • pname:pipelineLayout is the pipeline layout to destroy.

  • pname:pAllocator controls host memory allocation as described in the Memory Allocation chapter.

Valid Usage
  • If sname:VkAllocationCallbacks were provided when pname:pipelineLayout was created, a compatible set of callbacks must: be provided here

  • If no sname:VkAllocationCallbacks were provided when pname:pipelineLayout was created, pname:pAllocator must: be NULL

  • pname:pipelineLayout must: not have been passed to any ftext:vkCmd* command for any command buffers that are still in the recording state when fname:vkDestroyPipelineLayout is called

Pipeline Layout Compatibility

Two pipeline layouts are defined to be “compatible for push constants” if they were created with identical push constant ranges. Two pipeline layouts are defined to be “compatible for set N” if they were created with identically defined descriptor set layouts for sets zero through N, and if they were created with identical push constant ranges.

When binding a descriptor set (see Descriptor Set Binding) to set number N, if the previously bound descriptor sets for sets zero through N-1 were all bound using compatible pipeline layouts, then performing this binding does not disturb any of the lower numbered sets. If, additionally, the previously bound descriptor set for set N was bound using a pipeline layout compatible for set N, then the bindings in sets numbered greater than N are also not disturbed.

Similarly, when binding a pipeline, the pipeline can: correctly access any previously bound descriptor sets which were bound with compatible pipeline layouts, as long as all lower numbered sets were also bound with compatible layouts.

Layout compatibility means that descriptor sets can: be bound to a command buffer for use by any pipeline created with a compatible pipeline layout, and without having bound a particular pipeline first. It also means that descriptor sets can: remain valid across a pipeline change, and the same resources will be accessible to the newly bound pipeline.

Note
Note

Place the least frequently changing descriptor sets near the start of the pipeline layout, and place the descriptor sets representing the most frequently changing resources near the end. When pipelines are switched, only the descriptor set bindings that have been invalidated will need to be updated and the remainder of the descriptor set bindings will remain in place.

The maximum number of descriptor sets that can: be bound to a pipeline layout is queried from physical device properties (see pname:maxBoundDescriptorSets in Limits).

API example
const VkDescriptorSetLayout layouts[] = { layout1, layout2 };

const VkPushConstantRange ranges[] =
{
    {
        VK_SHADER_STAGE_VERTEX_BIT,    // stageFlags
        0,                             // offset
        4                              // size
    },

    {
        VK_SHADER_STAGE_FRAGMENT_BIT,  // stageFlags
        4,                             // offset
        4                              // size
    },
};

const VkPipelineLayoutCreateInfo createInfo =
{
    VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,  // sType
    NULL,                                           // pNext
    0,                                              // flags
    2,                                              // setLayoutCount
    layouts,                                        // pSetLayouts
    2,                                              // pushConstantRangeCount
    ranges                                          // pPushConstantRanges
};

VkPipelineLayout myPipelineLayout;
myResult = vkCreatePipelineLayout(
    myDevice,
    &createInfo,
    NULL,
    &myPipelineLayout);

Allocation of Descriptor Sets

A descriptor pool maintains a pool of descriptors, from which descriptor sets are allocated. Descriptor pools are externally synchronized, meaning that the application must: not allocate and/or free descriptor sets from the same pool in multiple threads simultaneously.

Descriptor pools are represented by sname:VkDescriptorPool handles:

To create a descriptor pool object, call:

  • pname:device is the logical device that creates the descriptor pool.

  • pname:pCreateInfo is a pointer to a slink:VkDescriptorPoolCreateInfo structure specifying the state of the descriptor pool object.

  • pname:pAllocator controls host memory allocation as described in the Memory Allocation chapter.

  • pname:pDescriptorPool is a pointer to a slink:VkDescriptorPool handle in which the resulting descriptor pool object is returned.

The created descriptor pool is returned in pname:pDescriptorPool.

Additional information about the pool is passed in a sname:VkDescriptorPoolCreateInfo structure:

  • pname:sType is the type of this structure.

  • pname:pNext is NULL or a pointer to a structure extending this structure.

  • pname:flags is a bitmask of elink:VkDescriptorPoolCreateFlagBits specifying certain supported operations on the pool.

  • pname:maxSets is the maximum number of descriptor sets that can: be allocated from the pool.

  • pname:poolSizeCount is the number of elements in pname:pPoolSizes.

  • pname:pPoolSizes is a pointer to an array of slink:VkDescriptorPoolSize structures, each containing a descriptor type and number of descriptors of that type to be allocated in the pool.

If multiple sname:VkDescriptorPoolSize structures containing the same descriptor type appear in the pname:pPoolSizes array then the pool will be created with enough storage for the total number of descriptors of each type.

Fragmentation of a descriptor pool is possible and may: lead to descriptor set allocation failures. A failure due to fragmentation is defined as failing a descriptor set allocation despite the sum of all outstanding descriptor set allocations from the pool plus the requested allocation requiring no more than the total number of descriptors requested at pool creation. Implementations provide certain guarantees of when fragmentation must: not cause allocation failure, as described below.

If a descriptor pool has not had any descriptor sets freed since it was created or most recently reset then fragmentation must: not cause an allocation failure (note that this is always the case for a pool created without the ename:VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT bit set). Additionally, if all sets allocated from the pool since it was created or most recently reset use the same number of descriptors (of each type) and the requested allocation also uses that same number of descriptors (of each type), then fragmentation must: not cause an allocation failure.

If an allocation failure occurs due to fragmentation, an application can: create an additional descriptor pool to perform further descriptor set allocations.

Valid Usage
  • pname:maxSets must: be greater than 0

Bits which can: be set in slink:VkDescriptorPoolCreateInfo::pname:flags, enabling operations on a descriptor pool, are:

  • ename:VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT specifies that descriptor sets can: return their individual allocations to the pool, i.e. all of flink:vkAllocateDescriptorSets, flink:vkFreeDescriptorSets, and flink:vkResetDescriptorPool are allowed. Otherwise, descriptor sets allocated from the pool must: not be individually freed back to the pool, i.e. only flink:vkAllocateDescriptorSets and flink:vkResetDescriptorPool are allowed.

tname:VkDescriptorPoolCreateFlags is a bitmask type for setting a mask of zero or more elink:VkDescriptorPoolCreateFlagBits.

The sname:VkDescriptorPoolSize structure is defined as:

  • pname:type is the type of descriptor.

  • pname:descriptorCount is the number of descriptors of that type to allocate.

Valid Usage
  • pname:descriptorCount must: be greater than 0

To destroy a descriptor pool, call:

  • pname:device is the logical device that destroys the descriptor pool.

  • pname:descriptorPool is the descriptor pool to destroy.

  • pname:pAllocator controls host memory allocation as described in the Memory Allocation chapter.

When a pool is destroyed, all descriptor sets allocated from the pool are implicitly freed and become invalid. Descriptor sets allocated from a given pool do not need to be freed before destroying that descriptor pool.

Valid Usage
  • All submitted commands that refer to pname:descriptorPool (via any allocated descriptor sets) must: have completed execution

  • If sname:VkAllocationCallbacks were provided when pname:descriptorPool was created, a compatible set of callbacks must: be provided here

  • If no sname:VkAllocationCallbacks were provided when pname:descriptorPool was created, pname:pAllocator must: be NULL

Descriptor sets are allocated from descriptor pool objects, and are represented by sname:VkDescriptorSet handles:

To allocate descriptor sets from a descriptor pool, call:

  • pname:device is the logical device that owns the descriptor pool.

  • pname:pAllocateInfo is a pointer to a slink:VkDescriptorSetAllocateInfo structure describing parameters of the allocation.

  • pname:pDescriptorSets is a pointer to an array of slink:VkDescriptorSet handles in which the resulting descriptor set objects are returned.

The allocated descriptor sets are returned in pname:pDescriptorSets.

When a descriptor set is allocated, the initial state is largely uninitialized and all descriptors are undefined:, with the exception that samplers with a non-null pname:pImmutableSamplers are initialized on allocation. Descriptors also become undefined: if the underlying resource or view object is destroyed. Descriptor sets containing undefined: descriptors can: still be bound and used, subject to the following conditions:

  • Descriptors that are statically used must: have been populated before the descriptor set is consumed.

  • Entries that are not used by a pipeline can: have undefined: descriptors.

If an allocation fails due to fragmentation, an indeterminate error is returned with an unspecified error code. Any returned error other than ename:VK_ERROR_FRAGMENTED_POOL does not imply its usual meaning: applications should: assume that the allocation failed due to fragmentation, and create a new descriptor pool.

Note
Note

Applications should: check for a negative return value when allocating new descriptor sets, assume that any error effectively means ename:VK_ERROR_FRAGMENTED_POOL, and try to create a new descriptor pool. If ename:VK_ERROR_FRAGMENTED_POOL is the actual return value, it adds certainty to that decision.

The reason for this is that ename:VK_ERROR_FRAGMENTED_POOL was only added in a later version of the 1.0 specification, and so drivers may: return other errors if they were written against earlier versions. To ensure full compatibility with earlier patch versions, these other errors are allowed.

The sname:VkDescriptorSetAllocateInfo structure is defined as:

  • pname:sType is the type of this structure.

  • pname:pNext is NULL or a pointer to a structure extending this structure.

  • pname:descriptorPool is the pool which the sets will be allocated from.

  • pname:descriptorSetCount determines the number of descriptor sets to be allocated from the pool.

  • pname:pSetLayouts is a pointer to an array of descriptor set layouts, with each member specifying how the corresponding descriptor set is allocated.

Valid Usage
  • pname:descriptorSetCount must: not be greater than the number of sets that are currently available for allocation in pname:descriptorPool

  • pname:descriptorPool must: have enough free descriptor capacity remaining to allocate the descriptor sets of the specified layouts

To free allocated descriptor sets, call:

  • pname:device is the logical device that owns the descriptor pool.

  • pname:descriptorPool is the descriptor pool from which the descriptor sets were allocated.

  • pname:descriptorSetCount is the number of elements in the pname:pDescriptorSets array.

  • pname:pDescriptorSets is a pointer to an array of handles to slink:VkDescriptorSet objects.

After calling fname:vkFreeDescriptorSets, all descriptor sets in pname:pDescriptorSets are invalid.

Valid Usage
  • All submitted commands that refer to any element of pname:pDescriptorSets must: have completed execution

  • pname:pDescriptorSets must: be a valid pointer to an array of pname:descriptorSetCount sname:VkDescriptorSet handles, each element of which must: either be a valid handle or dlink:VK_NULL_HANDLE

  • pname:descriptorPool must: have been created with the ename:VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag

To return all descriptor sets allocated from a given pool to the pool, rather than freeing individual descriptor sets, call:

  • pname:device is the logical device that owns the descriptor pool.

  • pname:descriptorPool is the descriptor pool to be reset.

  • pname:flags is reserved for future use.

Resetting a descriptor pool recycles all of the resources from all of the descriptor sets allocated from the descriptor pool back to the descriptor pool, and the descriptor sets are implicitly freed.

Valid Usage
  • All uses of pname:descriptorPool (via any allocated descriptor sets) must: have completed execution

tname:VkDescriptorPoolResetFlags is a bitmask type for setting a mask, but is currently reserved for future use.

Descriptor Set Updates

Once allocated, descriptor sets can: be updated with a combination of write and copy operations. To update descriptor sets, call:

  • pname:device is the logical device that updates the descriptor sets.

  • pname:descriptorWriteCount is the number of elements in the pname:pDescriptorWrites array.

  • pname:pDescriptorWrites is a pointer to an array of slink:VkWriteDescriptorSet structures describing the descriptor sets to write to.

  • pname:descriptorCopyCount is the number of elements in the pname:pDescriptorCopies array.

  • pname:pDescriptorCopies is a pointer to an array of slink:VkCopyDescriptorSet structures describing the descriptor sets to copy between.

The operations described by pname:pDescriptorWrites are performed first, followed by the operations described by pname:pDescriptorCopies. Within each array, the operations are performed in the order they appear in the array.

Each element in the pname:pDescriptorWrites array describes an operation updating the descriptor set using descriptors for resources specified in the structure.

Each element in the pname:pDescriptorCopies array is a slink:VkCopyDescriptorSet structure describing an operation copying descriptors between sets.

If the pname:dstSet member of any element of pname:pDescriptorWrites or pname:pDescriptorCopies is bound, accessed, or modified by any command that was recorded to a command buffer which is currently in the recording or executable state, that command buffer becomes invalid.

Valid Usage
  • For each element i where pname:pDescriptorWrites[i].pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, elements of the pname:pTexelBufferView member of pname:pDescriptorWrites[i] must: have been created on pname:device

  • For each element i where pname:pDescriptorWrites[i].pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the pname:buffer member of any element of the pname:pBufferInfo member of pname:pDescriptorWrites[i] must: have been created on pname:device

  • For each element i where pname:pDescriptorWrites[i].pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLER or ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and pname:dstSet was not allocated with a layout that included immutable samplers for pname:dstBinding with pname:descriptorType, the pname:sampler member of any element of the pname:pImageInfo member of pname:pDescriptorWrites[i] must: have been created on pname:device

  • For each element i where pname:pDescriptorWrites[i].pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, or ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER the pname:imageView member of any element of pname:pDescriptorWrites[i] must: have been created on pname:device

  • For each element i where pname:pDescriptorWrites[i].pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLER, ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, or ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pname:pDescriptorWrites[i].pname:pImageInfo must: be a valid pointer to an array of pname:pDescriptorWrites[i].pname:descriptorCount valid sname:VkDescriptorImageInfo structures

  • The pname:dstSet member of each element of pname:pDescriptorWrites or pname:pDescriptorCopies must: not be used by any command that was recorded to a command buffer which is in the pending state

  • Host access to pname:pDescriptorWrites[i].pname:dstSet and pname:pDescriptorCopies[i].pname:dstSet must: be externally synchronized

The sname:VkWriteDescriptorSet structure is defined as:

  • pname:sType is the type of this structure.

  • pname:pNext is NULL or a pointer to a structure extending this structure.

  • pname:dstSet is the destination descriptor set to update.

  • pname:dstBinding is the descriptor binding within that set.

  • pname:dstArrayElement is the starting element in that array.

  • pname:descriptorCount is the number of descriptors to update. pname:descriptorCount is one of

    • the number of elements in pname:pImageInfo

    • the number of elements in pname:pBufferInfo

    • the number of elements in pname:pTexelBufferView

  • pname:descriptorType is a elink:VkDescriptorType specifying the type of each descriptor in pname:pImageInfo, pname:pBufferInfo, or pname:pTexelBufferView, as described below. It must: be the same type as the pname:descriptorType specified in sname:VkDescriptorSetLayoutBinding for pname:dstSet at pname:dstBinding. The type of the descriptor also controls which array the descriptors are taken from.

  • pname:pImageInfo is a pointer to an array of slink:VkDescriptorImageInfo structures or is ignored, as described below.

  • pname:pBufferInfo is a pointer to an array of slink:VkDescriptorBufferInfo structures or is ignored, as described below.

  • pname:pTexelBufferView is a pointer to an array of slink:VkBufferView handles as described in the Buffer Views section or is ignored, as described below.

Only one of pname:pImageInfo, pname:pBufferInfo, or pname:pTexelBufferView members is used according to the descriptor type specified in the pname:descriptorType member of the containing sname:VkWriteDescriptorSet structure, as specified below.

If the pname:dstBinding has fewer than pname:descriptorCount array elements remaining starting from pname:dstArrayElement, then the remainder will be used to update the subsequent binding - pname:dstBinding+1 starting at array element zero. If a binding has a pname:descriptorCount of zero, it is skipped. This behavior applies recursively, with the update affecting consecutive bindings as needed to update all pname:descriptorCount descriptors. Consecutive bindings must: have identical elink:VkDescriptorType, tlink:VkShaderStageFlags, and immutable samplers references.

Valid Usage
  • pname:dstBinding must: be less than or equal to the maximum value of pname:binding of all slink:VkDescriptorSetLayoutBinding structures specified when pname:dstSet’s descriptor set layout was created

  • pname:dstBinding must: be a binding with a non-zero pname:descriptorCount

  • All consecutive bindings updated via a single sname:VkWriteDescriptorSet structure, except those with a pname:descriptorCount of zero, must: have identical pname:descriptorType and pname:stageFlags

  • All consecutive bindings updated via a single sname:VkWriteDescriptorSet structure, except those with a pname:descriptorCount of zero, must: all either use immutable samplers or must: all not use immutable samplers

  • pname:descriptorType must: match the type of pname:dstBinding within pname:dstSet

  • pname:dstSet must: be a valid slink:VkDescriptorSet handle

  • The sum of pname:dstArrayElement and pname:descriptorCount must: be less than or equal to the number of array elements in the descriptor set binding specified by pname:dstBinding, and all applicable consecutive bindings, as described by consecutive binding updates

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, each element of pname:pTexelBufferView must: be either a valid sname:VkBufferView handle or dlink:VK_NULL_HANDLE

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER and the pname:nullDescriptor feature is not enabled, each element of pname:pTexelBufferView must: not be dlink:VK_NULL_HANDLE

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pname:pBufferInfo must: be a valid pointer to an array of pname:descriptorCount valid sname:VkDescriptorBufferInfo structures

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLER or ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and pname:dstSet was not allocated with a layout that included immutable samplers for pname:dstBinding with pname:descriptorType, the pname:sampler member of each element of pname:pImageInfo must: be a valid sname:VkSampler object

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, or ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, the pname:imageView member of each element of pname:pImageInfo must: be either a valid sname:VkImageView handle or dlink:VK_NULL_HANDLE

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, or ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, and the pname:nullDescriptor feature is not enabled, the pname:imageView member of each element of pname:pImageInfo must: not be dlink:VK_NULL_HANDLE

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the pname:imageView member of each element of pname:pImageInfo must: not be dlink:VK_NULL_HANDLE

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the pname:offset member of each element of pname:pBufferInfo must: be a multiple of sname:VkPhysicalDeviceLimits::pname:minUniformBufferOffsetAlignment

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the pname:offset member of each element of pname:pBufferInfo must: be a multiple of sname:VkPhysicalDeviceLimits::pname:minStorageBufferOffsetAlignment

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, and the pname:buffer member of any element of pname:pBufferInfo is the handle of a non-sparse buffer, then that buffer must: be bound completely and contiguously to a single sname:VkDeviceMemory object

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the pname:buffer member of each element of pname:pBufferInfo must: have been created with ename:VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the pname:buffer member of each element of pname:pBufferInfo must: have been created with ename:VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the pname:range member of each element of pname:pBufferInfo, or the effective range if pname:range is ename:VK_WHOLE_SIZE, must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxUniformBufferRange

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the pname:range member of each element of pname:pBufferInfo, or the effective range if pname:range is ename:VK_WHOLE_SIZE, must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxStorageBufferRange

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, the sname:VkBuffer that each element of pname:pTexelBufferView was created from must: have been created with ename:VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, the sname:VkBuffer that each element of pname:pTexelBufferView was created from must: have been created with ename:VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the pname:imageView member of each element of pname:pImageInfo must: have been created with the identity swizzle

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the pname:imageView member of each element of pname:pImageInfo must: have been created with exactly one aspect

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE or ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, the pname:imageView member of each element of pname:pImageInfo must: have been created with ename:VK_IMAGE_USAGE_SAMPLED_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE the pname:imageLayout member of each element of pname:pImageInfo must: be a member of the list given in Sampled Image

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER the pname:imageLayout member of each element of pname:pImageInfo must: be a member of the list given in Combined Image Sampler

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT the pname:imageLayout member of each element of pname:pImageInfo must: be a member of the list given in Input Attachment

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE the pname:imageLayout member of each element of pname:pImageInfo must: be a member of the list given in Storage Image

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the pname:imageView member of each element of pname:pImageInfo must: have been created with ename:VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, the pname:imageView member of each element of pname:pImageInfo must: have been created with ename:VK_IMAGE_USAGE_STORAGE_BIT set

  • If pname:descriptorType is ename:VK_DESCRIPTOR_TYPE_SAMPLER, then pname:dstSet must: not have been allocated with a layout that included immutable samplers for pname:dstBinding

The type of descriptors in a descriptor set is specified by slink:VkWriteDescriptorSet::pname:descriptorType, which must: be one of the values:

When a descriptor set is updated via elements of slink:VkWriteDescriptorSet, members of pname:pImageInfo, pname:pBufferInfo and pname:pTexelBufferView are only accessed by the implementation when they correspond to descriptor type being defined - otherwise they are ignored. The members accessed are as follows for each descriptor type:

  • For ename:VK_DESCRIPTOR_TYPE_SAMPLER, only the pname:sampler member of each element of slink:VkWriteDescriptorSet::pname:pImageInfo is accessed.

  • For ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, or ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, only the pname:imageView and pname:imageLayout members of each element of slink:VkWriteDescriptorSet::pname:pImageInfo are accessed.

  • For ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, all members of each element of slink:VkWriteDescriptorSet::pname:pImageInfo are accessed.

  • For ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, or ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, all members of each element of slink:VkWriteDescriptorSet::pname:pBufferInfo are accessed.

  • For ename:VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or ename:VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, each element of slink:VkWriteDescriptorSet::pname:pTexelBufferView is accessed.

The sname:VkDescriptorBufferInfo structure is defined as:

  • pname:buffer is the buffer resource.

  • pname:offset is the offset in bytes from the start of pname:buffer. Access to buffer memory via this descriptor uses addressing that is relative to this starting offset.

  • pname:range is the size in bytes that is used for this descriptor update, or ename:VK_WHOLE_SIZE to use the range from pname:offset to the end of the buffer.

When setting pname:range to ename:VK_WHOLE_SIZE, the effective range must: not be larger than the maximum range for the descriptor type (pname:maxUniformBufferRange or pname:maxStorageBufferRange). This means that ename:VK_WHOLE_SIZE is not typically useful in the common case where uniform buffer descriptors are suballocated from a buffer that is much larger than pname:maxUniformBufferRange.

For ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC and ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC descriptor types, pname:offset is the base offset from which the dynamic offset is applied and pname:range is the static size used for all dynamic offsets.

When pname:range is ename:VK_WHOLE_SIZE the effective range is calculated at flink:vkUpdateDescriptorSets is by taking the size of pname:buffer minus the pname:offset.

Valid Usage
  • pname:offset must: be less than the size of pname:buffer

  • If pname:range is not equal to ename:VK_WHOLE_SIZE, pname:range must: be greater than 0

  • If pname:range is not equal to ename:VK_WHOLE_SIZE, pname:range must: be less than or equal to the size of pname:buffer minus pname:offset

  • If the pname:nullDescriptor feature is not enabled, pname:buffer must: not be dlink:VK_NULL_HANDLE

The sname:VkDescriptorImageInfo structure is defined as:

  • pname:sampler is a sampler handle, and is used in descriptor updates for types ename:VK_DESCRIPTOR_TYPE_SAMPLER and ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER if the binding being updated does not use immutable samplers.

  • pname:imageView is an image view handle, and is used in descriptor updates for types ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT.

  • pname:imageLayout is the layout that the image subresources accessible from pname:imageView will be in at the time this descriptor is accessed. pname:imageLayout is used in descriptor updates for types ename:VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, ename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, ename:VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and ename:VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT.

Members of sname:VkDescriptorImageInfo that are not used in an update (as described above) are ignored.

Valid Usage
  • If pname:imageView is created from a depth/stencil image, the pname:aspectMask used to create the pname:imageView must: include either ename:VK_IMAGE_ASPECT_DEPTH_BIT or ename:VK_IMAGE_ASPECT_STENCIL_BIT but not both

  • pname:imageLayout must: match the actual elink:VkImageLayout of each subresource accessible from pname:imageView at the time this descriptor is accessed as defined by the image layout matching rules

The sname:VkCopyDescriptorSet structure is defined as:

  • pname:sType is the type of this structure.

  • pname:pNext is NULL or a pointer to a structure extending this structure.

  • pname:srcSet, pname:srcBinding, and pname:srcArrayElement are the source set, binding, and array element, respectively.

  • pname:dstSet, pname:dstBinding, and pname:dstArrayElement are the destination set, binding, and array element, respectively.

  • pname:descriptorCount is the number of descriptors to copy from the source to destination. If pname:descriptorCount is greater than the number of remaining array elements in the source or destination binding, those affect consecutive bindings in a manner similar to slink:VkWriteDescriptorSet above.

Valid Usage
  • pname:srcBinding must: be a valid binding within pname:srcSet

  • The sum of pname:srcArrayElement and pname:descriptorCount must: be less than or equal to the number of array elements in the descriptor set binding specified by pname:srcBinding, and all applicable consecutive bindings, as described by consecutive binding updates

  • pname:dstBinding must: be a valid binding within pname:dstSet

  • The sum of pname:dstArrayElement and pname:descriptorCount must: be less than or equal to the number of array elements in the descriptor set binding specified by pname:dstBinding, and all applicable consecutive bindings, as described by consecutive binding updates

  • The type of pname:dstBinding within pname:dstSet must: be equal to the type of pname:srcBinding within pname:srcSet

  • If pname:srcSet is equal to pname:dstSet, then the source and destination ranges of descriptors must: not overlap, where the ranges may: include array elements from consecutive bindings as described by consecutive binding updates

  • If the descriptor type of the descriptor set binding specified by pname:dstBinding is ename:VK_DESCRIPTOR_TYPE_SAMPLER, then pname:dstSet must: not have been allocated with a layout that included immutable samplers for pname:dstBinding

Descriptor Set Binding

To bind one or more descriptor sets to a command buffer, call:

  • pname:commandBuffer is the command buffer that the descriptor sets will be bound to.

  • pname:pipelineBindPoint is a elink:VkPipelineBindPoint indicating the type of the pipeline that will use the descriptors. There is a separate set of bind points for each pipeline type, so binding one does not disturb the others.

  • pname:layout is a slink:VkPipelineLayout object used to program the bindings.

  • pname:firstSet is the set number of the first descriptor set to be bound.

  • pname:descriptorSetCount is the number of elements in the pname:pDescriptorSets array.

  • pname:pDescriptorSets is a pointer to an array of handles to slink:VkDescriptorSet objects describing the descriptor sets to bind to.

  • pname:dynamicOffsetCount is the number of dynamic offsets in the pname:pDynamicOffsets array.

  • pname:pDynamicOffsets is a pointer to an array of code:uint32_t values specifying dynamic offsets.

fname:vkCmdBindDescriptorSets binds descriptor sets pname:pDescriptorSets[0..pname:descriptorSetCount-1] to set numbers [pname:firstSet..pname:firstSet+pname:descriptorSetCount-1] for subsequent bound pipeline commands set by pname:pipelineBindPoint. Any bindings that were previously applied via these sets are no longer valid.

Once bound, a descriptor set affects rendering of subsequent commands that interact with the given pipeline type in the command buffer until either a different set is bound to the same set number, or the set is disturbed as described in Pipeline Layout Compatibility.

A compatible descriptor set must: be bound for all set numbers that any shaders in a pipeline access, at the time that a drawing or dispatching command is recorded to execute using that pipeline. However, if none of the shaders in a pipeline statically use any bindings with a particular set number, then no descriptor set need be bound for that set number, even if the pipeline layout includes a non-trivial descriptor set layout for that set number.

When consuming a descriptor, a descriptor is considered valid if the descriptor is not undefined: as described by descriptor set allocation. A descriptor that was disturbed by Pipeline Layout Compatibility, or was never bound by fname:vkCmdBindDescriptorSets is not considered valid. If a pipeline accesses a descriptor either statically or dynamically depending on the elink:VkDescriptorBindingFlagBits, the consuming descriptor type in the pipeline must: match the elink:VkDescriptorType in slink:VkDescriptorSetLayoutCreateInfo for the descriptor to be considered valid.

Note
Note

Further validation may be carried out beyond validation for descriptor types, e.g. Texel Input Validation.

If any of the sets being bound include dynamic uniform or storage buffers, then pname:pDynamicOffsets includes one element for each array element in each dynamic descriptor type binding in each set. Values are taken from pname:pDynamicOffsets in an order such that all entries for set N come before set N+1; within a set, entries are ordered by the binding numbers in the descriptor set layouts; and within a binding array, elements are in order. pname:dynamicOffsetCount must: equal the total number of dynamic descriptors in the sets being bound.

The effective offset used for dynamic uniform and storage buffer bindings is the sum of the relative offset taken from pname:pDynamicOffsets, and the base address of the buffer plus base offset in the descriptor set. The range of the dynamic uniform and storage buffer bindings is the buffer range as specified in the descriptor set.

Each of the pname:pDescriptorSets must: be compatible with the pipeline layout specified by pname:layout. The layout used to program the bindings must: also be compatible with the pipeline used in subsequent bound pipeline commands with that pipeline type, as defined in the Pipeline Layout Compatibility section.

The descriptor set contents bound by a call to fname:vkCmdBindDescriptorSets may: be consumed at the following times:

  • during host execution of the command, or during shader execution of the resulting draws and dispatches, or any time in between.

Thus, the contents of a descriptor set binding must: not be altered (overwritten by an update command, or freed) between the first point in time that it may: be consumed, and when the command completes executing on the queue.

The contents of pname:pDynamicOffsets are consumed immediately during execution of fname:vkCmdBindDescriptorSets. Once all pending uses have completed, it is legal to update and reuse a descriptor set.

Valid Usage
  • Each element of pname:pDescriptorSets must: have been allocated with a sname:VkDescriptorSetLayout that matches (is the same as, or identically defined as) the sname:VkDescriptorSetLayout at set n in pname:layout, where n is the sum of pname:firstSet and the index into pname:pDescriptorSets

  • pname:dynamicOffsetCount must: be equal to the total number of dynamic descriptors in pname:pDescriptorSets

  • The sum of pname:firstSet and pname:descriptorSetCount must: be less than or equal to slink:VkPipelineLayoutCreateInfo::pname:setLayoutCount provided when pname:layout was created

  • pname:pipelineBindPoint must: be supported by the pname:commandBuffer’s parent sname:VkCommandPool’s queue family

  • Each element of pname:pDynamicOffsets which corresponds to a descriptor binding with type ename:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC must: be a multiple of sname:VkPhysicalDeviceLimits::pname:minUniformBufferOffsetAlignment

  • Each element of pname:pDynamicOffsets which corresponds to a descriptor binding with type ename:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC must: be a multiple of sname:VkPhysicalDeviceLimits::pname:minStorageBufferOffsetAlignment

  • For each dynamic uniform or storage buffer binding in pname:pDescriptorSets, the sum of the effective offset and the range of the binding must: be less than or equal to the size of the buffer

  • For each dynamic uniform or storage buffer binding in pname:pDescriptorSets, if the range was set with ename:VK_WHOLE_SIZE then pname:pDynamicOffsets which corresponds to the descriptor binding must: be 0

  • Each element of pname:pDescriptorSets must: be a valid slink:VkDescriptorSet

Push Constant Updates

As described above in section Pipeline Layouts, the pipeline layout defines shader push constants which are updated via Vulkan commands rather than via writes to memory or copy commands.

Note
Note

Push constants represent a high speed path to modify constant data in pipelines that is expected to outperform memory-backed resource updates.

To update push constants, call:

  • pname:commandBuffer is the command buffer in which the push constant update will be recorded.

  • pname:layout is the pipeline layout used to program the push constant updates.

  • pname:stageFlags is a bitmask of elink:VkShaderStageFlagBits specifying the shader stages that will use the push constants in the updated range.

  • pname:offset is the start offset of the push constant range to update, in units of bytes.

  • pname:size is the size of the push constant range to update, in units of bytes.

  • pname:pValues is a pointer to an array of pname:size bytes containing the new push constant values.

When a command buffer begins recording, all push constant values are undefined:.

Push constant values can: be updated incrementally, causing shader stages in pname:stageFlags to read the new data from pname:pValues for push constants modified by this command, while still reading the previous data for push constants not modified by this command. When a bound pipeline command is issued, the bound pipeline’s layout must: be compatible with the layouts used to set the values of all push constants in the pipeline layout’s push constant ranges, as described in Pipeline Layout Compatibility. Binding a pipeline with a layout that is not compatible with the push constant layout does not disturb the push constant values.

Note
Note

As pname:stageFlags needs to include all flags the relevant push constant ranges were created with, any flags that are not supported by the queue family that the slink:VkCommandPool used to allocate pname:commandBuffer was created on are ignored.

Valid Usage
  • For each byte in the range specified by pname:offset and pname:size and for each shader stage in pname:stageFlags, there must: be a push constant range in pname:layout that includes that byte and that stage

  • For each byte in the range specified by pname:offset and pname:size and for each push constant range that overlaps that byte, pname:stageFlags must: include all stages in that push constant range’s slink:VkPushConstantRange::pname:stageFlags

  • pname:offset must: be a multiple of 4

  • pname:size must: be a multiple of 4

  • pname:offset must: be less than sname:VkPhysicalDeviceLimits::pname:maxPushConstantsSize

  • pname:size must: be less than or equal to sname:VkPhysicalDeviceLimits::pname:maxPushConstantsSize minus pname:offset