Skip to content

Commit a690382

Browse files
authored
feat: Stabilize pipelines and entry functions (#2168)
1 parent b749bd9 commit a690382

123 files changed

Lines changed: 981 additions & 986 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ const wgsl = tgpu.resolve([main]);
3737
//
3838
// #3) Executed on the GPU (generates WGSL underneath)
3939
//
40-
root['~unstable']
41-
.createGuardedComputePipeline(main)
42-
.dispatchThreads();
40+
root.createGuardedComputePipeline(main).dispatchThreads();
4341
```
4442

4543
<div align="center">

apps/typegpu-docs/src/content/docs/ecosystem/typegpu-noise.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ using a set of `randf.seedN` functions, where `N` is the number of components ou
8484
import tgpu, { d } from 'typegpu';
8585
import { randf } from '@typegpu/noise';
8686

87-
const main = tgpu['~unstable'].fragmentFn({
87+
const main = tgpu.fragmentFn({
8888
in: { pos: d.builtin.position },
8989
out: d.vec4f,
9090
})(({ pos }) => {
@@ -148,7 +148,7 @@ import tgpu, { d } from 'typegpu';
148148
// ---cut---
149149
import { perlin2d } from '@typegpu/noise';
150150

151-
const main = tgpu['~unstable'].fragmentFn({
151+
const main = tgpu.fragmentFn({
152152
in: { pos: d.builtin.position },
153153
out: d.vec4f,
154154
})(({ pos }) => {
@@ -169,15 +169,15 @@ import tgpu, { d } from 'typegpu';
169169
const root = await tgpu.init();
170170
import { perlin3d } from '@typegpu/noise';
171171

172-
const main = tgpu['~unstable'].computeFn({ workgroupSize: [1] })(() => {
172+
const main = tgpu.computeFn({ workgroupSize: [1] })(() => {
173173
const value = perlin3d.sample(d.vec3f(0.5, 0, 0));
174174
const wrappedValue = perlin3d.sample(d.vec3f(10.5, 0, 0)); // the same as `value`!
175175
});
176176

177177
// ---cut---
178178
const cache = perlin3d.staticCache({ root, size: d.vec3u(10, 10, 1) });
179179

180-
const pipeline = root['~unstable']
180+
const pipeline = root
181181
// Plugging the cache into the pipeline
182182
.pipe(cache.inject())
183183
// ...
@@ -224,7 +224,7 @@ complex setup.
224224
import tgpu, { d } from 'typegpu';
225225
import { perlin3d } from '@typegpu/noise';
226226

227-
const main = tgpu['~unstable'].computeFn({ workgroupSize: [1] })(() => {
227+
const main = tgpu.computeFn({ workgroupSize: [1] })(() => {
228228
const value = perlin3d.sample(d.vec3f(0.5, 0, 0));
229229
const wrappedValue = perlin3d.sample(d.vec3f(10.5, 0, 0)); // the same as `value`!
230230
});
@@ -235,7 +235,7 @@ const cacheConfig = perlin3d.dynamicCacheConfig();
235235
// Holds all resources the perlin cache needs access to
236236
const dynamicLayout = tgpu.bindGroupLayout({ ...cacheConfig.layout });
237237

238-
const pipeline = root['~unstable']
238+
const pipeline = root
239239
// Plugging the cache into the pipeline
240240
.pipe(cacheConfig.inject(dynamicLayout.$))
241241
// ...
@@ -272,7 +272,7 @@ import { randf } from '@typegpu/noise';
272272
const root = await tgpu.init();
273273

274274
const b = root.createMutable(d.f32);
275-
const f = tgpu['~unstable'].computeFn({ workgroupSize: [1] })(() => {
275+
const f = tgpu.computeFn({ workgroupSize: [1] })(() => {
276276
b.$ = randf.sample();
277277
});
278278
// ---cut---
@@ -304,8 +304,7 @@ const LCG: StatefulGenerator = (() => {
304304
};
305305
})();
306306

307-
const pipeline = root['~unstable']
307+
const pipeline = root
308308
.with(randomGeneratorSlot, LCG)
309-
.withCompute(f)
310-
.createPipeline();
309+
.createComputePipeline({ compute: f });
311310
```

apps/typegpu-docs/src/content/docs/ecosystem/typegpu-sdf.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Here is an example of a fragment shader that draws a disk of radius 0.25 on the
2525
import tgpu, { d } from 'typegpu';
2626
import * as sdf from '@typegpu/sdf';
2727

28-
const mainFragment = tgpu['~unstable'].fragmentFn({
28+
const mainFragment = tgpu.fragmentFn({
2929
in: { uv: d.vec2f },
3030
out: d.vec4f,
3131
})(({ uv }) => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ const layout = tgpu.bindGroupLayout({
338338
points: { storage: d.arrayOf(d.vec2i), access: 'mutable' },
339339
});
340340

341-
const pipeline = root['~unstable'].createGuardedComputePipeline((x) => {
341+
const pipeline = root.createGuardedComputePipeline((x) => {
342342
'use gpu';
343343
// Access and modify the bound buffer via the layout
344344
layout.$.points[x] = d.vec2i(1, 2);
@@ -374,7 +374,7 @@ const root = await tgpu.init();
374374
// ---cut---
375375
const pointsMutable = root.createMutable(d.arrayOf(d.vec2i, 100));
376376

377-
const pipeline = root['~unstable'].createGuardedComputePipeline((x) => {
377+
const pipeline = root.createGuardedComputePipeline((x) => {
378378
'use gpu';
379379
// Access and modify the fixed buffer directly
380380
pointsMutable.$[x] = d.vec2i();

apps/typegpu-docs/src/content/docs/fundamentals/enabling-features.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const root = await tgpu.init({
3131
},
3232
// …other TypeGPU options…
3333
});
34-
````
34+
```
3535

3636
* **`requiredFeatures: GPUFeatureName[]`**
3737
All listed features must be supported by the GPU; otherwise `requestDevice()` rejects.

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ const wgsl = tgpu.resolve([main]);
6363
// ^?
6464

6565
// #3) Executed on the GPU (generates WGSL underneath)
66-
root['~unstable']
67-
.createGuardedComputePipeline(main)
68-
.dispatchThreads();
69-
````
66+
root.createGuardedComputePipeline(main).dispatchThreads();
67+
```
7068

7169
The contents of the `wgsl` variable would contain the following:
7270

@@ -81,7 +79,7 @@ fn main() -> vec2f {
8179
}
8280
8381
// ...
84-
````
82+
```
8583

8684
You can already notice a few things about TypeGPU functions:
8785
- Using operators like `+`, `-`, `*`, `/`, etc. is perfectly valid on numbers.
@@ -257,7 +255,7 @@ const settings = {
257255
speed: 1,
258256
};
259257

260-
const pipeline = root['~unstable'].createGuardedComputePipeline(() => {
258+
const pipeline = root.createGuardedComputePipeline(() => {
261259
'use gpu';
262260
const speed = settings.speed;
263261
// ^ generates: var speed = 1;
@@ -456,9 +454,9 @@ Entry functions are an *unstable* feature. The API may be subject to change in t
456454

457455
Instead of annotating a `TgpuFn` with attributes, entry functions are defined using dedicated shell constructors:
458456

459-
- `tgpu['~unstable'].computeFn`,
460-
- `tgpu['~unstable'].vertexFn`,
461-
- `tgpu['~unstable'].fragmentFn`.
457+
- `tgpu.computeFn`,
458+
- `tgpu.vertexFn`,
459+
- `tgpu.fragmentFn`.
462460

463461
### Entry point function I/O
464462

@@ -510,7 +508,7 @@ const deltaTime = root.createUniform(d.f32);
510508
const time = root.createMutable(d.f32);
511509
const particleDataStorage = particleDataBuffer.as('mutable');
512510
// ---cut---
513-
const mainCompute = tgpu['~unstable'].computeFn({
511+
const mainCompute = tgpu.computeFn({
514512
in: { gid: d.builtin.globalInvocationId },
515513
workgroupSize: [1],
516514
}) /* wgsl */`{
@@ -561,7 +559,7 @@ import tgpu, { d } from 'typegpu';
561559

562560
const getGradientColor = tgpu.fn([d.f32], d.vec4f)``;
563561
// ---cut---
564-
const mainVertex = tgpu['~unstable'].vertexFn({
562+
const mainVertex = tgpu.vertexFn({
565563
in: { vertexIndex: d.builtin.vertexIndex },
566564
out: { outPos: d.builtin.position, uv: d.vec2f },
567565
}) /* wgsl */`{
@@ -580,7 +578,7 @@ const mainVertex = tgpu['~unstable'].vertexFn({
580578
return Out(vec4f(pos[in.vertexIndex], 0.0, 1.0), uv[in.vertexIndex]);
581579
}`;
582580

583-
const mainFragment = tgpu['~unstable'].fragmentFn({
581+
const mainFragment = tgpu.fragmentFn({
584582
in: { uv: d.vec2f },
585583
out: d.vec4f,
586584
}) /* wgsl */`{
@@ -646,17 +644,17 @@ const root = await tgpu.init();
646644

647645
const getGradientColor = tgpu.fn([d.f32], d.vec4f)/* wgsl */``;
648646

649-
const mainVertex = tgpu['~unstable'].vertexFn({
647+
const mainVertex = tgpu.vertexFn({
650648
in: { vertexIndex: d.builtin.vertexIndex },
651649
out: { outPos: d.builtin.position, uv: d.vec2f },
652650
})``;
653651

654-
const mainFragment = tgpu['~unstable'].fragmentFn({
652+
const mainFragment = tgpu.fragmentFn({
655653
in: { uv: d.vec2f },
656654
out: d.vec4f,
657655
})``;
658656
// ---cut---
659-
const pipeline = root['~unstable'].createRenderPipeline({
657+
const pipeline = root.createRenderPipeline({
660658
vertex: mainVertex,
661659
fragment: mainFragment,
662660
targets: { format: presentationFormat },

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

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const root = await tgpu.init();
3131

3232
const presentationFormat = 'rgba8unorm';
3333

34-
const mainVertex = tgpu['~unstable'].vertexFn({
34+
const mainVertex = tgpu.vertexFn({
3535
in: { vertexIndex: d.builtin.vertexIndex },
3636
out: { pos: d.builtin.position },
3737
})((input) => {
@@ -42,27 +42,25 @@ const mainVertex = tgpu['~unstable'].vertexFn({
4242
};
4343
});
4444

45-
const mainFragment = tgpu['~unstable']
46-
.fragmentFn({ out: d.vec4f })(() => d.vec4f(1, 0, 0, 1));
45+
const mainFragment = tgpu.fragmentFn({ out: d.vec4f })(() => d.vec4f(1, 0, 0, 1));
4746

48-
const mainCompute = tgpu['~unstable'].computeFn({ workgroupSize: [1] })(() => {});
47+
const mainCompute = tgpu.computeFn({ workgroupSize: [1] })(() => {});
4948

5049
// ---cut---
51-
const renderPipeline = root['~unstable'].createRenderPipeline({
50+
const renderPipeline = root.createRenderPipeline({
5251
vertex: mainVertex,
5352
fragment: mainFragment,
5453
targets: { format: presentationFormat },
5554
});
5655

57-
const computePipeline1 = root['~unstable'].createComputePipeline({
56+
const computePipeline1 = root.createComputePipeline({
5857
compute: mainCompute,
5958
});
6059

61-
const computePipeline2 = root['~unstable']
62-
.createGuardedComputePipeline((x, y, z) => {
63-
'use gpu';
64-
// ...
65-
});
60+
const computePipeline2 = root.createGuardedComputePipeline((x, y, z) => {
61+
'use gpu';
62+
// ...
63+
});
6664
```
6765

6866
### createRenderPipeline
@@ -84,7 +82,7 @@ import tgpu, { d } from 'typegpu';
8482
const root = await tgpu.init();
8583
const presentationFormat = 'rgba8unorm';
8684

87-
const mainVertex = tgpu['~unstable'].vertexFn({
85+
const mainVertex = tgpu.vertexFn({
8886
in: { vertexIndex: d.builtin.vertexIndex, pos: d.vec2f },
8987
out: { pos: d.builtin.position },
9088
})((input) => {
@@ -95,12 +93,11 @@ const mainVertex = tgpu['~unstable'].vertexFn({
9593
};
9694
});
9795

98-
const mainFragment = tgpu['~unstable']
99-
.fragmentFn({ out: d.vec4f })(() => d.vec4f(1, 0, 0, 1));
96+
const mainFragment = tgpu.fragmentFn({ out: d.vec4f })(() => d.vec4f(1, 0, 0, 1));
10097
// ---cut---
10198
const vertexLayout = tgpu.vertexLayout(d.arrayOf(d.vec2f));
10299

103-
const renderPipeline = root['~unstable'].createRenderPipeline({
100+
const renderPipeline = root.createRenderPipeline({
104101
attribs: { pos: vertexLayout.attrib },
105102
vertex: mainVertex,
106103
fragment: mainFragment,
@@ -132,18 +129,18 @@ as long as there is no conflict between vertex and fragment location values.
132129
```ts twoslash
133130
import tgpu, { d } from 'typegpu';
134131

135-
const vertex = tgpu['~unstable'].vertexFn({
132+
const vertex = tgpu.vertexFn({
136133
out: { pos: d.builtin.position },
137134
})`(...)`;
138-
const fragment = tgpu['~unstable'].fragmentFn({
135+
const fragment = tgpu.fragmentFn({
139136
in: { uv: d.vec2f },
140137
out: d.vec4f,
141138
})`(...)`;
142139

143140
const root = await tgpu.init();
144141

145142
// @errors: 2769
146-
root['~unstable'].createRenderPipeline({
143+
root.createRenderPipeline({
147144
vertex,
148145
fragment,
149146
targets: { format: 'bgra8unorm' },
@@ -163,10 +160,10 @@ import tgpu, { d } from 'typegpu';
163160

164161
const root = await tgpu.init();
165162

166-
const mainCompute = tgpu['~unstable'].computeFn({ workgroupSize: [1] })(() => {});
163+
const mainCompute = tgpu.computeFn({ workgroupSize: [1] })(() => {});
167164

168165
// ---cut---
169-
const computePipeline = root['~unstable'].createComputePipeline({
166+
const computePipeline = root.createComputePipeline({
170167
compute: mainCompute,
171168
});
172169
```
@@ -188,11 +185,10 @@ const root = await tgpu.init();
188185
// ---cut---
189186
const data = root.createMutable(d.arrayOf(d.u32, 8), [0, 1, 2, 3, 4, 5, 6, 7]);
190187

191-
const doubleUpPipeline = root['~unstable']
192-
.createGuardedComputePipeline((x) => {
193-
'use gpu';
194-
data.$[x] *= 2;
195-
});
188+
const doubleUpPipeline = root.createGuardedComputePipeline((x) => {
189+
'use gpu';
190+
data.$[x] *= 2;
191+
});
196192

197193
doubleUpPipeline.dispatchThreads(8);
198194
doubleUpPipeline.dispatchThreads(8);
@@ -229,7 +225,7 @@ const waterLevelMutable = root.createMutable(
229225
d.arrayOf(d.arrayOf(d.f32, 512), 1024),
230226
);
231227

232-
root['~unstable'].createGuardedComputePipeline((x, y) => {
228+
root.createGuardedComputePipeline((x, y) => {
233229
'use gpu';
234230
randf.seed2(d.vec2f(x, y).div(1024));
235231
waterLevelMutable.$[x][y] = 10 + randf.sample();
@@ -368,7 +364,7 @@ const colorBuffer = root
368364
])
369365
.$usage('vertex');
370366

371-
const vertex = tgpu['~unstable'].vertexFn({
367+
const vertex = tgpu.vertexFn({
372368
in: {
373369
idx: d.builtin.vertexIndex,
374370
color: d.vec4f,
@@ -385,7 +381,7 @@ const vertex = tgpu['~unstable'].vertexFn({
385381
});
386382

387383
const vertexLayout = tgpu.vertexLayout(d.arrayOf(d.vec4f));
388-
const mainFragment = tgpu['~unstable'].fragmentFn({
384+
const mainFragment = tgpu.fragmentFn({
389385
in: {
390386
color: d.vec4f,
391387
},
@@ -396,7 +392,7 @@ const indexBuffer = root
396392
.createBuffer(d.arrayOf(d.u16, 6), [0, 2, 1, 0, 3, 2])
397393
.$usage('index');
398394

399-
const pipeline = root['~unstable']
395+
const pipeline = root
400396
.createRenderPipeline({
401397
attribs: { color: vertexLayout.attrib },
402398
vertex,
@@ -440,11 +436,11 @@ import tgpu, { d } from 'typegpu';
440436

441437
const root = await tgpu.init();
442438

443-
const mainVertex = tgpu['~unstable'].vertexFn({ out: { pos: d.builtin.position } })`...`;
444-
const mainFragment = tgpu['~unstable'].fragmentFn({ out: d.vec4f })`...`;
439+
const mainVertex = tgpu.vertexFn({ out: { pos: d.builtin.position } })`...`;
440+
const mainFragment = tgpu.fragmentFn({ out: d.vec4f })`...`;
445441

446442
// ---cut---
447-
const pipeline = root['~unstable'].createRenderPipeline({
443+
const pipeline = root.createRenderPipeline({
448444
vertex: mainVertex,
449445
fragment: mainFragment,
450446
targets: { format: 'rg8unorm' },

0 commit comments

Comments
 (0)