Attributes: Support explicit disposal & invalidate bind groups on rebind#33468
Attributes: Support explicit disposal & invalidate bind groups on rebind#33468thelazylamaGit wants to merge 6 commits into
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
This change potentially breaks VAO setups which is why we have never supported per attribute disposal. Please study the past work on this topic, starting from #15261 and related PRs and issues. |
|
@Mugen87 I've read through the past writing on this topic and now see the problem. Allowing disposal on all attributes & backends safely would require some kind of reverse dependency tracking similar to how Textures.js currently handles it. This would mean broader architectural changes that I myself am not confident enough to implement. However, given the main issue here is the reassignment of // Standalone disposal is currently limited to WebGPU storage/indirect attributes.
// Other attribute types would require additional render-state invalidation before this is safe.
if ( this.backend.isWebGPUBackend === true && ( type === AttributeType.STORAGE || type === AttributeType.INDIRECT ) ) {
data.onDispose = () => this.delete( attribute );
attribute.addEventListener( 'dispose', data.onDispose );
}This would still fix the primary issue mentioned in #32969 as well as my own issues without requiring any wider changes or potential webGL regressions. |
|
@Mugen87 I understand the issue about VAO invalidation but with the new flexibility that WebGPU brings I think this needs to be resolved. As far as I understand it's possible to use a "StorageBufferAttribute" as a geometry buffer attribute so if we're going to allow for StorageBufferAttributes to be disposed then geometries need to be resilient to these disposal events. I don't necessarily think this needs to be fixed in WebGLRenderer but at a high level it seems like we could invalidate and dispose the geometry VAO (or the WebGPU equivalent) when one of these events fires. This wouldn't mean disposing of the whole geometry but before rendering the geometry, the renderer would check whether the VAO is present and recreate it and any attributes if needed. |
Related issue: #32969
Description
Adds
disposeevent listener to bufferAttributes so that they are able to be explicitly disposed rather than only disposed alongside geometry. This brings their behaviour more in line with other GPU resources such as textures.Additionally, #32847 made it so that
StorageBufferAttributescould be changed between compute calls, however, WebGPU would continue to use the old cachedGPUBindGroupcausing errors such as[Buffer] used in submit while destroyed.This PR makes it so that when bufferAttributes are reassigned, their bind group becomes invalidated.Overall, these changes allow for dynamic resizing & reassignment of storageBufferAttributes. Fixing the memory leak that can be seen with the example below
Before (note storageAttribute count):
storageBufferMemLeak.mp4
After:
fixedstorageBufferMemLeakFixed.mp4