|
@@ -449,7 +449,10 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
let uniformGPU;
|
|
|
|
|
|
- const bindings = this.bindings[ shaderStage ];
|
|
|
+ const group = node.groupNode;
|
|
|
+ const groupName = group.name;
|
|
|
+
|
|
|
+ const bindings = this.getBindGroupArray( groupName, shaderStage );
|
|
|
|
|
|
if ( type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'texture3D' ) {
|
|
|
|
|
@@ -457,15 +460,15 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
if ( type === 'texture' || type === 'storageTexture' ) {
|
|
|
|
|
|
- texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, node.access ? node.access : null );
|
|
|
+ texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group, node.access ? node.access : null );
|
|
|
|
|
|
} else if ( type === 'cubeTexture' ) {
|
|
|
|
|
|
- texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, node.access ? node.access : null );
|
|
|
+ texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, node.access ? node.access : null );
|
|
|
|
|
|
} else if ( type === 'texture3D' ) {
|
|
|
|
|
|
- texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, node.access ? node.access : null );
|
|
|
+ texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, node.access ? node.access : null );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -474,7 +477,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
if ( shaderStage === 'fragment' && this.isUnfilterable( node.value ) === false && texture.store === false ) {
|
|
|
|
|
|
- const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node );
|
|
|
+ const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node, group );
|
|
|
sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
|
|
|
|
bindings.push( sampler, texture );
|
|
@@ -492,7 +495,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
} else if ( type === 'buffer' || type === 'storageBuffer' ) {
|
|
|
|
|
|
const bufferClass = type === 'storageBuffer' ? NodeStorageBuffer : NodeUniformBuffer;
|
|
|
- const buffer = new bufferClass( node );
|
|
|
+ const buffer = new bufferClass( node, group );
|
|
|
buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
|
|
|
|
bindings.push( buffer );
|
|
@@ -501,9 +504,6 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- const group = node.groupNode;
|
|
|
- const groupName = group.name;
|
|
|
-
|
|
|
const uniformsStage = this.uniformGroups[ shaderStage ] || ( this.uniformGroups[ shaderStage ] = {} );
|
|
|
|
|
|
let uniformsGroup = uniformsStage[ groupName ];
|
|
@@ -527,12 +527,6 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
nodeData.uniformGPU = uniformGPU;
|
|
|
|
|
|
- if ( shaderStage === 'vertex' ) {
|
|
|
-
|
|
|
- this.bindingsOffset[ 'fragment' ] = bindings.length;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return uniformNode;
|
|
@@ -816,10 +810,11 @@ ${ flowData.code }
|
|
|
const structSnippets = [];
|
|
|
const uniformGroups = {};
|
|
|
|
|
|
- let index = this.bindingsOffset[ shaderStage ];
|
|
|
-
|
|
|
for ( const uniform of uniforms ) {
|
|
|
|
|
|
+ const groundName = uniform.groupNode.name;
|
|
|
+ const uniformIndexes = this.bindingsIndexes[ groundName ];
|
|
|
+
|
|
|
if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
|
|
|
|
|
|
const texture = uniform.node.value;
|
|
@@ -828,11 +823,11 @@ ${ flowData.code }
|
|
|
|
|
|
if ( texture.isDepthTexture === true && texture.compareFunction !== null ) {
|
|
|
|
|
|
- bindingSnippets.push( `@binding( ${index ++} ) @group( 0 ) var ${uniform.name}_sampler : sampler_comparison;` );
|
|
|
+ bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- bindingSnippets.push( `@binding( ${index ++} ) @group( 0 ) var ${uniform.name}_sampler : sampler;` );
|
|
|
+ bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler;` );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -865,7 +860,7 @@ ${ flowData.code }
|
|
|
const format = getFormat( texture );
|
|
|
const access = this.getStorageAccess( uniform.node );
|
|
|
|
|
|
- textureType = `texture_storage_2d<${ format }, ${access}>`;
|
|
|
+ textureType = `texture_storage_2d<${ format }, ${ access }>`;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -875,7 +870,7 @@ ${ flowData.code }
|
|
|
|
|
|
}
|
|
|
|
|
|
- bindingSnippets.push( `@binding( ${index ++} ) @group( 0 ) var ${uniform.name} : ${textureType};` );
|
|
|
+ bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name } : ${ textureType };` );
|
|
|
|
|
|
} else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' ) {
|
|
|
|
|
@@ -884,10 +879,10 @@ ${ flowData.code }
|
|
|
const bufferCount = bufferNode.bufferCount;
|
|
|
|
|
|
const bufferCountSnippet = bufferCount > 0 ? ', ' + bufferCount : '';
|
|
|
- const bufferSnippet = `\t${uniform.name} : array< ${bufferType}${bufferCountSnippet} >\n`;
|
|
|
+ const bufferSnippet = `\t${ uniform.name } : array< ${ bufferType }${ bufferCountSnippet } >\n`;
|
|
|
const bufferAccessMode = bufferNode.isStorageBufferNode ? 'storage,read_write' : 'uniform';
|
|
|
|
|
|
- bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, index ++ ) );
|
|
|
+ bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -895,7 +890,8 @@ ${ flowData.code }
|
|
|
const groupName = uniform.groupNode.name;
|
|
|
|
|
|
const group = uniformGroups[ groupName ] || ( uniformGroups[ groupName ] = {
|
|
|
- index: index ++,
|
|
|
+ index: uniformIndexes.binding ++,
|
|
|
+ id: uniformIndexes.group,
|
|
|
snippets: []
|
|
|
} );
|
|
|
|
|
@@ -909,7 +905,7 @@ ${ flowData.code }
|
|
|
|
|
|
const group = uniformGroups[ name ];
|
|
|
|
|
|
- structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index ) );
|
|
|
+ structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) );
|
|
|
|
|
|
}
|
|
|
|