Przeglądaj źródła

WebGPURenderer: Remove outdated bind groups. (#33011)

Michael Herzog 1 tydzień temu
rodzic
commit
f629c33ac5

+ 5 - 5
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;
-
 					}
 
 				}

+ 16 - 0
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 --;

粤ICP备19079148号