Skip to content

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

@iwoplaza

Description

@iwoplaza

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestjavascriptPull requests that update javascript code

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions