[Bf-blender-cvs] [11c34a0] object_nodes: Changing graph output mechanism to use proxy nodes.

Lukas Tönne noreply at git.blender.org
Thu Nov 26 12:47:58 CET 2015


Commit: 11c34a0934f6da67f0788397b31cf174a5563359
Author: Lukas Tönne
Date:   Thu Nov 26 11:13:11 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB11c34a0934f6da67f0788397b31cf174a5563359

Changing graph output mechanism to use proxy nodes.

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

M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/compile/bvm_codegen.cc
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/compile/bvm_nodegraph.h
M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/makesrna/intern/rna_blenvm.c

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

diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index d8d8d69..15f50b2 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -63,8 +63,9 @@ void BVM_nodegraph_add_link(struct BVMNodeGraph *graph,
                             struct BVMNodeInstance *from_node, const char *from_socket,
                             struct BVMNodeInstance *to_node, const char *to_socket,
                             bool autoconvert);
-void BVM_nodegraph_set_output_link(struct BVMNodeGraph *graph,
-                                   const char *name, struct BVMNodeInstance *node, const char *socket);
+
+void BVM_nodegraph_get_output(struct BVMNodeGraph *graph, const char *name,
+                              struct BVMNodeInstance **node, const char **socket);
 
 void BVM_node_set_input_value_float(struct BVMNodeInstance *node,
                                     const char *socket, float value);
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 2ba71e1..faaf275 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -324,14 +324,6 @@ static void count_output_users(const NodeGraph &graph, SocketUserMap &users)
 			}
 		}
 	}
-	for (NodeGraph::OutputList::const_iterator it = graph.outputs.begin(); it != graph.outputs.end(); ++it) {
-		const NodeGraphOutput &output = *it;
-		
-		if (output.link_node && output.link_socket) {
-			ConstSocketPair key(output.link_node, output.link_socket->name);
-			users[key] += 1;
-		}
-	}
 }
 
 static OpCode ptr_init_opcode(const TypeDesc &typedesc)
@@ -484,19 +476,12 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 	for (NodeGraph::OutputList::const_iterator it = graph.outputs.begin();
 	     it != graph.outputs.end();
 	     ++it) {
-		const NodeGraphOutput &output = *it;
+		const NodeGraph::Output &output = *it;
 		
-		ReturnValue &rval = fn->add_return_value(TypeDesc(output.type), output.name);
+		const NodeSocket *socket = output.key.node->type->find_input(output.key.socket);
+		ReturnValue &rval = fn->add_return_value(socket->typedesc, output.name);
 		
-		if (output.link_node && output.link_socket) {
-			ConstSocketPair link_key(output.link_node, output.link_socket->name);
-			assert(output_index.find(link_key) != output_index.end());
-			
-			rval.stack_offset = output_index[link_key];
-		}
-		else {
-			rval.stack_offset = codegen_value(output.default_value);
-		}
+		rval.stack_offset = input_index[output.key.node->input(0)];
 	}
 	
 	push_opcode(OP_END);
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index b8cbd2c..b270ac7 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -220,6 +220,30 @@ NodeInstance::~NodeInstance()
 {
 }
 
+SocketPair NodeInstance::input(const string &name)
+{
+	assert(type->find_input(name) != NULL);
+	return SocketPair(this, name);
+}
+
+SocketPair NodeInstance::output(const string &name)
+{
+	assert(type->find_output(name) != NULL);
+	return SocketPair(this, name);
+}
+
+SocketPair NodeInstance::input(int index)
+{
+	assert(type->find_input(index) != NULL);
+	return SocketPair(this, type->find_input(index)->name);
+}
+
+SocketPair NodeInstance::output(int index)
+{
+	assert(type->find_output(index) != NULL);
+	return SocketPair(this, type->find_output(index)->name);
+}
+
 NodeInstance *NodeInstance::find_input_link_node(const string &name) const
 {
 	InputMap::const_iterator it = inputs.find(name);
@@ -244,18 +268,6 @@ const NodeSocket *NodeInstance::find_input_link_socket(int index) const
 	return socket ? find_input_link_socket(socket->name) : NULL;
 }
 
-const NodeGraphInput *NodeInstance::find_input_extern(const string &name) const
-{
-	InputMap::const_iterator it = inputs.find(name);
-	return (it != inputs.end()) ? it->second.graph_input : NULL;
-}
-
-const NodeGraphInput *NodeInstance::find_input_extern(int index) const
-{
-	const NodeSocket *socket = type->find_input(index);
-	return socket ? find_input_extern(socket->name) : NULL;
-}
-
 Value *NodeInstance::find_input_value(const string &name) const
 {
 	InputMap::const_iterator it = inputs.find(name);
@@ -300,16 +312,6 @@ bool NodeInstance::set_input_link(const string &name, NodeInstance *from_node, c
 	return true;
 }
 
-bool NodeInstance::set_input_extern(const string &name, const NodeGraphInput *graph_input)
-{
-	InputInstance &input = inputs[name];
-	if (input.graph_input)
-		return false;
-	
-	input.graph_input = graph_input;
-	return true;
-}
-
 bool NodeInstance::has_input_link(const string &name) const
 {
 	InputMap::const_iterator it = inputs.find(name);
@@ -327,23 +329,6 @@ bool NodeInstance::has_input_link(int index) const
 	return socket ? has_input_link(socket->name) : false;
 }
 
-bool NodeInstance::has_input_extern(const string &name) const
-{
-	InputMap::const_iterator it = inputs.find(name);
-	if (it != inputs.end()) {
-		const InputInstance &input = it->second;
-		return (input.graph_input);
-	}
-	else
-		return false;
-}
-
-bool NodeInstance::has_input_extern(int index) const
-{
-	const NodeSocket *socket = type->find_input(index);
-	return socket ? has_input_extern(socket->name) : false;
-}
-
 bool NodeInstance::has_input_value(const string &name) const
 {
 	InputMap::const_iterator it = inputs.find(name);
@@ -485,19 +470,19 @@ NodeInstance *NodeGraph::add_node(const string &type, const string &name)
 	return (result.second)? result.first->second : NULL;
 }
 
-const NodeGraphInput *NodeGraph::get_input(int index) const
+const NodeGraph::Input *NodeGraph::get_input(int index) const
 {
 	BLI_assert(index >= 0 && index < inputs.size());
 	return &inputs[index];
 }
 
-const NodeGraphOutput *NodeGraph::get_output(int index) const
+const NodeGraph::Output *NodeGraph::get_output(int index) const
 {
 	BLI_assert(index >= 0 && index < outputs.size());
 	return &outputs[index];
 }
 
-const NodeGraphInput *NodeGraph::get_input(const string &name) const
+const NodeGraph::Input *NodeGraph::get_input(const string &name) const
 {
 	for (InputList::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
 		if (it->name == name)
@@ -506,7 +491,7 @@ const NodeGraphInput *NodeGraph::get_input(const string &name) const
 	return NULL;
 }
 
-const NodeGraphOutput *NodeGraph::get_output(const string &name) const
+const NodeGraph::Output *NodeGraph::get_output(const string &name) const
 {
 	for (OutputList::const_iterator it = outputs.begin(); it != outputs.end(); ++it) {
 		if (it->name == name)
@@ -515,42 +500,25 @@ const NodeGraphOutput *NodeGraph::get_output(const string &name) const
 	return NULL;
 }
 
-const NodeGraphInput *NodeGraph::add_input(const string &name, BVMType type)
+const NodeGraph::Input *NodeGraph::add_input(const string &name, BVMType type)
 {
 	BLI_assert(!get_input(name));
-	inputs.push_back(NodeGraphInput(name, type));
+	/* XXX these proxies (noop nodes) should be replaced by dedicated
+	 * 'argument' nodes, which ensure that we have a place on the stack
+	 * for writing input arguments to.
+	 * This also enables direct input->output connections.
+	 */
+	inputs.push_back(Input(name, add_proxy(TypeDesc(type))));
 	return &inputs.back();
 }
 
-const NodeGraphOutput *NodeGraph::add_output(const string &name, BVMType type, Value *default_value)
+const NodeGraph::Output *NodeGraph::add_output(const string &name, BVMType type, Value *default_value)
 {
 	BLI_assert(!get_output(name));
-	outputs.push_back(NodeGraphOutput(name, type, default_value));
+	outputs.push_back(Output(name, add_proxy(TypeDesc(type), default_value)));
 	return &outputs.back();
 }
 
-void NodeGraph::set_input_argument(const string &name, Value *value)
-{
-	for (InputList::iterator it = inputs.begin(); it != inputs.end(); ++it) {
-		NodeGraphInput &input = *it;
-		if (input.name == name) {
-			input.value = value;
-		}
-	}
-}
-
-void NodeGraph::set_output_link(const string &name, NodeInstance *link_node, const string &link_socket)
-{
-	for (OutputList::iterator it = outputs.begin(); it != outputs.end(); ++it) {
-		NodeGraphOutput &output = *it;
-		if (output.name == name) {
-			output.link_node = link_node;
-			output.link_socket = link_node->type->find_output(link_socket);
-			BLI_assert(output.link_node && output.link_socket);
-		}
-	}
-}
-
 /* ------------------------------------------------------------------------- */
 /* Link Type Converters */
 
@@ -680,6 +648,23 @@ SocketPair NodeGraph::add_type_converter(const SocketPair &from, const TypeDesc
 	return result;
 }
 
+SocketPair NodeGraph::add_proxy(const TypeDesc &typedesc, Value *default_value)
+{
+	NodeInstance *node = NULL;
+	switch (typedesc.base_type) {
+		case BVM_FLOAT: node = add_node("PASS_FLOAT"); break;
+		case BVM_FLOAT3: node = add_node("PASS_FLOAT3"); break;
+		case BVM_FLOAT4: node = add_node("PASS_FLOAT4"); break;
+		case BVM_INT: node = add_node("PASS_INT"); break;
+		case BVM_MATRIX44: node = add_node("PASS_MATRIX44"); break;
+		case BVM_MESH: node = add_node("PASS_MESH"); break;
+		case BVM_POINTER: node = add_node("PASS_POINTER"); break;
+	}
+	if (node && default_value)
+		node->set_input_value("value", default_value);
+	return SocketPair(node, "value");
+}
+
 /* ------------------------------------------------------------------------- */
 /* Optimization */
 
@@ -716,19 +701,20 @@ void NodeGraph::skip_pass_nodes()
 			input.link_socket = link_socket;
 		}
 	}
-	/* same for graph outputs */
-	for (OutputList::iterator it = outputs.begin(); it != outputs.end(); ++it) {
-		NodeGraphOutput &output = *it;
+	
+	/* move output references upstream as well */
+	for (OutputList::iterator it_output = outputs.begin(); it_output != outputs.end(); ++it_output) {
+		Output &output = *it_output;
 		
-		NodeInstance *link_node = output.link_node;
-		const NodeSocket *link_socket = output.link_socket;
+		NodeInstance *link_node = output.key.node;
+		const NodeSocket *link_socket = link_node->type->find_output(output.key.socket);
 		while (link_node && link_node->type->is_pass_node()) {
 			/* note: order of assignment is important here! */
 			link_socket = link_node->f

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list