Skip to content

Commit 2736431

Browse files
authored
feat: Stabilize samplers and textures (#2347)
1 parent ea5b2db commit 2736431

46 files changed

Lines changed: 148 additions & 117 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.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ import tgpu, { d, std } from 'typegpu';
308308

309309
const root = await tgpu.init();
310310
// ---cut---
311-
const texture = root['~unstable']
311+
const texture = root
312312
.createTexture({ format: 'rgba8unorm', size: [100, 100] })
313313
.$usage('storage');
314314

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Texture schemas serve two main purposes:
364364
import tgpu, { d, std } from 'typegpu';
365365

366366
const root = await tgpu.init();
367-
const texture = root['~unstable'].createTexture({
367+
const texture = root.createTexture({
368368
size: [256, 256],
369369
format: 'rgba8unorm',
370370
}).$usage('sampled', 'storage');

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import tgpu, { d } from 'typegpu';
2121

2222
const root = await tgpu.init();
2323

24-
const texture = root['~unstable'].createTexture({
24+
const texture = root.createTexture({
2525
size: [256, 256],
2626
format: 'rgba8unorm' as const,
2727
}).$usage('sampled');
@@ -40,7 +40,7 @@ const sampledView = texture.createView();
4040

4141
## Creating a texture
4242

43-
Textures can be created using the `root['~unstable'].createTexture` method. It accepts a descriptor similar to vanilla `GPUTextureDescriptor`. If specified, the properties will be reflected in the created texture type - this will later help with static checks when creating views or binding the texture in a layout.
43+
Textures can be created using the `root.createTexture` method. It accepts a descriptor similar to vanilla `GPUTextureDescriptor`. If specified, the properties will be reflected in the created texture type - this will later help with static checks when creating views or binding the texture in a layout.
4444

4545
```ts
4646
type TextureProps = {
@@ -57,7 +57,7 @@ type TextureProps = {
5757
import tgpu from 'typegpu';
5858
const root = await tgpu.init();
5959
// ---cut---
60-
const texture = root['~unstable'].createTexture({
60+
const texture = root.createTexture({
6161
// ^?
6262
size: [512, 512, 128],
6363
format: 'rgba8unorm',
@@ -74,7 +74,7 @@ Similar to buffers, textures need usage flags to specify how they will be used.
7474
import tgpu from 'typegpu';
7575
const root = await tgpu.init();
7676
// ---cut---
77-
const texture = root['~unstable'].createTexture({
77+
const texture = root.createTexture({
7878
size: [256, 256],
7979
format: 'rgba8unorm',
8080
})
@@ -89,7 +89,7 @@ You can also add multiple flags at once:
8989
import tgpu from 'typegpu';
9090
const root = await tgpu.init();
9191
// ---cut---
92-
const texture = root['~unstable'].createTexture({
92+
const texture = root.createTexture({
9393
size: [256, 256],
9494
format: 'rgba8unorm',
9595
}).$usage('sampled', 'storage', 'render');
@@ -122,7 +122,7 @@ You can write various image sources to textures. `ExternalImageSource` includes:
122122
import tgpu from 'typegpu';
123123
const root = await tgpu.init();
124124
// ---cut---
125-
const texture = root['~unstable'].createTexture({
125+
const texture = root.createTexture({
126126
size: [256, 256],
127127
format: 'rgba8unorm',
128128
}).$usage('sampled');
@@ -155,7 +155,7 @@ declare const imageBitmap1: ImageBitmap;
155155
declare const imageBitmap2: ImageBitmap;
156156
declare const imageBitmap3: ImageBitmap;
157157
// ---cut---
158-
const texture3d = root['~unstable'].createTexture({
158+
const texture3d = root.createTexture({
159159
size: [256, 256, 3],
160160
format: 'rgba8unorm',
161161
dimension: '3d',
@@ -173,7 +173,7 @@ You can write raw binary data directly to textures using `ArrayBuffer`, typed ar
173173
import tgpu from 'typegpu';
174174
const root = await tgpu.init();
175175
// ---cut---
176-
const texture = root['~unstable'].createTexture({
176+
const texture = root.createTexture({
177177
size: [2, 2],
178178
format: 'rgba8unorm',
179179
}).$usage('sampled');
@@ -198,12 +198,12 @@ You can also copy from another texture:
198198
import tgpu from 'typegpu';
199199
const root = await tgpu.init();
200200
// ---cut---
201-
const sourceTexture = root['~unstable'].createTexture({
201+
const sourceTexture = root.createTexture({
202202
size: [256, 256],
203203
format: 'rgba8unorm',
204204
}).$usage('sampled');
205205

206-
const targetTexture = root['~unstable'].createTexture({
206+
const targetTexture = root.createTexture({
207207
size: [256, 256],
208208
format: 'rgba8unorm',
209209
}).$usage('sampled');
@@ -220,7 +220,7 @@ import tgpu from 'typegpu';
220220
const root = await tgpu.init();
221221
declare const imageBitmap: ImageBitmap;
222222
// ---cut---
223-
const texture = root['~unstable'].createTexture({
223+
const texture = root.createTexture({
224224
size: [256, 256],
225225
format: 'rgba8unorm',
226226
mipLevelCount: 9, // log2(256) + 1
@@ -242,7 +242,7 @@ To create a view - which will also serve as fixed texture usage - you can use on
242242
import tgpu, { d } from 'typegpu';
243243
const root = await tgpu.init();
244244
// ---cut---
245-
const texture = root['~unstable'].createTexture({
245+
const texture = root.createTexture({
246246
size: [512, 512],
247247
format: 'rgba8unorm',
248248
}).$usage('sampled');
@@ -260,7 +260,7 @@ If type information is available the view schema will be staticly checked agains
260260
import tgpu, { d } from 'typegpu';
261261
const root = await tgpu.init();
262262
// ---cut---
263-
const texture = root['~unstable'].createTexture({
263+
const texture = root.createTexture({
264264
size: [512, 512],
265265
format: 'rgba8unorm',
266266
}); // <-- missing .$usage('sampled')
@@ -273,7 +273,7 @@ const sampledView = texture.createView(d.texture2d(d.f32));
273273
import tgpu, { d } from 'typegpu';
274274
const root = await tgpu.init();
275275
// ---cut---
276-
const texture = root['~unstable'].createTexture({
276+
const texture = root.createTexture({
277277
size: [512, 512],
278278
format: 'r32float',
279279
}).$usage('storage');
@@ -291,7 +291,7 @@ To sample textures in shaders, you'll often need a sampler that defines how the
291291
import tgpu from 'typegpu';
292292
const root = await tgpu.init();
293293
// ---cut---
294-
const sampler = root['~unstable'].createSampler({
294+
const sampler = root.createSampler({
295295
magFilter: 'linear',
296296
minFilter: 'linear',
297297
mipmapFilter: 'linear',
@@ -312,12 +312,12 @@ Textures can be used in shaders through bind groups or as fixed resources, simil
312312
import tgpu, { d } from 'typegpu';
313313
const root = await tgpu.init();
314314
// ---cut---
315-
const texture = root['~unstable'].createTexture({
315+
const texture = root.createTexture({
316316
size: [256, 256],
317317
format: 'rgba8unorm',
318318
}).$usage('sampled');
319319

320-
const sampler = root['~unstable'].createSampler({
320+
const sampler = root.createSampler({
321321
magFilter: 'linear',
322322
minFilter: 'linear',
323323
});
@@ -343,15 +343,15 @@ For textures that remain consistent across operations, you can create fixed text
343343
import tgpu, { d, std } from 'typegpu';
344344
const root = await tgpu.init();
345345
// ---cut---
346-
const texture = root['~unstable'].createTexture({
346+
const texture = root.createTexture({
347347
size: [256, 256],
348348
format: 'rgba8unorm',
349349
}).$usage('sampled');
350350

351351
// Create a fixed sampled view
352352
const sampledView = texture.createView();
353353

354-
const sampler = root['~unstable'].createSampler({
354+
const sampler = root.createSampler({
355355
magFilter: 'linear',
356356
minFilter: 'linear',
357357
});

apps/typegpu-docs/src/examples/algorithms/genetic-racing/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const params = root.createUniform(SimParams, {
5151

5252
const ga = createGeneticPopulation(root, params);
5353

54-
const trackTexture = root['~unstable']
54+
const trackTexture = root
5555
.createTexture({ size: [512, 512], format: 'rgba8unorm' })
5656
.$usage('render', 'sampled');
5757
const trackView = trackTexture.createView();
@@ -60,7 +60,7 @@ const carBitmap = await fetch('/TypeGPU/assets/genetic-car/car.png')
6060
.then((r) => r.blob())
6161
.then(createImageBitmap);
6262

63-
const carSpriteTexture = root['~unstable']
63+
const carSpriteTexture = root
6464
.createTexture({
6565
size: [carBitmap.width / 2, carBitmap.height / 2],
6666
format: 'rgba8unorm',
@@ -69,11 +69,11 @@ const carSpriteTexture = root['~unstable']
6969
carSpriteTexture.write(carBitmap);
7070
const carSpriteView = carSpriteTexture.createView();
7171

72-
const linearSampler = root['~unstable'].createSampler({
72+
const linearSampler = root.createSampler({
7373
magFilter: 'linear',
7474
minFilter: 'linear',
7575
});
76-
const nearestSampler = root['~unstable'].createSampler({
76+
const nearestSampler = root.createSampler({
7777
magFilter: 'nearest',
7878
minFilter: 'nearest',
7979
});

apps/typegpu-docs/src/examples/algorithms/jump-flood-distance/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,29 @@ const paramsUniform = root.createUniform(VisualizationParams, {
4949
showOutside: 1,
5050
});
5151

52-
const filteringSampler = root['~unstable'].createSampler({
52+
const filteringSampler = root.createSampler({
5353
magFilter: 'linear',
5454
minFilter: 'linear',
5555
});
5656

5757
function createResources() {
5858
const textures = [0, 1].map(() =>
59-
root['~unstable']
59+
root
6060
.createTexture({
6161
size: [width, height],
6262
format: 'rgba16float',
6363
})
6464
.$usage('storage'),
6565
) as [FloodTexture, FloodTexture];
6666

67-
const maskTexture = root['~unstable']
67+
const maskTexture = root
6868
.createTexture({
6969
size: [width, height],
7070
format: 'r32uint',
7171
})
7272
.$usage('storage') as MaskTexture;
7373

74-
const distanceTexture = root['~unstable']
74+
const distanceTexture = root
7575
.createTexture({
7676
size: [width, height],
7777
format: 'rgba16float',

apps/typegpu-docs/src/examples/algorithms/jump-flood-voronoi/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ type FloodTexture = TgpuTexture<{ size: [number, number, 2]; format: 'rgba16floa
5555
SampledFlag &
5656
StorageFlag;
5757

58-
const filteringSampler = root['~unstable'].createSampler({
58+
const filteringSampler = root.createSampler({
5959
magFilter: 'linear',
6060
minFilter: 'linear',
6161
});
6262

6363
function createResources() {
6464
const textures = [0, 1].map(() =>
65-
root['~unstable']
65+
root
6666
.createTexture({
6767
size: [canvas.width, canvas.height, 2],
6868
format: 'rgba16float',

apps/typegpu-docs/src/examples/image-processing/ascii-filter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const gammaCorrection = root.createUniform(d.f32);
1313
const glyphSize = root.createUniform(d.u32, 8);
1414
const uvTransformBuffer = root.createUniform(d.mat2x2f, d.mat2x2f.identity());
1515

16-
const shaderSampler = root['~unstable'].createSampler({
16+
const shaderSampler = root.createSampler({
1717
magFilter: 'linear',
1818
minFilter: 'linear',
1919
});

apps/typegpu-docs/src/examples/image-processing/background-segmentation/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ const paramsUniform = root.createUniform(Params, {
7070
sampleBias: blurStrength,
7171
});
7272

73-
const sampler = root['~unstable'].createSampler({
73+
const sampler = root.createSampler({
7474
magFilter: 'linear',
7575
minFilter: 'linear',
7676
mipmapFilter: 'linear',
7777
});
7878

79-
const maskTexture = root['~unstable']
79+
const maskTexture = root
8080
.createTexture({
8181
size: [MODEL_WIDTH, MODEL_HEIGHT],
8282
format: 'rgba8unorm',
@@ -214,7 +214,7 @@ function onVideoChange(size: { width: number; height: number }) {
214214
updateCropBounds(aspectRatio);
215215

216216
blurredTextures = [0, 1].map(() =>
217-
root['~unstable']
217+
root
218218
.createTexture({
219219
size: [size.width, size.height],
220220
format: 'rgba8unorm',

apps/typegpu-docs/src/examples/image-processing/blur/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const Settings = d.struct({
2727

2828
const settingsUniform = root.createUniform(Settings);
2929

30-
const imageTexture = root['~unstable']
30+
const imageTexture = root
3131
.createTexture({
3232
size: [srcWidth, srcHeight],
3333
format: 'rgba8unorm',
@@ -36,7 +36,7 @@ const imageTexture = root['~unstable']
3636
imageTexture.write(imageBitmap);
3737

3838
const textures = [0, 1].map(() => {
39-
return root['~unstable']
39+
return root
4040
.createTexture({
4141
size: [srcWidth, srcHeight],
4242
format: 'rgba8unorm',
@@ -45,7 +45,7 @@ const textures = [0, 1].map(() => {
4545
});
4646
const renderView = textures[1].createView(d.texture2d(d.f32));
4747

48-
const sampler = root['~unstable'].createSampler({
48+
const sampler = root.createSampler({
4949
magFilter: 'linear',
5050
minFilter: 'linear',
5151
});

apps/typegpu-docs/src/examples/image-processing/camera-thresholding/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const thresholdBuffer = root.createUniform(d.f32, 0.5);
5353
const colorUniform = root.createUniform(d.vec3f, d.vec3f(0, 1.0, 0));
5454
const uvTransformUniform = root.createUniform(d.mat2x2f, d.mat2x2f.identity());
5555

56-
const sampler = root['~unstable'].createSampler({
56+
const sampler = root.createSampler({
5757
magFilter: 'linear',
5858
minFilter: 'linear',
5959
});

0 commit comments

Comments
 (0)