Created
June 23, 2026 18:15
-
-
Save greggman/98a09f29445bd35db8b5e2b40f643086 to your computer and use it in GitHub Desktop.
WebGPU: Test onSubmittedWorkDone per requestAnimationFrame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :root { | |
| color-scheme: light dark; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*bug-in-github-api-content-can-not-be-empty*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function main() { | |
| const adapter = await navigator.gpu.requestAdapter(); | |
| const device = await adapter.requestDevice(); | |
| const texture = device.createTexture({ | |
| usage: GPUTextureUsage.RENDER_ATTACHMENT, | |
| size: [16, 16], | |
| format: 'rgba8unorm', | |
| }); | |
| const numTests = 20; | |
| let count = 0; | |
| for (let test = 0; test < numTests; ++test) { | |
| await rAF(); | |
| let done = false; | |
| requestAnimationFrame(() => { done = true }); | |
| while (!done) { | |
| const encoder = device.createCommandEncoder(); | |
| const pass = encoder.beginRenderPass({ | |
| colorAttachments: [ | |
| { | |
| view: texture, | |
| loadOp: 'clear', | |
| storeOp: 'store', | |
| }, | |
| ], | |
| }); | |
| pass.end(); | |
| device.queue.submit([encoder.finish()]); | |
| await device.queue.onSubmittedWorkDone(); | |
| ++count; | |
| } | |
| } | |
| log(`onSubmittedWorkDone per requestAnimationFrame = ${(count / numTests).toFixed(2)}`) | |
| } | |
| main(); | |
| function log(...args) { | |
| const elem = document.createElement('pre'); | |
| elem.textContent = args.join(' '); | |
| document.body.append(elem); | |
| } | |
| function rAF() { | |
| return new Promise(resolve => requestAnimationFrame(resolve)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"name":"WebGPU: Test onSubmittedWorkDone per requestAnimationFrame","settings":{},"filenames":["index.html","index.css","index.js"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment