Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
54 changes: 13 additions & 41 deletions src/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

}

Expand Down
8 changes: 4 additions & 4 deletions src/renderers/webgpu/utils/WebGPUPipelineUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down