Skip to content

Commit

Permalink
Fix average pass duration algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Nov 21, 2023
1 parent 538ebf7 commit 9127c73
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/sample/computeBoids/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,30 +309,32 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
device.queue.submit([commandEncoder.finish()]);

if (hasTimestampQuery) {
resultBuffer.mapAsync(GPUMapMode.READ).then(() => {
const times = new BigInt64Array(resultBuffer.getMappedRange());
computePassDurationSum += Number(times[1] - times[0]);
renderPassDurationSum += Number(times[3] - times[2]);
resultBuffer.unmap();

// Periodically update the text for the timer stats
const kNumTimerSamples = 100;
if (t % kNumTimerSamples === 0) {
const avgComputeMicroseconds = Math.round(
computePassDurationSum / kNumTimerSamples / 1000
);
const avgRenderMicroseconds = Math.round(
renderPassDurationSum / kNumTimerSamples / 1000
);
perfDisplay.textContent = `\
((t) => {
resultBuffer.mapAsync(GPUMapMode.READ).then(() => {
const times = new BigInt64Array(resultBuffer.getMappedRange());
computePassDurationSum += Number(times[1] - times[0]);
renderPassDurationSum += Number(times[3] - times[2]);
resultBuffer.unmap();

// Periodically update the text for the timer stats
const kNumTimerSamples = 100;
if (t % kNumTimerSamples === 0) {
const avgComputeMicroseconds = Math.round(
computePassDurationSum / kNumTimerSamples / 1000
);
const avgRenderMicroseconds = Math.round(
renderPassDurationSum / kNumTimerSamples / 1000
);
perfDisplay.textContent = `\
avg compute pass duration: ${avgComputeMicroseconds}µs
avg render pass duration: ${avgRenderMicroseconds}µs
spare readback buffers: ${spareResultBuffers.length}`;
computePassDurationSum = 0;
renderPassDurationSum = 0;
}
spareResultBuffers.push(resultBuffer);
});
computePassDurationSum = 0;
renderPassDurationSum = 0;
}
spareResultBuffers.push(resultBuffer);
});
})(t);
}

++t;
Expand Down

0 comments on commit 9127c73

Please sign in to comment.