Skip to content

Commit 12b2d38

Browse files
authored
docs: TypeGPU functions (#1793)
1 parent 0b9952b commit 12b2d38

File tree

7 files changed

+461
-303
lines changed

7 files changed

+461
-303
lines changed

apps/typegpu-docs/astro.config.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ export default defineConfig({
131131
label: 'Functions',
132132
slug: 'fundamentals/functions',
133133
},
134-
{
135-
label: 'TGSL',
136-
slug: 'fundamentals/tgsl',
137-
badge: { text: 'new' },
138-
},
139134
{
140135
label: 'Pipelines',
141136
slug: 'fundamentals/pipelines',

apps/typegpu-docs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
"remeda": "^2.21.2",
5151
"sharp": "^0.34.2",
5252
"starlight-blog": "^0.23.2",
53-
"starlight-typedoc": "^0.21.4",
53+
"starlight-typedoc": "^0.19.0",
5454
"tinybench": "^3.1.0",
55-
"typedoc": "^0.28.13",
56-
"typedoc-plugin-markdown": "^4.3.0",
55+
"typedoc": "^0.27.9",
56+
"typedoc-plugin-markdown": "4.3.0",
5757
"typegpu": "workspace:*",
5858
"typescript": "catalog:types",
5959
"unplugin-typegpu": "workspace:*",

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

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Since the buffer is already created, you are responsible for the buffer's lifecy
195195

196196
## Writing to a buffer
197197

198-
To write data to a buffer, you can use the `.write(value)` method. The typed schema enables auto-complete as well as static validation of this
198+
To write data to a buffer from the CPU, you can use the `.write(value)` method. The typed schema enables auto-complete as well as static validation of this
199199
method's arguments.
200200

201201
```ts twoslash
@@ -285,7 +285,7 @@ backupParticleBuffer.copyFrom(particleBuffer);
285285

286286
## Reading from a buffer
287287

288-
To read data from a buffer, you can use the `.read()` method.
288+
To read data from a buffer on the CPU, you can use the `.read()` method.
289289
It returns a promise that resolves to the data read from the buffer.
290290

291291
```ts twoslash
@@ -348,32 +348,25 @@ import * as d from 'typegpu/data';
348348

349349
const root = await tgpu.init();
350350
// ---cut---
351-
const pointsBuffer = root
352-
.createBuffer(d.arrayOf(d.vec2i, 100))
353-
.$usage('storage');
354-
355-
const bindGroupLayout = tgpu.bindGroupLayout({
356-
points: { storage: d.arrayOf(d.vec2i, 100), access: 'mutable' },
351+
const layout = tgpu.bindGroupLayout({
352+
points: { storage: d.arrayOf(d.vec2i), access: 'mutable' },
357353
});
358354

359-
const bindGroup = root
360-
.createBindGroup(bindGroupLayout, { points: pointsBuffer });
361-
362-
const mainCompute = tgpu['~unstable'].computeFn({
363-
in: { gid: d.builtin.globalInvocationId },
364-
workgroupSize: [1],
365-
})((input) => {
355+
const pipeline = root['~unstable'].createGuardedComputePipeline((x) => {
356+
'use gpu';
366357
// Access and modify the bound buffer via the layout
367-
bindGroupLayout.$.points[input.gid[0]] = d.vec2i(1, 2);
358+
layout.$.points[x] = d.vec2i(1, 2);
368359
});
369360

370-
const pipeline = root['~unstable']
371-
.withCompute(mainCompute)
372-
.createPipeline();
361+
const pointsBuffer = root
362+
.createBuffer(d.arrayOf(d.vec2i, 100))
363+
.$usage('storage');
364+
365+
const bindGroup = root.createBindGroup(layout, {
366+
points: pointsBuffer
367+
});
373368

374-
pipeline
375-
.with(bindGroupLayout, bindGroup)
376-
.dispatchWorkgroups(100);
369+
pipeline.with(bindGroup).dispatchThreads(100);
377370
```
378371

379372
### Using fixed resources
@@ -394,18 +387,15 @@ import * as d from 'typegpu/data';
394387

395388
const root = await tgpu.init();
396389
// ---cut---
397-
const pointsBuffer = root.createMutable(d.arrayOf(d.vec2i, 100));
390+
const pointsMutable = root.createMutable(d.arrayOf(d.vec2i, 100));
398391

399-
const mainCompute = tgpu['~unstable'].computeFn({
400-
in: { gid: d.builtin.globalInvocationId },
401-
workgroupSize: [1],
402-
})((input) => {
392+
const pipeline = root['~unstable'].createGuardedComputePipeline((x) => {
393+
'use gpu';
403394
// Access and modify the fixed buffer directly
404-
pointsBuffer.$[input.gid[0]] = d.vec2i();
395+
pointsMutable.$[x] = d.vec2i();
405396
});
406397

407-
const pipeline = root['~unstable'].withCompute(mainCompute).createPipeline();
408-
pipeline.dispatchWorkgroups(100);
398+
pipeline.dispatchThreads(100);
409399
```
410400

411401
TypeGPU automatically generates a "catch-all" bind group and populates it with the fixed resources.

0 commit comments

Comments
 (0)