[Bf-blender-cvs] [1254009] object_nodes: Distinguish 'function' and 'kernel' node types.

Lukas Tönne noreply at git.blender.org
Wed Nov 25 15:22:44 CET 2015


Commit: 1254009072f05c6a375950eb0fa5e378af1c70a4
Author: Lukas Tönne
Date:   Wed Nov 25 13:55:20 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB1254009072f05c6a375950eb0fa5e378af1c70a4

Distinguish 'function' and 'kernel' node types.

Only kernel nodes will be allowed to have function inputs. This is
necessary because any kernel node will define the boundaries of
node subtrees used for function inputs.

===================================================================

M	source/blender/blenvm/compile/bvm_codegen.cc
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/compile/bvm_nodegraph.h

===================================================================

diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 5cd4d3d..2ba71e1 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -304,7 +304,7 @@ static void count_output_users(const NodeGraph &graph, SocketUserMap &users)
 	for (NodeGraph::NodeInstanceMap::const_iterator it = graph.nodes.begin(); it != graph.nodes.end(); ++it) {
 		const NodeInstance *node = it->second;
 		for (int i = 0; i < node->num_outputs(); ++i) {
-			ConstSocketPair key(node, node->type->outputs[i].name);
+			ConstSocketPair key(node, node->type->find_output(i)->name);
 			users[key] = 0;
 		}
 	}
@@ -313,7 +313,7 @@ static void count_output_users(const NodeGraph &graph, SocketUserMap &users)
 		const NodeInstance *node = it->second;
 		
 		/* note: pass nodes are normally removed, but can exist for debugging purposes */
-		if (node->type->is_pass)
+		if (node->type->is_pass_node())
 			continue;
 		
 		for (int i = 0; i < node->num_inputs(); ++i) {
@@ -387,14 +387,14 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 	for (NodeList::const_iterator it = sorted_nodes.begin(); it != sorted_nodes.end(); ++it) {
 		const NodeInstance &node = **it;
 		
-		OpCode op = get_opcode_from_node_type(node.type->name);
+		OpCode op = get_opcode_from_node_type(node.type->name());
 		if (op == OP_NOOP)
 			continue;
 		
 		/* prepare input stack entries */
 		for (int i = 0; i < node.num_inputs(); ++i) {
-			const NodeSocket &input = node.type->inputs[i];
-			ConstSocketPair key(&node, input.name);
+			const NodeSocket *input = node.type->find_input(i);
+			ConstSocketPair key(&node, input->name);
 			assert(input_index.find(key) == input_index.end());
 			
 			if (node.is_input_constant(i)) {
@@ -413,20 +413,20 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 				input_index[key] = codegen_value(value);
 			}
 			else {
-				input_index[key] = codegen_value(input.default_value);
+				input_index[key] = codegen_value(input->default_value);
 			}
 		}
 		
 		/* initialize output data stack entries */
 		for (int i = 0; i < node.num_outputs(); ++i) {
-			const NodeSocket &output = node.type->outputs[i];
-			ConstSocketPair key(&node, output.name);
+			const NodeSocket *output = node.type->find_output(i);
+			ConstSocketPair key(&node, output->name);
 			assert(output_index.find(key) == output_index.end());
 			
-			output_index[key] = assign_stack_index(output.typedesc);
+			output_index[key] = assign_stack_index(output->typedesc);
 			
 			/* if necessary, add a user count initializer */
-			OpCode init_op = ptr_init_opcode(output.typedesc);
+			OpCode init_op = ptr_init_opcode(output->typedesc);
 			if (init_op != OP_NOOP) {
 				int users = output_users[key];
 				if (users > 0) {
@@ -441,8 +441,8 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 		push_opcode(op);
 		/* write input stack offsets and constants */
 		for (int i = 0; i < node.num_inputs(); ++i) {
-			const NodeSocket &input = node.type->inputs[i];
-			ConstSocketPair key(&node, input.name);
+			const NodeSocket *input = node.type->find_input(i);
+			ConstSocketPair key(&node, input->name);
 			
 			if (node.is_input_constant(i)) {
 				Value *value = node.find_input_value(i);
@@ -455,8 +455,8 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 		}
 		/* write output stack offsets */
 		for (int i = 0; i < node.num_outputs(); ++i) {
-			const NodeSocket &output = node.type->outputs[i];
-			ConstSocketPair key(&node, output.name);
+			const NodeSocket *output = node.type->find_output(i);
+			ConstSocketPair key(&node, output->name);
 			assert(output_index.find(key) != output_index.end());
 			
 			push_stack_index(output_index[key]);
@@ -464,14 +464,14 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 		
 		/* release input data stack entries */
 		for (int i = 0; i < node.num_inputs(); ++i) {
-			const NodeSocket &input = node.type->inputs[i];
+			const NodeSocket *input = node.type->find_input(i);
 			
 			if (node.has_input_link(i)) {
 				ConstSocketPair link_key(node.find_input_link_node(i),
 				                         node.find_input_link_socket(i)->name);
 				assert(output_index.find(link_key) != output_index.end());
 				
-				OpCode release_op = ptr_release_opcode(input.typedesc);
+				OpCode release_op = ptr_release_opcode(input->typedesc);
 				
 				if (release_op != OP_NOOP) {
 					push_opcode(release_op);
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index f01f044..b8cbd2c 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -58,9 +58,10 @@ NodeSocket::~NodeSocket()
 
 /* ------------------------------------------------------------------------- */
 
-NodeType::NodeType(const string &name) :
-    name(name),
-    is_pass(false)
+NodeType::NodeType(const string &name, bool is_kernel_node, bool is_pass_node) :
+    m_name(name),
+    m_is_pass_node(is_pass_node),
+    m_is_kernel_node(is_kernel_node)
 {
 }
 
@@ -193,6 +194,8 @@ const NodeSocket *NodeType::add_input(const string &name,
                                       eNodeSocketValueType value_type)
 {
 	BLI_assert(!find_input(name));
+	/* function inputs only allowed for kernel nodes */
+	BLI_assert(m_is_kernel_node || value_type != VALUE_FUNCTION);
 	inputs.push_back(NodeSocket(name, type, default_value, value_type));
 	return &inputs.back();
 }
@@ -406,9 +409,13 @@ const NodeType *NodeGraph::find_node_type(const string &name)
 	return (it != node_types.end())? &it->second : NULL;
 }
 
-NodeType *NodeGraph::add_node_type(const string &name)
+NodeType *NodeGraph::add_node_type(const string &name, bool is_kernel_node, bool is_pass_node)
 {
-	std::pair<NodeTypeMap::iterator, bool> result = node_types.insert(NodeTypeMapPair(name, NodeType(name)));
+	std::pair<NodeTypeMap::iterator, bool> result =
+	        node_types.insert(NodeTypeMapPair(
+	                              name,
+	                              NodeType(name, is_kernel_node, is_pass_node))
+	                          );
 	if (result.second) {
 		NodeType *type = &result.first->second;
 		return type;
@@ -417,6 +424,21 @@ NodeType *NodeGraph::add_node_type(const string &name)
 		return NULL;
 }
 
+NodeType *NodeGraph::add_function_node_type(const string &name)
+{
+	return add_node_type(name, false, false);
+}
+
+NodeType *NodeGraph::add_kernel_node_type(const string &name)
+{
+	return add_node_type(name, true, false);
+}
+
+NodeType *NodeGraph::add_pass_node_type(const string &name)
+{
+	return add_node_type(name, false, true);
+}
+
 void NodeGraph::remove_node_type(const string &name)
 {
 	NodeTypeMap::iterator it = node_types.find(name);
@@ -447,7 +469,7 @@ NodeInstance *NodeGraph::add_node(const string &type, const string &name)
 	string final = name;
 	if (final.empty()) {
 		std::stringstream ss;
-		ss << nodetype->name;
+		ss << nodetype->name();
 		final = ss.str();
 	}
 	if (nodes.find(final) != nodes.end()) {
@@ -675,7 +697,7 @@ void NodeGraph::skip_pass_nodes()
 	for (NodeInstanceMap::iterator it = nodes.begin(); it != nodes.end(); ++it) {
 		NodeInstance *node = it->second;
 		
-		if (node->type->is_pass)
+		if (node->type->is_pass_node())
 			continue;
 		
 		for (NodeInstance::InputMap::iterator it_input = node->inputs.begin();
@@ -685,7 +707,7 @@ void NodeGraph::skip_pass_nodes()
 			
 			NodeInstance *link_node = input.link_node;
 			const NodeSocket *link_socket = input.link_socket;
-			while (link_node && link_node->type->is_pass) {
+			while (link_node && link_node->type->is_pass_node()) {
 				/* note: order of assignment is important here! */
 				link_socket = link_node->find_input_link_socket(0);
 				link_node = link_node->find_input_link_node(0);
@@ -700,7 +722,7 @@ void NodeGraph::skip_pass_nodes()
 		
 		NodeInstance *link_node = output.link_node;
 		const NodeSocket *link_socket = output.link_socket;
-		while (link_node && link_node->type->is_pass) {
+		while (link_node && link_node->type->is_pass_node()) {
 			/* note: order of assignment is important here! */
 			link_socket = link_node->find_input_link_socket(0);
 			link_node = link_node->find_input_link_node(0);
@@ -771,8 +793,8 @@ void NodeGraph::dump(std::ostream &s)
 		const NodeType *type = node->type;
 		s << "  Node '" << node->name << "'\n";
 		
-		for (int i = 0; i < type->inputs.size(); ++i) {
-			const NodeSocket *socket = &type->inputs[i];
+		for (int i = 0; i < type->num_inputs(); ++i) {
+			const NodeSocket *socket = type->find_input(i);
 			
 			s << "    Input '" << socket->name << "'";
 			NodeInstance *link_node = node->find_input_link_node(i);
@@ -794,8 +816,8 @@ void NodeGraph::dump(std::ostream &s)
 			}
 		}
 		
-		for (int i = 0; i < type->outputs.size(); ++i) {
-			const NodeSocket *socket = &type->outputs[i];
+		for (int i = 0; i < type->num_outputs(); ++i) {
+			const NodeSocket *socket = type->find_output(i);
 			
 			s << "    Output '" << socket->name << "'";
 //			Value *value = node->find_output_value(i);
@@ -826,24 +848,18 @@ static void debug_fprintf(const DebugContext &ctx, const char *fmt, ...)
 
 inline static int debug_input_index(const NodeInstance *node, const string &name)
 {
-	int index = 0;
-	for (NodeType::SocketList::const_iterator it = node->type->inputs.begin();
-	     it != node->type->inputs.end();
-	     ++it, ++index) {
-		if ((*it).name == name)
-			return index;
+	for (int i = 0; i < node->type->num_inputs(); ++i) {
+		if (node->type->find_input(i)->name == name)
+			return i;
 	}
 	return -1;
 }
 
 inline static int debug_output_index(const NodeInstance *node, const string &name)
 {
-	int index = 0;
-	for (NodeType::SocketList::const_iterator it = node->type->outputs.begin();
-	     it != node->type->outputs.end();
-	     ++it, ++index) {
-		if ((*it).name == name)
-			return index;
+	for (int i = 0; i < node->type->num_outputs(); ++i) {
+		if (node->type->find_output(i)->name == name)
+			return i;
 	}
 	return -1;
 }
@@ -855,7 +871,7 @@ static void debug_graphviz_node(const DebugContext &ctx, const NodeInstance *nod
 	const char *color

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list