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
9 changes: 7 additions & 2 deletions src/nodes/gpgpu/BarrierNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ class BarrierNode extends Node {

}

setup( builder ) {

builder.allowEarlyReturns = false;
builder.allowGlobalVariables = false;

}

generate( builder ) {

const { scope } = this;
const { renderer } = builder;

builder.allowEarlyReturns = false;

if ( renderer.backend.isWebGLBackend === true ) {

builder.addFlowCode( `\t// ${scope}Barrier \n` );
Expand Down
17 changes: 15 additions & 2 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ class WGSLNodeBuilder extends NodeBuilder {
*/
this.allowEarlyReturns = true;

/**
* A flag that indicates that global variables are allowed.
*
* @type {boolean}
* @default true
*/
this.allowGlobalVariables = true;

}

/**
Expand Down Expand Up @@ -2081,12 +2089,14 @@ ${ flowData.code }

this.shaderStage = shaderStage;

const allowGlobal = this.allowGlobalVariables;

const stageData = shadersData[ shaderStage ];
stageData.uniforms = this.getUniforms( shaderStage );
stageData.attributes = this.getAttributes( shaderStage );
stageData.varyings = this.getVaryings( shaderStage );
stageData.structs = this.getStructs( shaderStage );
stageData.vars = this.getVars( shaderStage, true );
stageData.vars = this.getVars( shaderStage, allowGlobal );
stageData.codes = this.getCodes( shaderStage );
stageData.directives = this.getDirectives( shaderStage );
stageData.scopedArrays = this.getScopedArrays( shaderStage );
Expand Down Expand Up @@ -2445,14 +2455,17 @@ ${ shaderData.structs }
${ shaderData.uniforms }

// vars
${ shaderData.vars }
${ this.allowGlobalVariables ? shaderData.vars : '' }

// codes
${ shaderData.codes }

@compute @workgroup_size( ${ workgroupSizeX }, ${ workgroupSizeY }, ${ workgroupSizeZ } )
fn main( ${ shaderData.attributes } ) {

// local vars
${ this.allowGlobalVariables ? '' : shaderData.vars }

// system
instanceIndex = globalId.x
+ globalId.y * ( ${ workgroupSizeX } * numWorkgroups.x )
Expand Down
Loading