Skip to content

Commit 0980f2f

Browse files
jdarpiniangreggman
authored andcommitted
Remove timestamp-query support
The timestamp-query feature as currently specced cannot reliably measure anything other than the length of a single render or compute pass.
1 parent bafffe6 commit 0980f2f

File tree

1 file changed

+2
-59
lines changed

1 file changed

+2
-59
lines changed

sample/workloadSimulator/index.html

+2-59
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ <h2><center>Web graphics workload simulator</center></h2>
418418
let renderBundleAfterScissor;
419419
let renderBundleNumDrawCalls;
420420
let renderBundleInstances;
421-
let querySet;
422-
let queryBuffers = [];
423-
let queryResolveBuffer;
424421
let mapAsyncArray = new Float32Array(0);
425422
let mapAsyncTargetBuffer;
426423
let mapAsyncBufferSize = 0;
@@ -448,8 +445,6 @@ <h2><center>Web graphics workload simulator</center></h2>
448445
let timeout = null;
449446
let rafPending = 0;
450447
let postMessagePending = 0;
451-
let timeQueryResultsMs = [];
452-
let lastTimeQueryTime = 0;
453448

454449
const animationDirection = [1, 1];
455450
async function render(fromRaf, fromPostMessage) {
@@ -596,10 +591,7 @@ <h2><center>Web graphics workload simulator</center></h2>
596591
features: Array.from(adapter.features || []).sort(),
597592
limits: adapter.limits
598593
}, 0, 2);
599-
const useTimestampQueries = adapter.features.has('timestamp-query');
600-
device = await adapter.requestDevice({
601-
requiredFeatures: useTimestampQueries ? ['timestamp-query'] : [],
602-
});
594+
device = await adapter.requestDevice({});
603595
device.addEventListener('uncapturederror', (e)=>{
604596
if (!errorMessage.textContent) errorMessage.textContent = 'Uncaptured error: ' + e.error.message;
605597
});
@@ -709,13 +701,6 @@ <h2><center>Web graphics workload simulator</center></h2>
709701
{ binding: 2, resource: texture.createView() },
710702
],
711703
});
712-
if (useTimestampQueries && device.createQuerySet) {
713-
querySet = device.createQuerySet({type: 'timestamp', count: 2});
714-
queryResolveBuffer = device.createBuffer({
715-
size: 16,
716-
usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
717-
});
718-
}
719704
} catch(e) {
720705
if (!errorMessage.textContent) errorMessage.textContent = "Error initializing WebGPU: " + e;
721706
return;
@@ -732,13 +717,6 @@ <h2><center>Web graphics workload simulator</center></h2>
732717
try {
733718
const canvasView = canvasContext.getCurrentTexture().createView();
734719

735-
// Start off by writing a timestamp for the beginning of the frame.
736-
if (querySet) {
737-
const timestampEncoder = device.createCommandEncoder();
738-
timestampEncoder.beginComputePass({ timestampWrites: { querySet, beginningOfPassWriteIndex: 0, } }).end();
739-
device.queue.submit([timestampEncoder.finish()]);
740-
}
741-
742720
device.queue.writeBuffer(uniformBuffer, 0, new Float32Array([position[0] / size * 2 - 1, 1 - position[1] * 2 / size]));
743721
let buffer = null;
744722

@@ -817,7 +795,6 @@ <h2><center>Web graphics workload simulator</center></h2>
817795
clearValue: [1, 1, 1, 1],
818796
storeOp: multisampling.checked ? 'discard' : 'store',
819797
}, ],
820-
timestampWrites: querySet ? { querySet, endOfPassWriteIndex: 1 } : undefined,
821798
});
822799
if (useRenderBundles.checked && renderBundle && instances == renderBundleInstances && renderBundleNumDrawCalls == numDrawCalls) {
823800
// If we have valid RenderBundles to use, execute them and we're done.
@@ -893,36 +870,7 @@ <h2><center>Web graphics workload simulator</center></h2>
893870
}
894871
passEncoder.end();
895872
if (buffer) buffer.destroy();
896-
let queryBuffer;
897-
if (querySet) {
898-
// We create a queue of staging buffers to hold the timestamps while we
899-
// map them into CPU memory. If the queue is empty, create a new buffer.
900-
if (queryBuffers.length == 0) {
901-
const buffer = device.createBuffer({
902-
size: 16,
903-
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
904-
});
905-
queryBuffers.push(buffer);
906-
}
907-
// Write the timestamps into a GPU side buffer and copy into the staging buffer.
908-
queryBuffer = queryBuffers.shift();
909-
commandEncoder.resolveQuerySet(querySet, 0, 2, queryResolveBuffer, 0);
910-
commandEncoder.copyBufferToBuffer(queryResolveBuffer, 0, queryBuffer, 0, 16);
911-
}
912873
device.queue.submit([commandEncoder.finish()]);
913-
if (querySet) {
914-
// Once the staging buffer is mapped we can finally calculate the frame duration
915-
// and put the staging buffer back into the queue.
916-
queryBuffer.mapAsync(GPUMapMode.READ).then(()=>{
917-
let array = new BigInt64Array(queryBuffer.getMappedRange());
918-
let nanoseconds = Number(array[1] - array[0]);
919-
if (timeQueryResultsMs.length > 10) timeQueryResultsMs.shift();
920-
timeQueryResultsMs.push(nanoseconds / 1000000);
921-
lastTimeQueryTime = performance.now();
922-
queryBuffer.unmap();
923-
queryBuffers.push(queryBuffer);
924-
});
925-
}
926874
} catch(e) {
927875
if (!errorMessage.textContent) errorMessage.textContent = "Error: " + e;
928876
throw e;
@@ -1174,12 +1122,7 @@ <h2><center>Web graphics workload simulator</center></h2>
11741122
}
11751123

11761124
if (showFps.checked) {
1177-
if (performance.now() - lastTimeQueryTime < 1000 && timeQueryResultsMs.length) {
1178-
const averageTime = timeQueryResultsMs.reduce((x, y) => x + y) / timeQueryResultsMs.length;
1179-
fpsSpan.textContent = `${counters['render'].fps.toFixed()}, ${averageTime.toFixed(1)} ms GPU time`;
1180-
} else {
1181-
fpsSpan.textContent = counters['render'].fps.toFixed();
1182-
}
1125+
fpsSpan.textContent = counters['render'].fps.toFixed();
11831126
if (showStats.checked) {
11841127
let text = "";
11851128
for (let key in counters) {

0 commit comments

Comments
 (0)