Skip to content

Conversation

@lursz
Copy link
Contributor

@lursz lursz commented Jan 9, 2026

A new overload for tgpu.fn that 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

const countAccess = tgpu.accessor(d.f32);

const getDouble = () => {
  'use gpu';
  return countAccess.$ * 2;
};
// ^? () => number

const getDouble4 = tgpu.fn(getDouble).with(countAccess, 4);
//    ^? TgpuGenericFn<() => number>

const main = () => {
  'use gpu';
  return getDouble4(); // should return 8
};

Requirements

  • If a shell-less function foo is used in code, and tgpu.fn(foo) is also used in code, it should only generate one definition.

@lursz lursz linked an issue Jan 9, 2026 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Jan 9, 2026

pkg.pr.new

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

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

benchmark
view benchmark

commit
view commit

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.

feat: tgpu.fn(callback) for providing slots and accessors

3 participants