Skip to content

Commit 3ba2356

Browse files
authored
feat: Defaults for targets in .createRenderPipeline and .withColorAttachments (#2196)
1 parent 519c658 commit 3ba2356

60 files changed

Lines changed: 247 additions & 500 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/functions/index.mdx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,10 @@ const mainFragment = tgpu.fragmentFn({
657657
const pipeline = root.createRenderPipeline({
658658
vertex: mainVertex,
659659
fragment: mainFragment,
660-
targets: { format: presentationFormat },
661660
});
662661

663662
pipeline
664-
.withColorAttachment({
665-
view: context.getCurrentTexture().createView(),
666-
clearValue: [0, 0, 0, 0],
667-
loadOp: 'clear',
668-
storeOp: 'store',
669-
})
663+
.withColorAttachment({ view: context })
670664
.draw(3);
671665
```
672666

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,7 @@ tgpu.resolve([innerPipeline]);
250250

251251
```ts
252252
renderPipeline
253-
.withColorAttachment({
254-
view: context.getCurrentTexture().createView(),
255-
loadOp: 'clear',
256-
storeOp: 'store',
257-
})
253+
.withColorAttachment({ view: context })
258254
.draw(3);
259255

260256
computePipeline.dispatchWorkgroups(16);
@@ -274,7 +270,7 @@ renderPipeline
274270
.withColorAttachment({
275271
color: {
276272
view: msaaTextureView,
277-
resolveTarget: context.getCurrentTexture().createView(),
273+
resolveTarget: context,
278274
loadOp: 'clear',
279275
storeOp: 'store',
280276
},

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,10 @@ export function Triangle() {
156156
'use gpu';
157157
return d.vec4f(0.114, 0.447, 0.941, 1);
158158
},
159-
targets: { format: presentationFormat },
160159
});
161160

162161
pipeline
163-
.withColorAttachment({
164-
view: context.getCurrentTexture().createView(),
165-
clearValue: [0, 0, 0, 0],
166-
loadOp: 'clear',
167-
storeOp: 'store',
168-
})
162+
.withColorAttachment({ view: context })
169163
.draw(3);
170164

171165
context.present();

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,9 @@ function swap() {
287287
}
288288

289289
function render() {
290-
const colorAttachment = {
291-
view: context.getCurrentTexture().createView(),
292-
loadOp: 'clear' as const,
293-
storeOp: 'store' as const,
294-
};
295-
296290
distancePipeline
297291
.with(resources.renderBindGroups[0])
298-
.withColorAttachment(colorAttachment)
292+
.withColorAttachment({ view: context })
299293
.draw(3);
300294
}
301295

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,9 @@ function swap() {
223223
}
224224

225225
function render() {
226-
const colorAttachment = {
227-
view: context.getCurrentTexture().createView(),
228-
loadOp: 'clear' as const,
229-
storeOp: 'store' as const,
230-
};
231-
232226
voronoiPipeline
233227
.with(resources.renderBindGroups[sourceIdx])
234-
.withColorAttachment(colorAttachment)
228+
.withColorAttachment({ view: context })
235229
.draw(3);
236230
}
237231

apps/typegpu-docs/src/examples/geometry/circles/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,9 @@ setTimeout(() => {
140140
...(multisample
141141
? {
142142
view: msaaTextureView,
143-
resolveTarget: context.getCurrentTexture().createView(),
143+
resolveTarget: context,
144144
}
145-
: {
146-
view: context.getCurrentTexture().createView(),
147-
}),
145+
: { view: context }),
148146
clearValue: [0, 0, 0, 0],
149147
loadOp: 'clear',
150148
storeOp: 'store',

apps/typegpu-docs/src/examples/geometry/lines-combinations/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
startCapSlot,
1717
uvToLineSegment,
1818
} from '@typegpu/geometry';
19-
import tgpu from 'typegpu';
19+
import tgpu, { type ColorAttachment } from 'typegpu';
2020
import {
2121
arrayOf,
2222
builtin,
@@ -30,7 +30,6 @@ import {
3030
vec4f,
3131
} from 'typegpu/data';
3232
import { clamp, cos, min, mix, select, sin } from 'typegpu/std';
33-
import type { ColorAttachment } from '../../../../../../packages/typegpu/src/core/pipeline/renderPipeline.ts';
3433
import { TEST_SEGMENT_COUNT } from './constants.ts';
3534
import * as testCases from './testCases.ts';
3635
import { defineControls } from '../../common/defineControls.ts';
@@ -372,10 +371,9 @@ const draw = (timeMs: number) => {
372371
time: timeMs * 1e-3,
373372
});
374373
const colorAttachment: ColorAttachment = {
375-
view: context.getCurrentTexture().createView(),
374+
view: context,
376375
clearValue: [1, 1, 1, 1],
377376
loadOp: 'load',
378-
storeOp: 'store',
379377
};
380378
pipelines.fill
381379
.with(uniformsBindGroup)

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const video = document.querySelector('video') as HTMLVideoElement;
4848
const canvas = document.querySelector('canvas') as HTMLCanvasElement;
4949
const spinner = document.querySelector('.spinner-background') as HTMLDivElement;
5050
const context = root.configureContext({ canvas, alphaMode: 'premultiplied' });
51-
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
5251
canvas.parentElement?.appendChild(video);
5352

5453
const pipeline = root.createRenderPipeline({
@@ -156,7 +155,6 @@ const pipeline = root.createRenderPipeline({
156155
}
157156
return d.vec4f(resultColor, 1.0);
158157
},
159-
targets: { format: presentationFormat },
160158
});
161159

162160
if (navigator.mediaDevices.getUserMedia) {
@@ -213,11 +211,7 @@ function processVideoFrame(
213211

214212
pipeline
215213
.with(bindGroup)
216-
.withColorAttachment({
217-
loadOp: 'clear',
218-
storeOp: 'store',
219-
view: context.getCurrentTexture().createView(),
220-
})
214+
.withColorAttachment({ view: context })
221215
.draw(3);
222216

223217
spinner.style.display = 'none';

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ navigator.gpu.requestAdapter = async () => adapter;
6868
adapter.requestDevice = async () => device;
6969
const root = tgpu.initFromDevice({ device });
7070
const context = root.configureContext({ canvas, alphaMode: 'premultiplied' });
71-
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
7271

7372
// resources
7473

@@ -164,7 +163,6 @@ const drawWithMaskPipeline = root
164163
.createRenderPipeline({
165164
vertex: common.fullScreenTriangle,
166165
fragment: fragmentFn,
167-
targets: { format: presentationFormat },
168166
});
169167

170168
// recalculating mask
@@ -309,10 +307,8 @@ async function processVideoFrame(
309307

310308
drawWithMaskPipeline
311309
.withColorAttachment({
312-
view: context.getCurrentTexture().createView(),
310+
view: context,
313311
clearValue: [1, 1, 1, 1],
314-
loadOp: 'clear',
315-
storeOp: 'store',
316312
})
317313
.with(root.createBindGroup(drawWithMaskLayout, {
318314
inputTexture: device.importExternalTexture({ source: video }),

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const root = await tgpu.init();
88
const canvas = document.querySelector('canvas') as HTMLCanvasElement;
99
const context = root.configureContext({ canvas });
1010

11-
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
12-
1311
const response = await fetch('/TypeGPU/plums.jpg');
1412
const imageBitmap = await createImageBitmap(await response.blob());
1513
const [srcWidth, srcHeight] = [imageBitmap.width, imageBitmap.height];
@@ -155,7 +153,6 @@ const computePipeline = root.createComputePipeline({ compute: computeFn });
155153
const renderPipeline = root.createRenderPipeline({
156154
vertex: common.fullScreenTriangle,
157155
fragment: renderFragment,
158-
targets: { format: presentationFormat },
159156
});
160157

161158
function render() {
@@ -175,11 +172,9 @@ function render() {
175172
);
176173
}
177174

178-
renderPipeline.withColorAttachment({
179-
view: context.getCurrentTexture().createView(),
180-
loadOp: 'clear',
181-
storeOp: 'store',
182-
}).draw(3);
175+
renderPipeline
176+
.withColorAttachment({ view: context })
177+
.draw(3);
183178
}
184179
render();
185180

0 commit comments

Comments
 (0)