diff --git a/src/nodes/core/NodeBuilder.js b/src/nodes/core/NodeBuilder.js index 15af8f4e155279..237096e9f89b7e 100644 --- a/src/nodes/core/NodeBuilder.js +++ b/src/nodes/core/NodeBuilder.js @@ -625,14 +625,6 @@ class NodeBuilder { bindingGroupsCache.set( cacheKey, bindGroup ); - } else { - - for ( let i = 0; i < bindings.length; i ++ ) { - - bindGroup.bindings[ i ].visibility |= bindings[ i ].visibility; - - } - } } else { diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 32625036a78ae4..aa68369e4c0e0e 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1151,8 +1151,8 @@ class WGSLNodeBuilder extends NodeBuilder { } - // Update visibility to include this shader stage (bitwise OR) - uniformsGroup.setVisibility( uniformsGroup.getVisibility() | gpuShaderStageLib[ shaderStage ] ); + // TODO: Verifier caches + uniformsGroup.setVisibility( GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE ); // Add to bindings for this stage if not already present if ( bindings.indexOf( uniformsGroup ) === - 1 ) { diff --git a/src/renderers/webgpu/utils/WebGPUBindingUtils.js b/src/renderers/webgpu/utils/WebGPUBindingUtils.js index 3a90fb75077b1c..3136a7bf2978c4 100644 --- a/src/renderers/webgpu/utils/WebGPUBindingUtils.js +++ b/src/renderers/webgpu/utils/WebGPUBindingUtils.js @@ -6,7 +6,6 @@ import { import { FloatType, IntType, UnsignedIntType, Compatibility } from '../../../constants.js'; import { NodeAccess } from '../../../nodes/core/constants.js'; import { isTypedArray, error } from '../../../utils.js'; -import { hashString } from '../../../nodes/core/NodeUtils.js'; /** * Class representing a WebGPU bind group layout. @@ -89,63 +88,36 @@ class WebGPUBindingUtils { const bindingsData = backend.get( bindGroup ); - const entries = this._createLayoutEntries( bindGroup ); - const bindGroupLayoutHash = hashString( JSON.stringify( entries ) ); - - let layoutChanged = false; - - // check if the bind group already has a layout and if it's still valid + // check if the the bind group already has a layout if ( bindingsData.layout ) { - // if the layout hash changed (e.g. visibility was updated), invalidate the old layout - - if ( bindingsData.layoutHash !== bindGroupLayoutHash ) { - - bindingsData.layout.usedTimes --; - - if ( bindingsData.layout.usedTimes === 0 ) { - - this._bindGroupLayoutCache.delete( bindingsData.layoutHash ); - - } - - bindingsData.layout = undefined; - bindingsData.layoutHash = undefined; - - layoutChanged = true; + return bindingsData.layout.layoutGPU; - } else { + } - return bindingsData.layout.layoutGPU; + // if not, assing one - } + const entries = this._createLayoutEntries( bindGroup ); + const bindGroupLayoutKey = JSON.stringify( entries ); - } + // try to find an existing layout in the cache - // create or reuse a bind group layout from the cache + let bindGroupLayout = this._bindGroupLayoutCache.get( bindGroupLayoutKey ); - let bindGroupLayout = this._bindGroupLayoutCache.get( bindGroupLayoutHash ); + // if not create a new one if ( bindGroupLayout === undefined ) { bindGroupLayout = new BindGroupLayout( device.createBindGroupLayout( { entries } ) ); - this._bindGroupLayoutCache.set( bindGroupLayoutHash, bindGroupLayout ); + this._bindGroupLayoutCache.set( bindGroupLayoutKey, bindGroupLayout ); } bindGroupLayout.usedTimes ++; bindingsData.layout = bindGroupLayout; - bindingsData.layoutHash = bindGroupLayoutHash; - - // if layout changed, recreate the GPU bind group with the new layout - - if ( layoutChanged ) { - - bindingsData.group = this.createBindGroup( bindGroup, bindGroupLayout.layoutGPU ); - - } + bindingsData.layoutKey = bindGroupLayoutKey; return bindGroupLayout.layoutGPU; @@ -644,12 +616,12 @@ class WebGPUBindingUtils { if ( bindingsData.layout.usedTimes === 0 ) { - this._bindGroupLayoutCache.delete( bindingsData.layoutHash ); + this._bindGroupLayoutCache.delete( bindingsData.layoutKey ); } bindingsData.layout = undefined; - bindingsData.layoutHash = undefined; + bindingsData.layoutKey = undefined; } diff --git a/src/renderers/webgpu/utils/WebGPUPipelineUtils.js b/src/renderers/webgpu/utils/WebGPUPipelineUtils.js index edf130736544f0..1fac51cac04800 100644 --- a/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +++ b/src/renderers/webgpu/utils/WebGPUPipelineUtils.js @@ -105,8 +105,8 @@ class WebGPUPipelineUtils { for ( const bindGroup of renderObject.getBindings() ) { - // ensure layout is up to date (visibility may have changed due to shared bind groups) - const layoutGPU = backend.bindingUtils.createBindingsLayout( bindGroup ); + const bindingsData = backend.get( bindGroup ); + const { layoutGPU } = bindingsData.layout; bindGroupLayouts.push( layoutGPU ); @@ -366,8 +366,8 @@ class WebGPUPipelineUtils { for ( const bindingsGroup of bindings ) { - // ensure layout is up to date (visibility may have changed due to shared bind groups) - const layoutGPU = backend.bindingUtils.createBindingsLayout( bindingsGroup ); + const bindingsData = backend.get( bindingsGroup ); + const { layoutGPU } = bindingsData.layout; bindGroupLayouts.push( layoutGPU );