diff --git a/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js b/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js index 2be6228643a2d6ec5d6448cddc31e00762e295f1..f3021b4b84c5d0a150a0e08b8393db1584e489eb 100644 --- a/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +++ b/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js @@ -29,13 +29,13 @@ class WebGPURenderPipelines { const properties = this.properties; const material = object.material; - const materialProperties = properties.get( material ); - const objectProperties = properties.get( object ); - let currentPipeline = objectProperties.currentPipeline; + const cache = this._getCache( object ); + + let currentPipeline; - if ( this._needsUpdate( object ) ) { + if ( this._needsUpdate( object, cache ) ) { // get shader @@ -64,7 +64,7 @@ class WebGPURenderPipelines { // determine render pipeline currentPipeline = this._acquirePipeline( stageVertex, stageFragment, object, nodeBuilder ); - objectProperties.currentPipeline = currentPipeline; + cache.currentPipeline = currentPipeline; // keep track of all pipelines which are used by a material @@ -98,6 +98,10 @@ class WebGPURenderPipelines { } + } else { + + currentPipeline = cache.currentPipeline; + } return currentPipeline; @@ -174,6 +178,21 @@ class WebGPURenderPipelines { } + _getCache( object ) { + + let cache = this.objectCache.get( object ); + + if ( cache === undefined ) { + + cache = {}; + this.objectCache.set( object, cache ); + + } + + return cache; + + } + _releasePipeline( pipeline ) { if ( -- pipeline.usedTimes === 0 ) { @@ -204,16 +223,7 @@ class WebGPURenderPipelines { } - _needsUpdate( object ) { - - let cache = this.objectCache.get( object ); - - if ( cache === undefined ) { - - cache = {}; - this.objectCache.set( object, cache ); - - } + _needsUpdate( object, cache ) { const material = object.material;