playcanvas / playcanvas/engine

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

Open
#9,388 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: graphics
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

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):

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

First verify that Firefox and Safari stable report swizzle_assignment through navigator.gpu.wgslLanguageFeatures. When universal support is confirmed, inspect the WGSL chunks under src/scene/shader-lib/wgsl and ShaderDefinitionUtils.getWGSLEnables; rewrite suitable component-wise writes and optionally add the requires directive. Done means the changes use the extension without engine support flags or fallbacks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.