primitive-index
Specification: WebGPU § primitive-index · WGSL § primitive_index
Request primitive-index on the device, add enable primitive_index; to WGSL, and declare a fragment input with @builtin(primitive_index). The resulting u32 identifies the input primitive within the draw. It is a primitive number, not a vertex-buffer index or an index-buffer value.
A visibility-buffer renderer can store this value and use it later to retrieve triangle data, while other engines can use it for per-face material or debug information. The built-in avoids duplicating a triangle identifier across vertices solely to pass it through the vertex shader.
Primitive indices repeat across instances and restart for each draw, so combine them with your own draw or instance identity when you need a scene-wide key. Without this feature, pass a flat per-primitive identifier from the vertex shader using suitably prepared geometry, or structure draw calls so a separate binding identifies the relevant data.
Availability by month
| Month | With feature | Eligible reports | Availability |
|---|---|---|---|
| 2026-08 | 70 | 106 | 66.0% |
| 2026-09 | 25 | 36 | 69.4% |
By browser (last 30 days)
| Browser | Availability | n |
|---|---|---|
| chrome | 96.7% | 90 |
| edge | 100.0% | 8 |
| firefox | 0.0% | 44 |
Availability = share of first-party, non-quarantined reports with WebGPU on a hardware (non-fallback) adapter that expose this feature. Developer-leaning sample. Full methodology.