[Bf-blender-cvs] [0b80bb6] object_nodes: Get rid of the extra list of "outputs" for subgraph codegen.
Lukas Tönne
noreply at git.blender.org
Tue Dec 8 14:52:25 CET 2015
Commit: 0b80bb6bb86156a24637a4a8cbbb5d9feea0477c
Author: Lukas Tönne
Date: Tue Dec 8 12:09:02 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB0b80bb6bb86156a24637a4a8cbbb5d9feea0477c
Get rid of the extra list of "outputs" for subgraph codegen.
Instead we now pass a socket index map directly to subgraph codegen,
and then read out the final output indices externally.
===================================================================
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 506797e..356bc66 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -309,13 +309,10 @@ static OpCode ptr_release_opcode(const TypeDesc &typedesc)
int BVMCompiler::codegen_subgraph(const NodeList &nodes,
const SocketUserMap &socket_users,
- SubgraphOutputList &outputs)
+ SocketIndexMap &output_index)
{
- typedef std::map<ConstSocketPair, StackIndex> SocketIndexMap;
-
int entry_point = fn->get_instruction_count();
- SocketIndexMap output_index;
for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
const NodeInstance &node = **it;
@@ -423,18 +420,6 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
push_opcode(OP_END);
- for (SubgraphOutputList::iterator it = outputs.begin(); it != outputs.end(); ++it) {
- SubgraphOutput &output = *it;
-
- if (output.key.node) {
- assert(output_index.find(output.key) != output_index.end());
- output.stack_index = output_index[output.key];
- }
- else {
- output.stack_index = codegen_value(output.value);
- }
- }
-
return entry_point;
}
@@ -567,32 +552,42 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
* updated _after_ the main function is generated.
*/
- SubgraphOutputList outputs;
- ConstSocketPair link_key = key.node->link(key.socket);
- Value *value = key.node->type->find_input(key.socket)->default_value;
- outputs.push_back(SubgraphOutput(link_key, value));
+ SocketIndexMap output_index;
+ func.entry_point = codegen_subgraph(expr_nodes, output_users, output_index);
- func.entry_point = codegen_subgraph(expr_nodes, output_users, outputs);
- func.return_index = outputs[0].stack_index;
+ ConstSocketPair link_key = key.node->link(key.socket);
+ StackIndex stack_index;
+ if (link_key.node) {
+ assert(output_index.find(link_key) != output_index.end());
+ stack_index = output_index[link_key];
+ }
+ else {
+ Value *value = key.node->type->find_input(key.socket)->default_value;
+ stack_index = codegen_value(value);
+ }
+ func.return_index = stack_index;
}
/* now generate the main function */
{
- SubgraphOutputList outputs;
- for (size_t i = 0; i < graph.outputs.size(); ++i) {
- const NodeGraph::Output &output = graph.outputs[i];
- Value *value = output.key.node->type->find_output(output.key.socket)->default_value;
- outputs.push_back(SubgraphOutput(output.key, value));
- }
- int entry_point = codegen_subgraph(main_nodes, output_users, outputs);
+ SocketIndexMap output_index;
+ int entry_point = codegen_subgraph(main_nodes, output_users, output_index);
fn->set_entry_point(entry_point);
- /* store final stack indices for outputs, so we can return results to the caller */
for (size_t i = 0; i < graph.outputs.size(); ++i) {
const NodeGraph::Output &output = graph.outputs[i];
const NodeSocket *socket = output.key.node->type->find_output(output.key.socket);
- fn->add_return_value(socket->typedesc, output.name, outputs[i].stack_index);
+ StackIndex stack_index;
+ if (output.key.node) {
+ assert(output_index.find(output.key) != output_index.end());
+ stack_index = output_index[output.key];
+ }
+ else {
+ Value *value = output.key.node->type->find_output(output.key.socket)->default_value;
+ stack_index = codegen_value(value);
+ }
+ fn->add_return_value(socket->typedesc, output.name, stack_index);
}
}
diff --git a/source/blender/blenvm/compile/bvm_codegen.h b/source/blender/blenvm/compile/bvm_codegen.h
index 98665ee..b4f347e 100644
--- a/source/blender/blenvm/compile/bvm_codegen.h
+++ b/source/blender/blenvm/compile/bvm_codegen.h
@@ -51,15 +51,7 @@ struct TypeDesc;
typedef std::vector<const NodeInstance *> NodeList;
typedef std::set<const NodeInstance *> NodeSet;
-struct SubgraphOutput {
- SubgraphOutput(const ConstSocketPair &key, Value *default_value) :
- key(key), value(default_value), stack_index(BVM_STACK_INVALID)
- {}
- ConstSocketPair key;
- Value *value;
- StackIndex stack_index;
-};
-typedef std::vector<SubgraphOutput> SubgraphOutputList;
+typedef std::map<ConstSocketPair, StackIndex> SocketIndexMap;
typedef std::map<ConstSocketPair, int> SocketUserMap;
struct BVMCompiler {
@@ -92,7 +84,7 @@ struct BVMCompiler {
void codegen_constant(const Value *value);
int codegen_subgraph(const NodeList &nodes,
const SocketUserMap &socket_users,
- SubgraphOutputList &outputs);
+ SocketIndexMap &output_index);
Function *codegen_function(const NodeGraph &graph);
protected:
More information about the Bf-blender-cvs
mailing list