#9388·engine

feat(graphics): adopt WGSL swizzle_assignment once every WebGPU browser ships it

Author: mvaligurskyCreated Sep 15, 2026Updated Sep 15, 2026
Labelsarea: graphics

Background

The swizzle_assignment WGSL language extension allows a swizzle on the left-hand side of an assignment, so several vector components can be written in one statement (one read, one write):

wgsl
requires swizzle_assignment;

position.xy = vec2f(10.0, 20.0);   // instead of position = vec4f(10.0, 20.0, position.zw);
p.xz = vec2f(1.0, 2.0);            // also through pointers when pointer_composite_access is available

It is a requires extension. The directive only documents the dependency and makes shader creation fail early where the extension is missing; it does not gate the feature, which is always on where the implementation supports it.

Status

  • Shipped in Chrome 153 (What's New in WebGPU 153-154). Chrome Canary 155 lists it in navigator.gpu.wgslLanguageFeatures; Chrome 152 stable does not.
  • Not shipped in Firefox or Safari as far as we know.
  • Long-standing request: gpuweb/gpuweb#737.

Plan

Do not add engine support yet - no supports* flag, no CAPS_* define, no injected requires line, and no use in engine chunks - until every WebGPU browser ships it. Adopting it earlier means carrying a fallback for each use site; adopting it once it is universal lets us simply use the syntax.

When it is universally available:

  1. Rewrite component-wise vector writes in the WGSL chunks (roughly 150 sites under src/scene/shader-lib/wgsl) as swizzle assignments where that improves readability.
  2. Optionally add requires swizzle_assignment; to the directives injected by ShaderDefinitionUtils.getWGSLEnables, purely as documentation.

Triggers to revisit

  • Firefox and Safari stable report navigator.gpu.wgslLanguageFeatures.has('swizzle_assignment') === true.