@@ -309,30 +309,32 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
309309 device . queue . submit ( [ commandEncoder . finish ( ) ] ) ;
310310
311311 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 = `\
328329avg compute pass duration: ${ avgComputeMicroseconds } µs
329330avg render pass duration: ${ avgRenderMicroseconds } µs
330331spare 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 ) ;
336338 }
337339
338340 ++ t ;
0 commit comments