Skip to content

feat: switch in 'use gpu' functions - #2912

Open
aleksanderkatan wants to merge 20 commits into
feat/null-legal-at-comptimefrom
feat/switch-in-use-gpu
Open

feat: switch in 'use gpu' functions#2912
aleksanderkatan wants to merge 20 commits into
feat/null-legal-at-comptimefrom
feat/switch-in-use-gpu

Conversation

@aleksanderkatan

@aleksanderkatan aleksanderkatan commented Aug 24, 2026

Copy link
Copy Markdown
Member

Changes:

  • parse/obfuscate/tseynit/generate switch,
  • update some examples to use switch.

More than half of this PR is tests.

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/eslint-plugin-typegpu@5ab12f79819aeefc651a8621cca16765db8b102e
https://pkg.pr.new/software-mansion/TypeGPU/tinyest@5ab12f79819aeefc651a8621cca16765db8b102e
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@5ab12f79819aeefc651a8621cca16765db8b102e
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@5ab12f79819aeefc651a8621cca16765db8b102e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@5ab12f79819aeefc651a8621cca16765db8b102e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@5ab12f79819aeefc651a8621cca16765db8b102e
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@5ab12f79819aeefc651a8621cca16765db8b102e

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.78%) ❔ Unknown
0 304 21 0

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Test tsdown
STATIC_tgpu.ts 274.75 kB ($${\color{red}+0.8\%}$$)
tgpu_fn.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_init.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_lazy.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_slot.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_const.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_unroll.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_resolve.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_accessor.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_comptime.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_vertexFn.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_computeFn.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_fragmentFn.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_privateVar.ts 274.76 kB ($${\color{red}+0.8\%}$$)
tgpu_vertexLayout.ts 274.77 kB ($${\color{red}+0.8\%}$$)
tgpu_workgroupVar.ts 274.77 kB ($${\color{red}+0.8\%}$$)
tgpu_initFromDevice.ts 274.77 kB ($${\color{red}+0.8\%}$$)
tgpu_bindGroupLayout.ts 274.77 kB ($${\color{red}+0.8\%}$$)
tgpu_mutableAccessor.ts 274.77 kB ($${\color{red}+0.8\%}$$)
tgpu_resolveWithContext.ts 274.77 kB ($${\color{red}+0.8\%}$$)
STATIC_allImports.ts 301.01 kB ($${\color{red}+0.7\%}$$)

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 265.23 kB ($${\color{green}-3.5\%}$$)
tgpu_initFromDevice.ts 264.68 kB ($${\color{green}-3.7\%}$$)
tgpu_resolve.ts 163.87 kB ($${\color{green}-40.4\%}$$)
tgpu_resolveWithContext.ts 163.81 kB ($${\color{green}-40.4\%}$$)
tgpu_bindGroupLayout.ts 62.32 kB ($${\color{green}-77.3\%}$$)
tgpu_mutableAccessor.ts 57.04 kB ($${\color{green}-79.2\%}$$)
tgpu_accessor.ts 57.04 kB ($${\color{green}-79.2\%}$$)
tgpu_privateVar.ts 55.73 kB ($${\color{green}-79.7\%}$$)
tgpu_workgroupVar.ts 55.73 kB ($${\color{green}-79.7\%}$$)
tgpu_const.ts 55.15 kB ($${\color{green}-79.9\%}$$)
tgpu_lazy.ts 54.95 kB ($${\color{green}-80.0\%}$$)
tgpu_fragmentFn.ts 39.68 kB ($${\color{green}-85.6\%}$$)
tgpu_fn.ts 39.62 kB ($${\color{green}-85.6\%}$$)
tgpu_vertexFn.ts 39.50 kB ($${\color{green}-85.6\%}$$)
tgpu_computeFn.ts 39.20 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexLayout.ts 28.33 kB ($${\color{green}-89.7\%}$$)
tgpu_comptime.ts 15.93 kB ($${\color{green}-94.2\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 kB ($${\color{green}-99.4\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.84, 1.72, 3.38, 5.76, 6.79, 10.76, 20.28, 21.53]
  line [0.94, 1.81, 3.82, 5.82, 6.69, 11.27, 21.49, 20.84]
  line [0.87, 1.76, 3.42, 5.41, 7.17, 9.45, 22.01, 23.48]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.33, 0.44, 0.70, 0.78, 0.99, 1.07, 1.23, 1.40]
  line [0.34, 0.54, 0.67, 0.76, 1.03, 1.06, 1.26, 1.47]
  line [0.32, 0.49, 0.60, 0.73, 1.00, 1.04, 1.28, 1.45]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.76, 2.11, 3.40, 6.14, 10.65, 23.35, 49.83, 99.10]
  line [0.82, 1.99, 3.05, 6.94, 10.74, 23.68, 50.49, 103.44]
  line [0.80, 1.96, 2.99, 6.09, 10.90, 23.57, 51.32, 102.07]
Loading

@aleksanderkatan

Copy link
Copy Markdown
Member Author

@pullfrog review

pullfrog[bot]

This comment was marked as outdated.

pullfrog[bot]

This comment was marked as outdated.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — one commit (118097f8 Fix break pruning) re-reviewed against feat/null-legal-at-comptime:

  • Fixed WGSL switch break pruning in WgslGenerator._emitSwitchStatement: the old filter removed every statement whose resolved code was a bare break; (case endsWithControlFlow === 'break'), which corrupted cases where an intermediate break split reachable from unreachable statements. It now pops only a single trailing bare break — the switch's genuinely redundant terminal break (WGSL switch clauses don't fall through, so it's safe to drop).
  • Added the does not prune wrong breaks test, which fails under the old logic and pins the corrected emission (intermediate breaks kept, terminal break pruned, auto-added default).
  • Confirmed the pruning is WGSL-only: GlslGenerator._emitSwitchStatement overrides and re-emits without pruning, so C-style fall-through breaks are retained for GLSL.

I verified the change end-to-end: the new test and the full switch.test.ts suite (21 tests) pass.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Copilot AI lite review requested due to automatic review settings August 26, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aleksanderkatan aleksanderkatan linked an issue Aug 26, 2026 that may be closed by this pull request
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.

feat: Support switch in 'use gpu' functions

2 participants