Skip to content

wgsl: support swizzle assignment#5268

Open
dneto0 wants to merge 36 commits into
gpuweb:mainfrom
dneto0:swizzle-assignment
Open

wgsl: support swizzle assignment#5268
dneto0 wants to merge 36 commits into
gpuweb:mainfrom
dneto0:swizzle-assignment

Conversation

@dneto0

@dneto0 dneto0 commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Add language extension 'swizzle_assignment'

Example:

var v:vec4u;
v.yz = vec2(1,2);

Issue: #737

@dneto0 dneto0 force-pushed the swizzle-assignment branch from fe9ba88 to d7c5282 Compare July 28, 2025 22:48
@github-actions

github-actions Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (c55aadf):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

Comment thread wgsl/syntax.bnf
@dneto0 dneto0 force-pushed the swizzle-assignment branch from d7c5282 to c984105 Compare July 29, 2025 14:26
@dneto0 dneto0 added this to the Milestone 3+ milestone Jul 29, 2025
@dneto0 dneto0 force-pushed the swizzle-assignment branch 2 times, most recently from abeafa1 to 9aa6e7f Compare July 29, 2025 14:55
@Kangz

Kangz commented Aug 19, 2025

Copy link
Copy Markdown
Contributor
GPU Web WG 2025-07-30 Atlantic-time
  • (Revised)
  • DN: people have wanted swizzle assignment for a long time. We can give them what they want. Can show them what will work and what won't.
  • DN: subtle: order of operations in e.g. compound assignment. Eval of RHS can modify memory you're evaluating on the LHS. Have already spoken with Oguz and Alan about it.
    • JP: This happens today in assignment to component of a vector.

Comment thread wgsl/index.bs Outdated
@mwyrzykowski mwyrzykowski self-requested a review October 2, 2025 15:12

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an interaction with 15.2.5 Function Scope Variable Value Analysis, where a swizzle view should sometimes be considered a full reference. It would be if the root variable is of vector type, because a swizzle assignment is deemed to be overwriting the entire vector.

@jimblandy

Copy link
Copy Markdown
Contributor

@dneto0 I gather that, since this is a draft, it's not ready for committee discussion?

@dneto0 dneto0 force-pushed the swizzle-assignment branch from f17717e to 57f69a1 Compare January 6, 2026 20:21
@jimblandy jimblandy added this to WGSL Jan 12, 2026
@jimblandy jimblandy moved this to Future agenda in WGSL Jan 12, 2026
copybara-service Bot pushed a commit to google/dawn that referenced this pull request Jan 22, 2026
Add a new core type called Swizzle View that is used as the type of
swizzle expressions in the resolver. This change is based on the draft
spec in: gpuweb/gpuweb#5268

Currently, there should be no functional change, it simply changes the
sem node types, which are then lowered in ProgramToIR to the expected
vector types. However, this change supports a future implementation of
swizzle assignment, where it will be necessary for swizzled objects to
be treated as memory views rather than concrete values.

Bug: 473857629
Change-Id: I34342f921e6906b599f840c10dbb455eed37cb94
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/285675
Reviewed-by: dan sinclair <[email protected]>
Commit-Queue: Natalie Chouinard <[email protected]>
Reviewed-by: James Price <[email protected]>
@dneto0

dneto0 commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

@dneto0 I gather that, since this is a draft, it's not ready for committee discussion?

That's correct. We're implementing a prototype. We'll come back to committee when we are confident in the spec and tests. Also I haven't addressed Alan's feedback on the spec-writing aspect of it.

@jimblandy jimblandy moved this from Future agenda to Awaiting investigation / implementation in WGSL Feb 9, 2026
copybara-service Bot pushed a commit to google/dawn that referenced this pull request Feb 19, 2026
Add WGSL language support for swizzle assignment on vectors as a proof
of concept. This implementation is based on the draft spec and passes
all CTS tests. It is enabled behind the swizzle_assignment language
feature flag as an unsafe experimental feature.

Draft Spec: gpuweb/gpuweb#5268

Bug: 473857629
Change-Id: Ic111554c53e41a9f3305f3118258f7dd5df4a29d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/290357
Commit-Queue: Natalie Chouinard <[email protected]>
Reviewed-by: dan sinclair <[email protected]>
@dneto0 dneto0 force-pushed the swizzle-assignment branch 2 times, most recently from 32ce5fc to 9a0cd0e Compare February 26, 2026 22:16
@dneto0

dneto0 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

The latest patches from today include a fix for the order of evaluation, and includes two worked examples: one for assignment, another for compound assignment.

@dneto0 dneto0 requested a review from sudonatalie February 26, 2026 22:18
@dneto0

dneto0 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

index.html

Attaching rendered HTML

Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs Outdated
@dneto0

dneto0 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

updated index.html

@dneto0 dneto0 requested a review from sudonatalie February 27, 2026 23:45
dneto0 added 25 commits June 5, 2026 16:31
…zzle View

The result is always a reference, not just a memory view.
That makes it consistent with other "Algorithm" blocks.
SwizzleViewWrite is only usable with read_write swizzle views
This is in the "swizzle view from swizzle view" table.
This gives it structure parallel to compound assignment via swizzle
view, so they are easier to compare.
It removes a possibly-confusing reference to using the load rule.
@dneto0 dneto0 force-pushed the swizzle-assignment branch from 17026de to c55aadf Compare June 5, 2026 20:31
@dneto0

dneto0 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

For @alan-baker, two substantively reviewable changes:

  • swizzle view types are only defined when access mode is read or read_write
  • memory model:
    • restated rules about what memory locations are touched by a memory access: pull the "write to vector component" into the main part of the text, instead of as a note.
    • memory model section says what locations are touched by an operation occurring via swizzle-view.

@dneto0

dneto0 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

ok @jimblandy I have addressed all comments so far. Please mark your comments are "resolved" when you are happy that the changes are satisfactory. I've resolved a few of the more trivial cases.

@alan-baker alan-baker modified the milestones: Milestone 4+, Milestone 2 Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting for PR approval

Development

Successfully merging this pull request may close these issues.

9 participants