@@ -1468,23 +1468,23 @@ class WebGPUBackend extends Backend {
1468
1468
1469
1469
const renderContextData = this . get ( renderContext ) ;
1470
1470
1471
- if ( ! renderContextData . timestampQuerySet ) {
1471
+ // init query set if not exists
1472
1472
1473
+ if ( ! renderContextData . timestampQuerySet ) {
1473
1474
1474
1475
const type = renderContext . isComputeNode ? 'compute' : 'render' ;
1475
- const timestampQuerySet = this . device . createQuerySet ( { type : 'timestamp' , count : 2 , label : `timestamp_${ type } _${ renderContext . id } ` } ) ;
1476
1476
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 } ` } ) ;
1482
1478
1483
- Object . assign ( descriptor , { timestampWrites } ) ;
1479
+ }
1484
1480
1485
- renderContextData . timestampQuerySet = timestampQuerySet ;
1481
+ // augment descriptor
1486
1482
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
+ } ;
1488
1488
1489
1489
}
1490
1490
@@ -1553,18 +1553,15 @@ class WebGPUBackend extends Backend {
1553
1553
1554
1554
if ( resultBuffer . mapState === 'unmapped' ) {
1555
1555
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 ) ;
1561
1557
1562
- this . renderer . info . updateTimestamp ( type , duration ) ;
1558
+ const times = new BigUint64Array ( resultBuffer . getMappedRange ( ) ) ;
1559
+ const duration = Number ( times [ 1 ] - times [ 0 ] ) / 1000000 ;
1563
1560
1564
- resultBuffer . unmap ( ) ;
1565
1561
1562
+ this . renderer . info . updateTimestamp ( type , duration ) ;
1566
1563
1567
- } ) ;
1564
+ resultBuffer . unmap ( ) ;
1568
1565
1569
1566
}
1570
1567
0 commit comments