fix: Calling toTSL multiple times#1974
Merged
aleksanderkatan merged 8 commits intofeat/tgpu-threefrom Dec 16, 2025
Merged
Conversation
|
pkg.pr.new packages benchmark commit |
added 2 commits
December 12, 2025 16:39
There was a problem hiding this comment.
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')toindexOfwith 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.
apps/typegpu-docs/src/examples/threejs/test-reused-functions/index.ts
Outdated
Show resolved
Hide resolved
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.