[Bf-blender-cvs] [306235f] object_nodes: Use formal node graph inputs to create formal function arguments and initialize the stack.
Lukas Tönne
noreply at git.blender.org
Tue Dec 8 14:52:29 CET 2015
Commit: 306235fa70122b38236981677242345fb8c4c6c2
Author: Lukas Tönne
Date: Tue Dec 8 14:21:07 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB306235fa70122b38236981677242345fb8c4c6c2
Use formal node graph inputs to create formal function arguments and initialize the stack.
===================================================================
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_nodegraph.cc
M source/blender/blenvm/intern/bvm_api.cc
===================================================================
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 27d38bf..cacec12 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -804,8 +804,19 @@ void EvalContext::eval_function(const EvalGlobals *globals, const EvalData *data
{
float stack[BVM_STACK_SIZE] = {0};
+ /* initialize input arguments */
+ for (int i = 0; i < fn->num_arguments(); ++i) {
+ const Argument &arg = fn->argument(i);
+ if (arg.stack_offset != BVM_STACK_INVALID) {
+ float *value = &stack[arg.stack_offset];
+
+ arg.typedesc.copy_value((void *)value, arguments[i]);
+ }
+ }
+
eval_instructions(globals, data, fn, fn->entry_point(), stack);
+ /* read out return values */
for (int i = 0; i < fn->num_return_values(); ++i) {
const Argument &rval = fn->return_value(i);
float *value = &stack[rval.stack_offset];
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 356bc66..f176293 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -316,10 +316,6 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
const NodeInstance &node = **it;
- OpCode op = get_opcode_from_node_type(node.type->name());
- if (op == OP_NOOP)
- continue;
-
/* prepare input stack entries */
SocketIndexMap input_index;
for (int i = 0; i < node.num_inputs(); ++i) {
@@ -365,36 +361,39 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
}
}
- /* write main opcode */
- push_opcode(op);
- /* write input stack offsets and constants */
- for (int i = 0; i < node.num_inputs(); ++i) {
- 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);
- codegen_constant(value);
- }
- else if (node.is_input_function(i)) {
- assert(func_entry_map.find(key) != func_entry_map.end());
- FunctionInfo &func = func_entry_map[key];
- push_jump_address(func.entry_point);
- push_stack_index(func.return_index);
+ OpCode op = get_opcode_from_node_type(node.type->name());
+ if (op != OP_NOOP) {
+ /* write main opcode */
+ push_opcode(op);
+ /* write input stack offsets and constants */
+ for (int i = 0; i < node.num_inputs(); ++i) {
+ 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);
+ codegen_constant(value);
+ }
+ else if (node.is_input_function(i)) {
+ assert(func_entry_map.find(key) != func_entry_map.end());
+ FunctionInfo &func = func_entry_map[key];
+ push_jump_address(func.entry_point);
+ push_stack_index(func.return_index);
+ }
+ else {
+ assert(input_index.find(key) != input_index.end());
+ push_stack_index(input_index[key]);
+ }
}
- else {
- assert(input_index.find(key) != input_index.end());
- push_stack_index(input_index[key]);
+ /* write output stack offsets */
+ for (int i = 0; i < node.num_outputs(); ++i) {
+ 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]);
}
}
- /* write output stack offsets */
- for (int i = 0; i < node.num_outputs(); ++i) {
- 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]);
- }
/* release input data stack entries */
for (int i = 0; i < node.num_inputs(); ++i) {
@@ -574,20 +573,30 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
int entry_point = codegen_subgraph(main_nodes, output_users, output_index);
fn->set_entry_point(entry_point);
- 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);
+ /* store stack indices for inputs/outputs, to store arguments from and return results to the caller */
+ for (size_t i = 0; i < graph.inputs.size(); ++i) {
+ const NodeGraph::Input &input = graph.inputs[i];
StackIndex stack_index;
- if (output.key.node) {
- assert(output_index.find(output.key) != output_index.end());
- stack_index = output_index[output.key];
+ if (input.key.node) {
+ assert(output_index.find(input.key) != output_index.end());
+ stack_index = output_index[input.key];
}
else {
- Value *value = output.key.node->type->find_output(output.key.socket)->default_value;
- stack_index = codegen_value(value);
+ stack_index = BVM_STACK_INVALID;
}
- fn->add_return_value(socket->typedesc, output.name, stack_index);
+
+ fn->add_argument(input.typedesc, input.name, stack_index);
+ }
+ for (size_t i = 0; i < graph.outputs.size(); ++i) {
+ const NodeGraph::Output &output = graph.outputs[i];
+
+ /* every output must map to a node */
+ assert(output.key.node);
+ assert(output_index.find(output.key) != output_index.end());
+
+ StackIndex stack_index = output_index[output.key];
+ fn->add_return_value(output.typedesc, output.name, stack_index);
}
}
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index d773234..546c6aa 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -711,10 +711,18 @@ static void used_nodes_append(NodeInstance *node, NodeSet &used_nodes)
void NodeGraph::remove_unused_nodes()
{
NodeSet used_nodes;
+ /* all output nodes and their inputs subgraphs are used */
for (NodeGraph::OutputList::iterator it = outputs.begin(); it != outputs.end(); ++it) {
Output &output = *it;
used_nodes_append(output.key.node, used_nodes);
}
+ /* make sure unused inputs don't leave dangling node pointers */
+ for (NodeGraph::InputList::iterator it = inputs.begin(); it != inputs.end(); ++it) {
+ Input &input = *it;
+ if (used_nodes.find(input.key.node) == used_nodes.end()) {
+ input.key = SocketPair();
+ }
+ }
NodeInstanceMap::iterator it = nodes.begin();
while (it != nodes.end()) {
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 7a64c48..6f250b6 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -110,16 +110,28 @@ void BVM_nodegraph_get_input(struct BVMNodeGraph *graph, const char *name,
struct BVMNodeInstance **node, const char **socket)
{
const bvm::NodeGraph::Input *input = _GRAPH(graph)->get_input(name);
- if (node) *node = (BVMNodeInstance *)input->key.node;
- if (socket) *socket = input->key.socket.c_str();
+ if (input) {
+ if (node) *node = (BVMNodeInstance *)input->key.node;
+ if (socket) *socket = input->key.socket.c_str();
+ }
+ else {
+ if (node) *node = NULL;
+ if (socket) *socket = "";
+ }
}
void BVM_nodegraph_get_output(struct BVMNodeGraph *graph, const char *name,
struct BVMNodeInstance **node, const char **socket)
{
const bvm::NodeGraph::Output *output = _GRAPH(graph)->get_output(name);
- if (node) *node = (BVMNodeInstance *)output->key.node;
- if (socket) *socket = output->key.socket.c_str();
+ if (output) {
+ if (node) *node = (BVMNodeInstance *)output->key.node;
+ if (socket) *socket = output->key.socket.c_str();
+ }
+ else {
+ if (node) *node = NULL;
+ if (socket) *socket = "";
+ }
}
More information about the Bf-blender-cvs
mailing list