Skip to content

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

Open
iwoplaza wants to merge 2 commits into
mainfrom
test/dynamic-dispatch-test-case
Open

test: Test case for tgpu.unroll emulating dynamic dispatch#2710
iwoplaza wants to merge 2 commits 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@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@f886e403fa7c862a94d7fd6c8e33f4fe8cce0228

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 on lines +934 to +936
if (Tonemap[key] && fnIdx === tonemapKeyToIdx(key)) {
return Tonemap[key](color);
}
@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 256.12 kB ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 255.61 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 161.53 kB ($${\color{green}-38.9\%}$$)
tgpu_resolveWithContext.ts 161.47 kB ($${\color{green}-39.0\%}$$)
tgpu_bindGroupLayout.ts 69.02 kB ($${\color{green}-73.9\%}$$)
tgpu_mutableAccessor.ts 66.00 kB ($${\color{green}-75.1\%}$$)
tgpu_accessor.ts 65.98 kB ($${\color{green}-75.1\%}$$)
tgpu_privateVar.ts 65.32 kB ($${\color{green}-75.3\%}$$)
tgpu_workgroupVar.ts 65.32 kB ($${\color{green}-75.3\%}$$)
tgpu_const.ts 64.54 kB ($${\color{green}-75.6\%}$$)
tgpu_fn.ts 37.99 kB ($${\color{green}-85.6\%}$$)
tgpu_fragmentFn.ts 37.92 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexFn.ts 37.74 kB ($${\color{green}-85.7\%}$$)
tgpu_computeFn.ts 37.44 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.57 kB ($${\color{green}-99.4\%}$$)
tgpu_lazy.ts 1.22 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 [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]
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.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]
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.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]
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) | 𝕏

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