test: Test case for tgpu.unroll emulating dynamic dispatch#2710
Conversation
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this comment.
Pull request overview
Adds a new tgpu.unroll test that demonstrates a pattern for emulating “dynamic dispatch” on the GPU by unrolling over a compile-time list of keys and selecting an implementation via an index.
Changes:
- Added a new
tgpu.unrolltest case that builds a “dispatch table” (Tonemap) and selects an implementation based onfnIdx. - Introduced a snapshot asserting the generated WGSL contains the unrolled selection logic and direct calls to the chosen functions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 321 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 255.88 kB ( |
| tgpu_initFromDevice.ts | 255.37 kB ( |
| tgpu_resolve.ts | 161.34 kB ( |
| tgpu_resolveWithContext.ts | 161.28 kB ( |
| tgpu_bindGroupLayout.ts | 68.92 kB ( |
| tgpu_mutableAccessor.ts | 65.91 kB ( |
| tgpu_accessor.ts | 65.90 kB ( |
| tgpu_privateVar.ts | 65.27 kB ( |
| tgpu_workgroupVar.ts | 65.27 kB ( |
| tgpu_const.ts | 64.52 kB ( |
| tgpu_fn.ts | 37.98 kB ( |
| tgpu_fragmentFn.ts | 37.88 kB ( |
| tgpu_vertexFn.ts | 37.70 kB ( |
| tgpu_computeFn.ts | 37.40 kB ( |
| tgpu_vertexLayout.ts | 26.63 kB ( |
| tgpu_comptime.ts | 14.43 kB ( |
| tgpu_unroll.ts | 2.60 kB ( |
| tgpu_slot.ts | 1.54 kB ( |
| tgpu_lazy.ts | 1.19 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
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.99, 2.01, 4.54, 7.13, 8.18, 12.58, 21.99, 26.03]
line [0.99, 1.96, 4.33, 6.31, 7.63, 13.27, 23.70, 24.78]
line [0.98, 1.84, 4.14, 6.65, 7.65, 11.67, 22.42, 22.87]
---
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.32, 0.52, 0.68, 0.92, 1.24, 1.17, 1.50, 1.60]
line [0.33, 0.47, 0.74, 0.84, 1.13, 1.21, 1.44, 1.64]
line [0.31, 0.52, 0.67, 0.89, 1.16, 1.22, 1.47, 1.63]
---
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.85, 2.18, 4.44, 7.29, 13.11, 25.91, 56.69, 116.00]
line [1.02, 2.17, 4.08, 7.03, 12.62, 26.28, 57.60, 113.18]
line [1.02, 2.11, 3.88, 6.55, 12.95, 26.20, 56.91, 116.10]
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — added a single test demonstrating dynamic dispatch emulation via tgpu.unroll over compile-time function variants.
- Adds the
allows for emulating dynamic dispatchtest inpackages/typegpu/tests/unroll.test.ts— verifies the generated WGSL for unrolled conditionals overTonemapkeys, including an empty skip for theNonevariant and per-function index checks forPowerandTanh.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
f886e40 to
7e3b850
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-checked the single tgpu.unroll dynamic-dispatch emulation test since the prior Pullfrog review.
- Adds the
allows for emulating dynamic dispatchtest inpackages/typegpu/tests/unroll.test.ts— asserts the WGSL output of unrolled selection overTonemapvariants, including the emptyNoneblock and direct calls topowerand the compiler-renamedtanh_1.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
7e3b850 to
ea04448
Compare
ea04448 to
1e65177
Compare

No description provided.