Skip to content

Commit 5fb35c7

Browse files
authored
WebGPUBackend: Fix Timestamp Query (#30299)
* fix * await
1 parent 60e27ac commit 5fb35c7

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,23 +1468,23 @@ class WebGPUBackend extends Backend {
14681468

14691469
const renderContextData = this.get( renderContext );
14701470

1471-
if ( ! renderContextData.timestampQuerySet ) {
1471+
// init query set if not exists
14721472

1473+
if ( ! renderContextData.timestampQuerySet ) {
14731474

14741475
const type = renderContext.isComputeNode ? 'compute' : 'render';
1475-
const timestampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2, label: `timestamp_${type}_${renderContext.id}` } );
14761476

1477-
const timestampWrites = {
1478-
querySet: timestampQuerySet,
1479-
beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
1480-
endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
1481-
};
1477+
renderContextData.timestampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2, label: `timestamp_${type}_${renderContext.id}` } );
14821478

1483-
Object.assign( descriptor, { timestampWrites } );
1479+
}
14841480

1485-
renderContextData.timestampQuerySet = timestampQuerySet;
1481+
// augment descriptor
14861482

1487-
}
1483+
descriptor.timestampWrites = {
1484+
querySet: renderContextData.timestampQuerySet,
1485+
beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
1486+
endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
1487+
};
14881488

14891489
}
14901490

@@ -1553,18 +1553,15 @@ class WebGPUBackend extends Backend {
15531553

15541554
if ( resultBuffer.mapState === 'unmapped' ) {
15551555

1556-
resultBuffer.mapAsync( GPUMapMode.READ ).then( () => {
1557-
1558-
const times = new BigUint64Array( resultBuffer.getMappedRange() );
1559-
const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
1560-
1556+
await resultBuffer.mapAsync( GPUMapMode.READ );
15611557

1562-
this.renderer.info.updateTimestamp( type, duration );
1558+
const times = new BigUint64Array( resultBuffer.getMappedRange() );
1559+
const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
15631560

1564-
resultBuffer.unmap();
15651561

1562+
this.renderer.info.updateTimestamp( type, duration );
15661563

1567-
} );
1564+
resultBuffer.unmap();
15681565

15691566
}
15701567

0 commit comments

Comments
 (0)