[Bf-blender-cvs] [9b1456b] object_nodes: Unified handling of both the main function and expression functions.
Lukas Tönne
noreply at git.blender.org
Wed Dec 9 11:07:04 CET 2015
Commit: 9b1456ba37bc65b99ba054e1b88742f05e3e233b
Author: Lukas Tönne
Date: Wed Dec 9 11:02:57 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB9b1456ba37bc65b99ba054e1b88742f05e3e233b
Unified handling of both the main function and expression functions.
===================================================================
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_codegen.h
===================================================================
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 0444172..97cb7b2 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -82,6 +82,129 @@ StackIndex BVMCompiler::assign_stack_index(const TypeDesc &typedesc)
return stack_offset;
}
+void BVMCompiler::resolve_function_symbols(BVMCompiler::FunctionInfo &func)
+{
+ for (NodeList::const_iterator it = func.nodes.begin(); it != func.nodes.end(); ++it) {
+ const NodeInstance &node = **it;
+
+ /* prepare input stack entries */
+ for (int i = 0; i < node.num_inputs(); ++i) {
+ const NodeInput *input = node.type->find_input(i);
+ ConstSocketPair key(&node, input->name);
+ assert(func.input_index.find(key) == func.input_index.end());
+
+ if (node.is_input_constant(i) || node.is_input_function(i)) {
+ /* stored directly in the instructions list after creating values */
+ }
+ else if (node.has_input_link(i)) {
+ ConstSocketPair link_key(node.find_input_link_node(i),
+ node.find_input_link_socket(i)->name);
+ assert(func.output_index.find(link_key) != func.output_index.end());
+ func.input_index[key] = func.output_index[link_key];
+ }
+ else {
+ func.input_index[key] = assign_stack_index(input->typedesc);
+ }
+ }
+
+ /* initialize output data stack entries */
+ for (int i = 0; i < node.num_outputs(); ++i) {
+ const NodeOutput *output = node.type->find_output(i);
+ ConstSocketPair key(&node, output->name);
+
+ func.output_index[key] = assign_stack_index(output->typedesc);
+ }
+ }
+}
+
+void BVMCompiler::expression_node_append(const NodeInstance *node,
+ NodeList &sorted_nodes,
+ NodeSet &visited)
+{
+ if (node->type->is_kernel_node())
+ return;
+
+ if (visited.find(node) != visited.end())
+ return;
+ visited.insert(node);
+
+ for (size_t i = 0; i < node->num_inputs(); ++i) {
+ const NodeInstance *link_node = node->find_input_link_node(i);
+ if (link_node) {
+ expression_node_append(link_node, sorted_nodes, visited);
+ }
+ }
+
+ sorted_nodes.push_back(node);
+}
+
+void BVMCompiler::graph_node_append(const NodeInstance *node,
+ NodeList &sorted_nodes,
+ NodeSet &visited)
+{
+ if (visited.find(node) != visited.end())
+ return;
+ visited.insert(node);
+
+ for (size_t i = 0; i < node->num_inputs(); ++i) {
+ const NodeInput *socket = node->type->find_input(i);
+ const NodeInstance *link_node = node->find_input_link_node(i);
+
+ if (socket->value_type == INPUT_FUNCTION) {
+ FunctionInfo &func = func_entry_map[node->input(i)];
+
+ if (link_node) {
+ NodeSet func_visited;
+ expression_node_append(link_node, func.nodes, func_visited);
+ }
+ }
+ else {
+ if (link_node) {
+ graph_node_append(link_node, sorted_nodes, visited);
+ }
+ }
+ }
+
+ sorted_nodes.push_back(node);
+}
+
+void BVMCompiler::sort_graph_nodes(const NodeGraph &graph)
+{
+ NodeSet visited;
+
+ for (NodeGraph::NodeInstanceMap::const_iterator it = graph.nodes.begin(); it != graph.nodes.end(); ++it) {
+ graph_node_append(it->second, main.nodes, visited);
+ }
+}
+
+void BVMCompiler::resolve_symbols(const NodeGraph &graph)
+{
+ main = FunctionInfo();
+ func_entry_map.clear();
+
+ sort_graph_nodes(graph);
+
+ for (FunctionEntryMap::iterator it = func_entry_map.begin(); it != func_entry_map.end(); ++it) {
+ const ConstSocketPair &key = it->first;
+ FunctionInfo &func = it->second;
+
+ resolve_function_symbols(func);
+
+ ConstSocketPair link_key = key.node->link(key.socket);
+ StackIndex stack_index;
+ if (link_key.node) {
+ stack_index = func.output_index.at(link_key);
+ }
+ else {
+ const NodeInput *input = key.node->type->find_input(key.socket);
+ stack_index = assign_stack_index(input->typedesc);
+ }
+ func.return_index = stack_index;
+ }
+
+ resolve_function_symbols(main);
+}
+
void BVMCompiler::push_opcode(OpCode op) const
{
fn->add_instruction(op);
@@ -303,51 +426,51 @@ static OpCode ptr_release_opcode(const TypeDesc &typedesc)
return OP_NOOP;
}
-void BVMCompiler::resolve_subgraph_symbols(const NodeList &nodes,
- SocketIndexMap &input_index,
- SocketIndexMap &output_index)
+static void count_output_users(const NodeGraph &graph,
+ SocketUserMap &users)
{
- for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
- const NodeInstance &node = **it;
-
- /* prepare input stack entries */
- for (int i = 0; i < node.num_inputs(); ++i) {
- const NodeInput *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) || node.is_input_function(i)) {
- /* stored directly in the instructions list after creating values */
- }
- else 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());
- input_index[key] = output_index[link_key];
- }
- else {
- input_index[key] = assign_stack_index(input->typedesc);
- }
+ users.clear();
+ 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->find_output(i)->name);
+ users[key] = 0;
}
+ }
+
+ for (NodeGraph::NodeInstanceMap::const_iterator it = graph.nodes.begin(); it != graph.nodes.end(); ++it) {
+ const NodeInstance *node = it->second;
- /* initialize output data stack entries */
- for (int i = 0; i < node.num_outputs(); ++i) {
- const NodeOutput *output = node.type->find_output(i);
- ConstSocketPair key(&node, output->name);
-
- output_index[key] = assign_stack_index(output->typedesc);
+ /* note: pass nodes are normally removed, but can exist for debugging purposes */
+ if (node->type->is_pass_node())
+ continue;
+
+ for (int i = 0; i < node->num_inputs(); ++i) {
+ if (node->has_input_link(i)) {
+ ConstSocketPair key(node->find_input_link_node(i),
+ node->find_input_link_socket(i)->name);
+ users[key] += 1;
+ }
}
}
+ /* inputs are defined externally, they should be retained during evaluation */
+ for (NodeGraph::InputList::const_iterator it = graph.inputs.begin(); it != graph.inputs.end(); ++it) {
+ const NodeGraph::Input &input = *it;
+ users[input.key] += 1;
+ }
+ /* outputs are passed on to the caller, which is responsible for freeing them */
+ for (NodeGraph::OutputList::const_iterator it = graph.outputs.begin(); it != graph.outputs.end(); ++it) {
+ const NodeGraph::Output &output = *it;
+ users[output.key] += 1;
+ }
}
-int BVMCompiler::codegen_subgraph(const NodeList &nodes,
- const SocketUserMap &socket_users,
- const SocketIndexMap &input_index,
- const SocketIndexMap &output_index) const
+int BVMCompiler::codegen_function(const BVMCompiler::FunctionInfo &func,
+ const SocketUserMap &socket_users) const
{
int entry_point = fn->get_instruction_count();
- for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
+ for (NodeList::const_iterator it = func.nodes.begin(); it != func.nodes.end(); ++it) {
const NodeInstance &node = **it;
/* store values for unconnected inputs */
@@ -364,7 +487,7 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
else {
/* create a value node for the input */
Value *value = (node.has_input_value(i)) ? node.find_input_value(i) : input->default_value;
- codegen_value(value, input_index.at(key));
+ codegen_value(value, func.input_index.at(key));
}
}
/* initialize output data stack entries */
@@ -378,7 +501,7 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
int users = socket_users.find(key)->second;
if (users > 0) {
push_opcode(init_op);
- push_stack_index(output_index.at(key));
+ push_stack_index(func.output_index.at(key));
push_int(users);
}
}
@@ -403,7 +526,7 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
push_stack_index(func.return_index);
}
else {
- push_stack_index(input_index.at(key));
+ push_stack_index(func.input_index.at(key));
}
}
/* write output stack offsets */
@@ -411,7 +534,7 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
const NodeOutput *output = node.type->find_output(i);
ConstSocketPair key(&node, output->name);
- push_stack_index(output_index.at(key));
+ push_stack_index(func.output_index.at(key));
}
}
@@ -430,7 +553,7 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
if (release_op != OP_NOOP) {
push_opcode(release_op);
- push_stack_index(output_index.at(link_key));
+ push_stack_index(func.output_index.at(link_key));
}
}
}
@@ -441,135 +564,6 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
return entry_point;
}
-void BVMCompiler::expression_node_append(const NodeInstance *node,
- NodeList &sorted_nodes,
- NodeSet &visited)
-{
- if (node->type->is_kernel_node())
- return;
-
- if (visited.find(node) != visited.end())
- return;
- visited.insert(node);
-
- for (size_t i = 0; i < node->num_inputs(); ++i) {
- const NodeInstance *link_node = node->find_input_link_node(i);
- if (link_node) {
- expression_node_append(link_node, sorted_nodes, visited);
- }
- }
-
- sorted_nodes.push_back(node);
-}
-
-void BVMCompiler::graph_node_append(const NodeInstance *node,
- NodeList &sorted_nodes,
- NodeSet &visited)
-{
- if
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list