Skip to content

Commit 0a9e7fb

Browse files
sunagRuthySheffi
authored andcommitted
TSL: Fixes the return value of atomic* nodes (mrdoob#30971)
* add `parents` properties * TSL: Fixes the return value of `atomic*` nodes
1 parent 7f8f323 commit 0a9e7fb

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/nodes/core/Node.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ class Node extends EventDispatcher {
8787
*/
8888
this.global = false;
8989

90+
/**
91+
* Create a list of parents for this node during the build process.
92+
*
93+
* @type {boolean}
94+
* @default false
95+
*/
96+
this.parents = false;
97+
9098
/**
9199
* This flag can be used for type testing.
92100
*
@@ -643,6 +651,14 @@ class Node extends EventDispatcher {
643651

644652
if ( childNode && childNode.isNode === true ) {
645653

654+
if ( childNode.parents === true ) {
655+
656+
const childProperties = builder.getNodeProperties( childNode );
657+
childProperties.parents = childProperties.parents || [];
658+
childProperties.parents.push( this );
659+
660+
}
661+
646662
childNode.build( builder );
647663

648664
}

src/nodes/gpgpu/AtomicFunctionNode.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import TempNode from '../core/TempNode.js';
1+
import Node from '../core/Node.js';
22
import { nodeProxy } from '../tsl/TSLCore.js';
33

44
/**
@@ -10,9 +10,9 @@ import { nodeProxy } from '../tsl/TSLCore.js';
1010
*
1111
* This node can only be used with a WebGPU backend.
1212
*
13-
* @augments TempNode
13+
* @augments Node
1414
*/
15-
class AtomicFunctionNode extends TempNode {
15+
class AtomicFunctionNode extends Node {
1616

1717
static get type() {
1818

@@ -52,6 +52,14 @@ class AtomicFunctionNode extends TempNode {
5252
*/
5353
this.valueNode = valueNode;
5454

55+
/**
56+
* Creates a list of the parents for this node for detecting if the node needs to return a value.
57+
*
58+
* @type {boolean}
59+
* @default true
60+
*/
61+
this.parents = true;
62+
5563
}
5664

5765
/**
@@ -81,6 +89,8 @@ class AtomicFunctionNode extends TempNode {
8189

8290
generate( builder ) {
8391

92+
const parents = builder.getNodeProperties( this ).parents;
93+
8494
const method = this.method;
8595

8696
const type = this.getNodeType( builder );
@@ -101,8 +111,9 @@ class AtomicFunctionNode extends TempNode {
101111
}
102112

103113
const methodSnippet = `${ builder.getMethod( method, type ) }( ${ params.join( ', ' ) } )`;
114+
const isVoid = parents.length === 1 && parents[ 0 ].isStackNode === true;
104115

105-
if ( b !== null ) {
116+
if ( isVoid ) {
106117

107118
builder.addLineFlowCode( methodSnippet, this );
108119

0 commit comments

Comments
 (0)