SPIR-V Built-In

Layer

Layer index for layered rendering
Layer

Decorating a variable with the code:Layer built-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 code:Layer can be written with the framebuffer layer index to which the primitive produced by that shader will be directed.

The last active <<pipelines-graphics-subsets-pre-rasterization,pre-rasterization shader stage>> (in pipeline order) controls the code:Layer that is used. Outputs in previous shader stages are not used, even if the last stage fails to write the code:Layer.

If the last active <<pipelines-graphics-subsets-pre-rasterization,pre-rasterization shader stage>> shader entry point's interface does not include a variable decorated with code:Layer, then the first layer is used. If a <<pipelines-graphics-subsets-pre-rasterization,pre-rasterization shader stage>> shader entry point's interface includes a variable decorated with code:Layer, it must: write the same value to code:Layer for all output vertices of a given primitive. If the code:Layer value 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:. In a mesh shader this also applies when the code:Layer value is greater than or equal to the pname:maxMeshOutputLayers limit.

If a variable with the code:Layer decoration is also decorated with code:ViewportRelativeNV, then the code:ViewportIndex is 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 decorated code:ViewportMaskNV, then the layer selected has a different value for each viewport a primitive is rendered to.

In a fragment shader, a variable decorated with code:Layer contains the layer index of the primitive that the fragment invocation belongs to.

Valid Usage

VUID-Layer-Layer-04272

The Layer decoration must be used only within the MeshEXT, MeshNV, Vertex, TessellationEvaluation, Geometry, or Fragment Execution Model

VUID-Layer-Layer-04274

The variable decorated with Layer within the MeshEXT, MeshNV, Vertex, TessellationEvaluation, or Geometry

Execution Model must be declared using the Output Storage Class

VUID-Layer-Layer-04275

The variable decorated with Layer within the Fragment

Execution Model must be declared using the Input Storage Class

VUID-Layer-Layer-04276

The variable decorated with Layer must be declared as a scalar 32-bit integer value

VUID-Layer-Layer-07039

The variable decorated with Layer within the MeshEXT

Execution Model must also be decorated with the PerPrimitiveEXT decoration