Skip to content

Commit 67b9093

Browse files
authored
TSL: Fix member type in function layout (#31609)
1 parent 3340223 commit 67b9093

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/nodes/code/FunctionCallNode.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,31 @@ class FunctionCallNode extends TempNode {
6969

7070
}
7171

72+
/**
73+
* Returns the type of this function call node.
74+
*
75+
* @param {NodeBuilder} builder - The current node builder.
76+
* @returns {string} The type of this node.
77+
*/
7278
getNodeType( builder ) {
7379

7480
return this.functionNode.getNodeType( builder );
7581

7682
}
7783

84+
/**
85+
* Returns the function node of this function call node.
86+
*
87+
* @param {NodeBuilder} builder - The current node builder.
88+
* @param {string} [name] - The name of the member.
89+
* @returns {string} The type of the member.
90+
*/
91+
getMemberType( builder, name ) {
92+
93+
return this.functionNode.getMemberType( builder, name );
94+
95+
}
96+
7897
generate( builder ) {
7998

8099
const params = [];

src/nodes/code/FunctionNode.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,35 @@ class FunctionNode extends CodeNode {
4848

4949
}
5050

51+
/**
52+
* Returns the type of this function node.
53+
*
54+
* @param {NodeBuilder} builder - The current node builder.
55+
* @return {string} The type.
56+
*/
5157
getNodeType( builder ) {
5258

5359
return this.getNodeFunction( builder ).type;
5460

5561
}
5662

63+
/**
64+
* Returns the type of a member of this function node.
65+
*
66+
* @param {NodeBuilder} builder - The current node builder.
67+
* @param {string} name - The name of the member.
68+
* @return {string} The type of the member.
69+
*/
70+
getMemberType( builder, name ) {
71+
72+
const type = this.getNodeType( builder );
73+
74+
const structType = builder.getStructTypeNode( type );
75+
76+
return structType.getMemberType( builder, name );
77+
78+
}
79+
5780
/**
5881
* Returns the inputs of this function node.
5982
*

src/nodes/core/NodeBuilder.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ class NodeBuilder {
259259
*/
260260
this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
261261

262+
/**
263+
* This dictionary holds the types of the builder.
264+
*
265+
* @type {Object}
266+
*/
267+
this.types = { vertex: [], fragment: [], compute: [], index: 0 };
268+
262269
/**
263270
* This dictionary holds the bindings for each shader stage.
264271
*
@@ -1680,6 +1687,20 @@ class NodeBuilder {
16801687

16811688
}
16821689

1690+
/**
1691+
* Returns an instance of {@link StructType} for the given struct name and shader stage
1692+
* or null if not found.
1693+
*
1694+
* @param {string} name - The name of the struct.
1695+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
1696+
* @return {?StructType} The struct type or null if not found.
1697+
*/
1698+
getStructTypeNode( name, shaderStage = this.shaderStage ) {
1699+
1700+
return this.types[ shaderStage ][ name ] || null;
1701+
1702+
}
1703+
16831704
/**
16841705
* Returns an instance of {@link StructType} for the given output struct node.
16851706
*
@@ -1704,6 +1725,7 @@ class NodeBuilder {
17041725
structType = new StructType( name, membersLayout );
17051726

17061727
this.structs[ shaderStage ].push( structType );
1728+
this.types[ shaderStage ][ name ] = node;
17071729

17081730
nodeData.structType = structType;
17091731

0 commit comments

Comments
 (0)