feat: tgpu.fn(callback) for providing slots and accessors#2029
Merged
feat: tgpu.fn(callback) for providing slots and accessors#2029
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:
📋 All resultsClick to reveal the results table (335 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
…k' into feat/tgpufn-callback
iwoplaza
requested changes
Jan 13, 2026
Contributor
|
Free test it('allows for overloads', () => {
const mySlot = tgpu.slot<number | d.v2f>();
const f = (arg: number | d.v2f) => {
'use gpu';
return std.mul(arg, mySlot.$);
};
const fnum = tgpu.fn(f).with(mySlot, 3);
const fvec = tgpu.fn(f).with(mySlot, d.vec2f(1, 2));
const main = () => {
'use gpu';
fnum(1);
fnum(d.vec2f());
fvec(1);
fvec(d.vec2f());
};
expect(tgpu.resolve([main])).toMatchInlineSnapshot();
}); |
Contributor
|
How does this new API work with guarded pipelines? |
iwoplaza
reviewed
Feb 11, 2026
| export function setName(definition: object, name: string | undefined): void { | ||
| if (isForwarded(definition)) { | ||
| setName(definition[$getNameForward] as object, name); | ||
| return; |
Collaborator
There was a problem hiding this comment.
Has the same behavior, but we save memory by not storing unnecessary metadata
iwoplaza
approved these changes
Feb 11, 2026
Collaborator
iwoplaza
left a comment
There was a problem hiding this comment.
I give my unbiased approval
Collaborator
@aleksanderkatan Well now 👌 |
cieplypolar
approved these changes
Feb 11, 2026
Collaborator
cieplypolar
left a comment
There was a problem hiding this comment.
Very nice, very cool. Left some nits.
d31362f to
22db2cc
Compare
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.
A new overload for
tgpu.fnthat accepts a shell-less callback and returns a callable that has a.with()method. This allows shell-less functions to also be provided with slot and accessor overrides.Example
Requirements
foois used in code, andtgpu.fn(foo)is also used in code, it should only generate one definition.