Skip to content

test: Test case for tgpu.unroll emulating dynamic dispatch#2710

Merged
iwoplaza merged 1 commit into
mainfrom
test/dynamic-dispatch-test-case
Jul 13, 2026
Merged

test: Test case for tgpu.unroll emulating dynamic dispatch#2710
iwoplaza merged 1 commit into
mainfrom
test/dynamic-dispatch-test-case

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings July 12, 2026 13:53
@github-actions

github-actions Bot commented Jul 12, 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/tgpu-gen@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@1e65177bb0ebca7056848a2252052370fce6c171
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@1e65177bb0ebca7056848a2252052370fce6c171

benchmark
view benchmark

commit
view commit

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.unroll test case that builds a “dispatch table” (Tonemap) and selects an implementation based on fnIdx.
  • 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.

Comment thread packages/typegpu/tests/unroll.test.ts
@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown

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

🟢 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 ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 255.37 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 161.34 kB ($${\color{green}-38.9\%}$$)
tgpu_resolveWithContext.ts 161.28 kB ($${\color{green}-39.0\%}$$)
tgpu_bindGroupLayout.ts 68.92 kB ($${\color{green}-73.9\%}$$)
tgpu_mutableAccessor.ts 65.91 kB ($${\color{green}-75.1\%}$$)
tgpu_accessor.ts 65.90 kB ($${\color{green}-75.1\%}$$)
tgpu_privateVar.ts 65.27 kB ($${\color{green}-75.3\%}$$)
tgpu_workgroupVar.ts 65.27 kB ($${\color{green}-75.3\%}$$)
tgpu_const.ts 64.52 kB ($${\color{green}-75.6\%}$$)
tgpu_fn.ts 37.98 kB ($${\color{green}-85.6\%}$$)
tgpu_fragmentFn.ts 37.88 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexFn.ts 37.70 kB ($${\color{green}-85.7\%}$$)
tgpu_computeFn.ts 37.40 kB ($${\color{green}-85.8\%}$$)
tgpu_vertexLayout.ts 26.63 kB ($${\color{green}-89.9\%}$$)
tgpu_comptime.ts 14.43 kB ($${\color{green}-94.5\%}$$)
tgpu_unroll.ts 2.60 kB ($${\color{green}-99.0\%}$$)
tgpu_slot.ts 1.54 kB ($${\color{green}-99.4\%}$$)
tgpu_lazy.ts 1.19 kB ($${\color{green}-99.5\%}$$)

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 Jul 12, 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.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]
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.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]
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.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]
Loading

@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 — added a single test demonstrating dynamic dispatch emulation via tgpu.unroll over compile-time function variants.

  • Adds the allows for emulating dynamic dispatch test in packages/typegpu/tests/unroll.test.ts — verifies the generated WGSL for unrolled conditionals over Tonemap keys, including an empty skip for the None variant and per-function index checks for Power and Tanh.

Pullfrog  | Fix it ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@reczkok reczkok 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.

very cool

@iwoplaza iwoplaza force-pushed the test/dynamic-dispatch-test-case branch from f886e40 to 7e3b850 Compare July 13, 2026 14:32

@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 — re-checked the single tgpu.unroll dynamic-dispatch emulation test since the prior Pullfrog review.

  • Adds the allows for emulating dynamic dispatch test in packages/typegpu/tests/unroll.test.ts — asserts the WGSL output of unrolled selection over Tonemap variants, including the empty None block and direct calls to power and the compiler-renamed tanh_1.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@iwoplaza iwoplaza force-pushed the test/dynamic-dispatch-test-case branch from 7e3b850 to ea04448 Compare July 13, 2026 14:58
@iwoplaza iwoplaza force-pushed the test/dynamic-dispatch-test-case branch from ea04448 to 1e65177 Compare July 13, 2026 15:25
@iwoplaza iwoplaza merged commit 46dfab1 into main Jul 13, 2026
8 checks passed
@iwoplaza iwoplaza deleted the test/dynamic-dispatch-test-case branch July 13, 2026 16:17
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.

5 participants