#10463·wgpu

[naga] Constant index/swizzle reads the wrong lane through a nested zero vector

Author: ekarad1umCreated Sep 26, 2026Updated Oct 1, 2026

Description When a vector constructor takes a zero-value vector as a component, indexing or swizzling into it during constant evaluation reads the wrong lane. proc::flatten_compose correctly flattens nested Compose or Splat nodes, but treats a nested ZeroValue as a single component. This shifts all subsequent lanes to the left and happens in the WGSL frontend, the wrong constants silently propagate to all backends.

(Note: #7137 fixed a similar ZeroValue gap for binary operators, but ConstantEvaluator::access and swizzle still rely on flatten_compose)

Repro steps

wgsl
@group(0) @binding(0) var<storage, read_write> o: array<u32, 4>;
@compute @workgroup_size(1) fn main() {
  o[0] = vec4u(vec2u(), 7u, 9u).y;                  // WGSL: 0u
  o[1] = vec4u(vec2u(), 7u, 9u).z;                  // WGSL: 7u
  o[2] = vec4u(vec2u(), 7u, 9u)[1];                 // WGSL: 0u
  o[3] = bitcast<u32>(vec4f(1.0, vec2f(), 2.0).z);  // WGSL: 0u
}

naga repro.wgsl out.wgsl writes:

wgsl
    o[0] = 7u;
    o[1] = 9u;
    o[2] = 7u;
    o[3] = bitcast<u32>(2f);

The same happens at module scope (const y = vec4u(vec2u(), 7u, 9u).y; is written as const y: u32 = 7u;) and through a swizzled zero vector (vec4u(vec4u().zx, vec4u(255u, 3u, 5u, 2836987521u).wy).z folds to 3u, where WGSL gives 2836987521u).

Two valid shaders are rejected instead:

  • o[0] = vec4f(vec3f(), 1.0).w; fails with error: Cannot access at the index.
  • o[0] = vec4u(7u, vec2u(), 9u).y; fails validation of naga's own lowering with The type of [2] doesn't match the type stored in [1].

Expected vs observed behavior Expected: the WGSL values in the comments. tint folds the first shader to 0u, 7u, 0u, 0u and accepts both rejected lines.

Observed: wrong constants with no diagnostic, so wgpu and Firefox compute different values than Chrome for the same shader.

Extra materials Adding a ZeroValue arm in flatten_compose (yielding one zero per lane) would fix all of these. Alternatively, access and swizzle could explicitly expand zero values before flattening.

Platform naga 30.0.1 (crates.io) and wgpu trunk d8548d5 (2026-09-25), naga CLI, macOS.