@@ -1166,7 +1166,7 @@ class WebGPUBackend extends Backend {
1166
1166
}
1167
1167
1168
1168
1169
- async initTimestampQuery ( renderContext , descriptor ) {
1169
+ initTimestampQuery ( renderContext , descriptor ) {
1170
1170
1171
1171
if ( ! this . trackTimestamp ) return ;
1172
1172
@@ -1175,27 +1175,8 @@ class WebGPUBackend extends Backend {
1175
1175
if ( ! renderContextData . timeStampQuerySet ) {
1176
1176
1177
1177
1178
- // Push an error scope to catch any errors during query set creation
1179
- this . device . pushErrorScope ( 'out-of-memory' ) ;
1180
-
1181
- const timeStampQuerySet = await this . device . createQuerySet ( { type : 'timestamp' , count : 2 , label : `timestamp_renderContext_${ renderContext . id } ` } ) ;
1182
-
1183
- // Pop the error scope and check for errors
1184
- const error = await this . device . popErrorScope ( ) ;
1185
-
1186
- if ( error ) {
1187
-
1188
- if ( ! renderContextData . attemptingTimeStampQuerySetFailed ) {
1189
-
1190
- console . error ( `[GPUOutOfMemoryError][renderContext_${ renderContext . id } ]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.` ) ;
1191
- renderContextData . attemptingTimeStampQuerySetFailed = true ;
1192
-
1193
- }
1194
-
1195
- renderContextData . timeStampQuerySet = null ; // Mark as unavailable
1196
- return ;
1197
-
1198
- }
1178
+ const type = renderContext . isComputeNode ? 'compute' : 'render' ;
1179
+ const timeStampQuerySet = this . device . createQuerySet ( { type : 'timestamp' , count : 2 , label : `timestamp_${ type } _${ renderContext . id } ` } ) ;
1199
1180
1200
1181
const timestampWrites = {
1201
1182
querySet : timeStampQuerySet ,
@@ -1219,7 +1200,6 @@ class WebGPUBackend extends Backend {
1219
1200
1220
1201
const renderContextData = this . get ( renderContext ) ;
1221
1202
1222
- if ( ! renderContextData . timeStampQuerySet ) return ;
1223
1203
1224
1204
const size = 2 * BigInt64Array . BYTES_PER_ELEMENT ;
1225
1205
@@ -1235,18 +1215,21 @@ class WebGPUBackend extends Backend {
1235
1215
label : 'timestamp result buffer' ,
1236
1216
size : size ,
1237
1217
usage : GPUBufferUsage . COPY_DST | GPUBufferUsage . MAP_READ ,
1238
- } ) ,
1239
- isMappingPending : false ,
1218
+ } )
1240
1219
} ;
1241
1220
1242
1221
}
1243
1222
1244
- const { resolveBuffer, resultBuffer, isMappingPending } = renderContextData . currentTimestampQueryBuffers ;
1223
+ const { resolveBuffer, resultBuffer } = renderContextData . currentTimestampQueryBuffers ;
1245
1224
1246
- if ( isMappingPending === true ) return ;
1247
1225
1248
1226
encoder . resolveQuerySet ( renderContextData . timeStampQuerySet , 0 , 2 , resolveBuffer , 0 ) ;
1249
- encoder . copyBufferToBuffer ( resolveBuffer , 0 , resultBuffer , 0 , size ) ;
1227
+
1228
+ if ( resultBuffer . mapState === 'unmapped' ) {
1229
+
1230
+ encoder . copyBufferToBuffer ( resolveBuffer , 0 , resultBuffer , 0 , size ) ;
1231
+
1232
+ }
1250
1233
1251
1234
}
1252
1235
@@ -1256,29 +1239,28 @@ class WebGPUBackend extends Backend {
1256
1239
1257
1240
const renderContextData = this . get ( renderContext ) ;
1258
1241
1259
- if ( ! renderContextData . timeStampQuerySet ) return ;
1260
-
1261
1242
if ( renderContextData . currentTimestampQueryBuffers === undefined ) return ;
1262
1243
1263
- const { resultBuffer, isMappingPending } = renderContextData . currentTimestampQueryBuffers ;
1244
+ const { resultBuffer } = renderContextData . currentTimestampQueryBuffers ;
1264
1245
1265
- if ( isMappingPending === true ) return ;
1246
+ await this . device . queue . onSubmittedWorkDone ( ) ;
1266
1247
1267
- renderContextData . currentTimestampQueryBuffers . isMappingPending = true ;
1248
+ if ( resultBuffer . mapState === 'unmapped' ) {
1268
1249
1269
- resultBuffer . mapAsync ( GPUMapMode . READ ) . then ( ( ) => {
1250
+ resultBuffer . mapAsync ( GPUMapMode . READ ) . then ( ( ) => {
1270
1251
1271
- const times = new BigUint64Array ( resultBuffer . getMappedRange ( ) ) ;
1272
- const duration = Number ( times [ 1 ] - times [ 0 ] ) / 1000000 ;
1252
+ const times = new BigUint64Array ( resultBuffer . getMappedRange ( ) ) ;
1253
+ const duration = Number ( times [ 1 ] - times [ 0 ] ) / 1000000 ;
1273
1254
1274
1255
1275
- this . renderer . info . updateTimestamp ( type , duration ) ;
1256
+ this . renderer . info . updateTimestamp ( type , duration ) ;
1276
1257
1277
- resultBuffer . unmap ( ) ;
1258
+ resultBuffer . unmap ( ) ;
1278
1259
1279
- renderContextData . currentTimestampQueryBuffers . isMappingPending = false ;
1280
1260
1281
- } ) ;
1261
+ } ) ;
1262
+
1263
+ }
1282
1264
1283
1265
}
1284
1266
0 commit comments