[Bf-blender-cvs] [29daf7d] object_nodes: Prepend a value node on all (non-constant) node inputs without a link.

Lukas Tönne noreply at git.blender.org
Tue Jan 12 14:50:41 CET 2016


Commit: 29daf7dedbebff19c796abdc2ebfd739e7c94d70
Author: Lukas Tönne
Date:   Tue Jan 12 14:46:33 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB29daf7dedbebff19c796abdc2ebfd739e7c94d70

Prepend a value node on all (non-constant) node inputs without a link.

In principle the input value could be used directly in codegen, but this
approach means one less condition to check and has the same effect.

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

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

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

diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index f322549a..8b69204 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -864,6 +864,27 @@ NodeInstance *NodeGraph::copy_node(const NodeInstance *node, NodeMap &node_map)
 /* ------------------------------------------------------------------------- */
 /* Optimization */
 
+/* add a value node on unbound inputs */
+void NodeGraph::ensure_bound_inputs()
+{
+	/* copy node pointers to avoid looping over new nodes again */
+	NodeSet old_nodes;
+	for (NodeInstanceMap::iterator it = nodes.begin(); it != nodes.end(); ++it)
+		old_nodes.insert(it->second);
+	
+	for (NodeSet::iterator it = old_nodes.begin(); it != old_nodes.end(); ++it) {
+		NodeInstance *node = *it;
+		for (int i = 0; i < node->num_inputs(); ++i) {
+			InputKey input = node->input(i);
+			if (input.is_constant())
+				continue;
+			else if (!input.link()) {
+				input.link_set(add_value_node(input.value()->copy()));
+			}
+		}
+	}
+}
+
 OutputKey NodeGraph::find_root(const OutputKey &key)
 {
 	OutputKey root = key;
@@ -1126,6 +1147,7 @@ void NodeGraph::sort_nodes()
 
 void NodeGraph::finalize()
 {
+	ensure_bound_inputs();
 	skip_pass_nodes();
 	blockify_nodes();
 	remove_unused_nodes();
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.h b/source/blender/blenvm/compile/bvm_nodegraph.h
index 9f64da8..72a6b2a 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.h
+++ b/source/blender/blenvm/compile/bvm_nodegraph.h
@@ -356,6 +356,8 @@ protected:
 	
 	/* optimizations */
 	
+	void ensure_bound_inputs();
+	
 	OutputKey find_root(const OutputKey &key);
 	
 	void skip_pass_nodes();




More information about the Bf-blender-cvs mailing list