Просмотр исходного кода

Revert "TSL: Forces assignment of a function call if a loop is detected (#31961)" (#31975)

This reverts commit 27bed7203c3852b17def83bbcd916195fb61e54a.
sunag 3 месяцев назад
Родитель
Сommit
699e1fa3a2

+ 9 - 3
src/nodes/core/ContextNode.js

@@ -94,7 +94,9 @@ class ContextNode extends Node {
 
 
 	analyze( builder ) {
 	analyze( builder ) {
 
 
-		const previousContext = builder.addContext( this.value );
+		const previousContext = builder.getContext();
+
+		builder.setContext( { ...builder.context, ...this.value } );
 
 
 		this.node.build( builder );
 		this.node.build( builder );
 
 
@@ -104,7 +106,9 @@ class ContextNode extends Node {
 
 
 	setup( builder ) {
 	setup( builder ) {
 
 
-		const previousContext = builder.addContext( this.value );
+		const previousContext = builder.getContext();
+
+		builder.setContext( { ...builder.context, ...this.value } );
 
 
 		this.node.build( builder );
 		this.node.build( builder );
 
 
@@ -114,7 +118,9 @@ class ContextNode extends Node {
 
 
 	generate( builder, output ) {
 	generate( builder, output ) {
 
 
-		const previousContext = builder.addContext( this.value );
+		const previousContext = builder.getContext();
+
+		builder.setContext( { ...builder.context, ...this.value } );
 
 
 		const snippet = this.node.build( builder, output );
 		const snippet = this.node.build( builder, output );
 
 

+ 0 - 16
src/nodes/core/NodeBuilder.js

@@ -899,22 +899,6 @@ class NodeBuilder {
 
 
 	}
 	}
 
 
-	/**
-	 * Adds context data to the builder's current context.
-	 *
-	 * @param {Object} context - The context to add.
-	 * @return {Object} The previous context.
-	 */
-	addContext( context ) {
-
-		const previousContext = this.getContext();
-
-		this.setContext( { ...this.context, ...context } );
-
-		return previousContext;
-
-	}
-
 	/**
 	/**
 	 * Gets a context used in shader construction that can be shared across different materials.
 	 * Gets a context used in shader construction that can be shared across different materials.
 	 * This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
 	 * This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.

+ 16 - 4
src/nodes/core/StackNode.js

@@ -261,9 +261,15 @@ class StackNode extends Node {
 
 
 		for ( const childNode of this.getChildren() ) {
 		for ( const childNode of this.getChildren() ) {
 
 
-			if ( childNode.isVarNode && childNode.isAssign( builder ) !== true ) {
+			if ( childNode.isVarNode && childNode.intent === true ) {
 
 
-				continue;
+				const properties = builder.getNodeProperties( childNode );
+
+				if ( properties.assign !== true ) {
+
+					continue;
+
+				}
 
 
 			}
 			}
 
 
@@ -296,9 +302,15 @@ class StackNode extends Node {
 
 
 		for ( const node of this.nodes ) {
 		for ( const node of this.nodes ) {
 
 
-			if ( node.isVarNode && node.isAssign( builder ) !== true ) {
+			if ( node.isVarNode && node.intent === true ) {
 
 
-				continue;
+				const properties = builder.getNodeProperties( node );
+
+				if ( properties.assign !== true ) {
+
+					continue;
+
+				}
 
 
 			}
 			}
 
 

+ 2 - 41
src/nodes/core/VarNode.js

@@ -146,53 +146,14 @@ class VarNode extends Node {
 
 
 	}
 	}
 
 
-	isAssign( builder ) {
-
-		if ( this.intent !== true ) return true;
-
-		//
-
-		const properties = builder.getNodeProperties( this );
-
-		let assign = properties.assign;
-
-		if ( assign !== true ) {
-
-			if ( this.node.isShaderCallNodeInternal && this.node.shaderNode.getLayout() === null ) {
-
-				if ( builder.context.fnCall && builder.context.fnCall.shaderNode ) {
-
-					const nodeType = this.node.getNodeType( builder );
-
-					if ( nodeType !== 'void' ) {
-
-						const shaderNodeData = builder.getDataFromNode( this.node.shaderNode );
-
-						if ( shaderNodeData.hasLoop ) {
-
-							assign = true;
-
-						}
-
-					}
-
-				}
-
-			}
-
-		}
-
-		return assign;
-
-	}
-
 	build( ...params ) {
 	build( ...params ) {
 
 
 		if ( this.intent === true ) {
 		if ( this.intent === true ) {
 
 
 			const builder = params[ 0 ];
 			const builder = params[ 0 ];
+			const properties = builder.getNodeProperties( this );
 
 
-			if ( this.isAssign( builder ) !== true ) {
+			if ( properties.assign !== true ) {
 
 
 				return this.node.build( ...params );
 				return this.node.build( ...params );
 
 

+ 1 - 13
src/nodes/tsl/TSLCore.js

@@ -488,7 +488,6 @@ class ShaderCallNodeInternal extends Node {
 		//
 		//
 
 
 		const previousSubBuildFn = builder.subBuildFn;
 		const previousSubBuildFn = builder.subBuildFn;
-		const previousContext = builder.addContext( { fnCall: this } );
 
 
 		builder.subBuildFn = subBuild;
 		builder.subBuildFn = subBuild;
 
 
@@ -566,7 +565,6 @@ class ShaderCallNodeInternal extends Node {
 		}
 		}
 
 
 		builder.subBuildFn = previousSubBuildFn;
 		builder.subBuildFn = previousSubBuildFn;
-		builder.setContext( previousContext );
 
 
 		if ( shaderNode.once ) {
 		if ( shaderNode.once ) {
 
 
@@ -610,8 +608,6 @@ class ShaderCallNodeInternal extends Node {
 		const subBuildOutput = builder.getSubBuildOutput( this );
 		const subBuildOutput = builder.getSubBuildOutput( this );
 		const outputNode = this.getOutputNode( builder );
 		const outputNode = this.getOutputNode( builder );
 
 
-		const previousContext = builder.addContext( { fnCall: this } );
-
 		if ( buildStage === 'setup' ) {
 		if ( buildStage === 'setup' ) {
 
 
 			const subBuildInitialized = builder.getSubBuildProperty( 'initialized', this );
 			const subBuildInitialized = builder.getSubBuildProperty( 'initialized', this );
@@ -659,8 +655,6 @@ class ShaderCallNodeInternal extends Node {
 
 
 		}
 		}
 
 
-		builder.setContext( previousContext );
-
 		return result;
 		return result;
 
 
 	}
 	}
@@ -794,15 +788,9 @@ class ShaderNodeInternal extends Node {
 
 
 	}
 	}
 
 
-	getLayout() {
-
-		return this.layout;
-
-	}
-
 	call( rawInputs = null ) {
 	call( rawInputs = null ) {
 
 
-		return new ShaderCallNodeInternal( this, rawInputs );
+		return nodeObject( new ShaderCallNodeInternal( this, rawInputs ) );
 
 
 	}
 	}
 
 

+ 2 - 9
src/nodes/utils/LoopNode.js

@@ -1,6 +1,6 @@
 import Node from '../core/Node.js';
 import Node from '../core/Node.js';
 import { expression } from '../code/ExpressionNode.js';
 import { expression } from '../code/ExpressionNode.js';
-import { nodeArray, Fn } from '../tsl/TSLBase.js';
+import { nodeObject, nodeArray, Fn } from '../tsl/TSLBase.js';
 import { error } from '../../utils.js';
 import { error } from '../../utils.js';
 
 
 /**
 /**
@@ -139,13 +139,6 @@ class LoopNode extends Node {
 
 
 		this.getProperties( builder );
 		this.getProperties( builder );
 
 
-		if ( builder.context.fnCall ) {
-
-			const shaderNodeData = builder.getDataFromNode( builder.context.fnCall.shaderNode );
-			shaderNodeData.hasLoop = true;
-
-		}
-
 	}
 	}
 
 
 	generate( builder ) {
 	generate( builder ) {
@@ -340,7 +333,7 @@ export default LoopNode;
  * @param {...any} params - A list of parameters.
  * @param {...any} params - A list of parameters.
  * @returns {LoopNode}
  * @returns {LoopNode}
  */
  */
-export const Loop = ( ...params ) => new LoopNode( nodeArray( params, 'int' ) ).toStack();
+export const Loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).toStack();
 
 
 /**
 /**
  * TSL function for creating a `Continue()` expression.
  * TSL function for creating a `Continue()` expression.

粤ICP备19079148号