v148 · webgpu · wgsl · shipped
WebGPU: linear_indexing feature
A WGSL language extension shipping in Chrome 148 that adds two new compute shader built-in values — global_invocation_index and workgroup_index — giving compute shaders a flat linear index without manual 3D-to-1D coordinate math.
at a glance
| Shipped in | Chrome 148 (desktop, Android, WebView) |
|---|---|
| Status | Enabled by default |
| Feature detection | navigator.gpu.wgslLanguageFeatures.has("linear_indexing") |
| WGSL opt-in | None needed (language extension). Optional: requires linear_indexing; documents the dependency and fails shader creation where it is unsupported |
| Spec | W3C WGSL specification (PR #5554) |
| ChromeStatus | 5071243424432128 — WebGPU: linear_indexing feature (API record) |
why it exists
WebGPU compute shaders dispatch work in a 3D grid of workgroups, each containing a 3D grid of invocations. To process a flat buffer — the common case for data-parallel tasks — developers had to compute a linear index from three separate coordinates every time:
// Old pattern — manual linear index calculation
let linear = global_id.z * (workgroup_size.x * workgroup_size.y * num_workgroups.x * num_workgroups.y)
+ global_id.y * (workgroup_size.x * num_workgroups.x)
+ global_id.x;
This is boilerplate that must be repeated in every compute shader that processes linear data, and it's easy to get wrong. linear_indexing moves this calculation into the language itself.
new built-in values
| Built-in | Type | Description |
|---|---|---|
global_invocation_index |
u32 |
The linear index of this invocation within the entire dispatch grid. Equivalent to computing a 1D offset from global_invocation_id.xyz manually. |
workgroup_index |
u32 |
The linear index of this invocation's workgroup within the grid of workgroups. All invocations in the same workgroup share the same value. |
Formal syntax (WGSL)
The requires-directive grammar and the two built-in value definitions, verbatim from the WGSL spec:
requires_directive :
| 'requires' language_extension_list ';'
language_extension_list :
| language_extension_name ( ',' language_extension_name ) * ',' ?
| Name | Stage | Type | Direction | Description (spec) |
|---|---|---|---|---|
global_invocation_index | compute | u32 | Input | The current invocation’s global invocation index, i.e. its linear position in the compute shader grid. Equal to global_invocation_id.x + (global_invocation_id.y * workgroup_size.x * num_workgroups.x) + (global_invocation_id.z * workgroup_size.x * num_workgroups.x * workgroup_size.y * num_workgroups.y). |
workgroup_index | compute | u32 | Input | The current invocation’s workgroup index, i.e. the linear position of the workgroup in overall compute shader grid. All invocations in the same workgroup have the same workgroup index. |
Both are declared as compute entry-point inputs with the @builtin(...) attribute, e.g. @builtin(global_invocation_index) idx: u32. linear_indexing is a language extension: it is available automatically wherever navigator.gpu.wgslLanguageFeatures contains it, and a requires-directive only documents the dependency.
Errors
- A
requires linear_indexing;directive on an implementation that does not support the extension is a shader-creation error. - If the number of dispatched workgroups would push either value past the range of
u32, the dispatch fails: fordispatchWorkgroupstheGPUComputePassEncoderis invalidated; fordispatchWorkgroupsIndirectthe dispatch does not execute.
linear_indexing; built-in global_invocation_index; built-in workgroup_index (editor’s draft, fetched 2026-11-15).
example
WGSL shader compute invocation with linear indexing:
fn main(@builtin(global_invocation_index) idx: u32) { /* ... */ }
Feature detection and WGSL shader
// JavaScript: detect before using
if (!navigator.gpu.wgslLanguageFeatures.has('linear_indexing')) {
throw new Error('linear_indexing WGSL extension not available');
}
const shaderCode = `
requires linear_indexing;
@group(0) @binding(0) var<storage, read_write> data: array<f32>;
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_index) idx: u32) {
if (idx < arrayLength(&data)) {
data[idx] = data[idx] * 2.0;
}
}
`;
const shaderModule = device.createShaderModule({ code: shaderCode });
// ... create pipeline and dispatch as usual
workgroup_index example
requires linear_indexing;
var<workgroup> workgroup_data: array<f32, 64>;
@compute @workgroup_size(64)
fn accumulate(
@builtin(workgroup_index) wg_idx: u32,
@builtin(local_invocation_index) local_idx: u32,
) {
// wg_idx identifies which workgroup we're in (flat index)
// useful for indexing per-workgroup output buffers
workgroup_data[local_idx] = f32(wg_idx);
}
Source: W3C WGSL spec; blink-dev Intent to Ship; Chrome Platform Showcase demo.
Live example
linear_indexing language feature. Sibling concepts: workgroup index demo, shader code comparison, linear memory visualizer and compute benchmark.Source: chrome-platform-showcasebrowser support
Per-version data for api.WGSLLanguageFeatures.extension_linear_indexing from BCD api/WGSLLanguageFeatures.json (raw JSON fetched 2026-11-15; status experimental, standard_track). Chrome Android, WebView Android and Edge are BCD mirror entries, resolved here from Chrome.
| Browser | linear_indexing | Notes |
|---|---|---|
| Chrome | 148 | BCD note: supported on ChromeOS, macOS, Windows, and Linux (Intel Gen12+ GPUs only) |
| Chrome Android / WebView Android | 148 | BCD mirror; ChromeStatus also lists Android and WebView 148 |
| Edge | 148 | BCD mirror |
| Firefox | Not supported | BCD version_added: false; position: No signal (#1205) |
| Safari | Not supported | BCD version_added: false; WebKit closed its WebGPU position issue without a position (#294) |
Feature-detect at runtime with navigator.gpu.wgslLanguageFeatures.has("linear_indexing"); without it, compute the index from global_invocation_id using the formula above.