Skip to content

Commit b43f6d8

Browse files
authored
docs: Refresh docs for 0.10 (#2211)
* docs: Refresh docs for 0.10 * More changes to docs for 0.10
1 parent e875215 commit b43f6d8

16 files changed

Lines changed: 48 additions & 56 deletions

File tree

apps/typegpu-docs/astro.config.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ export default defineConfig({
152152
{
153153
label: 'Variables',
154154
slug: 'fundamentals/variables',
155-
badge: { text: 'new' },
156155
},
157156
{
158157
label: 'Data Schemas',
@@ -173,17 +172,14 @@ export default defineConfig({
173172
{
174173
label: 'Enabling Features',
175174
slug: 'fundamentals/enabling-features',
176-
badge: { text: 'new' },
177175
},
178176
{
179177
label: 'Timing Your Pipelines',
180178
slug: 'fundamentals/timestamp-queries',
181-
badge: { text: 'new' },
182179
},
183180
{
184181
label: 'Slots',
185182
slug: 'fundamentals/slots',
186-
badge: { text: 'new' },
187183
},
188184
{
189185
label: 'Utilities',
@@ -214,12 +210,10 @@ export default defineConfig({
214210
{
215211
label: '@typegpu/three',
216212
slug: 'ecosystem/typegpu-three',
217-
badge: { text: 'new' },
218213
},
219214
{
220215
label: '@typegpu/sdf',
221216
slug: 'ecosystem/typegpu-sdf',
222-
badge: { text: 'new' },
223217
},
224218
DEV && {
225219
label: '@typegpu/color',
@@ -241,7 +235,6 @@ export default defineConfig({
241235
{
242236
label: 'React Native',
243237
slug: 'integration/react-native',
244-
badge: { text: 'new' },
245238
},
246239
{
247240
label: 'WESL Interoperability',
@@ -259,7 +252,6 @@ export default defineConfig({
259252
{
260253
label: 'Build Plugin',
261254
slug: 'tooling/unplugin-typegpu',
262-
badge: { text: 'new' },
263255
},
264256
{
265257
label: 'Generator CLI',

apps/typegpu-docs/src/content/docs/fundamentals/data-schemas.mdx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TypeGPU does this automatically during buffer writes and reads.
1313
:::
1414

1515
The primary usage for data schemas is to define buffer and function signatures.
16-
Schemas can also be called in JS or TGSL to create instances of the types they represent.
16+
Schemas can also be called to create instances of the types they represent.
1717

1818
TypeGPU provides data schemas for scalar, vector and matrix types, as well as constructors for struct and array schemas.
1919

@@ -23,7 +23,7 @@ TypeGPU provides data schemas for scalar, vector and matrix types, as well as co
2323

2424
For scalar WGSL types `f32`, `u32`, `i32`, `f16` and `bool`, TypeGPU provides `d.f32`, `d.u32`, `d.i32`, `d.f16` and `d.bool` schemas respectively.
2525
Schemas can be called to cast a value to a given type.
26-
This works both in TGSL, and in plain JavaScript.
26+
This works both inside and outside 'use gpu' functions.
2727

2828
```ts twoslash
2929
import { d } from 'typegpu';
@@ -36,7 +36,7 @@ d.bool(0.01); // true
3636
```
3737

3838
:::caution
39-
On JavaScript side, the type of any number remains a number regardless of any casts.
39+
In JavaScript, the type of any number remains a number regardless of casts.
4040

4141
```ts twoslash
4242
import { d } from 'typegpu';
@@ -46,7 +46,7 @@ const myUnsignedInt = d.u32(1);
4646
const result = d.u32(3)/d.u32(2); // 1.5
4747
```
4848

49-
For the WGSL and JS functions to return consistent results, during WGSL resolution TypeGPU wraps all divisions in `f32` casts.
49+
To achieve consistent behavior of 'use gpu' functions in JS and on the GPU, TypeGPU wraps all divisions in `f32` casts implicitly.
5050
:::
5151

5252
For each of the scalar types, there is a vector schema of 2, 3 and 4 elements of that type.
@@ -106,7 +106,7 @@ to a seamless integration with `wgpu-matrix`, which you can [read more about her
106106

107107
:::caution
108108
For `wgpu-matrix` integration, matrix instances implement array access.
109-
Matrix array access is not supported in TGSL.
109+
Matrix array access is not supported in 'use gpu' functions.
110110

111111
```ts twoslash
112112
import { d } from 'typegpu';
@@ -474,16 +474,17 @@ const AtomicI32 = d.atomic(d.i32);
474474
```
475475

476476
:::tip
477-
The `std` module provides functions for manipulating atomic data in TGSL.
477+
The `std` module provides functions for manipulating atomic data in 'use gpu' functions.
478478

479479
```ts twoslash
480480
import tgpu, { d, std } from 'typegpu';
481481
// ---cut---
482482
const count = tgpu.workgroupVar(d.atomic(d.u32));
483483

484-
const incrementAndGet = tgpu.fn([], d.u32)(() => {
484+
function incrementAndGet() {
485+
'use gpu';
485486
return std.atomicAdd(count.$, 1);
486-
});
487+
}
487488
```
488489

489490
:::
@@ -514,19 +515,19 @@ This extension is enabled automatically when available.
514515
## Copy constructors
515516

516517
One of the biggest differences between JavaScript and WGSL is the existence of value/reference types.
517-
Let's take a look at a simple TGSL function and the WGSL code it resolves to.
518+
Let's take a look at a simple TypeGPU function and the WGSL code it resolves to.
518519

519520
```ts twoslash
520521
import tgpu, { d } from 'typegpu';
521522
// ---cut---
522-
// TGSL
523523
const MyStruct = d.struct({ n: d.u32 });
524524

525-
const myFn = tgpu.fn([])(() => {
525+
function myFn() {
526+
'use gpu';
526527
const s1 = MyStruct({ n: 0 });
527528
const s2 = s1;
528529
s2.n = 1; // s1 is modified
529-
});
530+
}
530531
```
531532

532533
```wgsl
@@ -537,29 +538,31 @@ struct MyStruct {
537538
538539
fn myFn(){
539540
var s1 = MyStruct(0);
540-
var s2 = s1;
541-
s2.n = 1; // s1 is not modified
541+
let s2 = &s1;
542+
(*s2).n = 1; // s1 is modified
542543
}
543544
```
544545

545-
On the JS side, s2 is a reference to s1 and therefore s1 is modified when s2 is modified.
546-
On the WGSL side, the assignment operator copies the value of s1, and thus s1 is not modified later on.
546+
In JavaScript, `s2` is a reference to `s1` and therefore `s1` is modified when `s2` is modified.
547+
On the WGSL side, we make `s2` a reference to `s1` and modifying `s2.n` is translated to modifying `(*s2).n`.
547548

548-
To help with this issue, schema calls can be used as "copy constructors", that copy the value on the JS side, and disappear on the WGSL side:
549+
Schemas can be used to create deep copies of values.
549550

550551
```ts twoslash
551552
import tgpu, { d } from 'typegpu';
552553
// ---cut---
553-
// TGSL
554554
const MyStruct = d.struct({ n: d.u32 });
555555

556-
const myFn = tgpu.fn([])(() => {
556+
function myFn() {
557+
'use gpu';
557558
const s1 = MyStruct({ n: 0 });
558559
const s2 = MyStruct(s1); // deep copy of s1
559560
s2.n = 1; // s1 is not modified
560-
});
561+
}
561562
```
562563

564+
The TypeGPU shader generator understands this and generates a simple assignment, which copies the value of `s1` into `s2`.
565+
563566
```wgsl
564567
// WGSL
565568
struct MyStruct {

apps/typegpu-docs/src/content/docs/fundamentals/functions/index.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,6 @@ However, there are cases where WGSL might be more suitable. Writing WGSL becomes
444444

445445
## Entry functions
446446

447-
:::caution[Experimental]
448-
Entry functions are an *unstable* feature. The API may be subject to change in the near future.
449-
:::
450-
451447
Instead of annotating a `TgpuFn` with attributes, entry functions are defined using dedicated shell constructors:
452448

453449
- `tgpu.computeFn`,

apps/typegpu-docs/src/content/docs/fundamentals/pipelines.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ title: Pipelines
33
description: A guide on how to use TypeGPU render and compute pipelines.
44
---
55

6-
:::caution[Experimental]
7-
Pipelines are an *unstable* feature. The API may be subject to change in the near future.
8-
:::
9-
106
:::note[Recommended reading]
117
It is assumed that you are familiar with the following concepts:
128
- <a href="https://webgpufundamentals.org/webgpu/lessons/webgpu-fundamentals.html" target="_blank" rel="noopener noreferrer">WebGPU Fundamentals</a>
@@ -404,6 +400,10 @@ const pipeline = root
404400

405401
## Low-level render pipeline execution API
406402

403+
:::caution[Experimental]
404+
`root.beginRenderPass` is an *unstable* feature. The API may be subject to change in the near future.
405+
:::
406+
407407
The higher-level API has several limitations, therefore another way of executing pipelines is exposed, for some custom, more demanding scenarios. For example, with the high-level API, it is not possible to execute multiple pipelines per one render pass. It also may be missing some more niche features of the WebGPU API.
408408

409409
`root['~unstable'].beginRenderPass` is a method that mirrors the WebGPU API, but enriches it with a direct TypeGPU resource support.

apps/typegpu-docs/src/content/docs/fundamentals/resolve.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Sometimes, it may not be clear which bind group layouts were used in a given res
258258
This may occur especially when using:
259259

260260
- Buffer usages/shorthands, which use a hidden, automatically created "catchall" bind group,
261-
- TypeGPU functions implemented in TGSL, which generate their externals automatically.
261+
- TypeGPU functions implemented in JavaScript/TypeScript, which generate their externals automatically.
262262

263263
For these cases, you can use `tgpu.resolveWithContext`, which has the same input API as `tgpu.resolve`, but in addition to the resolved code, it also returns information about the layouts used. `tgpu.resolveWithContext` returns an object with 3 props:
264264

@@ -290,7 +290,7 @@ console.log(catchall?.[0]); // 0 - the group index of the catchall bind group
290290
console.log(catchall?.[1]); // the catchall bind group
291291
```
292292

293-
An example, where a bind group layout is automatically included via a TGSL function:
293+
An example, where a bind group layout is automatically included via a TypeScript function:
294294

295295
```ts twoslash
296296
import tgpu, { d } from 'typegpu';
@@ -299,9 +299,10 @@ const root = await tgpu.init();
299299
// ---cut---
300300
const myLayout = tgpu.bindGroupLayout({ count: { uniform: d.u32 } });
301301

302-
const exampleFn = tgpu.fn([])(() => {
302+
function exampleFn() {
303+
'use gpu';
303304
myLayout.$.count += 1;
304-
});
305+
}
305306

306307
const { code, usedBindGroupLayouts, catchall } = tgpu.resolveWithContext({
307308
externals: { exampleFn },

apps/typegpu-docs/src/content/docs/fundamentals/slots.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Similarly to bind group layouts, you can think of slots as of typed "holes" in T
77
The main differences between slots and bound resources include the following:
88

99
- Slots are filled in before the shader module compile time, instead of just before the shader execution starts.
10-
- Slots can contain not only buffers, but also basically anything that is allowed in TGSL, even TypeGPU functions.
10+
- Slots can contain not only buffers, but also basically any JavaScript value, even TypeGPU functions.
1111

1212
Main use cases for slots include:
1313

apps/typegpu-docs/src/content/docs/fundamentals/textures.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ const ctx = canvas.getContext('2d');
140140
texture.write(canvas);
141141
```
142142

143+
:::tip
144+
If image dimensions don't match the texture size, the image will be automatically resampled to fit (requires 'render' usage).
145+
:::
146+
143147
### Writing arrays of images
144148

145149
For 3D textures or texture arrays, you can write multiple images:
@@ -188,10 +192,6 @@ const mipData = new Uint8Array(4 * 128 * 128); // Data for 128x128
188192
texture.write(mipData, 1); // Write to mip level 1
189193
```
190194

191-
:::tip
192-
If image dimensions don't match the texture size, the image will be automatically resampled to fit.
193-
:::
194-
195195
You can also copy from another texture:
196196

197197
```ts twoslash

apps/typegpu-docs/src/content/docs/fundamentals/utils.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Other supported `console` functionalities include `console.debug`, `console.info
262262

263263
There are some limitations (some of which we intend to alleviate in the future):
264264

265-
- `console.log` only works when used in TGSL, when calling or resolving a TypeGPU pipeline.
265+
- `console.log` only works when used in TypeGPU functions that are transitively called in a TypeGPU pipeline.
266266
Otherwise, for example when using `tgpu.resolve` on a WGSL template, logs are ignored.
267267
- `console.log` only works in fragment and compute shaders.
268268
This is due to a [WebGPU limitation](https://www.w3.org/TR/WGSL/#address-space) that does not allow modifying buffers during the vertex shader stage.

apps/typegpu-docs/src/content/docs/integration/react-native/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ npm i --save-dev @webgpu/types
5959
}
6060
```
6161

62-
If you want to be able to use the TGSL functions feature of TypeGPU (JS functions transpiled to WGSL), you need to install the [unplugin-typegpu](https://www.npmjs.com/package/unplugin-typegpu) package.
62+
If you want to be able to implement TypeGPU functions in JavaScript/TypeScript, you need to install the [unplugin-typegpu](https://www.npmjs.com/package/unplugin-typegpu) package.
6363

6464
```sh
6565
npm install --save-dev unplugin-typegpu

apps/typegpu-docs/src/examples/rendering/xor-dev-runner/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This is a port of XorDev's "Runner" example using TypeGPU. Most of the shader is
3-
* written in TGSL (TypeScript + Standard Library), but parts of it are implemented
4-
* in WGSL to showcase the flexibility of TypeGPU.
3+
* written in TypeScript, but parts of it are implemented in WGSL to showcase the
4+
* flexibility of TypeGPU.
55
*
66
* ## Credits
77
* XorDev (xordev.com) for the idea and original implementation

0 commit comments

Comments
 (0)