-
-
Notifications
You must be signed in to change notification settings - Fork 25
docs: TypeGPU functions #1793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: TypeGPU functions #1793
Conversation
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually 10/10 docs - I would read them for fun even though I know all those things 🙇
|
|
||
| In order to construct a TypeGPU function, you need to start by defining its shell, an object holding only the input and output types. | ||
| :::note[WGSL enthusiasts!] | ||
| Don't let the JavaScript scare you! TypeGPU functions can be implemented using either WGSL or JS, both being able to call one another. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe discourage over scare? Scare sounds a little condescending to me.
| const main = () => { | ||
| 'use gpu'; | ||
| // Call from another function | ||
| return neighborhood(1.1, 0.5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those numbers are quite carefully chosen I see 😄 I think we should either wrap them in d.f32() or at least explain the dangers of using plain literals (eg: showing the 1.0 case)
EDIT: I just now reached a section where you explain it in depth - maybe we should do a short warning with a reference to that in case people get trigger happy and do not reach that?
| To make this all work, we perform a small transformation to functions marked with `'use gpu'`, leaving all other code untouched. Every project's setup is different, and we want to be as non-invasive as possible. The [unplugin-typegpu](/TypeGPU/tooling/unplugin-typegpu) package hooks into existing bundlers and build tools, extracts ASTs from TypeGPU functions and compacts them into our custom format called [tinyest](https://www.npmjs.com/package/tinyest). This metadata is injected into the final JS bundle, then used to efficiently generate equivalent WGSL at runtime. | ||
| :::tip | ||
| If you wish for all WGSL generation to happen at build time, combine [unplugin-macros](https://github.com/unplugin/unplugin-macros) and our [resolve API](/TypeGPU/fundamentals/resolve). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all WGSL generation at build time is not possible most of the time so we shouldn't sell it like that - maybe all build time known WGSL generation?
| * **Operators** -- | ||
| JavaScript does not support operator overloading. | ||
| This means that, while you can still use operators for numbers, | ||
| you have to use supplementary functions from `typegpu/std` (*add, mul, eq, lt, ge...*) for operations involving vectors and matrices, or use a fluent interface (*abc.mul(xyz), ...*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could mention the //ts-ignore (no @ since of course there is a user with that username) trick for people who like cursed code 😅
| * **Math.\*** -- | ||
| Utility functions on the `Math` object can't automatically run on the GPU, but can usually be swapped with functions exported from `typegpu/std`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could mention that constants are fine
| "starlight-typedoc": "^0.19.0", | ||
| "tinybench": "^3.1.0", | ||
| "typedoc": "^0.28.13", | ||
| "typedoc-plugin-markdown": "^4.3.0", | ||
| "typedoc": "^0.27.9", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason for this change?
No description provided.