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
17 changes: 17 additions & 0 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ class NodeBuilder {

}

sortBindingGroups() {

const bindingsGroups = this.getBindings();

bindingsGroups.sort( ( a, b ) => ( a.bindings[ 0 ].groupNode.order - b.bindings[ 0 ].groupNode.order ) );

for ( let i = 0; i < bindingsGroups.length; i ++ ) {

const bindingGroup = bindingsGroups[ i ];
this.bindingsIndexes[ bindingGroup.name ].group = i;

bindingGroup.index = i;

}

}

setHashNode( node, hash ) {

this.hashNodes[ hash ] = node;
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/core/UniformGroupNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class UniformGroupNode extends Node {

}

constructor( name, shared = false ) {
constructor( name, shared = false, order = 1 ) {

super( 'string' );

this.name = name;
this.version = 0;

this.shared = shared;

this.order = order;
this.isUniformGroup = true;

}
Expand Down Expand Up @@ -52,7 +52,7 @@ class UniformGroupNode extends Node {
export default UniformGroupNode;

export const uniformGroup = ( name ) => new UniformGroupNode( name );
export const sharedUniformGroup = ( name ) => new UniformGroupNode( name, true );
export const sharedUniformGroup = ( name, order = 0 ) => new UniformGroupNode( name, true, order );

export const frameGroup = /*@__PURE__*/ sharedUniformGroup( 'frame' );
export const renderGroup = /*@__PURE__*/ sharedUniformGroup( 'render' );
Expand Down
15 changes: 11 additions & 4 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class WebGPUBackend extends Backend {
renderContextData.descriptor = descriptor;
renderContextData.encoder = encoder;
renderContextData.currentPass = currentPass;
renderContextData.currentSets = { attributes: {}, pipeline: null, index: null };
renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
renderContextData.renderBundles = [];

//
Expand Down Expand Up @@ -848,12 +848,19 @@ class WebGPUBackend extends Backend {

// bind groups

const currentBindingGroups = currentSets.bindingGroups;

for ( let i = 0, l = bindings.length; i < l; i ++ ) {

const bindGroup = bindings[ i ];
const bindingsData = this.get( bindGroup );

passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) {

passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
currentBindingGroups[ bindGroup.index ] = bindGroup.id;

}

}

Expand Down Expand Up @@ -1286,7 +1293,7 @@ class WebGPUBackend extends Backend {
renderContextData._currentPass = renderContextData.currentPass;
renderContextData._currentSets = renderContextData.currentSets;

renderContextData.currentSets = { attributes: {}, pipeline: null, index: null };
renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
renderContextData.currentPass = this.pipelineUtils.createBundleEncoder( renderContext );

}
Expand Down Expand Up @@ -1515,7 +1522,7 @@ class WebGPUBackend extends Backend {
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;

renderContextData.currentPass = encoder.beginRenderPass( descriptor );
renderContextData.currentSets = { attributes: {}, pipeline: null, index: null };
renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };

}

Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ ${ flowData.code }

const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };

this.sortBindingGroups();

for ( const shaderStage in shadersData ) {

const stageData = shadersData[ shaderStage ];
Expand Down