@@ -309,30 +309,32 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
309
309
device . queue . submit ( [ commandEncoder . finish ( ) ] ) ;
310
310
311
311
if ( hasTimestampQuery ) {
312
- resultBuffer . mapAsync ( GPUMapMode . READ ) . then ( ( ) => {
313
- const times = new BigInt64Array ( resultBuffer . getMappedRange ( ) ) ;
314
- computePassDurationSum += Number ( times [ 1 ] - times [ 0 ] ) ;
315
- renderPassDurationSum += Number ( times [ 3 ] - times [ 2 ] ) ;
316
- resultBuffer . unmap ( ) ;
317
-
318
- // Periodically update the text for the timer stats
319
- const kNumTimerSamples = 100 ;
320
- if ( t % kNumTimerSamples === 0 ) {
321
- const avgComputeMicroseconds = Math . round (
322
- computePassDurationSum / kNumTimerSamples / 1000
323
- ) ;
324
- const avgRenderMicroseconds = Math . round (
325
- renderPassDurationSum / kNumTimerSamples / 1000
326
- ) ;
327
- perfDisplay . textContent = `\
312
+ ( ( t ) => {
313
+ resultBuffer . mapAsync ( GPUMapMode . READ ) . then ( ( ) => {
314
+ const times = new BigInt64Array ( resultBuffer . getMappedRange ( ) ) ;
315
+ computePassDurationSum += Number ( times [ 1 ] - times [ 0 ] ) ;
316
+ renderPassDurationSum += Number ( times [ 3 ] - times [ 2 ] ) ;
317
+ resultBuffer . unmap ( ) ;
318
+
319
+ // Periodically update the text for the timer stats
320
+ const kNumTimerSamples = 100 ;
321
+ if ( t % kNumTimerSamples === 0 ) {
322
+ const avgComputeMicroseconds = Math . round (
323
+ computePassDurationSum / kNumTimerSamples / 1000
324
+ ) ;
325
+ const avgRenderMicroseconds = Math . round (
326
+ renderPassDurationSum / kNumTimerSamples / 1000
327
+ ) ;
328
+ perfDisplay . textContent = `\
328
329
avg compute pass duration: ${ avgComputeMicroseconds } µs
329
330
avg render pass duration: ${ avgRenderMicroseconds } µs
330
331
spare readback buffers: ${ spareResultBuffers . length } ` ;
331
- computePassDurationSum = 0 ;
332
- renderPassDurationSum = 0 ;
333
- }
334
- spareResultBuffers . push ( resultBuffer ) ;
335
- } ) ;
332
+ computePassDurationSum = 0 ;
333
+ renderPassDurationSum = 0 ;
334
+ }
335
+ spareResultBuffers . push ( resultBuffer ) ;
336
+ } ) ;
337
+ } ) ( t ) ;
336
338
}
337
339
338
340
++ t ;
0 commit comments