|
|
@@ -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;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -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 );
|
|
|
@@ -2445,7 +2455,7 @@ ${ shaderData.structs }
|
|
|
${ shaderData.uniforms }
|
|
|
|
|
|
// vars
|
|
|
-${ shaderData.vars }
|
|
|
+${ this.allowGlobalVariables ? shaderData.vars : '' }
|
|
|
|
|
|
// codes
|
|
|
${ shaderData.codes }
|
|
|
@@ -2453,6 +2463,9 @@ ${ 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 )
|