v148 · WebGPU · WGSL

Compute Benchmark

Run the same sum-of-squares compute shader two ways: the old manual 3D-to-linear conversion, and the Chrome 148 built-in global_invocation_index. Compare GPU execution time, shader line count, and correctness.

Checking WebGPU support…

Larger = longer GPU execution, clearer timing difference.

Manual index pre-148

Computes flat index by hand: x + y*W + z*W*H

GPU time (ms)
— extra WGSL lines

global_invocation_index Chrome 148

Built-in linear index; compiler handles the math

GPU time (ms)
— WGSL lines needed

Benchmark log

Click "Run benchmark" to start…

Shader comparison

// Before Chrome 148 — manual 3D→1D conversion
@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_id) id: vec3<u32>,
        @builtin(num_workgroups) nwg: vec3<u32>) {
  let W = nwg.x * 64u;
  let H = nwg.y;
  let flat = id.x + id.y * W + id.z * W * H; // ← boilerplate every shader
  if (flat >= arrayLength(&data)) { return; }
  result[flat] = data[flat] * data[flat];
}

// Chrome 148 — global_invocation_index built-in
@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_index) flat: u32) { // ← one line replaces four
  if (flat >= arrayLength(&data)) { return; }
  result[flat] = data[flat] * data[flat];
}

references

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗