Przeglądaj źródła

WGSLNodeBuilder: Add `allowGlobalVariables` (#33319)

sunag 1 tydzień temu
rodzic
commit
97d4621e96

+ 7 - 2
src/nodes/gpgpu/BarrierNode.js

@@ -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` );

+ 15 - 2
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -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 )

粤ICP备19079148号