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

TSL: Fix member type in function layout (#31609)

sunag 8 месяцев назад
Родитель
Сommit
67b9093557
3 измененных файлов с 64 добавлено и 0 удалено
  1. 19 0
      src/nodes/code/FunctionCallNode.js
  2. 23 0
      src/nodes/code/FunctionNode.js
  3. 22 0
      src/nodes/core/NodeBuilder.js

+ 19 - 0
src/nodes/code/FunctionCallNode.js

@@ -69,12 +69,31 @@ class FunctionCallNode extends TempNode {
 
 	}
 
+	/**
+	 * Returns the type of this function call node.
+	 *
+	 * @param {NodeBuilder} builder - The current node builder.
+	 * @returns {string} The type of this node.
+	 */
 	getNodeType( builder ) {
 
 		return this.functionNode.getNodeType( builder );
 
 	}
 
+	/**
+	 * Returns the function node of this function call node.
+	 *
+	 * @param {NodeBuilder} builder - The current node builder.
+	 * @param {string} [name] - The name of the member.
+	 * @returns {string} The type of the member.
+	 */
+	getMemberType( builder, name ) {
+
+		return this.functionNode.getMemberType( builder, name );
+
+	}
+
 	generate( builder ) {
 
 		const params = [];

+ 23 - 0
src/nodes/code/FunctionNode.js

@@ -48,12 +48,35 @@ class FunctionNode extends CodeNode {
 
 	}
 
+	/**
+	 * Returns the type of this function node.
+	 *
+	 * @param {NodeBuilder} builder - The current node builder.
+	 * @return {string} The type.
+	 */
 	getNodeType( builder ) {
 
 		return this.getNodeFunction( builder ).type;
 
 	}
 
+	/**
+	 * Returns the type of a member of this function node.
+	 *
+	 * @param {NodeBuilder} builder - The current node builder.
+	 * @param {string} name - The name of the member.
+	 * @return {string} The type of the member.
+	 */
+	getMemberType( builder, name ) {
+
+		const type = this.getNodeType( builder );
+
+		const structType = builder.getStructTypeNode( type );
+
+		return structType.getMemberType( builder, name );
+
+	}
+
 	/**
 	 * Returns the inputs of this function node.
 	 *

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

@@ -259,6 +259,13 @@ class NodeBuilder {
 		 */
 		this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
 
+		/**
+		 * This dictionary holds the types of the builder.
+		 *
+		 * @type {Object}
+		 */
+		this.types = { vertex: [], fragment: [], compute: [], index: 0 };
+
 		/**
 		 * This dictionary holds the bindings for each shader stage.
 		 *
@@ -1680,6 +1687,20 @@ class NodeBuilder {
 
 	}
 
+	/**
+	 * Returns an instance of {@link StructType} for the given struct name and shader stage
+	 * or null if not found.
+	 *
+	 * @param {string} name - The name of the struct.
+	 * @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
+	 * @return {?StructType} The struct type or null if not found.
+	 */
+	getStructTypeNode( name, shaderStage = this.shaderStage ) {
+
+		return this.types[ shaderStage ][ name ] || null;
+
+	}
+
 	/**
 	 * Returns an instance of {@link StructType} for the given output struct node.
 	 *
@@ -1704,6 +1725,7 @@ class NodeBuilder {
 			structType = new StructType( name, membersLayout );
 
 			this.structs[ shaderStage ].push( structType );
+			this.types[ shaderStage ][ name ] = node;
 
 			nodeData.structType = structType;
 

粤ICP备19079148号