test: Test case for tgpu.unroll emulating dynamic dispatch#2710
test: Test case for tgpu.unroll emulating dynamic dispatch#2710iwoplaza wants to merge 2 commits into
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.
| if (Tonemap[key] && fnIdx === tonemapKeyToIdx(key)) { | ||
| return Tonemap[key](color); | ||
| } |
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 | 256.12 kB ( |
| tgpu_initFromDevice.ts | 255.61 kB ( |
| tgpu_resolve.ts | 161.53 kB ( |
| tgpu_resolveWithContext.ts | 161.47 kB ( |
| tgpu_bindGroupLayout.ts | 69.02 kB ( |
| tgpu_mutableAccessor.ts | 66.00 kB ( |
| tgpu_accessor.ts | 65.98 kB ( |
| tgpu_privateVar.ts | 65.32 kB ( |
| tgpu_workgroupVar.ts | 65.32 kB ( |
| tgpu_const.ts | 64.54 kB ( |
| tgpu_fn.ts | 37.99 kB ( |
| tgpu_fragmentFn.ts | 37.92 kB ( |
| tgpu_vertexFn.ts | 37.74 kB ( |
| tgpu_computeFn.ts | 37.44 kB ( |
| tgpu_vertexLayout.ts | 26.63 kB ( |
| tgpu_comptime.ts | 14.43 kB ( |
| tgpu_unroll.ts | 2.60 kB ( |
| tgpu_slot.ts | 1.57 kB ( |
| tgpu_lazy.ts | 1.22 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 [1.01, 2.01, 4.53, 6.57, 7.55, 11.32, 22.26, 25.89]
line [0.99, 1.95, 4.38, 7.43, 7.84, 11.32, 22.46, 23.44]
line [0.97, 1.99, 4.31, 6.64, 7.56, 10.50, 22.25, 25.70]
---
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.31, 0.52, 0.70, 0.88, 1.18, 1.27, 1.56, 1.67]
line [0.33, 0.52, 0.69, 0.86, 1.14, 1.24, 1.46, 1.65]
line [0.32, 0.59, 0.79, 0.89, 1.23, 1.30, 1.46, 1.55]
---
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.91, 2.10, 4.29, 6.50, 12.57, 26.93, 57.36, 116.51]
line [0.98, 2.09, 4.23, 6.74, 13.05, 26.52, 56.59, 119.71]
line [1.02, 2.18, 4.23, 6.52, 12.91, 27.16, 56.55, 117.16]
|
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) | 𝕏

No description provided.