Skip to content

Commit 699e1fa

Browse files
authored
Revert "TSL: Forces assignment of a function call if a loop is detected (#31961)" (#31975)
This reverts commit 27bed72.
1 parent a559830 commit 699e1fa

File tree

6 files changed

+30
-86
lines changed

6 files changed

+30
-86
lines changed

src/nodes/core/ContextNode.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ class ContextNode extends Node {
9494

9595
analyze( builder ) {
9696

97-
const previousContext = builder.addContext( this.value );
97+
const previousContext = builder.getContext();
98+
99+
builder.setContext( { ...builder.context, ...this.value } );
98100

99101
this.node.build( builder );
100102

@@ -104,7 +106,9 @@ class ContextNode extends Node {
104106

105107
setup( builder ) {
106108

107-
const previousContext = builder.addContext( this.value );
109+
const previousContext = builder.getContext();
110+
111+
builder.setContext( { ...builder.context, ...this.value } );
108112

109113
this.node.build( builder );
110114

@@ -114,7 +118,9 @@ class ContextNode extends Node {
114118

115119
generate( builder, output ) {
116120

117-
const previousContext = builder.addContext( this.value );
121+
const previousContext = builder.getContext();
122+
123+
builder.setContext( { ...builder.context, ...this.value } );
118124

119125
const snippet = this.node.build( builder, output );
120126

src/nodes/core/NodeBuilder.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -899,22 +899,6 @@ class NodeBuilder {
899899

900900
}
901901

902-
/**
903-
* Adds context data to the builder's current context.
904-
*
905-
* @param {Object} context - The context to add.
906-
* @return {Object} The previous context.
907-
*/
908-
addContext( context ) {
909-
910-
const previousContext = this.getContext();
911-
912-
this.setContext( { ...this.context, ...context } );
913-
914-
return previousContext;
915-
916-
}
917-
918902
/**
919903
* Gets a context used in shader construction that can be shared across different materials.
920904
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.

src/nodes/core/StackNode.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,15 @@ class StackNode extends Node {
261261

262262
for ( const childNode of this.getChildren() ) {
263263

264-
if ( childNode.isVarNode && childNode.isAssign( builder ) !== true ) {
264+
if ( childNode.isVarNode && childNode.intent === true ) {
265265

266-
continue;
266+
const properties = builder.getNodeProperties( childNode );
267+
268+
if ( properties.assign !== true ) {
269+
270+
continue;
271+
272+
}
267273

268274
}
269275

@@ -296,9 +302,15 @@ class StackNode extends Node {
296302

297303
for ( const node of this.nodes ) {
298304

299-
if ( node.isVarNode && node.isAssign( builder ) !== true ) {
305+
if ( node.isVarNode && node.intent === true ) {
300306

301-
continue;
307+
const properties = builder.getNodeProperties( node );
308+
309+
if ( properties.assign !== true ) {
310+
311+
continue;
312+
313+
}
302314

303315
}
304316

src/nodes/core/VarNode.js

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -146,53 +146,14 @@ class VarNode extends Node {
146146

147147
}
148148

149-
isAssign( builder ) {
150-
151-
if ( this.intent !== true ) return true;
152-
153-
//
154-
155-
const properties = builder.getNodeProperties( this );
156-
157-
let assign = properties.assign;
158-
159-
if ( assign !== true ) {
160-
161-
if ( this.node.isShaderCallNodeInternal && this.node.shaderNode.getLayout() === null ) {
162-
163-
if ( builder.context.fnCall && builder.context.fnCall.shaderNode ) {
164-
165-
const nodeType = this.node.getNodeType( builder );
166-
167-
if ( nodeType !== 'void' ) {
168-
169-
const shaderNodeData = builder.getDataFromNode( this.node.shaderNode );
170-
171-
if ( shaderNodeData.hasLoop ) {
172-
173-
assign = true;
174-
175-
}
176-
177-
}
178-
179-
}
180-
181-
}
182-
183-
}
184-
185-
return assign;
186-
187-
}
188-
189149
build( ...params ) {
190150

191151
if ( this.intent === true ) {
192152

193153
const builder = params[ 0 ];
154+
const properties = builder.getNodeProperties( this );
194155

195-
if ( this.isAssign( builder ) !== true ) {
156+
if ( properties.assign !== true ) {
196157

197158
return this.node.build( ...params );
198159

src/nodes/tsl/TSLCore.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ class ShaderCallNodeInternal extends Node {
488488
//
489489

490490
const previousSubBuildFn = builder.subBuildFn;
491-
const previousContext = builder.addContext( { fnCall: this } );
492491

493492
builder.subBuildFn = subBuild;
494493

@@ -566,7 +565,6 @@ class ShaderCallNodeInternal extends Node {
566565
}
567566

568567
builder.subBuildFn = previousSubBuildFn;
569-
builder.setContext( previousContext );
570568

571569
if ( shaderNode.once ) {
572570

@@ -610,8 +608,6 @@ class ShaderCallNodeInternal extends Node {
610608
const subBuildOutput = builder.getSubBuildOutput( this );
611609
const outputNode = this.getOutputNode( builder );
612610

613-
const previousContext = builder.addContext( { fnCall: this } );
614-
615611
if ( buildStage === 'setup' ) {
616612

617613
const subBuildInitialized = builder.getSubBuildProperty( 'initialized', this );
@@ -659,8 +655,6 @@ class ShaderCallNodeInternal extends Node {
659655

660656
}
661657

662-
builder.setContext( previousContext );
663-
664658
return result;
665659

666660
}
@@ -794,15 +788,9 @@ class ShaderNodeInternal extends Node {
794788

795789
}
796790

797-
getLayout() {
798-
799-
return this.layout;
800-
801-
}
802-
803791
call( rawInputs = null ) {
804792

805-
return new ShaderCallNodeInternal( this, rawInputs );
793+
return nodeObject( new ShaderCallNodeInternal( this, rawInputs ) );
806794

807795
}
808796

src/nodes/utils/LoopNode.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Node from '../core/Node.js';
22
import { expression } from '../code/ExpressionNode.js';
3-
import { nodeArray, Fn } from '../tsl/TSLBase.js';
3+
import { nodeObject, nodeArray, Fn } from '../tsl/TSLBase.js';
44
import { error } from '../../utils.js';
55

66
/**
@@ -139,13 +139,6 @@ class LoopNode extends Node {
139139

140140
this.getProperties( builder );
141141

142-
if ( builder.context.fnCall ) {
143-
144-
const shaderNodeData = builder.getDataFromNode( builder.context.fnCall.shaderNode );
145-
shaderNodeData.hasLoop = true;
146-
147-
}
148-
149142
}
150143

151144
generate( builder ) {
@@ -340,7 +333,7 @@ export default LoopNode;
340333
* @param {...any} params - A list of parameters.
341334
* @returns {LoopNode}
342335
*/
343-
export const Loop = ( ...params ) => new LoopNode( nodeArray( params, 'int' ) ).toStack();
336+
export const Loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).toStack();
344337

345338
/**
346339
* TSL function for creating a `Continue()` expression.

0 commit comments

Comments
 (0)