When a shader stage accesses buffer or image resources, as described in the Resource Descriptors section, the shader resource variables must be matched with the pipeline layout that is provided at pipeline creation time.
The set of shader resources that form the shader resource interface
for a stage are the variables statically used by OpEntryPoint
with the storage class of Uniform, UniformConstant, or
PushConstant. For the fragment shader, this includes the
fragment input attachment interface.
The shader resource interface consists of two sub-interfaces: the push constant interface and the descriptor set interface.
The shader variables defined with a storage class of PushConstant
that are statically used by the shader entry-points for the pipeline
define the push constant interface. They must be:
OpTypeStruct,
Block decoration, and
Offset, ArrayStride, and
MatrixStride decorations as specified in
Offset and Stride Assignment.
There must be no more than one push constant block statically used per shader entry-point.
Each variable in a push constant block must be placed at an Offset
such that the entire constant value is entirely contained within the
VkPushConstantRange for each OpEntryPoint that uses it, and the
stageFlags for that range must specify the appropriate
VkShaderStageFlagBits for that stage. The Offset decoration for
any variable in a push constant block must not cause the space required for
that variable to extend outside the range
$[0,
\mathit{maxPushConstantsSize})$
.
Any variable in a push constant block that is declared as an array must only be accessed with dynamically uniform indices.
The descriptor set interface is comprised of the shader variables with the
storage class of Uniform or UniformConstant (including the variables
in the fragment input attachment interface)
that are statically used by the shader entry-points for the pipeline.
These variables must have DescriptorSet and Binding decorations
specified, which are assigned and matched with the
VkDescriptorSetLayout objects in the pipeline layout as described in
DescriptorSet and Binding Assignment.
Variables identified with the UniformConstant storage class are used
only as handles to refer to opaque resources. Such variables must be typed
as OpTypeImage, OpTypeSampler, OpTypeSampledImage, or arrays
of only these types. Variables of type OpTypeImage must have a
Sampled operand of 1 (sampled image) or 2 (storage image).
Any array of these types must only be indexed with constant integral expressions, except under the following conditions:
OpTypeImage variables with Sampled operand of 2,
if the shaderStorageImageArrayDynamicIndexing feature is enabled
and the shader module declares the StorageImageArrayDynamicIndexing
capability, the array must only be indexed by dynamically uniform
expressions.
OpTypeSampler, OpTypeSampledImage variables, or
OpTypeImage variables with Sampled operand of 1,
if the shaderSampledImageArrayDynamicIndexing feature is enabled
and the shader module declares the SampledImageArrayDynamicIndexing
capability, the array must only be indexed by dynamically uniform
expressions.
The Sampled Type of an OpTypeImage declaration must match
the same basic data type as the corresponding resource, or the values
obtained by reading or sampling from this image are undefined.
The Image Format of an OpTypeImage declaration must not be
Unknown, for variables which are used for OpImageRead or
OpImageWrite operations, except under the following conditions:
OpImageWrite, if the shaderStorageImageWriteWithoutFormat
feature is enabled and the shader module declares the
StorageImageWriteWithoutFormat capability.
OpImageRead, if the shaderStorageImageReadWithoutFormat
feature is enabled and the shader module declares the
StorageImageReadWithoutFormat capability.
Variables identified with the Uniform storage class are used to access
transparent buffer backed resources. Such variables must be:
OpTypeStruct, or arrays of only this type,
Block or BufferBlock decoration, and
Offset, ArrayStride, and
MatrixStride decorations as specified in
Offset and Stride Assignment.
Any array of these types must only be indexed with constant integral expressions, except under the following conditions.
Block variables, if the
shaderUniformBufferArrayDynamicIndexing feature is enabled and
the shader module declares the UniformBufferArrayDynamicIndexing
capability, the array must only be indexed by dynamically uniform
expressions.
BufferBlock variables, if the
shaderStorageBufferArrayDynamicIndexing feature is enabled and
the shader module declares the StorageBufferArrayDynamicIndexing
capability, the array must only be indexed by dynamically uniform
expressions.
The Offset decoration for any variable in a Block must not
cause the space required for that variable to extend outside the
range
$[0, \mathit{maxUniformBufferRange})$
. The Offset
decoration for any variable in a BufferBlock must not cause the
space required for that variable to extend outside the range
$[0, \mathit{maxStorageBufferRange})$
.
Variables identified with a storage class of UniformConstant and a
decoration of InputAttachmentIndex must be declared as described in
Fragment Input Attachment Interface.
Each shader variable declaration must refer to the same type of resource as
is indicated by the descriptorType. See
Shader Resource and Descriptor Type Correspondence for the relationship between shader declarations and
descriptor types.
Table 14.2. Shader Resource and Descriptor Type Correspondence
| Resource type | Descriptor Type |
|---|---|
sampler |
|
sampled image |
|
storage image |
|
combined image sampler |
|
uniform texel buffer |
|
storage texel buffer |
|
uniform buffer |
|
storage buffer |
|
input attachment |
|
Table 14.3. Shader Resource and Storage Class Correspondence
| Resource type | Storage Class | Type | Decoration(s)1 |
|---|---|---|---|
sampler |
|
| |
sampled image |
|
| |
storage image |
|
| |
combined image sampler |
|
| |
uniform texel buffer |
|
| |
storage texel buffer |
|
| |
uniform buffer |
|
|
|
storage buffer |
|
|
|
input attachment |
|
|
|
DescriptorSet and Binding
A variable identified with a DescriptorSet decoration of
$s$
and a Binding decoration of
$b$
indicates
that this variable is associated with the VkDescriptorSetLayoutBinding
that has a binding equal to
$b$
in pSetLayouts[s]
that was specified in VkPipelineLayoutCreateInfo.
The range of descriptor sets is between zero and
maxBoundDescriptorSets minus one. If a descriptor set value
is statically used by an entry-point there must be an associated
pSetLayout in the corresponding pipeline layout as described in
Pipeline Layouts consistency.
If the Binding decoration is used with an array, the entire array is
identified with that binding value. The size of the array declaration must
be no larger than the descriptorCount of that
VkDescriptorSetLayoutBinding. The index of each element of the array
is referred to as the arrayElement. For the purposes of interface matching
and descriptor set operations, if a resource
variable is not an array, it is treated as if it has an arrayElement of
zero.
The binding can be any 32-bit unsigned integer value, as described in Section 13.2.1, “Descriptor Set Layout”. Each descriptor set has its own binding name space.
There is a limit on the number of resources of each type that can be accessed by a pipeline stage as shown in Shader Resource Limits. The “Resources Per Stage” column gives the limit on the number each type of resource that can be statically used for an entry-point in any given stage in a pipeline. The “Resource Types” column lists which resource types are counted against the limit. Some resource types count against multiple limits.
If multiple entry-points in the same pipeline refer to the same set and
binding, all variable definitions with that DescriptorSet and
Binding must have the same basic type.
Not all descriptor sets and bindings specified in a pipeline layout need to
be used in a particular shader stage or pipeline, but if a
DescriptorSet and Binding decoration is specified for a variable
that is statically used in that shader there must be a pipeline layout
entry identified with that descriptor set and binding and the
corresponding stageFlags must specify the appropriate
VkShaderStageFlagBits for that stage.
Table 14.4. Shader Resource Limits
| Resources per Stage | Resource Types |
|---|---|
maxPerStageDescriptorSamplers | sampler |
combined image sampler | |
maxPerStageDescriptorSampledImages | sampled image |
combined image sampler | |
uniform texel buffer | |
maxPerStageDescriptorStorageImages | storage image |
storage texel buffer | |
maxPerStageDescriptorUniformBuffers | uniform buffer |
uniform buffer dynamic | |
maxPerStageDescriptorStorageBuffers | storage buffer |
storage buffer dynamic | |
maxPerStageDescriptorInputAttachments | input attachment1 |
All variables with a storage class of PushConstant or Uniform must
be explicitly laid out using the Offset, ArrayStride, and
MatrixStride decorations. There are two different layouts requirements
depending on the specific resources.
Standard Uniform Buffer Layout
Member variables of an OpTypeStruct with storage class of
Uniform and a decoration of Block (uniform buffers) must be laid
out according to the following rules.
The Offset Decoration must be a multiple of its base alignment,
computed recursively as follows:
ArrayStride or MatrixStride decoration must be an integer
multiple of the base alignment of the array or matrix from above.
Offset Decoration of a member immediately following a structure or
an array must be greater than or equal to the next multiple of the base
alignment of that structure or array.
| Note | |
|---|---|
The std140 layout in GLSL satisfies these rules. |
Standard Storage Buffer Layout
Member variables of an OpTypeStruct with a storage class of
PushConstant (push constants), or a storage class of Uniform
with a decoration of BufferBlock (storage buffers) must be laid
out as above, except
for array and structure base alignment which do not need to be
rounded up to a multiple of
$16$
.
| Note | |
|---|---|
The std430 layout in GLSL satisfies these rules. |