Просмотр исходного кода

WebGPURenderer: Reduce bindingGroup creation for data texture content updates. (#29183)

Cleanup code

Co-authored-by: aardgoose <angus.sawyer@email.com>
aardgoose 1 год назад
Родитель
Сommit
00f91753a7

+ 2 - 2
src/renderers/common/Backend.js

@@ -43,9 +43,9 @@ class Backend {
 
 	// bindings
 
-	createBindings( /*renderObject*/ ) { }
+	createBindings( /*bingGroup, bindings*/ ) { }
 
-	updateBindings( /*renderObject*/ ) { }
+	updateBindings( /*bingGroup, bindings*/ ) { }
 
 	// pipeline
 

+ 13 - 15
src/renderers/common/Bindings.js

@@ -70,21 +70,21 @@ class Bindings extends DataMap {
 
 	updateForCompute( computeNode ) {
 
-		this._updateBindings( computeNode, this.getForCompute( computeNode ) );
+		this._updateBindings( this.getForCompute( computeNode ) );
 
 	}
 
 	updateForRender( renderObject ) {
 
-		this._updateBindings( renderObject, this.getForRender( renderObject ) );
+		this._updateBindings( this.getForRender( renderObject ) );
 
 	}
 
-	_updateBindings( object, bindings ) {
+	_updateBindings( bindings ) {
 
 		for ( const bindGroup of bindings ) {
 
-			this._update( object, bindGroup, bindings );
+			this._update( bindGroup, bindings );
 
 		}
 
@@ -110,7 +110,7 @@ class Bindings extends DataMap {
 
 	}
 
-	_update( object, bindGroup, bindings ) {
+	_update( bindGroup, bindings ) {
 
 		const { backend } = this;
 
@@ -144,26 +144,26 @@ class Bindings extends DataMap {
 
 			} else if ( binding.isSampledTexture ) {
 
-				const texture = binding.texture;
-
-				if ( binding.needsBindingsUpdate ) needsBindingsUpdate = true;
+				if ( binding.needsBindingsUpdate( this.textures.get( binding.texture ).generation ) ) needsBindingsUpdate = true;
 
 				const updated = binding.update();
 
+				const texture = binding.texture;
+
 				if ( updated ) {
 
-					this.textures.updateTexture( binding.texture );
+					this.textures.updateTexture( texture );
 
 				}
 
-				const textureData = backend.get( binding.texture );
+				const textureData = backend.get( texture );
 
 				if ( backend.isWebGPUBackend === true && textureData.texture === undefined && textureData.externalTexture === undefined ) {
 
 					// TODO: Remove this once we found why updated === false isn't bound to a texture in the WebGPU backend
-					console.error( 'Bindings._update: binding should be available:', binding, updated, binding.texture, binding.textureNode.value );
+					console.error( 'Bindings._update: binding should be available:', binding, updated, texture, binding.textureNode.value, needsBindingsUpdate );
 
-					this.textures.updateTexture( binding.texture );
+					this.textures.updateTexture( texture );
 					needsBindingsUpdate = true;
 
 				}
@@ -192,9 +192,7 @@ class Bindings extends DataMap {
 
 		if ( needsBindingsUpdate === true ) {
 
-			const pipeline = this.pipelines.getForRender( object );
-
-			this.backend.updateBindings( bindGroup, bindings, pipeline );
+			this.backend.updateBindings( bindGroup, bindings );
 
 		}
 

+ 12 - 3
src/renderers/common/SampledTexture.js

@@ -13,16 +13,25 @@ class SampledTexture extends Binding {
 		this.texture = texture;
 		this.version = texture ? texture.version : 0;
 		this.store = false;
+		this.generation = null;
 
 		this.isSampledTexture = true;
 
 	}
 
-	get needsBindingsUpdate() {
+	needsBindingsUpdate( generation ) {
 
-		const { texture, version } = this;
+		const { texture } = this;
+
+		if ( generation !== this.generation ) {
+
+			this.generation = generation;
+
+			return true;
+
+		}
 
-		return texture.isVideoTexture ? true : version !== texture.version; // @TODO: version === 0 && texture.version > 0 ( add it just to External Textures like PNG,JPG )
+		return texture.isVideoTexture;
 
 	}
 

+ 5 - 0
src/renderers/common/Textures.js

@@ -173,6 +173,8 @@ class Textures extends DataMap {
 			backend.createSampler( texture );
 			backend.createTexture( texture, options );
 
+			textureData.generation = texture.version;
+
 		} else {
 
 			const needsCreate = textureData.initialized !== true;
@@ -216,6 +218,7 @@ class Textures extends DataMap {
 						backend.createTexture( texture, options );
 
 						textureData.isDefaultTexture = false;
+						textureData.generation = texture.version;
 
 					}
 
@@ -232,6 +235,7 @@ class Textures extends DataMap {
 				backend.createDefaultTexture( texture );
 
 				textureData.isDefaultTexture = true;
+				textureData.generation = texture.version;
 
 			}
 
@@ -242,6 +246,7 @@ class Textures extends DataMap {
 		if ( textureData.initialized !== true ) {
 
 			textureData.initialized = true;
+			textureData.generation = texture.version;
 
 			//
 

+ 2 - 2
src/renderers/common/nodes/NodeSampledTexture.js

@@ -13,9 +13,9 @@ class NodeSampledTexture extends SampledTexture {
 
 	}
 
-	get needsBindingsUpdate() {
+	needsBindingsUpdate( generation ) {
 
-		return this.textureNode.value !== this.texture || super.needsBindingsUpdate;
+		return this.textureNode.value !== this.texture || super.needsBindingsUpdate( generation );
 
 	}
 

粤ICP备19079148号