Skip to content

TSL: Generate native WGSL switch statement (#33548) - #33852

Open
ShiKirill wants to merge 1 commit into
mrdoob:devfrom
ShiKirill:tsl-wgsl-native-switch
Open

TSL: Generate native WGSL switch statement (#33548)#33852
ShiKirill wants to merge 1 commit into
mrdoob:devfrom
ShiKirill:tsl-wgsl-native-switch

Conversation

@ShiKirill

Copy link
Copy Markdown
Contributor

Related issue: #33548

Description

Switch() / Case() / Default() previously desugared into a nested if / else chain on every
backend. This adds a dedicated SwitchNode that emits a native WGSL switch statement on the
WebGPU backend, while the WebGL backend keeps the equivalent if / else if / else fallback (GLSL
behaviour unchanged).

  • multi-value cases (Case( 1, 2, 3, … )) generate case 1, 2, 3:
  • a default clause is always emitted on WGSL (required by the spec)
  • selectors are coerced to the integer (i32 / u32) type of the switch expression

Verified identical rendering on both the WebGPU and WebGL backends for single/multi-value cases,
with and without a Default().

@github-actions

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 365.63
86.86
365.63
86.86
+0 B
+0 B
WebGPU 667.42
185.02
668.77
185.47
+1.35 kB
+441 B
WebGPU Nodes 665.47
184.71
666.82
185.15
+1.35 kB
+435 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 507.76
123.44
507.76
123.44
+0 B
+0 B
WebGPU 747.09
201.45
748.43
201.86
+1.33 kB
+412 B
WebGPU Nodes 697.44
189.04
698.77
189.44
+1.33 kB
+403 B

@ShiKirill

Copy link
Copy Markdown
Contributor Author

@Mugen87

@mrdoob
mrdoob requested a review from sunag June 27, 2026 02:59
@sunag

sunag commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

@ShiKirill Thanks for the PR, it might take me a bit longer to do the analysis; there are some things in the conditional flow which I was working on in another PR that I’d like to resolve before merge this.

@mrdoob mrdoob added this to the r186 milestone Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants