Skip to content

Commit 3282f4f

Browse files
Fix WebGPU renderer memory churn
1 parent 4da2c67 commit 3282f4f

4 files changed

Lines changed: 468 additions & 114 deletions

File tree

src/renderers/common/RenderContexts.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,29 @@ class RenderContexts {
5353
const format = renderTarget.texture.format;
5454
const type = renderTarget.texture.type;
5555
const count = renderTarget.textures.length;
56-
57-
attachmentState = `${ count }:${ format }:${ type }:${ renderTarget.samples }:${ renderTarget.depthBuffer }:${ renderTarget.stencilBuffer }`;
56+
const samples = renderTarget.samples;
57+
const depthBuffer = renderTarget.depthBuffer;
58+
const stencilBuffer = renderTarget.stencilBuffer;
59+
60+
if ( renderTarget._attachmentState === undefined ||
61+
renderTarget._attachmentStateFormat !== format ||
62+
renderTarget._attachmentStateType !== type ||
63+
renderTarget._attachmentStateSamples !== samples ||
64+
renderTarget._attachmentStateCount !== count ||
65+
renderTarget._attachmentStateDepth !== depthBuffer ||
66+
renderTarget._attachmentStateStencil !== stencilBuffer ) {
67+
68+
renderTarget._attachmentState = `${ count }:${ format }:${ type }:${ samples }:${ depthBuffer }:${ stencilBuffer }`;
69+
renderTarget._attachmentStateFormat = format;
70+
renderTarget._attachmentStateType = type;
71+
renderTarget._attachmentStateSamples = samples;
72+
renderTarget._attachmentStateCount = count;
73+
renderTarget._attachmentStateDepth = depthBuffer;
74+
renderTarget._attachmentStateStencil = stencilBuffer;
75+
76+
}
77+
78+
attachmentState = renderTarget._attachmentState;
5879

5980
}
6081

src/renderers/common/Renderer.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,17 @@ class Renderer {
594594
*/
595595
this.onDeviceLost = this._onDeviceLost;
596596

597+
/**
598+
* A callback function that defines what should happen when an uncaptured
599+
* backend error is reported (e.g. a WebGPU validation/out-of-memory/internal
600+
* error raised outside an error scope). Applications can override this to
601+
* surface errors in their own UI without letting them escalate to a device
602+
* loss. The default implementation logs to the console.
603+
*
604+
* @type {Function}
605+
*/
606+
this.onError = this._onError;
607+
597608
/**
598609
* Defines the type of output buffers. The default `HalfFloatType` is recommend for
599610
* best quality. To save memory and bandwidth, `UnsignedByteType` might be used.
@@ -1196,6 +1207,26 @@ class Renderer {
11961207

11971208
}
11981209

1210+
/**
1211+
* Default implementation of the uncaptured backend error callback.
1212+
*
1213+
* @private
1214+
* @param {Object} info - Information about the uncaptured error.
1215+
*/
1216+
_onError( info ) {
1217+
1218+
let errorMessage = `THREE.WebGPURenderer: Uncaptured ${ info.api } ${ info.type }`;
1219+
1220+
if ( info.message ) {
1221+
1222+
errorMessage += `: ${ info.message }`;
1223+
1224+
}
1225+
1226+
error( errorMessage );
1227+
1228+
}
1229+
11991230
/**
12001231
* Renders the given render bundle.
12011232
*

0 commit comments

Comments
 (0)