diff --git a/js/webgpu_main.js b/js/webgpu_main.js index d09ad38..a330a24 100644 --- a/js/webgpu_main.js +++ b/js/webgpu_main.js @@ -13,11 +13,12 @@ export default async (canvas, config) => { const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); const canvasContext = canvas.getContext("webgpu"); + const presentationFormat = canvasContext.getPreferredFormat(adapter); const queue = device.queue; const canvasConfig = { device, - format: canvasContext.getPreferredFormat(adapter), + format: presentationFormat, size: getCanvasSize(canvas), }; @@ -37,6 +38,13 @@ export default async (canvas, config) => { // TODO: create pipelines, bind groups, shaders + const bundleEncoder = device.createRenderBundleEncoder({ + colorFormats: [presentationFormat], + }); + // TODO: create render bundle(s) + const bundle = bundleEncoder.finish(); + const renderBundles = [bundle]; + const frame = (now) => { const canvasSize = getCanvasSize(canvas); if (canvasSize[0] !== canvasConfig.size[0] || canvasSize[1] !== canvasConfig.size[1]) { @@ -50,19 +58,16 @@ export default async (canvas, config) => { // TODO: update the uniforms that change, write to queue - // TODO: passes and pipelines - renderPassConfig.colorAttachments[0].loadValue.g = Math.sin((now / 1000) * 2) / 2 + 0.5; renderPassConfig.colorAttachments[0].view = canvasContext.getCurrentTexture().createView(); const encoder = device.createCommandEncoder(); const renderPass = encoder.beginRenderPass(renderPassConfig); + renderPass.executeBundles(renderBundles); renderPass.endPass(); const commandBuffer = encoder.finish(); queue.submit([commandBuffer]); - // TODO: Record this, so it doesn't have to be reencoded - requestAnimationFrame(frame); }; diff --git a/webgpu_notes.txt b/webgpu_notes.txt index 857b7d2..ebe43f7 100644 --- a/webgpu_notes.txt +++ b/webgpu_notes.txt @@ -37,3 +37,6 @@ You DO need a canvas to display what you're rendering Textures were never resizable, you simply forgot Screen-size textures have to be destroyed and recreated Transfer the data over if you need to + +Bind groups let you bind a bunch of resources at once +Render bundles let you reissue commands