Skip to content

Conversation

@iwoplaza
Copy link
Collaborator

@iwoplaza iwoplaza commented Oct 8, 2025

No description provided.

@github-actions
Copy link

github-actions bot commented Oct 8, 2025

pkg.pr.new

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

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@946f45f4e404e7de8b450211cf0557cb8180dda6
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@946f45f4e404e7de8b450211cf0557cb8180dda6
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@946f45f4e404e7de8b450211cf0557cb8180dda6

benchmark
view benchmark

commit
view commit

@iwoplaza iwoplaza changed the title docs: JS Kernels docs: TypeGPU functions Oct 16, 2025
@iwoplaza iwoplaza marked this pull request as ready for review October 29, 2025 15:07
Copy link
Contributor

@reczkok reczkok left a 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.
Copy link
Contributor

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);
Copy link
Contributor

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).
Copy link
Contributor

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?

Comment on lines +306 to +309
* **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), ...*)
Copy link
Contributor

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 😅

Comment on lines +311 to +312
* **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`.
Copy link
Contributor

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

Comment on lines +53 to +55
"starlight-typedoc": "^0.19.0",
"tinybench": "^3.1.0",
"typedoc": "^0.28.13",
"typedoc-plugin-markdown": "^4.3.0",
"typedoc": "^0.27.9",
Copy link
Contributor

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?

@iwoplaza iwoplaza merged commit 12b2d38 into main Oct 29, 2025
3 checks passed
@iwoplaza iwoplaza deleted the docs/js-kernels branch October 29, 2025 17:05
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.

3 participants