Skip to content

Commit d532d48

Browse files
committed
Batched examples
1 parent 85f5ff0 commit d532d48

File tree

7 files changed

+88
-81
lines changed

7 files changed

+88
-81
lines changed

apps/typegpu-docs/src/content/examples/rendering/3d-fish/index.ts

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -256,55 +256,57 @@ function frame(timestamp: DOMHighResTimeStamp) {
256256
lastTimestamp = timestamp;
257257
cameraBuffer.write(camera);
258258

259-
computePipeline
260-
.with(computeBindGroupLayout, computeBindGroups[odd ? 1 : 0])
261-
.dispatchWorkgroups(p.fishAmount / p.workGroupSize);
262-
263-
renderPipeline
264-
.withColorAttachment({
265-
view: context.getCurrentTexture().createView(),
266-
clearValue: [
267-
p.backgroundColor.x,
268-
p.backgroundColor.y,
269-
p.backgroundColor.z,
270-
1,
271-
],
272-
loadOp: 'clear',
273-
storeOp: 'store',
274-
})
275-
.withDepthStencilAttachment({
276-
view: depthTexture.createView(),
277-
depthClearValue: 1,
278-
depthLoadOp: 'clear',
279-
depthStoreOp: 'store',
280-
})
281-
.with(modelVertexLayout, oceanFloorModel.vertexBuffer)
282-
.with(renderInstanceLayout, oceanFloorDataBuffer)
283-
.with(renderBindGroupLayout, renderOceanFloorBindGroup)
284-
.draw(oceanFloorModel.polygonCount, 1);
285-
286-
renderPipeline
287-
.withColorAttachment({
288-
view: context.getCurrentTexture().createView(),
289-
clearValue: [
290-
p.backgroundColor.x,
291-
p.backgroundColor.y,
292-
p.backgroundColor.z,
293-
1,
294-
],
295-
loadOp: 'load',
296-
storeOp: 'store',
297-
})
298-
.withDepthStencilAttachment({
299-
view: depthTexture.createView(),
300-
depthClearValue: 1,
301-
depthLoadOp: 'load',
302-
depthStoreOp: 'store',
303-
})
304-
.with(modelVertexLayout, fishModel.vertexBuffer)
305-
.with(renderInstanceLayout, fishDataBuffers[odd ? 1 : 0])
306-
.with(renderBindGroupLayout, renderFishBindGroups[odd ? 1 : 0])
307-
.draw(fishModel.polygonCount, p.fishAmount);
259+
root['~unstable'].batch(() => {
260+
computePipeline
261+
.with(computeBindGroupLayout, computeBindGroups[odd ? 1 : 0])
262+
.dispatchWorkgroups(p.fishAmount / p.workGroupSize);
263+
264+
renderPipeline
265+
.withColorAttachment({
266+
view: context.getCurrentTexture().createView(),
267+
clearValue: [
268+
p.backgroundColor.x,
269+
p.backgroundColor.y,
270+
p.backgroundColor.z,
271+
1,
272+
],
273+
loadOp: 'clear',
274+
storeOp: 'store',
275+
})
276+
.withDepthStencilAttachment({
277+
view: depthTexture.createView(),
278+
depthClearValue: 1,
279+
depthLoadOp: 'clear',
280+
depthStoreOp: 'store',
281+
})
282+
.with(modelVertexLayout, oceanFloorModel.vertexBuffer)
283+
.with(renderInstanceLayout, oceanFloorDataBuffer)
284+
.with(renderBindGroupLayout, renderOceanFloorBindGroup)
285+
.draw(oceanFloorModel.polygonCount, 1);
286+
287+
renderPipeline
288+
.withColorAttachment({
289+
view: context.getCurrentTexture().createView(),
290+
clearValue: [
291+
p.backgroundColor.x,
292+
p.backgroundColor.y,
293+
p.backgroundColor.z,
294+
1,
295+
],
296+
loadOp: 'load',
297+
storeOp: 'store',
298+
})
299+
.withDepthStencilAttachment({
300+
view: depthTexture.createView(),
301+
depthClearValue: 1,
302+
depthLoadOp: 'load',
303+
depthStoreOp: 'store',
304+
})
305+
.with(modelVertexLayout, fishModel.vertexBuffer)
306+
.with(renderInstanceLayout, fishDataBuffers[odd ? 1 : 0])
307+
.with(renderBindGroupLayout, renderFishBindGroups[odd ? 1 : 0])
308+
.draw(fishModel.polygonCount, p.fishAmount);
309+
});
308310

309311
requestAnimationFrame(frame);
310312
}

apps/typegpu-docs/src/content/examples/rendering/cubemap-reflection/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ function loop() {
312312
if (exampleDestroyed) {
313313
return;
314314
}
315-
render();
315+
root['~unstable'].batch(render);
316316
requestAnimationFrame(loop);
317317
}
318318

apps/typegpu-docs/src/content/examples/simulation/boids-next/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,22 @@ function frame() {
294294

295295
even = !even;
296296

297-
computePipeline
298-
.with(computeBindGroupLayout, computeBindGroups[even ? 0 : 1])
299-
.dispatchWorkgroups(triangleAmount);
300-
301-
renderPipeline
302-
.withColorAttachment({
303-
view: context.getCurrentTexture().createView(),
304-
clearValue: [1, 1, 1, 1],
305-
loadOp: 'clear' as const,
306-
storeOp: 'store' as const,
307-
})
308-
.with(instanceLayout, trianglePosBuffers[even ? 1 : 0])
309-
.with(renderLayout, renderBindGroups[even ? 1 : 0])
310-
.draw(3, triangleAmount);
297+
root['~unstable'].batch(() => {
298+
computePipeline
299+
.with(computeBindGroupLayout, computeBindGroups[even ? 0 : 1])
300+
.dispatchWorkgroups(triangleAmount);
301+
302+
renderPipeline
303+
.withColorAttachment({
304+
view: context.getCurrentTexture().createView(),
305+
clearValue: [1, 1, 1, 1],
306+
loadOp: 'clear' as const,
307+
storeOp: 'store' as const,
308+
})
309+
.with(instanceLayout, trianglePosBuffers[even ? 1 : 0])
310+
.with(renderLayout, renderBindGroups[even ? 1 : 0])
311+
.draw(3, triangleAmount);
312+
});
311313

312314
requestAnimationFrame(frame);
313315
}

apps/typegpu-docs/src/content/examples/simulation/confetti/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,18 @@ onFrame((dt) => {
210210
deltaTime.write(dt);
211211
aspectRatio.write(canvas.width / canvas.height);
212212

213-
computePipeline.dispatchWorkgroups(PARTICLE_AMOUNT);
214-
215-
renderPipeline
216-
.withColorAttachment({
217-
view: context.getCurrentTexture().createView(),
218-
clearValue: [0, 0, 0, 0],
219-
loadOp: 'clear' as const,
220-
storeOp: 'store' as const,
221-
})
222-
.draw(4, PARTICLE_AMOUNT);
213+
root['~unstable'].batch(() => {
214+
computePipeline.dispatchWorkgroups(PARTICLE_AMOUNT);
215+
216+
renderPipeline
217+
.withColorAttachment({
218+
view: context.getCurrentTexture().createView(),
219+
clearValue: [0, 0, 0, 0],
220+
loadOp: 'clear' as const,
221+
storeOp: 'store' as const,
222+
})
223+
.draw(4, PARTICLE_AMOUNT);
224+
});
223225
});
224226

225227
// example controls and cleanup

apps/typegpu-docs/src/content/examples/simulation/fluid-double-buffering/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,12 @@ onFrame((deltaTime) => {
586586
msSinceLastTick += deltaTime;
587587

588588
if (msSinceLastTick >= timestep) {
589-
for (let i = 0; i < stepsPerTick; ++i) {
590-
tick();
591-
}
592-
primary.render();
589+
root['~unstable'].batch(() => {
590+
for (let i = 0; i < stepsPerTick; ++i) {
591+
tick();
592+
}
593+
primary.render();
594+
});
593595
msSinceLastTick -= timestep;
594596
}
595597
});

apps/typegpu-docs/src/content/examples/simulation/fluid-with-atomics/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ function resetGameData() {
372372
storeOp: 'store' as const,
373373
})
374374
.draw(4, options.size ** 2);
375-
376375
currentStateBuffer.copyFrom(nextState.buffer);
377376
};
378377

@@ -397,7 +396,7 @@ function resetGameData() {
397396

398397
createSampleScene();
399398
applyDrawCanvas();
400-
render();
399+
root['~unstable'].batch(render);
401400
}
402401

403402
let isDrawing = false;

apps/typegpu-docs/src/content/examples/simulation/gravity/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function frame(timestamp: DOMHighResTimeStamp) {
199199
passed: Math.min((timestamp - lastTimestamp) / 1000, 0.1),
200200
});
201201
lastTimestamp = timestamp;
202-
render();
202+
root['~unstable'].batch(render);
203203
requestAnimationFrame(frame);
204204
}
205205
requestAnimationFrame(frame);

0 commit comments

Comments
 (0)