Skip to content

Commit 0756c03

Browse files
committed
Update syntax in Build Plugin guide
1 parent 1a7d5ee commit 0756c03

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

apps/typegpu-docs/src/content/docs/tooling/unplugin-typegpu.mdx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,37 @@ The package includes the following functionalities:
2323
import tgpu from 'typegpu';
2424
import * as d from 'typegpu/data';
2525

26-
const add = tgpu['~unstable'].fn(
27-
{ a: d.u32, b: d.u32 },
28-
d.u32,
29-
)(({ a, b }) => a + b);
26+
const add = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)(
27+
(a, b) => a + b,
28+
);
3029
```
3130

3231
However, if the implementation function, or the shell, is referenced via a variable, the plugin will not recognize it as TGSL,
3332
thus to make it work, the function needs to be marked with a `"kernel"` directive.
3433

3534
```ts
36-
const addFn = tgpu['~unstable'].fn({ a: d.u32, b: d.u32 }, d.u32);
35+
const addFn = tgpu['~unstable'].fn([d.u32, d.u32], d.u32);
3736

38-
const add = addFn(({ a, b }) => {
37+
const add = addFn((a, b) => {
3938
'kernel';
4039
return a + b;
4140
});
4241
```
4342

4443
```ts
45-
const addImpl = ({ a, b }) => {
44+
const addImpl = (a, b) => {
4645
'kernel';
4746
return a + b;
4847
};
4948

50-
const add = tgpu['~unstable'].fn({ a: d.u32, b: d.u32 }, d.u32)(addImpl);
49+
const add = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)(addImpl);
5150
```
5251

5352
After transpiling the function, the JS implementation is removed from the bundle in order to save space.
5453
To be able to invoke the function both on GPU and CPU, it needs to be marked with `"kernel & js"` directive;
5554

5655
```ts
57-
const add = tgpu['~unstable'].fn(
58-
{ a: d.u32, b: d.u32 },
59-
d.u32,
60-
)(({ a, b }) => {
56+
const add = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)((a, b) => {
6157
'kernel & js';
6258
return a + b;
6359
});

0 commit comments

Comments
 (0)