# PrimitiveId(3) Manual Page

## Name

PrimitiveId - Primitive ID

Loading… please wait.

## Description

`PrimitiveId`

  Decorating a variable with the `PrimitiveId` built-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 `PrimitiveId` are 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 corresponds 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 mesh shader if a mesh shader is present, or 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 within the geometry of the triangle or bounding box being processed.

Note | When the `PrimitiveId` decoration is applied to an output variable in the mesh shader or geometry shader, the resulting value is seen through the `PrimitiveId` decorated input variable in the fragment shader. The fragment shader using `PrimitiveId` will need to declare either the `MeshShadingNV`, `MeshShadingEXT`, `Geometry` or `Tessellation` capability to satisfy the requirement SPIR-V has to use `PrimitiveId`.

Valid Usage

- VUID-PrimitiveId-PrimitiveId-04330
  The `PrimitiveId` decoration must be used only within the `MeshEXT`, `MeshNV`, `IntersectionKHR`, `AnyHitKHR`, `ClosestHitKHR`, `TessellationControl`, `TessellationEvaluation`, `Geometry`, or `Fragment` `Execution` `Model`

- VUID-PrimitiveId-Fragment-04331
  If pipeline contains both the `Fragment` and `Geometry` `Execution` `Model` and a variable decorated with `PrimitiveId` is read from `Fragment` shader, then the `Geometry` shader must write to the output variables decorated with `PrimitiveId` in all execution paths

- VUID-PrimitiveId-Fragment-04332
  If pipeline contains both the `Fragment` and `MeshEXT` or `MeshNV` `Execution` `Model` and a variable decorated with `PrimitiveId` is read from `Fragment` shader, then the `MeshEXT` or `MeshNV` shader must write to the output variables decorated with `PrimitiveId` in all execution paths

- VUID-PrimitiveId-Fragment-04333
  If `Fragment` `Execution` `Model` contains a variable decorated with `PrimitiveId`, then either the `MeshShadingEXT`, `MeshShadingNV`, `Geometry` or `Tessellation` capability must also be declared

- VUID-PrimitiveId-PrimitiveId-04334
  The variable decorated with `PrimitiveId` within the `TessellationControl`, `TessellationEvaluation`, `Fragment`, `IntersectionKHR`, `AnyHitKHR`, or `ClosestHitKHR` `Execution` `Model` must be declared using the `Input` `Storage` `Class`

- VUID-PrimitiveId-PrimitiveId-04335
  The variable decorated with `PrimitiveId` within the `Geometry` `Execution` `Model` must be declared using the `Input` or `Output` `Storage` `Class`

- VUID-PrimitiveId-PrimitiveId-04336
  The variable decorated with `PrimitiveId` within the `MeshEXT` or `MeshNV` `Execution` `Model` must be declared using the `Output` `Storage` `Class`

- VUID-PrimitiveId-PrimitiveId-04337
  The variable decorated with `PrimitiveId` must be declared as a scalar 32-bit integer value for all supported execution models except `MeshEXT`

- VUID-PrimitiveId-PrimitiveId-07040
  The variable decorated with `PrimitiveId` within the `MeshEXT` `Execution` `Model` must also be decorated with the `PerPrimitiveEXT` decoration

- VUID-PrimitiveId-PrimitiveId-10595
  `PrimitiveId` within the `MeshEXT` `Execution` `Model` must decorate a scalar 32-bit integer member of a structure decorated as `Block`, or decorate a variable of type `OpTypeArray` of 32-bit integer values

- VUID-PrimitiveId-PrimitiveId-10596
  If `PrimitiveId` is declared as an array of 32-bit integer values, within the `MeshEXT` `Execution` `Model`, size of the array must match the value specified by `OutputPrimitivesEXT`

- VUID-PrimitiveId-PrimitiveId-10597
  If `PrimitiveId` decorates a member of a structure, the variable declaration of the containing `Block` type must have an array size that matches the value specified by `OutputPrimitivesEXT`

## See Also

No cross-references are available

## Document Notes

For more information, see the Vulkan Specification

This page is extracted from the Vulkan Specification. Fixes and changes should be made to the Specification, not directly.

## Copyright

Copyright 2014-2025 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0