Skip to content

Commit 009a3e4

Browse files
committed
updates
1 parent 845c408 commit 009a3e4

File tree

7 files changed

+84
-17
lines changed

7 files changed

+84
-17
lines changed

src/nodes/core/ArrayNode.js

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

44
/** @module ArrayNode **/
@@ -16,7 +16,7 @@ import { nodeObject } from '../tsl/TSLCore.js';
1616
*
1717
* @augments Node
1818
*/
19-
class ArrayNode extends Node {
19+
class ArrayNode extends TempNode {
2020

2121
static get type() {
2222

src/nodes/core/NodeBuilder.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ class NodeBuilder {
10621062
*/
10631063
generateArrayDeclaration( type, count ) {
10641064

1065-
return type + '[ ' + count + ' ]';
1065+
return this.getType( type ) + '[ ' + count + ' ]';
10661066

10671067
}
10681068

@@ -1084,7 +1084,7 @@ class NodeBuilder {
10841084

10851085
if ( value !== null ) {
10861086

1087-
snippet += value.build( this );
1087+
snippet += value.build( this, type );
10881088

10891089
} else {
10901090

@@ -1653,6 +1653,23 @@ class NodeBuilder {
16531653

16541654
}
16551655

1656+
/**
1657+
* Returns the array length.
1658+
*
1659+
* @param {Node} node - The node.
1660+
* @return {Number?} The array length.
1661+
*/
1662+
getArrayCount( node ) {
1663+
1664+
let count = null;
1665+
1666+
if ( node.isArrayNode ) count = node.count;
1667+
else if ( node.isVarNode && node.node.isArrayNode ) count = node.node.count;
1668+
1669+
return count;
1670+
1671+
}
1672+
16561673
/**
16571674
* Returns an instance of {@link NodeVar} for the given variable node.
16581675
*
@@ -1685,7 +1702,11 @@ class NodeBuilder {
16851702

16861703
}
16871704

1688-
nodeVar = new NodeVar( name, type, readOnly );
1705+
//
1706+
1707+
const count = this.getArrayCount( node );
1708+
1709+
nodeVar = new NodeVar( name, type, readOnly, count );
16891710

16901711
if ( ! readOnly ) {
16911712

@@ -1720,6 +1741,24 @@ class NodeBuilder {
17201741
return this.isDeterministic( node.aNode ) &&
17211742
( node.bNode ? this.isDeterministic( node.bNode ) : true );
17221743

1744+
} else if ( node.isArrayNode ) {
1745+
1746+
if ( node.values !== null ) {
1747+
1748+
for ( const n of node.values ) {
1749+
1750+
if ( ! this.isDeterministic( n ) ) {
1751+
1752+
return false;
1753+
1754+
}
1755+
1756+
}
1757+
1758+
}
1759+
1760+
return true;
1761+
17231762
} else if ( node.isConstNode ) {
17241763

17251764
return true;
@@ -2183,11 +2222,12 @@ class NodeBuilder {
21832222
*
21842223
* @param {String} type - The variable's type.
21852224
* @param {String} name - The variable's name.
2225+
* @param {Number?} [count=null] - The array length.
21862226
* @return {String} The shader string.
21872227
*/
2188-
getVar( type, name ) {
2228+
getVar( type, name, count = null ) {
21892229

2190-
return `${ this.getType( type ) } ${ name }`;
2230+
return `${ count !== null ? this.generateArrayDeclaration( type, count ) : this.getType( type ) } ${ name }`;
21912231

21922232
}
21932233

src/nodes/core/NodeVar.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class NodeVar {
1212
* @param {String} name - The name of the variable.
1313
* @param {String} type - The type of the variable.
1414
* @param {Boolean} [readOnly=false] - The read-only flag.
15+
* @param {Number?} [count=null] - The size.
1516
*/
16-
constructor( name, type, readOnly = false ) {
17+
constructor( name, type, readOnly = false, count = null ) {
1718

1819
/**
1920
* This flag can be used for type testing.
@@ -41,10 +42,17 @@ class NodeVar {
4142
/**
4243
* The read-only flag.
4344
*
44-
* @type {boolean}
45+
* @type {Boolean}
4546
*/
4647
this.readOnly = readOnly;
4748

49+
/**
50+
* The size.
51+
*
52+
* @type {Number?}
53+
*/
54+
this.count = count;
55+
4856
}
4957

5058
}

src/nodes/core/TempNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TempNode extends Node {
6868
const nodeVar = builder.getVarFromNode( this, null, type );
6969
const propertyName = builder.getPropertyName( nodeVar );
7070

71-
builder.addLineFlowCode( `${propertyName} = ${snippet}`, this );
71+
builder.addLineFlowCode( `${ propertyName } = ${ snippet }`, this );
7272

7373
nodeData.snippet = snippet;
7474
nodeData.propertyName = propertyName;

src/nodes/core/VarNode.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class VarNode extends Node {
8282

8383
}
8484

85+
getElementType( builder ) {
86+
87+
return this.node.getElementType( builder );
88+
89+
}
90+
8591
getNodeType( builder ) {
8692

8793
return this.node.getNodeType( builder );
@@ -117,8 +123,6 @@ class VarNode extends Node {
117123

118124
if ( shouldTreatAsReadOnly ) {
119125

120-
const type = builder.getType( nodeVar.type );
121-
122126
if ( isWebGPUBackend ) {
123127

124128
declarationPrefix = isDeterministic
@@ -127,7 +131,9 @@ class VarNode extends Node {
127131

128132
} else {
129133

130-
declarationPrefix = `const ${ type } ${ propertyName }`;
134+
const count = builder.getArrayCount( node );
135+
136+
declarationPrefix = `const ${ builder.getVar( nodeVar.type, propertyName, count ) }`;
131137

132138
}
133139

src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ ${ flowData.code }
496496

497497
for ( const variable of vars ) {
498498

499-
snippets.push( `${ this.getVar( variable.type, variable.name ) };` );
499+
snippets.push( `${ this.getVar( variable.type, variable.name, variable.count ) };` );
500500

501501
}
502502

src/renderers/webgpu/nodes/WGSLNodeBuilder.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,11 +1477,24 @@ ${ flowData.code }
14771477
*
14781478
* @param {String} type - The variable's type.
14791479
* @param {String} name - The variable's name.
1480+
* @param {Number?} [count=null] - The array length.
14801481
* @return {String} The WGSL snippet that defines a variable.
14811482
*/
1482-
getVar( type, name ) {
1483+
getVar( type, name, count = null ) {
14831484

1484-
return `var ${ name } : ${ this.getType( type ) }`;
1485+
let snippet = `var ${ name } : `;
1486+
1487+
if ( count !== null ) {
1488+
1489+
snippet += this.generateArrayDeclaration( type, count );
1490+
1491+
} else {
1492+
1493+
snippet += this.getType( type );
1494+
1495+
}
1496+
1497+
return snippet;
14851498

14861499
}
14871500

@@ -1500,7 +1513,7 @@ ${ flowData.code }
15001513

15011514
for ( const variable of vars ) {
15021515

1503-
snippets.push( `\t${ this.getVar( variable.type, variable.name ) };` );
1516+
snippets.push( `\t${ this.getVar( variable.type, variable.name, variable.count ) };` );
15041517

15051518
}
15061519

0 commit comments

Comments
 (0)