Skip to content

Commit

Permalink
WebGPURenderer: Cache GPUBindGroupLayouts (#29158)
Browse files Browse the repository at this point in the history
* cache BindGroupLayouts

* rename parameter and add default

---------

Co-authored-by: aardgoose <[email protected]>
  • Loading branch information
aardgoose and aardgoose authored Aug 19, 2024
1 parent bc35f46 commit 9e7f112
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ class NodeBuilder {

if ( bindGroup === undefined ) {

bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray );

bindGroupsCache.set( bindingsArray, bindGroup );

}

} else {

bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray );

}

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/common/BindGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ let _id = 0;

class BindGroup {

constructor( name = '', bindings = [], index = 0 ) {
constructor( name = '', bindings = [], index = 0, bindingsReference = [] ) {

this.name = name;
this.bindings = bindings;
this.index = index;
this.bindingsReference = bindingsReference;

this.id = _id ++;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/nodes/NodeBuilderState.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NodeBuilderState {

if ( shared !== true ) {

const bindingsGroup = new BindGroup( instanceGroup.name, [], instanceGroup.index );
const bindingsGroup = new BindGroup( instanceGroup.name, [], instanceGroup.index, instanceGroup );
bindings.push( bindingsGroup );

for ( const instanceBinding of instanceGroup.bindings ) {
Expand Down
13 changes: 11 additions & 2 deletions src/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WebGPUBindingUtils {
constructor( backend ) {

this.backend = backend;
this.bindGroupLayoutCache = new WeakMap();

}

Expand Down Expand Up @@ -135,12 +136,20 @@ class WebGPUBindingUtils {

createBindings( bindGroup ) {

const backend = this.backend;
const { backend, bindGroupLayoutCache } = this;
const bindingsData = backend.get( bindGroup );

// setup (static) binding layout and (dynamic) binding group

const bindLayoutGPU = this.createBindingsLayout( bindGroup );
let bindLayoutGPU = bindGroupLayoutCache.get( bindGroup.bindingsReference );

if ( bindLayoutGPU === undefined ) {

bindLayoutGPU = this.createBindingsLayout( bindGroup );
bindGroupLayoutCache.set( bindGroup.bindingsReference, bindLayoutGPU );

}

const bindGroupGPU = this.createBindGroup( bindGroup, bindLayoutGPU );

bindingsData.layout = bindLayoutGPU;
Expand Down

0 comments on commit 9e7f112

Please sign in to comment.