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

WebGPURenderer: Improve cache key verification (#32138)

* NodeBuilder: add `id`

* improve custom cache key
sunag 2 месяцев назад
Родитель
Сommit
e681ffb807

+ 2 - 2
src/nodes/core/Node.js

@@ -402,7 +402,7 @@ class Node extends EventDispatcher {
 
 			//
 
-			const values = [ this.id ];
+			const values = [];
 
 			for ( const { property, childNode } of this._getChildren( ignores ) ) {
 
@@ -428,7 +428,7 @@ class Node extends EventDispatcher {
 	 */
 	customCacheKey() {
 
-		return 0;
+		return this.id;
 
 	}
 

+ 4 - 0
src/nodes/core/NodeBuilder.js

@@ -33,6 +33,8 @@ import { Vector4 } from '../../math/Vector4.js';
 import { Float16BufferAttribute } from '../../core/BufferAttribute.js';
 import { warn, error } from '../../utils.js';
 
+let _id = 0;
+
 const rendererCache = new WeakMap();
 
 const typeFromArray = new Map( [
@@ -459,6 +461,8 @@ class NodeBuilder {
 		 */
 		this.fnCall = null;
 
+		Object.defineProperty( this, 'id', { value: _id ++ } );
+
 	}
 
 	/**

+ 7 - 0
src/nodes/core/PropertyNode.js

@@ -1,5 +1,6 @@
 import Node from './Node.js';
 import { nodeImmutable, nodeObject } from '../tsl/TSLCore.js';
+import { hashString } from './NodeUtils.js';
 
 /**
  * This class represents a shader property. It can be used
@@ -68,6 +69,12 @@ class PropertyNode extends Node {
 
 	}
 
+	customCacheKey() {
+
+		return hashString( this.type + ':' + ( this.name || '' ) + ':' + ( this.varying ? '1' : '0' ) );
+
+	}
+
 	getHash( builder ) {
 
 		return this.name || super.getHash( builder );

+ 2 - 0
src/renderers/common/RenderObject.js

@@ -869,6 +869,8 @@ class RenderObject {
 
 		}
 
+		cacheKey = hash( cacheKey, this.camera.id );
+
 		return cacheKey;
 
 	}

粤ICP备19079148号