@@ -23,41 +23,37 @@ The package includes the following functionalities:
23
23
import tgpu from ' typegpu' ;
24
24
import * as d from ' typegpu/data' ;
25
25
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
+ );
30
29
```
31
30
32
31
However, if the implementation function, or the shell, is referenced via a variable, the plugin will not recognize it as TGSL,
33
32
thus to make it work, the function needs to be marked with a ` "kernel" ` directive.
34
33
35
34
``` 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 );
37
36
38
- const add = addFn (({ a , b } ) => {
37
+ const add = addFn ((a , b ) => {
39
38
' kernel' ;
40
39
return a + b ;
41
40
});
42
41
```
43
42
44
43
``` ts
45
- const addImpl = ({ a , b } ) => {
44
+ const addImpl = (a , b ) => {
46
45
' kernel' ;
47
46
return a + b ;
48
47
};
49
48
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 );
51
50
```
52
51
53
52
After transpiling the function, the JS implementation is removed from the bundle in order to save space.
54
53
To be able to invoke the function both on GPU and CPU, it needs to be marked with ` "kernel & js" ` directive;
55
54
56
55
``` 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 ) => {
61
57
' kernel & js' ;
62
58
return a + b ;
63
59
});
0 commit comments