Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Handle OutOfMemory in Timestamp Tracking #29857

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class WebGPUBackend extends Backend {

//

occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount } );
occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount, label: `occlusionQuerySet_${ renderContext.id }` } );

renderContextData.occlusionQuerySet = occlusionQuerySet;
renderContextData.occlusionQueryIndex = 0;
Expand Down Expand Up @@ -1166,27 +1166,44 @@ class WebGPUBackend extends Backend {
}


initTimestampQuery( renderContext, descriptor ) {
async initTimestampQuery( renderContext, descriptor ) {

if ( ! this.trackTimestamp ) return;

const renderContextData = this.get( renderContext );

if ( ! renderContextData.timeStampQuerySet ) {

// Create a GPUQuerySet which holds 2 timestamp query results: one for the
// beginning and one for the end of compute pass execution.
const timeStampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2 } );

// Push an error scope to catch any errors during query set creation
this.device.pushErrorScope( 'out-of-memory' );

const timeStampQuerySet = await this.device.createQuerySet( { type: 'timestamp', count: 2, label: `timestamp_renderContext_${renderContext.id}` } );

// Pop the error scope and check for errors
const error = await this.device.popErrorScope();

if ( error ) {

if ( ! renderContextData.attemptingTimeStampQuerySetFailed ) {

console.error( `[GPUOutOfMemoryError][renderContext_${renderContext.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.` );
renderContextData.attemptingTimeStampQuerySetFailed = true;

}

renderContextData.timeStampQuerySet = null; // Mark as unavailable
return;

}

const timestampWrites = {
querySet: timeStampQuerySet,
beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
};

Object.assign( descriptor, {
timestampWrites,
} );
Object.assign( descriptor, { timestampWrites } );

renderContextData.timeStampQuerySet = timeStampQuerySet;

Expand All @@ -1202,6 +1219,7 @@ class WebGPUBackend extends Backend {

const renderContextData = this.get( renderContext );

if ( ! renderContextData.timeStampQuerySet ) return;

const size = 2 * BigInt64Array.BYTES_PER_ELEMENT;

Expand Down Expand Up @@ -1238,6 +1256,8 @@ class WebGPUBackend extends Backend {

const renderContextData = this.get( renderContext );

if ( ! renderContextData.timeStampQuerySet ) return;

if ( renderContextData.currentTimestampQueryBuffers === undefined ) return;

const { resultBuffer, isMappingPending } = renderContextData.currentTimestampQueryBuffers;
Expand Down