14. Shader Interfaces
When a pipeline is created, the set of shaders specified in the
corresponding Vk*PipelineCreateInfo structure are implicitly linked at
a number of different interfaces.
Interface definitions make use of the following SPIR-V decorations:
-
DescriptorSetandBinding -
Location,Component, andIndex -
Flat,NoPerspective,Centroid, andSample -
BlockandBufferBlock -
InputAttachmentIndex -
Offset,ArrayStride, andMatrixStride -
BuiltIn
This specification describes valid uses for Vulkan of these decorations. Any other use of one of these decorations is invalid.
14.1. Shader Input and Output Interfaces
When multiple stages are present in a pipeline, the outputs of one stage form an interface with the inputs of the next stage. When such an interface involves a shader, shader outputs are matched against the inputs of the next stage, and shader inputs are matched against the outputs of the previous stage.
There are two classes of variables that can be matched between shader stages, built-in variables and user-defined variables. Each class has a different set of matching criteria. Generally, when non-shader stages are between shader stages, the user-defined variables, and most built-in variables, form an interface between the shader stages.
The variables forming the input or output interfaces are listed as
operands to the OpEntryPoint instruction and are declared with the
Input or Output storage classes, respectively, in the SPIR-V
module.
Output variables of a shader stage have undefined values until the
shader writes to them or uses the Initializer operand when declaring
the variable.
14.1.1. Built-in Interface Block
Shader built-in variables meeting the following requirements define the built-in interface block. They must
-
be explicitly declared (there are no implicit built-ins),
-
be identified with a
BuiltIndecoration, -
form object types as described in the Built-in Variables section, and
-
be declared in a block whose top-level members are the built-ins.
Built-ins only participate in interface matching if they are declared in
such a block.
They must not have any Location or Component decorations.
There must be no more than one built-in interface block per shader per interface.
14.1.2. User-defined Variable Interface
The remaining variables listed by OpEntryPoint with the Input or
Output storage class form the user-defined variable interface.
By default such variables have a type with a width of 32 or 64.
If an implementation supports
storageInputOutput16, user-defined
variables in the Input and Output storage classes can also have
types with a width of 16.
These variables must be identified with a Location decoration and can
also be identified with a Component decoration.
14.1.3. Interface Matching
A user-defined output variable is considered to match an input variable in
the subsequent stage if the two variables are declared with the same
Location and Component decoration and match in type and
decoration, except that interpolation
decorations are not required to match.
XfbBuffer, XfbStride, Offset, and Stream are also not
required to match for the purposes of interface matching.
For the purposes of interface matching, variables declared without a
Component decoration are considered to have a Component decoration
of zero.
|
Note
Matching rules for passthrough geometry shaders are slightly different and are described in the Passthrough Interface Matching section. |
Variables or block members declared as structures are considered to match in type if and only if the structure members match in type, decoration, number, and declaration order. Variables or block members declared as arrays are considered to match in type only if both declarations specify the same element type and size.
Tessellation control and mesh shader per-vertex output variables and blocks, and tessellation control, tessellation evaluation, and geometry shader per-vertex input variables and blocks are required to be declared as arrays, with each element representing input or output values for a single vertex of a multi-vertex primitive. For the purposes of interface matching, the outermost array dimension of such variables and blocks is ignored.
At an interface between two non-fragment shader stages, the built-in interface block must match exactly, as described above, except for per-view outputs as described in Mesh Shader Per-View Outputs. At an interface involving the fragment shader inputs, the presence or absence of any built-in output does not affect the interface matching.
At an interface between two shader stages, the user-defined variable interface must match exactly, as described above.
Any input value to a shader stage is well-defined as long as the preceding stages writes to a matching output, as described above.
Additionally, scalar and vector inputs are well-defined if there is a corresponding output satisfying all of the following conditions:
-
the input and output match exactly in decoration,
-
the output is a vector with the same basic type and has at least as many components as the input, and
-
the common component type of the input and output is 16-bit integer or floating-point, or 32-bit integer or floating-point (64-bit component types are excluded).
In this case, the components of the input will be taken from the first components of the output, and any extra components of the output will be ignored.
14.1.4. Location Assignment
This section describes how many locations are consumed by a given type. As mentioned above, geometry shader inputs, tessellation control shader inputs and outputs, and tessellation evaluation inputs all have an additional level of arrayness relative to other shader inputs and outputs. This outer array level is removed from the type before considering how many locations the type consumes.
The Location value specifies an interface slot comprised of a 32-bit
four-component vector conveyed between stages.
The Component specifies
components within these vector
locations.
Only types with widths of
16,
32 or 64 are supported in shader interfaces.
Inputs and outputs of the following types consume a single interface location:
-
16-bit scalar and vector types, and
-
32-bit scalar and vector types, and
-
64-bit scalar and 2-component vector types.
64-bit three- and four-component vectors consume two consecutive locations.
If a declared input or output is an array of size n and each element takes m locations, it will be assigned m × n consecutive locations starting with the location specified.
If the declared input or output is an n × m 16-, 32- or 64-bit matrix, it will be assigned multiple locations starting with the location specified. The number of locations assigned for each matrix will be the same as for an n-element array of m-component vectors.
The layout of a structure type used as an Input or Output depends
on whether it is also a Block (i.e. has a Block decoration).
If it is a not a Block, then the structure type must have a
Location decoration.
Its members are assigned consecutive locations in their declaration order,
with the first member assigned to the location specified for the structure
type.
The members, and their nested types, must not themselves have Location
decorations.
If the structure type is a Block but without a Location, then each
of its members must have a Location decoration.
If it is a Block with a Location decoration, then its members are
assigned consecutive locations in declaration order, starting from the first
member which is initially assigned the location specified for the
Block.
Any member with its own Location decoration is assigned that location.
Each remaining member is assigned the location after the immediately
preceding member in declaration order.
The locations consumed by block and structure members are determined by applying the rules above in a depth-first traversal of the instantiated members as though the structure or block member were declared as an input or output variable of the same type.
Any two inputs listed as operands on the same OpEntryPoint must not be
assigned the same location, either explicitly or implicitly.
Any two outputs listed as operands on the same OpEntryPoint must not
be assigned the same location, either explicitly or implicitly.
The number of input and output locations available for a shader input or output interface are limited, and dependent on the shader stage as described in Shader Input and Output Locations. All variables in both the built-in interface block and the user-defined variable interface count against these limits.
| Shader Interface | Locations Available |
|---|---|
vertex input |
|
vertex output |
|
tessellation control input |
|
tessellation control output |
|
tessellation evaluation input |
|
tessellation evaluation output |
|
geometry input |
|
geometry output |
|
fragment input |
|
fragment output |
|
14.1.5. Component Assignment
The Component decoration allows the Location to be more finely
specified for scalars and vectors, down to the individual components within
a location that are consumed.
The components within a location are 0, 1, 2, and 3.
A variable or block member starting at component N will consume components
N, N+1, N+2, …
up through its size.
For 16-, and 32-bit types,
it is invalid if this sequence of components gets larger than 3.
A scalar 64-bit type will consume two of these components in sequence, and a
two-component 64-bit vector type will consume all four components available
within a location.
A three- or four-component 64-bit vector type must not specify a
Component decoration.
A three-component 64-bit vector type will consume all four components of the
first location and components 0 and 1 of the second location.
This leaves components 2 and 3 available for other component-qualified
declarations.
A scalar or two-component 64-bit data type must not specify a
Component decoration of 1 or 3.
A Component decoration must not be specified for any type that is not
a scalar or vector.
14.2. Vertex Input Interface
When the vertex stage is present in a pipeline, the vertex shader input
variables form an interface with the vertex input attributes.
The vertex shader input variables are matched by the Location and
Component decorations to the vertex input attributes specified in the
pVertexInputState member of the VkGraphicsPipelineCreateInfo
structure.
The vertex shader input variables listed by OpEntryPoint with the
Input storage class form the vertex input interface.
These variables must be identified with a Location decoration and can
also be identified with a Component decoration.
For the purposes of interface matching: variables declared without a
Component decoration are considered to have a Component decoration
of zero.
The number of available vertex input locations is given by the
maxVertexInputAttributes member of the VkPhysicalDeviceLimits
structure.
See Attribute Location and Component Assignment for details.
All vertex shader inputs declared as above must have a corresponding attribute and binding in the pipeline.
14.3. Fragment Output Interface
When the fragment stage is present in a pipeline, the fragment shader
outputs form an interface with the output attachments of the current
subpass.
The fragment shader output variables are matched by the Location and
Component decorations to the color attachments specified in the
pColorAttachments array of the VkSubpassDescription structure
that describes the subpass that the fragment shader is executed in.
The fragment shader output variables listed by OpEntryPoint with the
Output storage class form the fragment output interface.
These variables must be identified with a Location decoration.
They can also be identified with a Component decoration and/or an
Index decoration.
For the purposes of interface matching: variables declared without a
Component decoration are considered to have a Component decoration
of zero, and variables declared without an Index decoration are
considered to have an Index decoration of zero.
A fragment shader output variable identified with a Location decoration
of i is directed to the color attachment indicated by
pColorAttachments[i], after passing through the blending unit as
described in Blending, if enabled.
Locations are consumed as described in
Location Assignment.
The number of available fragment output locations is given by the
maxFragmentOutputAttachments member of the
VkPhysicalDeviceLimits structure.
Components of the output variables are assigned as described in Component Assignment. Output components identified as 0, 1, 2, and 3 will be directed to the R, G, B, and A inputs to the blending unit, respectively, or to the output attachment if blending is disabled. If two variables are placed within the same location, they must have the same underlying type (floating-point or integer). The input values to blending or color attachment writes are undefined for components which do not correspond to a fragment shader output.
Fragment outputs identified with an Index of zero are directed to the
first input of the blending unit associated with the corresponding
Location.
Outputs identified with an Index of one are directed to the second
input of the corresponding blending unit.
No component aliasing of output variables is allowed, that is there must not be two output variables which have the same location, component, and index, either explicitly declared or implied.
Output values written by a fragment shader must be declared with either
OpTypeFloat or OpTypeInt, and a Width of 32.
If storageInputOutput16 is supported, output values written by a
fragment shader can be also declared with either OpTypeFloat or
OpTypeInt and a Width of 16.
Composites of these types are also permitted.
If the color attachment has a signed or unsigned normalized fixed-point
format, color values are assumed to be floating-point and are converted to
fixed-point as described in Conversion from Floating-Point to Normalized Fixed-Point; If the color
attachment has an integer format, color values are assumed to be integers
and converted to the bit-depth of the target.
Any value that cannot be represented in the attachment’s format is
undefined.
For any other attachment format no conversion is performed.
If the type of the values written by the fragment shader do not match the
format of the corresponding color attachment, the resulting values are
undefined for those components.
14.4. Fragment Input Attachment Interface
When a fragment stage is present in a pipeline, the fragment shader subpass
inputs form an interface with the input attachments of the current subpass.
The fragment shader subpass input variables are matched by
InputAttachmentIndex decorations to the input attachments specified in
the pInputAttachments array of the VkSubpassDescription
structure that describes the subpass that the fragment shader is executed
in.
The fragment shader subpass input variables with the UniformConstant
storage class and a decoration of InputAttachmentIndex that are
statically used by OpEntryPoint form the fragment input attachment
interface.
These variables must be declared with a type of OpTypeImage, a
Dim operand of SubpassData, and a Sampled operand of 2.
A subpass input variable identified with an InputAttachmentIndex
decoration of i reads from the input attachment indicated by
pInputAttachments[i] member of VkSubpassDescription.
If the subpass input variable is declared as an array of size N, it consumes
N consecutive input attachments, starting with the index specified.
There must not be more than one input variable with the same
InputAttachmentIndex whether explicitly declared or implied by an array
declaration.
The number of available input attachment indices is given by the
maxPerStageDescriptorInputAttachments member of the
VkPhysicalDeviceLimits structure.
Variables identified with the InputAttachmentIndex must only be used
by a fragment stage.
The basic data type (floating-point, integer, unsigned integer) of the
subpass input must match the basic format of the corresponding input
attachment, or the values of subpass loads from these variables are
undefined.
See Input Attachment for more details.
14.5. Shader Resource Interface
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.
14.5.1. Push Constant 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:
-
typed as
OpTypeStruct, -
identified with a
Blockdecoration, and -
laid out explicitly using the
Offset,ArrayStride, andMatrixStridedecorations as specified in Offset and Stride Assignment.
There must be no more than one push constant block statically used per shader entry point.
Each statically used member of a push constant block must be placed at an
Offset such that the entire member 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 member of a push constant block must not
cause the space required for that member to extend outside the range
[0, maxPushConstantsSize).
Any member of a push constant block that is declared as an array must only be accessed with dynamically uniform indices.
14.5.2. Descriptor Set Interface
The descriptor set interface is comprised of the shader variables with the
storage class of
StorageBuffer,
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 an array of one of these types.
The Sampled Type of an OpTypeImage declaration must match
the numeric format of the corresponding resource in type and signedness, as
shown in the SPIR-V Sampled Type column of the Interpretation of Numeric Format
table, 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,
OpImageSparseRead, or OpImageWrite operations, except under the
following conditions:
-
For
OpImageWrite, if theshaderStorageImageWriteWithoutFormatfeature is enabled and the shader module declares theStorageImageWriteWithoutFormatcapability. -
For
OpImageReadorOpImageSparseRead, if theshaderStorageImageReadWithoutFormatfeature is enabled and the shader module declares theStorageImageReadWithoutFormatcapability. -
For
OpImageRead, ifDimisSubpassData(indicating a read from an input attachment).
The Image Format of an OpTypeImage declaration must not be
Unknown, for variables which are used for OpAtomic* operations.
Variables identified with the Uniform storage class are used to access
transparent buffer backed resources.
Such variables must be:
-
typed as
OpTypeStruct, or an array of this type, -
identified with a
BlockorBufferBlockdecoration, and -
laid out explicitly using the
Offset,ArrayStride, andMatrixStridedecorations as specified in Offset and Stride Assignment.
Variables identified with the StorageBuffer storage class are used to
access transparent buffer backed resources.
Such variables must be:
-
typed as
OpTypeStruct, or an array of this type, -
identified with a
Blockdecoration, and -
laid out explicitly using the
Offset,ArrayStride, andMatrixStridedecorations as specified in Offset and Stride Assignment.
The Offset decoration for any member of a Block-decorated variable
in the Uniform storage class must not cause the space required for
that variable to extend outside the range [0,
maxUniformBufferRange).
The Offset decoration for any member of a Block-decorated variable
in the StorageBuffer storage class must not cause the space required
for that variable to extend outside the range [0,
maxStorageBufferRange).
Variables identified with the Uniform storage class can also be used
to access transparent descriptor set backed resources when the variable is
assigned to a descriptor set layout binding with a descriptorType of
VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT.
In this case the variable must be typed as OpTypeStruct and cannot be
aggregated into arrays of that type.
Further, the Offset decoration for any member of such a variable must
not cause the space required for that variable to extend outside the range
[0,maxInlineUniformBlockSize).
Variables identified with a storage class of UniformConstant and a
decoration of InputAttachmentIndex must be declared as described in
Fragment Input Attachment Interface.
SPIR-V variables decorated with a descriptor set and binding that identify a
combined image sampler descriptor
can have a type of OpTypeImage, OpTypeSampler (Sampled=1),
or OpTypeSampledImage.
Arrays of any of these types can be indexed with constant integral expressions. The following features must be enabled and capabilities must be declared in order to index such arrays with dynamically uniform or non-uniform indices:
-
Storage images (except storage texel buffers and input attachments):
-
Dynamically uniform:
shaderStorageImageArrayDynamicIndexingandStorageImageArrayDynamicIndexing -
Non-uniform:
shaderStorageImageArrayNonUniformIndexingandStorageImageArrayNonUniformIndexingEXT
-
-
Storage texel buffers:
-
Dynamically uniform:
shaderStorageTexelBufferArrayDynamicIndexingandStorageTexelBufferArrayDynamicIndexingEXT -
Non-uniform:
shaderStorageTexelBufferArrayNonUniformIndexingandStorageTexelBufferArrayNonUniformIndexingEXT
-
-
Input attachments:
-
Dynamically uniform:
shaderInputAttachmentArrayDynamicIndexingandInputAttachmentArrayDynamicIndexingEXT -
Non-uniform:
shaderInputAttachmentArrayNonUniformIndexingandInputAttachmentArrayNonUniformIndexingEXT
-
-
Sampled images (except uniform texel buffers):
-
Dynamically uniform:
shaderSampledImageArrayDynamicIndexingandSampledImageArrayDynamicIndexing -
Non-uniform:
shaderSampledImageArrayNonUniformIndexingandSampledImageArrayNonUniformIndexingEXT
-
-
Uniform texel buffers:
-
Dynamically uniform:
shaderUniformTexelBufferArrayDynamicIndexingandUniformTexelBufferArrayDynamicIndexingEXT -
Non-uniform:
shaderUniformTexelBufferArrayNonUniformIndexingandUniformTexelBufferArrayNonUniformIndexingEXT
-
-
Uniform buffers:
-
Dynamically uniform:
shaderUniformBufferArrayDynamicIndexingandUniformBufferArrayDynamicIndexing -
Non-uniform:
shaderUniformBufferArrayNonUniformIndexingandUniformBufferArrayNonUniformIndexingEXT
-
-
Storage buffers:
-
Dynamically uniform:
shaderStorageBufferArrayDynamicIndexingandStorageBufferArrayDynamicIndexing -
Non-uniform:
shaderStorageBufferArrayNonUniformIndexingandStorageBufferArrayNonUniformIndexingEXT
-
-
Acceleration structures:
-
No additional capabilities needed.
-
If an instruction loads from or stores to a resource (including atomics and image instructions) and the resource descriptor being accessed is not dynamically uniform, then the corresponding non-uniform indexing feature must be enabled and the capability must be declared. If an instruction loads from or stores to a resource (including atomics and image instructions) and the resource descriptor being accessed is not uniform, then the corresponding dynamic indexing or non-uniform feature must be enabled and the capability must be declared.
If the combined image sampler enables sampler Y’CBCR
conversion or samples a subsampled image,
it must be indexed only by constant integral expressions when aggregated
into arrays in shader code, irrespective of the
shaderSampledImageArrayDynamicIndexing feature.
| Resource type | Descriptor Type |
|---|---|
sampler |
|
sampled image |
|
storage image |
|
combined image sampler |
|
uniform texel buffer |
|
storage texel buffer |
|
uniform buffer |
|
storage buffer |
|
input attachment |
|
inline uniform block |
|
acceleration structure |
|
| 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 |
|
|
|
inline uniform block |
|
|
|
- 1
-
in addition to
DescriptorSetandBinding
14.5.3. DescriptorSet and Binding Assignment
A variable decorated 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.
DescriptorSet decoration values must be between zero and
maxBoundDescriptorSets minus one, inclusive.
Binding decoration values can be any 32-bit unsigned integer value, as
described in Descriptor Set Layout.
Each descriptor set has its own binding name space.
If the Binding decoration is used with an array, the entire array is
assigned that binding value.
The array must be a single-dimensional array and size of the array must be
no larger than the number of descriptors in the binding.
If the array is runtime-sized, then array elements greater than or equal to
the size of that binding in the bound descriptor set must not be used.
If the array is runtime-sized, the runtimeDescriptorArray feature
must be enabled and the RuntimeDescriptorArrayEXT capability must be
declared.
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.
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.
The pipeline layout may include descriptor sets and bindings which are not
referenced by any variables statically used by the entry points for the
shader stages in the binding’s stageFlags.
However, if a variable assigned to a given DescriptorSet and
Binding is statically used by the entry point for a shader stage, the
pipeline layout must contain a descriptor set layout binding in that
descriptor set layout and for that binding number, and that binding’s
stageFlags must include the appropriate VkShaderStageFlagBits
for that stage.
The variable must be of a valid resource type determined by its SPIR-V type
and storage class, as defined in
Shader Resource and
Storage Class Correspondence.
The descriptor set layout binding must be of a corresponding descriptor
type, as defined in Shader Resource
and Descriptor Type Correspondence.
|
Note
There are no limits on the number of shader variables that can have overlapping set and binding values in a shader; but which resources are statically used has an impact. If any shader variable identifying a resource is statically used in a shader, then the underlying descriptor bound at the declared set and binding must support the declared type in the shader when the shader executes. If multiple shader variables are declared with the same set and binding
values, and with the same underlying descriptor type, they can all be
statically used within the same shader.
However, accesses are not automatically synchronized, and If multiple shader variables with the same set and binding values are declared in a single shader, but with different declared types, where any of those are not supported by the relevant bound descriptor, that shader can only be executed if the variables with the unsupported type are not statically used. A noteworthy example of using multiple statically-used shader variables
sharing the same descriptor set and binding values is a descriptor of type
|
| Resources per Stage | Resource Types |
|---|---|
|
sampler |
combined image sampler |
|
|
sampled image |
combined image sampler |
|
uniform texel buffer |
|
|
storage image |
storage texel buffer |
|
|
uniform buffer |
uniform buffer dynamic |
|
|
storage buffer |
storage buffer dynamic |
|
|
input attachment1 |
|
inline uniform block |
- 1
-
Input attachments can only be used in the fragment shader stage
14.5.4. Offset and Stride Assignment
All variables with a storage class of Uniform, StorageBuffer, or
PushConstant must be explicitly laid out using the Offset,
ArrayStride, and MatrixStride decorations.
|
Note
The numeric order of |
Alignment Requirements
There are different alignment requirements depending on the specific resources and on the features enabled on the device.
The scalar alignment of the type of an OpTypeStruct member is defined
recursively as follows:
-
A scalar of size N has a scalar alignment of N.
-
A vector or matrix type has a scalar alignment equal to that of its component type.
-
An array type has a scalar alignment equal to that of its element type.
-
A structure has a scalar alignment equal to the largest scalar alignment of any of its members.
The base alignment of the type of an OpTypeStruct member is defined
recursively as follows:
-
A scalar has a base alignment equal to its scalar alignment.
-
A two-component vector has a base alignment equal to twice its scalar alignment.
-
A three- or four-component vector has a base alignment equal to four times its scalar alignment.
-
An array has a base alignment equal to the base alignment of its element type.
-
A structure has a base alignment equal to the largest base alignment of any of its members.
-
A row-major matrix of C columns has a base alignment equal to the base alignment of a vector of C matrix components.
-
A column-major matrix has a base alignment equal to the base alignment of the matrix column type.
The extended alignment of the type of an OpTypeStruct member is
similarly defined as follows:
-
A scalar, vector or matrix type has an extended alignment equal to its base alignment.
-
An array or structure type has an extended alignment equal to the largest extended alignment of any of its members, rounded up to a multiple of 16.
A member is defined to improperly straddle if either of the following are true:
-
It is a vector with total size less than or equal to 16 bytes, and has
Offsetdecorations placing its first byte at F and its last byte at L, where floor(F / 16) != floor(L / 16). -
It is a vector with total size greater than 16 bytes and has its
Offsetdecorations placing its first byte at a non-integer multiple of 16.
Standard Buffer Layout
Every member of an OpTypeStruct with storage class of Uniform,
StorageBuffer, or PushConstant must be aligned according to the
first matching rule as follows:
-
If the
scalarBlockLayoutfeature is enabled on the device then every member must be aligned according to its scalar alignment. -
All vectors must be aligned according to their scalar alignment.
-
If the
uniformBufferStandardLayoutfeature is not enabled on the device, then any member of anOpTypeStructwith a storage class ofUniformand a decoration ofBlockmust be aligned according to its extended alignment. -
Every other member must be aligned according to its base alignment.
|
Note
Even if scalar alignment is supported, it is generally more performant to use the base alignment. |
The memory layout must obey the following rules:
-
The
Offsetdecoration of any member must be a multiple of its alignment. -
Any
ArrayStrideorMatrixStridedecoration must be a multiple of the alignment of the array or matrix as defined above.
Unless the scalarBlockLayout feature is enabled on the device:
-
Vectors must not improperly straddle, as defined above.
-
The
Offsetdecoration of a member must not place it between the end of a structure or an array and the next multiple of the alignment of that structure or array.
|
Note
The std430 layout in GLSL satisfies these rules for types using the base alignment. The std140 layout satisfies the rules for types using the extended alignment. |
14.6. Built-In Variables
Built-in variables are accessed in shaders by declaring a variable decorated
with a BuiltIn SPIR-V decoration.
The meaning of each BuiltIn decoration is as follows.
In the remainder of this section, the name of a built-in is used
interchangeably with a term equivalent to a variable decorated with that
particular built-in.
Built-ins that represent integer values can be declared as either signed or
unsigned 32-bit integers.
BaryCoordNV-
The
BaryCoordNVdecoration can be used to decorate a fragment shader input variable. This variable will contain a three-component floating-point vector with barycentric weights that indicate the location of the fragment relative to the screen-space locations of vertices of its primitive, obtained using perspective interpolation.The
BaryCoordNVdecoration must be used only within fragment shaders.The variable decorated with
BaryCoordNVmust be declared using theInputstorage class.The variable decorated with
BaryCoordNVmust be declared as three-component vector of 32-bit floating-point values. BaryCoordNoPerspAMD-
The
BaryCoordNoPerspAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain the (I,J) pair of the barycentric coordinates corresponding to the fragment evaluated using linear interpolation at the fragment’s center. The K coordinate of the barycentric coordinates can be derived given the identity I + J + K = 1.0.
BaryCoordNoPerspNV-
The
BaryCoordNoPerspNVdecoration can be used to decorate a fragment shader input variable. This variable will contain a three-component floating-point vector with barycentric weights that indicate the location of the fragment relative to the screen-space locations of vertices of its primitive, obtained using linear interpolation.The
BaryCoordNoPerspNVdecoration must be used only within fragment shaders.The variable decorated with
BaryCoordNoPerspNVmust be declared using theInputstorage class.The variable decorated with
BaryCoordNoPerspNVmust be declared as three-component vector of 32-bit floating-point values. BaryCoordNoPerspCentroidAMD-
The
BaryCoordNoPerspCentroidAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain the (I,J) pair of the barycentric coordinates corresponding to the fragment evaluated using linear interpolation at the centroid. The K coordinate of the barycentric coordinates can be derived given the identity I + J + K = 1.0. BaryCoordNoPerspSampleAMD-
The
BaryCoordNoPerspCentroidAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain the (I,J) pair of the barycentric coordinates corresponding to the fragment evaluated using linear interpolation at each covered sample. The K coordinate of the barycentric coordinates can be derived given the identity I + J + K = 1.0. BaryCoordPullModelAMD-
The
BaryCoordPullModelAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain (1/W, 1/I, 1/J) evaluated at the fragment center and can be used to calculate gradients and then interpolate I, J, and W at any desired sample location. BaryCoordSmoothAMD-
The
BaryCoordSmoothAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain the (I,J) pair of the barycentric coordinates corresponding to the fragment evaluated using perspective interpolation at the fragment’s center. The K coordinate of the barycentric coordinates can be derived given the identity I + J + K = 1.0. BaryCoordSmoothCentroidAMD-
The
BaryCoordSmoothCentroidAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain the (I,J) pair of the barycentric coordinates corresponding to the fragment evaluated using perspective interpolation at the centroid. The K coordinate of the barycentric coordinates can be derived given the identity I + J + K = 1.0. BaryCoordSmoothSampleAMD-
The
BaryCoordSmoothCentroidAMDdecoration can be used to decorate a fragment shader input variable. This variable will contain the (I,J) pair of the barycentric coordinates corresponding to the fragment evaluated using perspective interpolation at each covered sample. The K coordinate of the barycentric coordinates can be derived given the identity I + J + K = 1.0.
BaseInstance-
Decorating a variable with the
BaseInstancebuilt-in will make that variable contain the integer value corresponding to the first instance that was passed to the command that invoked the current vertex shader invocation.BaseInstanceis thefirstInstanceparameter to a direct drawing command or thefirstInstancemember of a structure consumed by an indirect drawing command.The
BaseInstancedecoration must be used only within vertex shaders.The variable decorated with BaseInstance must be declared using the input storage class.
The variable decorated with BaseInstance must be declared as a scalar 32-bit integer.
BaseVertex-
Decorating a variable with the
BaseVertexbuilt-in will make that variable contain the integer value corresponding to the first vertex or vertex offset that was passed to the command that invoked the current vertex shader invocation. For non-indexed drawing commands, this variable is thefirstVertexparameter to a direct drawing command or thefirstVertexmember of the structure consumed by an indirect drawing command. For indexed drawing commands, this variable is thevertexOffsetparameter to a direct drawing command or thevertexOffsetmember of the structure consumed by an indirect drawing command.The
BaseVertexdecoration must be used only within vertex shaders.The variable decorated with
BaseVertexmust be declared using the input storage class.The variable decorated with
BaseVertexmust be declared as a scalar 32-bit integer. ClipDistance-
Decorating a variable with the
ClipDistancebuilt-in decoration will make that variable contain the mechanism for controlling user clipping.ClipDistanceis an array such that the ith element of the array specifies the clip distance for plane i. A clip distance of 0 means the vertex is on the plane, a positive distance means the vertex is inside the clip half-space, and a negative distance means the point is outside the clip half-space.The
ClipDistancedecoration must be used only within mesh, vertex, fragment, tessellation control, tessellation evaluation, and geometry shaders.In mesh or vertex shaders, any variable decorated with
ClipDistancemust be declared using theOutputstorage class.In fragment shaders, any variable decorated with
ClipDistancemust be declared using theInputstorage class.In tessellation control, tessellation evaluation, or geometry shaders, any variable decorated with
ClipDistancemust not be in a storage class other thanInputorOutput.Any variable decorated with
ClipDistancemust be declared as an array of 32-bit floating-point values.
|
Note
The array variable decorated with |
|
Note
In the last vertex processing stage, these values will be linearly
interpolated across the primitive and the portion of the primitive with
interpolated distances less than 0 will be considered outside the clip
volume.
If |
ClipDistancePerViewNV-
Decorating a variable with the
ClipDistancePerViewNVbuilt-in decoration will make that variable contain the per-view clip distances. The per-view clip distances have the same semantics asClipDistance.The
ClipDistancePerViewNVmust be used only within mesh shaders.Any variable decorated with
ClipDistancePerViewNVmust be declared using theOutputstorage class, and must also be decorated with thePerViewNVdecoration.Any variable decorated with
ClipDistancePerViewNVmust be declared as a two-dimensional array of 32-bit floating-point values. CullDistance-
Decorating a variable with the
CullDistancebuilt-in decoration will make that variable contain the mechanism for controlling user culling. If any member of this array is assigned a negative value for all vertices belonging to a primitive, then the primitive is discarded before rasterization.The
CullDistancedecoration must be used only within mesh, vertex, fragment, tessellation control, tessellation evaluation, and geometry shaders.In mesh or vertex shaders, any variable decorated with
CullDistancemust be declared using theOutputstorage class.In fragment shaders, any variable decorated with
CullDistancemust be declared using theInputstorage class.In tessellation control, tessellation evaluation, or geometry shaders, any variable decorated with
CullDistancemust not be declared in a storage class other than input or output.Any variable decorated with
CullDistancemust be declared as an array of 32-bit floating-point values.
|
Note
In fragment shaders, the values of the |
|
Note
If |
CullDistancePerViewNV-
Decorating a variable with the
CullDistancePerViewNVbuilt-in decoration will make that variable contain the per-view cull distances. The per-view clip distances have the same semantics asCullDistance.The
CullDistancePerViewNVmust be used only within mesh shaders.Any variable decorated with
CullDistancePerViewNVmust be declared using theOutputstorage class, and must also be decorated with thePerViewNVdecoration.Any variable decorated with
CullDistancePerViewNVmust be declared as a two-dimensional array of 32-bit floating-point values.
DeviceIndex-
The
DeviceIndexdecoration can be applied to a shader input which will be filled with the device index of the physical device that is executing the current shader invocation. This value will be in the range \([0,max(1,physicalDeviceCount))\), where physicalDeviceCount is thephysicalDeviceCountmember of VkDeviceGroupDeviceCreateInfo.The
DeviceIndexdecoration can be used in any shader.The variable decorated with
DeviceIndexmust be declared using theInputstorage class.The variable decorated with
DeviceIndexmust be declared as a scalar 32-bit integer.
DrawIndex-
Decorating a variable with the
DrawIndexbuilt-in will make that variable contain the integer value corresponding to the zero-based index of the drawing command that invoked the current task, mesh, or vertex shader invocation. For indirect drawing commands,DrawIndexbegins at zero and increments by one for each draw command executed. The number of draw commands is given by thedrawCountparameter. For direct drawing commands,DrawIndexis always zero.DrawIndexis dynamically uniform.The
DrawIndexdecoration must be used only within task, mesh or vertex shaders.The variable decorated with
DrawIndexmust be declared using the input storage class.The variable decorated with
DrawIndexmust be declared as a scalar 32-bit integer.When task or mesh shaders are used, only the first active stage will have proper access to the variable, other stages will have undefined values.
FragCoord-
Decorating a variable with the
FragCoordbuilt-in decoration will make that variable contain the framebuffer coordinate \((x,y,z,\frac{1}{w})\) of the fragment being processed. The (x,y) coordinate (0,0) is the upper left corner of the upper left pixel in the framebuffer.When Sample Shading is enabled, the x and y components of
FragCoordreflect the location of one of the samples corresponding to the shader invocation.Otherwise, the x and y components of
FragCoordreflect the location of the center of the fragment.The z component of
FragCoordis the interpolated depth value of the primitive.The w component is the interpolated \(\frac{1}{w}\).
The
FragCoorddecoration must be used only within fragment shaders.The variable decorated with
FragCoordmust be declared using theInputstorage class.The
Centroidinterpolation decoration is ignored, but allowed, onFragCoord.The variable decorated with
FragCoordmust be declared as a four-component vector of 32-bit floating-point values. FragDepth-
To have a shader supply a fragment-depth value, the shader must declare the
DepthReplacingexecution mode. Such a shader’s fragment-depth value will come from the variable decorated with theFragDepthbuilt-in decoration.This value will be used for any subsequent depth testing performed by the implementation or writes to the depth attachment.
The
FragDepthdecoration must be used only within fragment shaders.The variable decorated with
FragDepthmust be declared using theOutputstorage class.The variable decorated with
FragDepthmust be declared as a scalar 32-bit floating-point value.
FragInvocationCountEXT-
Decorating a variable with the
FragInvocationCountEXTbuilt-in decoration will make that variable contain the maximum number of fragment shader invocations for the fragment, as determined byminSampleShading.The
FragInvocationCountEXTdecoration must be used only within fragment shaders and theFragmentDensityEXTcapability must be declared.If Sample Shading is not enabled,
FragInvocationCountEXTwill be filled with a value of 1.The variable decorated with
FragInvocationCountEXTmust be declared using theInputstorage class.The variable decorated with
FragInvocationCountEXTmust be declared as a scalar 32-bit integer.
FragSizeEXT-
Decorating a variable with the
FragSizeEXTbuilt-in decoration will make that variable contain the dimensions in pixels of the area that the fragment covers for that invocation.The
FragSizeEXTdecoration must be used only within fragment shaders and theFragmentDensityEXTcapability must be declared.If fragment density map is not enabled,
FragSizeEXTwill be filled with a value of (1,1).The variable decorated with
FragSizeEXTmust be declared using theInputstorage class.The variable decorated with
FragSizeEXTmust be declared as a two-component vector of 32-bit integers. FragStencilRefEXT-
Decorating a variable with the
FragStencilRefEXTbuilt-in decoration will make that variable contain the new stencil reference value for all samples covered by the fragment. This value will be used as the stencil reference value used in stencil testing.To write to
FragStencilRefEXT, a shader must declare theStencilRefReplacingEXTexecution mode. If a shader declares theStencilRefReplacingEXTexecution mode and there is an execution path through the shader that does not setFragStencilRefEXT, then the fragment’s stencil reference value is undefined for executions of the shader that take that path.The
FragStencilRefEXTdecoration must be used only within fragment shaders.The variable decorated with
FragStencilRefEXTmust be declared using theOutputstorage class.The variable decorated with
FragStencilRefEXTmust be declared as a scalar integer value. Only the least significant s bits of the integer value of the variable decorated withFragStencilRefEXTare considered for stencil testing, where s is the number of bits in the stencil framebuffer attachment, and higher order bits are discarded. FragmentSizeNV-
Decorating a variable with the
FragmentSizeNVbuilt-in decoration will make that variable contain the width and height of the fragment.The
FragmentSizeNVdecoration must be used only within fragment shaders.The variable decorated with
FragmentSizeNVmust be declared using theInputstorage class.The variable decorated with
FragmentSizeNVmust be declared as a two-component vector of 32-bit integers. FrontFacing-
Decorating a variable with the
FrontFacingbuilt-in decoration will make that variable contain whether the fragment is front or back facing. This variable is non-zero if the current fragment is considered to be part of a front-facing polygon primitive or of a non-polygon primitive and is zero if the fragment is considered to be part of a back-facing polygon primitive.The
FrontFacingdecoration must be used only within fragment shaders.The variable decorated with
FrontFacingmust be declared using theInputstorage class.The variable decorated with
FrontFacingmust be declared as a boolean. FullyCoveredEXT-
Decorating a variable with the
FullyCoveredEXTbuilt-in decoration will make that variable indicate whether the fragment area is fully covered by the generating primitive. This variable is non-zero if conservative rasterization is enabled and the current fragment area is fully covered by the generating primitive, and is zero if the fragment is not covered or partially covered, or conservative rasterization is disabled.The
FullyCoveredEXTdecoration must be used only within fragment shaders and theFragmentFullyCoveredEXTcapability must be declared.The variable decorated with
FullyCoveredEXTmust be declared using theInputstorage class.The variable decorated with
FullyCoveredEXTmust be declared as a boolean.If the implementation supports
VkPhysicalDeviceConservativeRasterizationPropertiesEXT::conservativeRasterizationPostDepthCoverageand thePostDepthCoverageexecution mode is specified theSampleMaskbuilt-in input variable will reflect the coverage after the early per-fragment depth and stencil tests are applied. IfVkPhysicalDeviceConservativeRasterizationPropertiesEXT::conservativeRasterizationPostDepthCoverageis not supported thePostDepthCoverageexecution mode must not be specified. GlobalInvocationId-
Decorating a variable with the
GlobalInvocationIdbuilt-in decoration will make that variable contain the location of the current invocation within the global workgroup. Each component is equal to the index of the local workgroup multiplied by the size of the local workgroup plusLocalInvocationId.The
GlobalInvocationIddecoration must be used only within task, mesh, or compute shaders.The variable decorated with
GlobalInvocationIdmust be declared using theInputstorage class.The variable decorated with
GlobalInvocationIdmust be declared as a three-component vector of 32-bit integers. HelperInvocation-
Decorating a variable with the
HelperInvocationbuilt-in decoration will make that variable contain whether the current invocation is a helper invocation. This variable is non-zero if the current fragment being shaded is a helper invocation and zero otherwise. A helper invocation is an invocation of the shader that is produced to satisfy internal requirements such as the generation of derivatives.The
HelperInvocationdecoration must be used only within fragment shaders.The variable decorated with
HelperInvocationmust be declared using theInputstorage class.The variable decorated with
HelperInvocationmust be declared as a boolean.
|
Note
It is very likely that a helper invocation will have a value of
|
HitKindNV-
A variable decorated with the
HitKindNVdecoration will describe the intersection that triggered the execution of the current shader. The values are determined by the intersection shader.The
HitKindNVdecoration must only be used in any-hit and closest hit shaders.Any variable decorated with
HitKindNVmust be declared using theInputstorage class.Any variable decorated with
HitKindNVmust be declared as a scalar 32-bit integer.
HitTNV-
A variable decorated with the
HitTNVdecoration is equivalent to a variable decorated with theRayTmaxNVdecoration.The
HitTNVdecoration must only be used in any-hit and closest hit shaders.Any variable decorated with
HitTNVmust be declared using theInputstorage class.Any variable decorated with
HitTNVmust be declared as a scalar 32-bit floating-point value.
IncomingRayFlagsNV-
A variable with the
IncomingRayFlagsNVdecoration will contain the ray flags passed in to the trace call that invoked this particular shader.The
IncomingRayFlagsNVdecoration must only be used in the intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
IncomingRayFlagsNVmust be declared using theInputstorage class.Any variable decorated with
IncomingRayFlagsNVmust be declared as a scalar 32-bit integer.
InstanceCustomIndexNV-
A variable decorated with the
InstanceCustomIndexNVdecoration will contain the application-defined value of the instance that intersects the current ray. Only the lower 24 bits are valid, the upper 8 bits will be ignored.The
InstanceCustomIndexNVdecoration must only be used in the intersection, any-hit, and closest hit shaders.Any variable decorated with
InstanceCustomIndexNVmust be declared using theInputstorage class.Any variable decorated with
InstanceCustomIndexNVmust be declared as a scalar 32-bit integer.
InstanceId-
Decorating a variable in an intersection, any-hit, or closest hit shader with the
InstanceIddecoration will make that variable contain the index of the instance that intersects the current ray.The
InstanceIddecoration must be used only within intersection, any-hit, or closest hit shaders.The variable decorated with
InstanceIdmust be declared using theInputstorage class.The variable decorated with
InstanceIdmust be declared as a scalar 32-bit integer. InvocationId-
Decorating a variable with the
InvocationIdbuilt-in decoration will make that variable contain the index of the current shader invocation in a geometry shader, or the index of the output patch vertex in a tessellation control shader.In a geometry shader, the index of the current shader invocation ranges from zero to the number of instances declared in the shader minus one. If the instance count of the geometry shader is one or is not specified, then
InvocationIdwill be zero.The
InvocationIddecoration must be used only within tessellation control and geometry shaders.The variable decorated with
InvocationIdmust be declared using theInputstorage class.The variable decorated with
InvocationIdmust be declared as a scalar 32-bit integer. InvocationsPerPixelNV-
Decorating a variable with the
InvocationsPerPixelNVbuilt-in decoration will make that variable contain the maximum number of fragment shader invocations per pixel, as derived from the effective shading rate for the fragment. If a primitive does not fully cover a pixel, the number of fragment shader invocations for that pixel may be less than the value ofInvocationsPerPixelNV. If the shading rate indicates a fragment covering multiple pixels, thenInvocationsPerPixelNVwill be one.The
InvocationsPerPixelNVdecoration must be used only within fragment shaders.The variable decorated with
InvocationsPerPixelNVmust be declared using theInputstorage class.The variable decorated with
InvocationsPerPixelNVmust be declared as a scalar 32-bit integer. InstanceIndex-
Decorating a variable in a vertex shader with the
InstanceIndexbuilt-in decoration will make that variable contain the index of the instance that is being processed by the current vertex shader invocation.InstanceIndexbegins at thefirstInstanceparameter to vkCmdDraw or vkCmdDrawIndexed or at thefirstInstancemember of a structure consumed by vkCmdDrawIndirect or vkCmdDrawIndexedIndirect.The
InstanceIndexdecoration must be used only within vertex shaders.The variable decorated with
InstanceIndexmust be declared using theInputstorage class.The variable decorated with
InstanceIndexmust be declared as a scalar 32-bit integer.
LaunchIDNV-
A variable decorated with the
LaunchIDNVdecoration will specify the index of the work item being process. One work item is generated for each of thewidth×height×depthitems dispatched by a vkCmdTraceRaysNV command. All shader invocations inherit the same value for variables decorated withLaunchIDNV.The
LaunchIDNVdecoration must only be used within the ray generation, intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
LaunchIDNVmust be declared using theInputstorage class.Any variable decorated with
LaunchIDNVmust be declared as a three-component vector of 32-bit integer values.
LaunchSizeNV-
A variable decorated with the
LaunchSizeNVdecoration will contain thewidth,height, anddepthdimensions passed to the vkCmdTraceRaysNV command that initiated this shader execution. Thewidthis in the first component, theheightis in the second component, and thedepthis in the third component.The
LaunchSizeNVdecoration must only be used within ray generation, intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
LaunchSizeNVmust be declared using theInputstorage class.Any variable decorated with
LaunchSizeNVmust be declared as a three-component vector of 32-bit integer values.
Layer-
Decorating a variable with the
Layerbuilt-in decoration will make that variable contain the select layer of a multi-layer framebuffer attachment.In a mesh, vertex, tessellation evaluation, or geometry shader, any variable decorated with
Layercan be written with the framebuffer layer index to which the primitive produced by that shader will be directed.The last active vertex processing stage (in pipeline order) controls the
Layerthat is used. Outputs in previous shader stages are not used, even if the last stage fails to write theLayer.If the last active vertex processing stage shader entry point’s interface does not include a variable decorated with
Layer, then the first layer is used. If a vertex processing stage shader entry point’s interface includes a variable decorated withLayer, it must write the same value toLayerfor all output vertices of a given primitive. If theLayervalue is less than 0 or greater than or equal to the number of layers in the framebuffer, then primitives may still be rasterized, fragment shaders may be executed, and the framebuffer values for all layers are undefined.The
Layerdecoration must be used only within mesh, vertex, tessellation evaluation, geometry, and fragment shaders.In a mesh, vertex, tessellation evaluation, or geometry shader, any variable decorated with
Layermust be declared using theOutputstorage class. If such a variable is also decorated withViewportRelativeNV, then theViewportIndexis added to the layer that is used for rendering and that is made available in the fragment shader. If the shader writes to a variable decoratedViewportMaskNV, then the layer selected has a different value for each viewport a primitive is rendered to.In a fragment shader, a variable decorated with
Layercontains the layer index of the primitive that the fragment invocation belongs to.In a fragment shader, any variable decorated with
Layermust be declared using theInputstorage class.Any variable decorated with
Layermust be declared as a scalar 32-bit integer.
LayerPerViewNV-
Decorating a variable with the
LayerPerViewNVbuilt-in decoration will make that variable contain the per-view layer information. The per-view layer has the same semantics asLayer, for each view.The
LayerPerViewNVmust only be used within mesh shaders.Any variable decorated with
LayerPerViewNVmust be declared using theOutputstorage class, and must also be decorated with thePerViewNVdecoration.Any variable decorated with
LayerPerViewNVmust be declared as an array of scalar 32-bit integer values. LocalInvocationId-
Decorating a variable with the
LocalInvocationIdbuilt-in decoration will make that variable contain the location of the current task, mesh, or compute shader invocation within the local workgroup. Each component ranges from zero through to the size of the workgroup in that dimension minus one.The
LocalInvocationIddecoration must be used only within task, mesh, or compute shaders.The variable decorated with
LocalInvocationIdmust be declared using theInputstorage class.The variable decorated with
LocalInvocationIdmust be declared as a three-component vector of 32-bit integers.
|
Note
If the size of the workgroup in a particular dimension is one, then the
|
LocalInvocationIndex-
Decorating a variable with the
LocalInvocationIndexbuilt-in decoration will make that variable contain a one-dimensional representation ofLocalInvocationId. This is computed as:LocalInvocationIndex = LocalInvocationId.z * WorkgroupSize.x * WorkgroupSize.y + LocalInvocationId.y * WorkgroupSize.x + LocalInvocationId.x;The
LocalInvocationIndexdecoration must be used only within task, mesh, or compute shaders.The variable decorated with
LocalInvocationIndexmust be declared using theInputstorage class.The variable decorated with
LocalInvocationIndexmust be declared as a scalar 32-bit integer.
MeshViewCountNV-
Decorating a variable with the
MeshViewCountNVbuilt-in decoration will make that variable contain the number of views processed by the current mesh or task shader invocations.The
MeshViewCountNVdecoration must only be used in task and mesh shaders.Any variable decorated with
MeshViewCountNVmust be declared using theInputstorage class.Any variable decorated with
MeshViewCountNVmust be declared as a scalar 32-bit integer.
MeshViewIndicesNV-
Decorating a variable with the
MeshViewIndicesNVbuilt-in decoration will make that variable contain the mesh view indices. The mesh view indices is an array of values where each element holds the view number of one of the views being processed by the current mesh or task shader invocations. The array elements with indices great than or equal toMeshViewCountNVare undefined. If the value ofMeshViewIndicesNV[i] is j, then any outputs decorated withPerViewNVwill take on the value of array element i when processing primitives for view index j.The
MeshViewIndicesNVdecoration must only be used in task and mesh shaders.Any variable decorated with
MeshViewIndicesNVmust be declared using theInputstorage class.Any variable decorated with
MeshViewIndicesNVmust be declared as an array of scalar 32-bit integers. NumSubgroups-
Decorating a variable with the
NumSubgroupsbuilt-in decoration will make that variable contain the number of subgroups in the local workgroup.The
NumSubgroupsdecoration must be used only within task, mesh, or compute shaders.The variable decorated with
NumSubgroupsmust be declared using theInputstorage class.The object decorated with
NumSubgroupsmust be declared as a scalar 32-bit integer. NumWorkgroups-
Decorating a variable with the
NumWorkgroupsbuilt-in decoration will make that variable contain the number of local workgroups that are part of the dispatch that the invocation belongs to. Each component is equal to the values of the workgroup count parameters passed into the dispatch commands.The
NumWorkgroupsdecoration must be used only within compute shaders.The variable decorated with
NumWorkgroupsmust be declared using theInputstorage class.The variable decorated with
NumWorkgroupsmust be declared as a three-component vector of 32-bit integers.
ObjectRayDirectionNV-
A variable decorated with the
ObjectRayDirectionNVdecoration will specify the direction of the ray being processed, in object space.The
ObjectRayDirectionNVdecoration must only be used within intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
ObjectRayDirectionNVmust be declared using theInputstorage class.Any variable decorated with
ObjectRayDirectionNVmust be declared as a three-component vector of 32-bit floating-point values.
ObjectRayOriginNV-
A variable decorated with the
ObjectRayOriginNVdecoration will specify the origin of the ray being processed, in object space.The
ObjectRayOriginNVdecoration must only be used within intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
ObjectRayOriginNVmust be declared using theInputstorage class.Any variable decorated with
ObjectRayOriginNVmust be declared as a three-component vector of 32-bit floating-point values.
ObjectToWorldNV-
A variable decorated with the
ObjectToWorldNVdecoration will contain the current object-to-world transformation matrix, which is determined by the instance of the current intersection.The
ObjectToWorldNVdecoration must only be used within intersection, any-hit, and closest hit shaders.Any variable decorated with
ObjectToWorldNVmust be declared using theInputstorage class.Any variable decorated with
ObjectToWorldNVmust be declared as a matrix with four columns of three-component vectors of 32-bit floating-point values. PatchVertices-
Decorating a variable with the
PatchVerticesbuilt-in decoration will make that variable contain the number of vertices in the input patch being processed by the shader. A single tessellation control or tessellation evaluation shader can read patches of differing sizes, so the value of thePatchVerticesvariable may differ between patches.The
PatchVerticesdecoration must be used only within tessellation control and tessellation evaluation shaders.The variable decorated with
PatchVerticesmust be declared using theInputstorage class.The variable decorated with
PatchVerticesmust be declared as a scalar 32-bit integer. PointCoord-
Decorating a variable with the
PointCoordbuilt-in decoration will make that variable contain the coordinate of the current fragment within the point being rasterized, normalized to the size of the point with origin in the upper left corner of the point, as described in Basic Point Rasterization. If the primitive the fragment shader invocation belongs to is not a point, then the variable decorated withPointCoordcontains an undefined value.The
PointCoorddecoration must be used only within fragment shaders.The variable decorated with
PointCoordmust be declared using theInputstorage class.The variable decorated with
PointCoordmust be declared as two-component vector of 32-bit floating-point values.
|
Note
Depending on how the point is rasterized, |
PointSize-
Decorating a variable with the
PointSizebuilt-in decoration will make that variable contain the size of point primitives. The value written to the variable decorated withPointSizeby the last vertex processing stage in the pipeline is used as the framebuffer-space size of points produced by rasterization.The
PointSizedecoration must be used only within mesh, vertex, tessellation control, tessellation evaluation, and geometry shaders.In a mesh or vertex shader, any variable decorated with
PointSizemust be declared using theOutputstorage class.In a tessellation control, tessellation evaluation, or geometry shader, any variable decorated with
PointSizemust be declared using either theInputorOutputstorage class.Any variable decorated with
PointSizemust be declared as a scalar 32-bit floating-point value.
|
Note
When |
Position-
Decorating a variable with the
Positionbuilt-in decoration will make that variable contain the position of the current vertex. In the last vertex processing stage, the value of the variable decorated withPositionis used in subsequent primitive assembly, clipping, and rasterization operations.The
Positiondecoration must be used only within mesh, vertex, tessellation control, tessellation evaluation, and geometry shaders.In a mesh or vertex shader, any variable decorated with
Positionmust be declared using theOutputstorage class.In a tessellation control, tessellation evaluation, or geometry shader, any variable decorated with
Positionmust not be declared in a storage class other thanInputorOutput.Any variable decorated with
Positionmust be declared as a four-component vector of 32-bit floating-point values.
|
Note
When |
PositionPerViewNV-
Decorating a variable with the
PositionPerViewNVbuilt-in decoration will make that variable contain the position of the current vertex, for each view.The
PositionPerViewNVdecoration must be used only within mesh, vertex, tessellation control, tessellation evaluation, and geometry shaders.In a vertex shader, any variable decorated with
PositionPerViewNVmust be declared using theOutputstorage class.In a tessellation control, tessellation evaluation, or geometry shader, any variable decorated with
PositionPerViewNVmust not be declared in a storage class other than input or output.Any variable decorated with
PositionPerViewNVmust be declared as an array of four-component vector of 32-bit floating-point values with at least as many elements as the maximum view in the subpass’s view mask plus one. The array must be indexed by a constant or specialization constant.Elements of the array correspond to views in a multiview subpass, and those elements corresponding to views in the view mask of the subpass the shader is compiled against will be used as the position value for those views. For the final vertex processing stage in the pipeline, values written to an output variable decorated with
PositionPerViewNVare used in subsequent primitive assembly, clipping, and rasterization operations, as withPosition.PositionPerViewNVoutput in an earlier vertex processing stage is available as an input in the subsequent vertex processing stage.If a shader is compiled against a subpass that has the
VK_SUBPASS_DESCRIPTION_PER_VIEW_POSITION_X_ONLY_BIT_NVXbit set, then the position values for each view must not differ in any component other than the X component. If the values do differ, one will be chosen in an implementation-dependent manner.
PrimitiveCountNV-
Decorating a variable with the
PrimitiveCountNVdecoration will make that variable contain the primitive count. The primitive count specifies the number of primitives in the output mesh produced by the mesh shader that will be processed by subsequent pipeline stages.The
PrimitiveCountNVdecoration must only be used in mesh shaders.Any variable decorated with
PrimitiveCountNVmust be declared using theOutputstorage class.Any variable decorated with
PrimitiveCountNVmust be declared as a scalar 32-bit integer. PrimitiveId-
Decorating a variable with the
PrimitiveIdbuilt-in decoration will make that variable contain the index of the current primitive.The index of the first primitive generated by a drawing command is zero, and the index is incremented after every individual point, line, or triangle primitive is processed.
For triangles drawn as points or line segments (see Polygon Mode), the primitive index is incremented only once, even if multiple points or lines are eventually drawn.
Variables decorated with
PrimitiveIdare reset to zero between each instance drawn.Restarting a primitive topology using primitive restart has no effect on the value of variables decorated with
PrimitiveId.In tessellation control and tessellation evaluation shaders, it will contain the index of the patch within the current set of rendering primitives that correspond to the shader invocation.
In a geometry shader, it will contain the number of primitives presented as input to the shader since the current set of rendering primitives was started.
In a fragment shader, it will contain the primitive index written by the geometry shader if a geometry shader is present, or with the value that would have been presented as input to the geometry shader had it been present.
In an intersection, any-hit, or closest hit shader, it will contain the index of the triangle or bounding box being processed.
If a geometry shader is present and the fragment shader reads from an input variable decorated with
PrimitiveId, then the geometry shader must write to an output variable decorated withPrimitiveIdin all execution paths.If a mesh shader is present and the fragment shader reads from an input variable decorated with
PrimitiveId, then the mesh shader must write to the output variables decorated withPrimitiveIdin all execution paths.The
PrimitiveIddecoration must be used only within mesh, intersection, any-hit, closest hit, fragment, tessellation control, tessellation evaluation, and geometry shaders.In an intersection, any-hit, closest hit, tessellation control, or tessellation evaluation shader, any variable decorated with
PrimitiveIdmust be declared using theInputstorage class.In a geometry shader, any variable decorated with
PrimitiveIdmust be declared using either theInputorOutputstorage class.In a mesh shader, any variable decorated with
PrimitiveIdmust be declared using theOutputstorage class.In a fragment shader, any variable decorated with
PrimitiveIdmust be declared using theInputstorage class, and either theGeometryorTessellationcapability must also be declared.Any variable decorated with
PrimitiveIdmust be declared as a scalar 32-bit integer.
|
Note
When the |
PrimitiveIndicesNV-
Decorating a variable with the
PrimitiveIndicesNVdecoration will make that variable contain the output array of vertex index values. Depending on the output primitive type declared using the execution mode, the indices are split into groups of one (OutputPoints), two (OutputLinesNV), or three (OutputTriangles) indices and each group generates a primitive.All index values must be in the range [0, N-1], where N is the value specified by the
OutputVerticesexecution mode.The
PrimitiveIndicesNVdecoration must only be used in mesh shaders.Any variable decorated with
PrimitiveIndicesNVmust be declared using theOutputstorage class.Any variable decorated with
PrimitiveIndicesNVmust be declared as an array of scalar 32-bit integers. The array must be sized according to the primitive type andOutputPrimitivesNVexecution modes, where the size is:-
the value specified by
OutputPrimitivesNVif the execution mode isOutputPoints, -
two times the value specified by
OutputPrimitivesNVif the execution mode isOutputLinesNV, or -
three times the value specified by
OutputPrimitivesNVif the execution mode isOutputTrianglesNV.
-
RayTmaxNV-
A variable decorated with the
RayTmaxNVdecoration will contain the parametrictmaxvalues of the ray being processed. The values are independent of the space in which the ray and origin exist.The
tmaxvalue changes throughout the lifetime of the ray query that produced the intersection. In the closest hit shader, the value reflects the closest distance to the intersected primitive. In the any-hit shader, it reflects the distance to the primitive currently being intersected. In the intersection shader, it reflects the distance to the closest primitive intersected so far. The value can change in the intersection shader after callingOpReportIntersectionNVif the corresponding any-hit shader does not ignore the intersection. In a miss shader, the value is identical to the parameter passed intoOpTraceNV.The
RayTmaxNVdecoration must only be used with the intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
RayTmaxNVmust be declared with theInputstorage class.Any variable decorated with
RayTmaxNVmust be declared as a scalar 32-bit floating-point value.
RayTminNV-
A variable decorated with the
RayTminNVdecoration will contain the parametrictminvalues of the ray being processed. The values are independent of the space in which the ray and origin exist.The
tminvalue remains constant for the duration of the ray query.The
RayTminNVdecoration must only be used with the intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
RayTminNVmust be declared with theInputstorage class.Any variable decorated with
RayTminNVmust be declared as a scalar 32-bit floating-point value. SampleId-
Decorating a variable with the
SampleIdbuilt-in decoration will make that variable contain the zero-based index of the sample the invocation corresponds to.SampleIdranges from zero to the number of samples in the framebuffer minus one. If a fragment shader entry point’s interface includes an input variable decorated withSampleId, Sample Shading is considered enabled with aminSampleShadingvalue of 1.0.The
SampleIddecoration must be used only within fragment shaders.The variable decorated with
SampleIdmust be declared using theInputstorage class.The variable decorated with
SampleIdmust be declared as a scalar 32-bit integer.
SampleMask-
Decorating a variable with the
SampleMaskbuilt-in decoration will make any variable contain the sample coverage mask for the current fragment shader invocation.A variable in the
Inputstorage class decorated withSampleMaskwill contain a bitmask of the set of samples covered by the primitive generating the fragment during rasterization. It has a sample bit set if and only if the sample is considered covered for this fragment shader invocation.SampleMask[] is an array of integers. Bits are mapped to samples in a manner where bit B of mask M (SampleMask[M]) corresponds to sample 32 × M + B.When state specifies multiple fragment shader invocations for a given fragment, the sample mask for any single fragment shader invocation specifies the subset of the covered samples for the fragment that correspond to the invocation. In this case, the bit corresponding to each covered sample will be set in exactly one fragment shader invocation.
If the
PostDepthCoverageexecution mode is specified, the sample is considered covered if and only if the sample is covered by the primitive and the sample passes the early per-fragment tests. Otherwise the sample is considered covered if the sample is covered by the primitive, regardless of the result of the fragment tests.A variable in the
Outputstorage class decorated withSampleMaskis an array of integers forming a bit array in a manner similar an input variable decorated withSampleMask, but where each bit represents coverage as computed by the shader. Modifying the sample mask by writing zero to a bit ofSampleMaskcauses the sample to be considered uncovered. If this variable is also decorated withOverrideCoverageNV, the fragment coverage is replaced with the sample mask bits set in the shader otherwise the fragment coverage isANDedwith the bits of the sample mask. If the fragment shader is being evaluated at any frequency other than per-fragment, bits of the sample mask not corresponding to the current fragment shader invocation are ignored. This array must be sized in the fragment shader either implicitly or explicitly, to be no larger than the implementation-dependent maximum sample-mask (as an array of 32-bit elements), determined by the maximum number of samples. If a fragment shader entry point’s interface includes an output variable decorated withSampleMask, the sample mask will be undefined for any array elements of any fragment shader invocations that fail to assign a value. If a fragment shader entry point’s interface does not include an output variable decorated withSampleMask, the sample mask has no effect on the processing of a fragment.The
SampleMaskdecoration must be used only within fragment shaders.Any variable decorated with
SampleMaskmust be declared using either theInputorOutputstorage class.Any variable decorated with
SampleMaskmust be declared as an array of 32-bit integers. SamplePosition-
Decorating a variable with the
SamplePositionbuilt-in decoration will make that variable contain the sub-pixel position of the sample being shaded. The top left of the pixel is considered to be at coordinate (0,0) and the bottom right of the pixel is considered to be at coordinate (1,1).If the render pass has a fragment density map attachment, the variable will instead contain the sub-fragment position of the sample being shaded. The top left of the fragment is considered to be at coordinate (0,0) and the bottom right of the fragment is considered to be at coordinate (1,1) for any fragment area.
If a fragment shader entry point’s interface includes an input variable decorated with
SamplePosition, Sample Shading is considered enabled with aminSampleShadingvalue of 1.0.The
SamplePositiondecoration must be used only within fragment shaders.The variable decorated with
SamplePositionmust be declared using theInputstorage class. If the current pipeline uses custom sample locations the value of any variable decorated with theSamplePositionbuilt-in decoration is undefined.The variable decorated with
SamplePositionmust be declared as a two-component vector of 32-bit floating-point values.
SMCountNV-
Decorating a variable with the
SMCountNVbuilt-in decoration will make that variable contain the number of SMs on the device.The variable decorated with
SMCountNVmust be declared using theInputstorage class.The variable decorated with
SMCountNVmust be declared as a scalar 32-bit integer value.
SMIDNV-
Decorating a variable with the
SMIDNVbuilt-in decoration will make that variable contain the ID of the SM on which the current shader invocation is running. This variable is in the range [0,SMCountNV-1].The variable decorated with
SMIDNVmust be declared using theInputstorage class.The variable decorated with
SMIDNVmust be declared as a scalar 32-bit integer value. SubgroupId-
Decorating a variable with the
SubgroupIdbuilt-in decoration will make that variable contain the index of the subgroup within the local workgroup. This variable is in range [0,NumSubgroups-1].The
SubgroupIddecoration must be used only within task, mesh or, compute shaders.The variable decorated with
SubgroupIdmust be declared using theInputstorage class.The variable decorated with
SubgroupIdmust be declared as a scalar 32-bit integer.
SubgroupEqMask-
Decorating a variable with the
SubgroupEqMaskbuiltin decoration will make that variable contain the subgroup mask of the current subgroup invocation. The bit corresponding to theSubgroupLocalInvocationIdis set in the variable decorated withSubgroupEqMask. All other bits are set to zero.The variable decorated with
SubgroupEqMaskmust be declared using theInputstorage class.The variable decorated with
SubgroupEqMaskmust be declared as a four-component vector of 32-bit integer values.SubgroupEqMaskKHRis an alias ofSubgroupEqMask.
SubgroupGeMask-
Decorating a variable with the
SubgroupGeMaskbuiltin decoration will make that variable contain the subgroup mask of the current subgroup invocation. The bits corresponding to the invocations greater than or equal toSubgroupLocalInvocationIdthroughSubgroupSize-1 are set in the variable decorated withSubgroupGeMask. All other bits are set to zero.The variable decorated with
SubgroupGeMaskmust be declared using theInputstorage class.The variable decorated with
SubgroupGeMaskmust be declared as a four-component vector of 32-bit integer values.SubgroupGeMaskKHRis an alias ofSubgroupGeMask.
SubgroupGtMask-
Decorating a variable with the
SubgroupGtMaskbuiltin decoration will make that variable contain the subgroup mask of the current subgroup invocation. The bits corresponding to the invocations greater thanSubgroupLocalInvocationIdthroughSubgroupSize-1 are set in the variable decorated withSubgroupGtMask. All other bits are set to zero.The variable decorated with
SubgroupGtMaskmust be declared using theInputstorage class.The variable decorated with
SubgroupGtMaskmust be declared as a four-component vector of 32-bit integer values.SubgroupGtMaskKHRis an alias ofSubgroupGtMask.
SubgroupLeMask-
Decorating a variable with the
SubgroupLeMaskbuiltin decoration will make that variable contain the subgroup mask of the current subgroup invocation. The bits corresponding to the invocations less than or equal toSubgroupLocalInvocationIdare set in the variable decorated withSubgroupLeMask. All other bits are set to zero.The variable decorated with
SubgroupLeMaskmust be declared using theInputstorage class.The variable decorated with
SubgroupLeMaskmust be declared as a four-component vector of 32-bit integer values.SubgroupLeMaskKHRis an alias ofSubgroupLeMask.
SubgroupLtMask-
Decorating a variable with the
SubgroupLtMaskbuiltin decoration will make that variable contain the subgroup mask of the current subgroup invocation. The bits corresponding to the invocations less thanSubgroupLocalInvocationIdare set in the variable decorated withSubgroupLtMask. All other bits are set to zero.The variable decorated with
SubgroupLtMaskmust be declared using theInputstorage class.The variable decorated with
SubgroupLtMaskmust be declared as a four-component vector of 32-bit integer values.SubgroupLtMaskKHRis an alias ofSubgroupLtMask.
SubgroupLocalInvocationId-
Decorating a variable with the
SubgroupLocalInvocationIdbuiltin decoration will make that variable contain the index of the invocation within the subgroup. This variable is in range [0,SubgroupSize-1].The variable decorated with
SubgroupLocalInvocationIdmust be declared using theInputstorage class.The variable decorated with
SubgroupLocalInvocationIdmust be declared as a scalar 32-bit integer.
SubgroupSize-
Decorating a variable with the
SubgroupSizebuiltin decoration will make that variable contain the implementation-dependent maximum number of invocations in a subgroup. The maximum number of invocations that an implementation can support per subgroup is 128.The variable decorated with
SubgroupSizemust be declared using theInputstorage class.The variable decorated with
SubgroupSizemust be declared as a scalar 32-bit integer.
TaskCountNV-
Decorating a variable with the
TaskCountNVdecoration will make that variable contain the task count. The task count specifies the number of subsequent mesh shader workgroups that get generated upon completion of the task shader.The
TaskCountNVdecoration must only be used in task shaders.Any variable decorated with
TaskCountNVmust be declared using theOutputstorage class.Any variable decorated with
TaskCountNVmust be declared as a scalar 32-bit integer. TessCoord-
Decorating a variable with the
TessCoordbuilt-in decoration will make that variable contain the three-dimensional (u,v,w) barycentric coordinate of the tessellated vertex within the patch. u, v, and w are in the range [0,1] and vary linearly across the primitive being subdivided. For the tessellation modes ofQuadsorIsoLines, the third component is always zero.The
TessCoorddecoration must be used only within tessellation evaluation shaders.The variable decorated with
TessCoordmust be declared using theInputstorage class.The variable decorated with
TessCoordmust be declared as three-component vector of 32-bit floating-point values. TessLevelOuter-
Decorating a variable with the
TessLevelOuterbuilt-in decoration will make that variable contain the outer tessellation levels for the current patch.In tessellation control shaders, the variable decorated with
TessLevelOutercan be written to which controls the tessellation factors for the resulting patch. These values are used by the tessellator to control primitive tessellation and can be read by tessellation evaluation shaders.In tessellation evaluation shaders, the variable decorated with
TessLevelOutercan read the values written by the tessellation control shader.The
TessLevelOuterdecoration must be used only within tessellation control and tessellation evaluation shaders.In a tessellation control shader, any variable decorated with
TessLevelOutermust be declared using theOutputstorage class.In a tessellation evaluation shader, any variable decorated with
TessLevelOutermust be declared using theInputstorage class.Any variable decorated with
TessLevelOutermust be declared as an array of size four, containing 32-bit floating-point values. TessLevelInner-
Decorating a variable with the
TessLevelInnerbuilt-in decoration will make that variable contain the inner tessellation levels for the current patch.In tessellation control shaders, the variable decorated with
TessLevelInnercan be written to, which controls the tessellation factors for the resulting patch. These values are used by the tessellator to control primitive tessellation and can be read by tessellation evaluation shaders.In tessellation evaluation shaders, the variable decorated with
TessLevelInnercan read the values written by the tessellation control shader.The
TessLevelInnerdecoration must be used only within tessellation control and tessellation evaluation shaders.In a tessellation control shader, any variable decorated with
TessLevelInnermust be declared using theOutputstorage class.In a tessellation evaluation shader, any variable decorated with
TessLevelInnermust be declared using theInputstorage class.Any variable decorated with
TessLevelInnermust be declared as an array of size two, containing 32-bit floating-point values. VertexIndex-
Decorating a variable with the
VertexIndexbuilt-in decoration will make that variable contain the index of the vertex that is being processed by the current vertex shader invocation. For non-indexed draws, this variable begins at thefirstVertexparameter to vkCmdDraw or thefirstVertexmember of a structure consumed by vkCmdDrawIndirect and increments by one for each vertex in the draw. For indexed draws, its value is the content of the index buffer for the vertex plus thevertexOffsetparameter to vkCmdDrawIndexed or thevertexOffsetmember of the structure consumed by vkCmdDrawIndexedIndirect.The
VertexIndexdecoration must be used only within vertex shaders.The variable decorated with
VertexIndexmust be declared using theInputstorage class.The variable decorated with
VertexIndexmust be declared as a scalar 32-bit integer.
|
Note
|
ViewIndex-
The
ViewIndexdecoration can be applied to a shader input which will be filled with the index of the view that is being processed by the current shader invocation.If multiview is enabled in the render pass, this value will be one of the bits set in the view mask of the subpass the pipeline is compiled against. If multiview is not enabled in the render pass, this value will be zero.
The
ViewIndexdecoration must not be used within compute shaders.The variable decorated with
ViewIndexmust be declared using theInputstorage class.The variable decorated with
ViewIndexmust be declared as a scalar 32-bit integer.
ViewportIndex-
Decorating a variable with the
ViewportIndexbuilt-in decoration will make that variable contain the index of the viewport.In a mesh, vertex, tessellation evaluation, or geometry shader, the variable decorated with
ViewportIndexcan be written to with the viewport index to which the primitive produced by that shader will be directed.The selected viewport index is used to select the viewport transform, scissor rectangle, and exclusive scissor rectangle.
The last active vertex processing stage (in pipeline order) controls the
ViewportIndexthat is used. Outputs in previous shader stages are not used, even if the last stage fails to write theViewportIndex.If the last active vertex processing stage shader entry point’s interface does not include a variable decorated with
ViewportIndex, then the first viewport is used. If a vertex processing stage shader entry point’s interface includes a variable decorated withViewportIndex, it must write the same value toViewportIndexfor all output vertices of a given primitive.The
ViewportIndexdecoration must be used only within mesh, vertex, tessellation evaluation, geometry, and fragment shaders.In a mesh, vertex, tessellation evaluation, or geometry shader, any variable decorated with
ViewportIndexmust be declared using theOutputstorage class.In a fragment shader, the variable decorated with
ViewportIndexcontains the viewport index of the primitive that the fragment invocation belongs to.In a fragment shader, any variable decorated with
ViewportIndexmust be declared using theInputstorage class.Any variable decorated with
ViewportIndexmust be declared as a scalar 32-bit integer.
ViewportMaskNV-
Decorating a variable with the
ViewportMaskNVbuilt-in decoration will make that variable contain the viewport mask.In a mesh, vertex, tessellation evaluation, or geometry shader, the variable decorated with
ViewportMaskNVcan be written to with the mask of which viewports the primitive produced by that shader will directed.The
ViewportMaskNVvariable must be an array that has ⌈(VkPhysicalDeviceLimits::maxViewports/ 32)⌉ elements. When a shader writes to this variable, bit B of element M controls whether a primitive is emitted to viewport 32 × M +B. The viewports indicated by the mask are used to select the viewport transform, scissor rectangle, and exclusive scissor rectangle that a primitive will be transformed by.The last active vertex processing stage (in pipeline order) controls the
ViewportMaskNVthat is used. Outputs in previous shader stages are not used, even if the last stage fails to write theViewportMaskNV. WhenViewportMaskNVis written by the final vertex processing stage, any variable decorated withViewportIndexin the fragment shader will have the index of the viewport that was used in generating that fragment.If a vertex processing stage shader entry point’s interface includes a variable decorated with
ViewportMaskNV, it must write the same value toViewportMaskNVfor all output vertices of a given primitive.The
ViewportMaskNVdecoration must be used only within mesh, vertex, tessellation evaluation, and geometry shaders.Any variable decorated with
ViewportMaskNVmust be declared using theOutputstorage class.Any variable decorated with
ViewportMaskNVmust be declared as an array of 32-bit integers.
ViewportMaskPerViewNV-
Decorating a variable with the
ViewportMaskPerViewNVbuilt-in decoration will make that variable contain the mask of viewports primitives are broadcast to, for each view.The
ViewportMaskPerViewNVdecoration must be used only within mesh, vertex, tessellation control, tessellation evaluation, and geometry shaders.Any variable decorated with
ViewportMaskPerViewNVmust be declared using theOutputstorage class.The value written to an element of
ViewportMaskPerViewNVin the last vertex processing stage is a bitmask indicating which viewports the primitive will be directed to. The primitive will be broadcast to the viewport corresponding to each non-zero bit of the bitmask, and that viewport index is used to select the viewport transform, scissor rectangle, and exclusive scissor rectangle, for each view. The same values must be written to all vertices in a given primitive, or else the set of viewports used for that primitive is undefined.Any variable decorated with
ViewportMaskPerViewNVmust be declared as an array of scalar 32-bit integers with at least as many elements as the maximum view in the subpass’s view mask plus one. The array must be indexed by a constant or specialization constant.Elements of the array correspond to views in a multiview subpass, and those elements corresponding to views in the view mask of the subpass the shader is compiled against will be used as the viewport mask value for those views.
ViewportMaskPerViewNVoutput in an earlier vertex processing stage is not available as an input in the subsequent vertex processing stage.Although
ViewportMaskNVis an array,ViewportMaskPerViewNVis not a two-dimensional array. Instead,ViewportMaskPerViewNVis limited to 32 viewports.
WarpsPerSMNV-
Decorating a variable with the
WarpsPerSMNVbuilt-in decoration will make that variable contain the maximum number of warps executing on a SM.The variable decorated with
WarpsPerSMNVmust be declared using theInputstorage class.The variable decorated with
WarpsPerSMNVmust be declared as a scalar 32-bit integer value.
WarpIDNV-
Decorating a variable with the
WarpIDNVbuilt-in decoration will make that variable contain the ID of the warp on a SM on which the current shader invocation is running. This variable is in the range [0,WarpsPerSMNV-1].The variable decorated with
WarpIDNVmust be declared using theInputstorage class.The variable decorated with
WarpIDNVmust be declared as a scalar 32-bit integer value. WorkgroupId-
Decorating a variable with the
WorkgroupIdbuilt-in decoration will make that variable contain the global workgroup that the current invocation is a member of. Each component ranges from a base value to a base + count value, based on the parameters passed into the dispatch commands.The
WorkgroupIddecoration must be used only within task, mesh, or compute shaders.The variable decorated with
WorkgroupIdmust be declared using theInputstorage class.The variable decorated with
WorkgroupIdmust be declared as a three-component vector of 32-bit integers. WorkgroupSize-
Decorating an object with the
WorkgroupSizebuilt-in decoration will make that object contain the dimensions of a local workgroup. If an object is decorated with theWorkgroupSizedecoration, this must take precedence over any execution mode set forLocalSize.The
WorkgroupSizedecoration must be used only within task, mesh, or compute shaders.The object decorated with
WorkgroupSizemust be a specialization constant or a constant.The object decorated with
WorkgroupSizemust be declared as a three-component vector of 32-bit integers.
WorldRayDirectionNV-
A variable decorated with the
WorldRayDirectionNVdecoration will specify the direction of the ray being processed, in world space.The
WorldRayDirectionNVdecoration must only be used within intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
WorldRayDirectionNVmust be declared using theInputstorage class.Any variable decorated with
WorldRayDirectionNVmust be declared as a three-component vector of 32-bit floating-point values.
WorldRayOriginNV-
A variable decorated with the
WorldRayOriginNVdecoration will specify the origin of the ray being processed, in world space.The
WorldRayOriginNVdecoration must only be used within intersection, any-hit, closest hit, and miss shaders.Any variable decorated with
WorldRayOriginNVmust be declared using theInputstorage class.Any variable decorated with
WorldRayOriginNVmust be declared as a three-component vector of 32-bit floating-point values.
WorldToObjectNV-
A variable decorated with the
WorldToObjectNVdecoration will contain the current world-to-object transformation matrix, which is determined by the instance of the current intersection.The
WorldToObjectNVdecoration must only be used within intersection, any-hit, and closest hit shaders.Any variable decorated with
WorldToObjectNVmust be declared using theInputstorage class.Any variable decorated with
WorldToObjectNVmust be declared as a matrix with four columns of three-component vectors of 32-bit floating-point values.