Skip to content

Instantly share code, notes, and snippets.

@greggman
Last active July 24, 2025 19:09
Show Gist options
  • Save greggman/89c0411946f59b8ccdfafc89b295b049 to your computer and use it in GitHub Desktop.
Save greggman/89c0411946f59b8ccdfafc89b295b049 to your computer and use it in GitHub Desktop.
WebGPU: Check how many QuerySets we can have
/*bug-in-github-api-content-can-not-be-empty*/
/*bug-in-github-api-content-can-not-be-empty*/
async function main () {
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has('timestamp-query')) {
console.error('need timestamp-query');
return;
}
const device = await adapter.requestDevice({ requiredFeatures: ['timestamp-query'] });
const queries = [];
for (;;) {
device.pushErrorScope('validation');
const querySet = device.createQuerySet({ type: 'timestamp', count: 2, label: `QuerySet#${queries.length + 1} ` });
queries.push(querySet);
device.queue.submit([]);
{
const err = await device.popErrorScope();
if (err) {
console.error('at creation:', err.message);
break;
}
}
device.pushErrorScope('validation');
const encoder = device.createCommandEncoder();
const pass = encoder.beginComputePass({
timestampWrites: {
querySet,
beginningOfPassWriteIndex: 0,
gendOfPassWriteIndex: 1,
},
});
pass.end();
device.queue.submit([encoder.finish()]);
{
const err = await device.popErrorScope();
if (err) {
console.error('at usage:', err.message);
break;
}
}
if (queries.length % 100 === 0) {
console.log(queries.length);
await new Promise(resolve => setTimeout(resolve, 100));
}
}
console.log('num queries:', queries.length - 1);
}
main();
{"name":"WebGPU: Check how many QuerySets we can have","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