From f43a827cbd1c129614e3d47562d0d7e865e05bf7 Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 23 Jun 2024 23:29:19 -0300 Subject: [PATCH] WebGPURenderer: Bind groups cache per renderer (#28730) --- examples/jsm/nodes/core/NodeBuilder.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/jsm/nodes/core/NodeBuilder.js b/examples/jsm/nodes/core/NodeBuilder.js index 75e560e01436b8..96b2af785c3bdc 100644 --- a/examples/jsm/nodes/core/NodeBuilder.js +++ b/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 = [];