Skip to content

fix: Calling toTSL multiple times#1974

Merged
aleksanderkatan merged 8 commits intofeat/tgpu-threefrom
fix/calling-totsl-multiple-times
Dec 16, 2025
Merged

fix: Calling toTSL multiple times#1974
aleksanderkatan merged 8 commits intofeat/tgpu-threefrom
fix/calling-totsl-multiple-times

Conversation

@aleksanderkatan
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented Dec 12, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@a774c35c35fcdd023320c39dd4cc98f752336c5f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@a774c35c35fcdd023320c39dd4cc98f752336c5f
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@a774c35c35fcdd023320c39dd4cc98f752336c5f

benchmark
view benchmark

commit
view commit

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the @typegpu/three package where calling toTSL multiple times with the same function or with nested function dependencies would fail due to incorrect function code extraction logic. The fix properly accumulates generated code and searches for specific functions by their IDs rather than using a generic "last function" pattern.

Key Changes

  • Refactored function code accumulation to track all generated code cumulatively
  • Changed function lookup from lastIndexOf('\nfn') to indexOf with specific function ID
  • Removed a brittle hack that modified Three.js internal code generation
  • Improved error message clarity for invalid external types

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/typegpu-three/src/typegpu-node.ts Core fix: Added codeGeneratedThusFar tracking, changed function extraction to use specific function IDs instead of generic pattern matching, removed code override hack
packages/typegpu/src/core/resolve/externals.ts Updated warning message to explicitly mention 'use gpu' functions as valid external types
packages/typegpu/tests/resolve.test.ts Updated test to match the improved warning message
apps/typegpu-docs/src/examples/threejs/test-reused-functions/index.ts New test example demonstrating toTSL with reused and nested functions
apps/typegpu-docs/src/examples/threejs/test-reused-functions/cubes.ts Test cases covering different scenarios: two different functions, same function twice, nested function references, and diamond dependency patterns
apps/typegpu-docs/src/examples/threejs/test-reused-functions/functions.ts Helper functions demonstrating various function reuse patterns for testing
apps/typegpu-docs/src/examples/threejs/test-reused-functions/meta.json Metadata for the test example (dev-only, experimental tag)
apps/typegpu-docs/src/examples/threejs/test-reused-functions/index.html HTML boilerplate for the example
apps/typegpu-docs/src/examples/threejs/test-reused-functions/thumbnail.png Screenshot/thumbnail for the example

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aleksanderkatan aleksanderkatan marked this pull request as ready for review December 15, 2025 09:11
Copy link
Collaborator

@iwoplaza iwoplaza left a comment

Choose a reason for hiding this comment

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

👽🍔👽

@aleksanderkatan aleksanderkatan merged commit 0de6b04 into feat/tgpu-three Dec 16, 2025
3 checks passed
iwoplaza added a commit that referenced this pull request Dec 22, 2025
)

* feat: tgpu.comptime, tgpu.rawCodeSnippet and `this` allowed in TypeGPU
shader functions

* Fix tests

* Better docs for rawCodeSnippet

* Docs for comptime

* - Namable comptime - Turned `extensionEnabled` into a comptime function

* Fixes

* Add @typegpu/three package and Three.js integration example (very WIP)

* Update tgpuThree.ts

* Three.js types for example code view

* More tweaks and experiments

* More work

* A bit more work

* More work

* Using @typegpu/noise in Three.js

* Add a new example

* Testing compute in Three.js

* Update examples

* Update typegpu-material.ts

* Update index.ts

* Some more work

* Works again

* TypeGPU compute shaders in TSL!

* A bit of a refactor of the cloth example

* Cleanup 🧹

* Comparing Three and TypeGPU output

* triNoise3D in TypeGPU

* comptime

* Support for 'this' in TypeGPU shader functions

* Update verlet.ts

* feat: Attractors example (#1949)

* Tweaks

* feat: Tweaks to feat/tgpu-three (#1954)

* Some review fixes

* Thumbnails and tags

* Comptime fromTSL

* Update shellless.test.ts

* fix: Calling `toTSL` multiple times (#1974)

* feat: Inform user about type mismatches (#1988)

* Fix renderer resizing when browser zoom

* docs: Cloth example controls (#1986)

* feat: ThreeJS 'Compute Particles' with tgpu (#1947)

* feat: ThreeJS 'Compute Geometry' with tgpu (#1948)

* feat: ThreeJS 'Compute Snow Particles' example in tgpu (#1972)

* fix: @typegpu/three toTSL should have a per-stage namespace (#1994)

---------

Co-authored-by: Iwo Plaza <iwoplaza@gmail.com>
Co-authored-by: Aleksander Katan <56294622+aleksanderkatan@users.noreply.github.com>
Co-authored-by: Rafal Lukosz <93160829+lursz@users.noreply.github.com>
Co-authored-by: Szymon Szulc <103948576+cieplypolar@users.noreply.github.com>
@aleksanderkatan aleksanderkatan deleted the fix/calling-totsl-multiple-times branch January 12, 2026 09:51
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