Skip to content

Commit bafffe6

Browse files
jdarpiniangreggman
authored andcommitted
Updated API for timestamp queries
1 parent 66f360d commit bafffe6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

sample/workloadSimulator/index.html

+11-11
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ <h2><center>Web graphics workload simulator</center></h2>
598598
}, 0, 2);
599599
const useTimestampQueries = adapter.features.has('timestamp-query');
600600
device = await adapter.requestDevice({
601-
nonGuaranteedFeatures: useTimestampQueries ? ['timestamp-query'] : [],
601+
requiredFeatures: useTimestampQueries ? ['timestamp-query'] : [],
602602
});
603603
device.addEventListener('uncapturederror', (e)=>{
604604
if (!errorMessage.textContent) errorMessage.textContent = 'Uncaptured error: ' + e.error.message;
@@ -731,14 +731,16 @@ <h2><center>Web graphics workload simulator</center></h2>
731731
}
732732
try {
733733
const canvasView = canvasContext.getCurrentTexture().createView();
734-
const commandBuffers = [];
735-
device.queue.writeBuffer(uniformBuffer, 0, new Float32Array([position[0] / size * 2 - 1, 1 - position[1] * 2 / size]));
736-
let buffer = null;
737734

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

743745
// Upload data using createBuffer with mappedAtCreation.
744746
if (bufferData.value > 0) {
@@ -815,6 +817,7 @@ <h2><center>Web graphics workload simulator</center></h2>
815817
clearValue: [1, 1, 1, 1],
816818
storeOp: multisampling.checked ? 'discard' : 'store',
817819
}, ],
820+
timestampWrites: querySet ? { querySet, endOfPassWriteIndex: 1 } : undefined,
818821
});
819822
if (useRenderBundles.checked && renderBundle && instances == renderBundleInstances && renderBundleNumDrawCalls == numDrawCalls) {
820823
// If we have valid RenderBundles to use, execute them and we're done.
@@ -892,8 +895,6 @@ <h2><center>Web graphics workload simulator</center></h2>
892895
if (buffer) buffer.destroy();
893896
let queryBuffer;
894897
if (querySet) {
895-
// Timestamp for the end of the frame.
896-
commandEncoder.writeTimestamp(querySet, 1);
897898
// We create a queue of staging buffers to hold the timestamps while we
898899
// map them into CPU memory. If the queue is empty, create a new buffer.
899900
if (queryBuffers.length == 0) {
@@ -908,8 +909,7 @@ <h2><center>Web graphics workload simulator</center></h2>
908909
commandEncoder.resolveQuerySet(querySet, 0, 2, queryResolveBuffer, 0);
909910
commandEncoder.copyBufferToBuffer(queryResolveBuffer, 0, queryBuffer, 0, 16);
910911
}
911-
commandBuffers.push(commandEncoder.finish());
912-
device.queue.submit(commandBuffers);
912+
device.queue.submit([commandEncoder.finish()]);
913913
if (querySet) {
914914
// Once the staging buffer is mapped we can finally calculate the frame duration
915915
// and put the staging buffer back into the queue.

0 commit comments

Comments
 (0)