Skip to content

fix: Remove 'use gpu' after transformation#2706

Merged
aleksanderkatan merged 8 commits into
mainfrom
fix/remove-use-gpu
Jul 10, 2026
Merged

fix: Remove 'use gpu' after transformation#2706
aleksanderkatan merged 8 commits into
mainfrom
fix/remove-use-gpu

Conversation

@aleksanderkatan

Copy link
Copy Markdown
Contributor

No description provided.

@aleksanderkatan aleksanderkatan linked an issue Jul 10, 2026 that may be closed by this pull request
@github-actions

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

benchmark
view benchmark

commit
view commit

@github-actions

Copy link
Copy Markdown

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

🟢 Decreased (max -6.74%) ➖ Unchanged 🔴 Increased ❔ Unknown
1 320 0 0

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

Test tsdown
STATIC_useGpuFunction.ts 263 B ($${\color{green}-6.7\%}$$)

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

Test tsdown
tgpu_init.ts 256.45 kB ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 255.93 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 187.16 kB ($${\color{green}-29.3\%}$$)
tgpu_resolveWithContext.ts 187.10 kB ($${\color{green}-29.4\%}$$)
tgpu_bindGroupLayout.ts 69.01 kB ($${\color{green}-74.0\%}$$)
tgpu_mutableAccessor.ts 65.98 kB ($${\color{green}-75.1\%}$$)
tgpu_accessor.ts 65.97 kB ($${\color{green}-75.1\%}$$)
tgpu_privateVar.ts 65.30 kB ($${\color{green}-75.3\%}$$)
tgpu_workgroupVar.ts 65.30 kB ($${\color{green}-75.4\%}$$)
tgpu_const.ts 64.53 kB ($${\color{green}-75.6\%}$$)
tgpu_fn.ts 37.97 kB ($${\color{green}-85.7\%}$$)
tgpu_fragmentFn.ts 37.91 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexFn.ts 37.72 kB ($${\color{green}-85.8\%}$$)
tgpu_computeFn.ts 37.43 kB ($${\color{green}-85.9\%}$$)
tgpu_vertexLayout.ts 26.61 kB ($${\color{green}-90.0\%}$$)
tgpu_comptime.ts 14.41 kB ($${\color{green}-94.6\%}$$)
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 10, 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.80, 1.65, 3.31, 5.29, 6.68, 10.82, 18.68, 19.70]
  line [0.87, 1.69, 3.85, 5.64, 6.42, 10.23, 19.79, 21.99]
  line [0.85, 1.64, 3.61, 5.73, 7.27, 10.58, 18.91, 19.57]
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.27, 0.50, 0.60, 0.70, 0.98, 0.96, 1.27, 1.37]
  line [0.29, 0.49, 0.71, 0.76, 1.04, 1.09, 1.27, 1.42]
  line [0.28, 0.50, 0.61, 0.75, 1.00, 1.06, 1.27, 1.41]
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.80, 1.90, 4.33, 6.16, 11.75, 24.06, 48.56, 100.40]
  line [0.87, 1.88, 4.03, 5.50, 10.91, 23.79, 48.61, 99.19]
  line [0.84, 1.88, 3.80, 5.72, 11.05, 23.25, 49.95, 100.05]
Loading

@aleksanderkatan

Copy link
Copy Markdown
Contributor Author

@pullfrog review

@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 — This PR removes the custom "use gpu" directive from functions after TypeGPU transforms them, replacing the previous alreadyTransformed WeakSet guard with directive deletion to prevent re-transformation.

  • Remove "use gpu" after transformation in both the Babel and unplugin/rollup plugin paths by adding a removeUseGpuDirective method to TransformMethods.
  • Drop the alreadyTransformed state from PluginState; since the directive is stripped, a second pass no longer recognizes the function as a GPU target.
  • Add test coverage for directive removal, coexistence with other directives like 'worklet', and double transformation round-trips for both backends.
  • Update inline snapshots across auto-naming, typescript-syntax, and autoname tests to reflect the absence of the leftover directive.

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

@aleksanderkatan aleksanderkatan marked this pull request as ready for review July 10, 2026 10:28
Copilot AI review requested due to automatic review settings July 10, 2026 10:28

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.

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

@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 — this PR removes the 'use gpu' directive from transformed functions so a second transform pass doesn't re-process them, replacing the previous alreadyTransformed WeakSet guard.

  • Updated the Babel transform (packages/unplugin-typegpu/src/babel.ts) by adding removeUseGpuDirective and dropping the alreadyTransformed check in assignMetadata.
  • Updated the unplugin/Rollup transform (packages/unplugin-typegpu/src/core/factory.ts) with a MagicString-based directive removal implementation.
  • Updated shared core state (packages/unplugin-typegpu/src/core/common.ts) to expose removeUseGpuDirective and remove the now-unused alreadyTransformed state.
  • Refreshed inline snapshots in auto-naming, TypeScript-syntax, and the internal TypeGPU autoname test.
  • Added regression tests covering directive removal (with siblings preserved) and double transformation for both Babel and Rollup.

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

@aleksanderkatan aleksanderkatan merged commit bb20d84 into main Jul 10, 2026
8 checks passed
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.

fix: Remove 'use gpu' directive after transforming a function

3 participants