瀏覽代碼

WebGPURenderer: Bind groups cache per renderer (#28730)

sunag 1 年之前
父節點
當前提交
f43a827cbd
共有 1 個文件被更改,包括 19 次插入1 次删除
  1. 19 1
      examples/jsm/nodes/core/NodeBuilder.js

+ 19 - 1
examples/jsm/nodes/core/NodeBuilder.js

@@ -30,7 +30,7 @@ import ChainMap from '../../renderers/common/ChainMap.js';
 
 import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
 
-const bindGroupsCache = new ChainMap();
+const rendererCache = new WeakMap();
 
 const typeFromLength = new Map( [
 	[ 2, 'vec2' ],
@@ -123,6 +123,22 @@ class NodeBuilder {
 
 	}
 
+	getBingGroupsCache() {
+
+		let bindGroupsCache = rendererCache.get( this.renderer );
+
+		if ( bindGroupsCache === undefined ) {
+
+			bindGroupsCache = new ChainMap();
+
+			rendererCache.set( this.renderer, bindGroupsCache );
+
+		}
+
+		return bindGroupsCache;
+
+	}
+
 	createRenderTarget( width, height, options ) {
 
 		return new RenderTarget( width, height, options );
@@ -151,6 +167,8 @@ class NodeBuilder {
 
 	_getBindGroup( groupName, bindings ) {
 
+		const bindGroupsCache = this.getBingGroupsCache();
+
 		// cache individual uniforms group
 
 		const bindingsArray = [];