From fc6821f4db65a758d93436b86067b3aa619f229e Mon Sep 17 00:00:00 2001 From: Rezmason Date: Tue, 9 Aug 2022 22:25:35 -0700 Subject: [PATCH] Making sure copyTextureToTexture can run, even though the WebGPU project still relies on endPass --- js/webgpu/main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/webgpu/main.js b/js/webgpu/main.js index f452ad7..bb36793 100644 --- a/js/webgpu/main.js +++ b/js/webgpu/main.js @@ -72,6 +72,7 @@ export default async (canvas, config) => { let frames = 0; let start = NaN; + let outputs; const renderLoop = (now) => { if (isNaN(start)) { @@ -81,10 +82,11 @@ export default async (canvas, config) => { const devicePixelRatio = window.devicePixelRatio ?? 1; const canvasWidth = canvas.clientWidth * devicePixelRatio; const canvasHeight = canvas.clientHeight * devicePixelRatio; + const canvasSize = [canvasWidth, canvasHeight]; if (canvas.width !== canvasWidth || canvas.height !== canvasHeight) { canvas.width = canvasWidth; canvas.height = canvasHeight; - pipeline.build([canvasWidth, canvasHeight]); + outputs = pipeline.build(canvasSize); } device.queue.writeBuffer(timeBuffer, 0, timeUniforms.toBuffer({ seconds: (now - start) / 1000, frames })); @@ -93,7 +95,7 @@ export default async (canvas, config) => { const encoder = device.createCommandEncoder(); pipeline.run(encoder); // Eventually, when WebGPU allows it, we'll remove the endPass and just copy from our pipeline's output to the canvas texture. - // encoder.copyTextureToTexture({ texture: output.primary }, { texture: canvasContext.getCurrentTexture() }, canvasSize); + // encoder.copyTextureToTexture({ texture: outputs?.primary }, { texture: canvasContext.getCurrentTexture() }, canvasSize); device.queue.submit([encoder.finish()]); requestAnimationFrame(renderLoop); };