Skip to content

Commit

Permalink
barrier, private array, workgroup array support
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhhelgeson committed Aug 25, 2024
1 parent a0c9a2f commit 2880e0f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export { default as RangeNode, range } from './geometry/RangeNode.js';

// gpgpu
export { default as ComputeNode, compute } from './gpgpu/ComputeNode.js';
export { default as ScopedArrayNode, workgroupArray, privateArray } from './gpgpu/ScopedArrayNode.js';
export { workgroupBarrier, textureBarrier, storageBarrier } from './gpgpu/BarrierNode.js';

// lighting
export { default as LightNode, lightTargetDirection } from './lighting/LightNode.js';
Expand Down
5 changes: 5 additions & 0 deletions src/nodes/gpgpu/BarrierNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expression } from '../code/ExpressionNode';

export const workgroupBarrier = () => expression( 'workgroupBarrier();' ).append();
export const storageBarrier = () => expression( 'storageBarrier();' ).append();
export const textureBarrier = () => expression( 'textureBarrier();' ).append();
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ArrayElementNode from '../utils/ArrayElementNode.js';
import { nodeObject, addNodeElement } from '../shadernode/ShaderNode.js';
import Node, { addNodeClass } from '../core/Node.js';

class ScopedArrayElementNode extends ArrayElementNode {

Expand Down Expand Up @@ -36,17 +38,16 @@ class ScopedArrayElementNode extends ArrayElementNode {

class ScopedArrayNode extends Node {

constructor( value, bufferType, bufferCount = 0 ) {
constructor( scope, bufferType, bufferCount = 0 ) {

super( value, bufferType );
super( bufferType );

this.bufferType = bufferType;
this.bufferCount = bufferCount;

this.isWorkgroupArrayNode = true;

this.scope = 'workgroup';
this.isScopedArrayNode = true;

this.scope = scope;

}

Expand Down Expand Up @@ -80,16 +81,22 @@ class ScopedArrayNode extends Node {

element( indexNode ) {

return new ScopedArrayElementNode( this, indexNode );
return nodeObject( new ScopedArrayElementNode( this, indexNode ) );

}

generate( builder ) {

return builder.getScopedArray( this.name || `${this.scope}Array${this.id}`, this.scope, this.bufferType, this.bufferCount );
return builder.getScopedArray( this.name || `${this.scope}Array_${this.id}`, this.scope.toLowerCase(), this.bufferType, this.bufferCount );

}

}

export default ScopedArrayNode;

export const workgroupArray = ( type, count ) => nodeObject( new ScopedArrayNode( 'Workgroup', type, count ) );
export const privateArray = ( type, count ) => nodeObject( new ScopedArrayNode( 'Private', type, count ) );

addNodeClass( 'ScopedArrayNode', ScopedArrayNode );

5 changes: 3 additions & 2 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,11 @@ ${ flowData.code }

const type = this.getType( bufferType );

snippets.push( `@var<${scope}> ${name}: array< ${type} : ${bufferCount};` );
snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` );

}

return snippets.join( ',\n\t' );
return snippets.join( '\n' );

}

Expand Down Expand Up @@ -1173,6 +1173,7 @@ ${ flowData.code }
} else {

this.computeShader = this._getWGSLComputeCode( shadersData.compute, ( this.object.workgroupSize || [ 64 ] ).join( ', ' ) );
console.log( this.computeShader );

}

Expand Down

0 comments on commit 2880e0f

Please sign in to comment.