From f629c33ac57a59ccccee9aa85d3934c62172e7ac Mon Sep 17 00:00:00 2001 From: Michael Herzog Date: Tue, 17 Feb 2026 02:30:15 +0100 Subject: [PATCH] WebGPURenderer: Remove outdated bind groups. (#33011) --- src/renderers/common/Bindings.js | 10 +++++----- src/renderers/common/Textures.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/renderers/common/Bindings.js b/src/renderers/common/Bindings.js index ef50fa4d412f61..6c188fc1cf3787 100644 --- a/src/renderers/common/Bindings.js +++ b/src/renderers/common/Bindings.js @@ -306,7 +306,7 @@ class Bindings extends DataMap { this.textures.updateTexture( texture ); - // generation: update the bindings if a new texture has been created + // generation: update the bindings if the binding refers to a different texture object if ( binding.generation !== texturesTextureData.generation ) { @@ -314,10 +314,12 @@ class Bindings extends DataMap { needsBindingsUpdate = true; - cacheBindings = false; - } + // keep track which bind groups refer to the current texture (this is needed for dispose) + + texturesTextureData.bindGroups.add( bindGroup ); + } const textureData = backend.get( texture ); @@ -365,8 +367,6 @@ class Bindings extends DataMap { needsBindingsUpdate = true; - cacheBindings = false; - } } diff --git a/src/renderers/common/Textures.js b/src/renderers/common/Textures.js index b1eab665e9b526..37dd6b2eb60fb8 100644 --- a/src/renderers/common/Textures.js +++ b/src/renderers/common/Textures.js @@ -318,6 +318,7 @@ class Textures extends DataMap { textureData.initialized = true; textureData.generation = texture.version; + textureData.bindGroups = new Set(); // @@ -531,6 +532,21 @@ class Textures extends DataMap { const isDefaultTexture = textureData.isDefaultTexture; this.backend.destroyTexture( texture, isDefaultTexture ); + // delete cached bind groups so they don't point to destroyed textures + + if ( textureData.bindGroups ) { + + for ( const bindGroup of textureData.bindGroups ) { + + const bindingsData = this.backend.get( bindGroup ); + + bindingsData.groups = undefined; + bindingsData.versions = undefined; + + } + + } + this.delete( texture ); this.info.memory.textures --;