[Bf-blender-cvs] [239c864] object_nodes: Updated codegen for handling variables and expressions.
Lukas Tönne
noreply at git.blender.org
Fri Jan 29 14:37:03 CET 2016
Commit: 239c864318a6524248409b47df41bfd80b13bfd5
Author: Lukas Tönne
Date: Fri Jan 29 14:31:59 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB239c864318a6524248409b47df41bfd80b13bfd5
Updated codegen for handling variables and expressions.
Note that kernel nodes now don't have explicit 'function' inputs
any more. Any expression input can be a separate block. Eventually
this should be handled by creating true loops, branches, etc. in the
generated code, rather than reading a jump address from the instructions
and passing it to a blackbox method as a "function pointer".
For the time being the kernel nodes simply prepend a jump address before
*every* input, using BVM_JMP_INVALID in case the input node is not in a
separate block.
===================================================================
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_eval_mesh.h
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_nodegraph.cc
===================================================================
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 549238d..56f91ff 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -457,11 +457,11 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Instructio
}
case OP_RANGE_INT: {
StackIndex offset_index = fn->read_stack_index(&instr);
- StackIndex offset_start = fn->read_int(&instr);
- StackIndex offset_end = fn->read_int(&instr);
- StackIndex offset_step = fn->read_int(&instr);
+ int start = fn->read_int(&instr);
+ int end = fn->read_int(&instr);
+ int step = fn->read_int(&instr);
StackIndex offset_value = fn->read_stack_index(&instr);
- eval_op_range_int(stack, offset_index, offset_start, offset_end, offset_step, offset_value);
+ eval_op_range_int(stack, start, end, step, offset_index, offset_value);
break;
}
case OP_FLOAT_TO_INT: {
@@ -1079,27 +1079,29 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Instructio
break;
}
case OP_MESH_ARRAY: {
+ fn->read_jump_address(&instr);
StackIndex offset_mesh_in = fn->read_stack_index(&instr);
+ fn->read_jump_address(&instr);
StackIndex offset_count = fn->read_stack_index(&instr);
- int fn_transform = fn->read_jump_address(&instr);
+ int adr_transform = fn->read_jump_address(&instr);
StackIndex offset_transform = fn->read_stack_index(&instr);
StackIndex offset_mesh_out = fn->read_stack_index(&instr);
- StackIndex offset_iteration = fn->read_stack_index(&instr);
+ StackIndex offset_index = fn->read_stack_index(&instr);
eval_op_mesh_array(globals, &kd, stack,
offset_mesh_in, offset_mesh_out, offset_count,
- fn_transform, offset_transform, offset_iteration);
+ adr_transform, offset_transform, offset_index);
break;
}
case OP_MESH_DISPLACE: {
+ fn->read_jump_address(&instr);
StackIndex offset_mesh_in = fn->read_stack_index(&instr);
int fn_vector = fn->read_jump_address(&instr);
StackIndex offset_vector = fn->read_stack_index(&instr);
StackIndex offset_mesh_out = fn->read_stack_index(&instr);
- StackIndex offset_elem_index = fn->read_stack_index(&instr);
- StackIndex offset_elem_loc = fn->read_stack_index(&instr);
+ StackIndex offset_index = fn->read_stack_index(&instr);
eval_op_mesh_displace(globals, &kd, stack,
offset_mesh_in, offset_mesh_out, fn_vector, offset_vector,
- offset_elem_index, offset_elem_loc);
+ offset_index);
break;
}
case OP_MESH_BOOLEAN: {
diff --git a/source/blender/blenvm/bvm/bvm_eval_mesh.h b/source/blender/blenvm/bvm/bvm_eval_mesh.h
index e026b13..57d7d8b 100644
--- a/source/blender/blenvm/bvm/bvm_eval_mesh.h
+++ b/source/blender/blenvm/bvm/bvm_eval_mesh.h
@@ -298,8 +298,8 @@ static void eval_op_mesh_array(const EvalGlobals *globals, const EvalKernelData
}
static DerivedMesh *do_displace(const EvalGlobals *globals, const EvalKernelData *kernel_data, EvalStack *stack,
- DerivedMesh *dm, int fn_vector, StackIndex offset_vector,
- StackIndex offset_elem_index, StackIndex offset_elem_loc)
+ DerivedMesh *dm, int fn_vector, StackIndex offset_vector,
+ StackIndex offset_index)
{
DerivedMesh *result = CDDM_copy(dm);
MVert *orig_mv, *orig_mverts = dm->getVertArray(dm);
@@ -307,8 +307,7 @@ static DerivedMesh *do_displace(const EvalGlobals *globals, const EvalKernelData
int i, numverts = result->getNumVerts(result);
for (i = 0, mv = mverts, orig_mv = orig_mverts; i < numverts; ++i, ++mv, ++orig_mv) {
- stack_store_int(stack, offset_elem_index, i);
- stack_store_float3(stack, offset_elem_loc, float3::from_data(orig_mv->co));
+ stack_store_int(stack, offset_index, i);
kernel_data->context->eval_expression(globals, kernel_data->function, fn_vector, stack);
float3 dco = stack_load_float3(stack, offset_vector);
@@ -323,14 +322,14 @@ static DerivedMesh *do_displace(const EvalGlobals *globals, const EvalKernelData
static void eval_op_mesh_displace(const EvalGlobals *globals, const EvalKernelData *kernel_data, EvalStack *stack,
StackIndex offset_mesh_in, StackIndex offset_mesh_out,
- int fn_vector, StackIndex offset_vector,
- StackIndex offset_elem_index, StackIndex offset_elem_loc)
+ int adr_vector, StackIndex offset_vector,
+ StackIndex offset_index)
{
DerivedMesh *dm = stack_load_mesh(stack, offset_mesh_in);
DerivedMesh *result = do_displace(globals, kernel_data, stack,
- dm, fn_vector, offset_vector,
- offset_elem_index, offset_elem_loc);
+ dm, adr_vector, offset_vector,
+ offset_index);
stack_store_mesh(stack, offset_mesh_out, result);
}
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 58daa45..c7481c3 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -421,68 +421,82 @@ int Compiler::codegen_node_block(const NodeBlock &block)
for (OrderedNodeSet::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
const NodeInstance &node = **it;
+#if 0
/* store values for unconnected inputs */
for (int i = 0; i < node.num_inputs(); ++i) {
- ConstInputKey key = node.input(i);
+ ConstInputKey input = node.input(i);
- if (key.value_type() == INPUT_CONSTANT ||
- key.value_type() == INPUT_EXPRESSION) {
- /* stored directly in instructions */
- }
- else if (key.link()) {
- /* uses linked output value on the stack */
- }
- else {
- /* create a value node for the input */
- codegen_value(key.value(), input_index.at(key));
+ switch (input.value_type()) {
+ case INPUT_CONSTANT:
+ /* stored directly in instructions */
+ break;
+ case INPUT_EXPRESSION:
+ case INPUT_VARIABLE:
+ /* uses linked output value on the stack */
+ assert(input.link());
+ break;
}
}
+#endif
/* initialize output data stack entries */
for (int i = 0; i < node.num_outputs(); ++i) {
- const NodeOutput *output = node.type->find_output(i);
- ConstOutputKey key(&node, output->name);
+ ConstOutputKey output = node.output(i);
/* if necessary, add a user count initializer */
- OpCode init_op = ptr_init_opcode(output->typedesc);
+ OpCode init_op = ptr_init_opcode(output.socket->typedesc);
if (init_op != OP_NOOP) {
- int users = output_users.at(key);
+ int users = output_users.at(output);
if (users > 0) {
push_opcode(init_op);
- push_stack_index(output_index.at(key));
+ push_stack_index(output_index.at(output));
push_int(users);
}
}
}
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) {
- ConstInputKey key = node.input(i);
+ ConstInputKey input = node.input(i);
+ ConstOutputKey link = input.link();
- if (key.value_type() == INPUT_CONSTANT) {
- push_constant(key.value());
- }
- else {
- if (key.value_type() == INPUT_EXPRESSION) {
- if (key.link() && key.link().node->block != &block) {
- const NodeBlock *expr_block = key.link().node->block;
- push_jump_address(block_info.at(expr_block).entry_point);
+ switch (input.value_type()) {
+ case INPUT_CONSTANT:
+ push_constant(input.value());
+ break;
+ case INPUT_EXPRESSION:
+ case INPUT_VARIABLE:
+ /* XXX This is neither ideal nor final:
+ * Ultimately loops, conditionals, etc. should
+ * be coded explicitly in the instructions,
+ * but for the time being we leave it to complex
+ * kernel blackbox functions to call functions.
+ * Every kernel op simply gets a jump address in front
+ * of each input variable, so we don't need an extra
+ * qualifier per input.
+ */
+ if (node.type->is_kernel_node()) {
+ if (link.node->block->parent() == &block) {
+ const NodeBlock *expr_block = input.link().node->block;
+ push_jump_address(block_info.at(expr_block).entry_point);
+ }
+ else
+ push_jump_address(BVM_JMP_INVALID);
}
- else
- push_jump_address(BVM_JMP_INVALID);
- }
-
- push_stack_index(input_index.at(key));
+
+ push_stack_index(input_index.at(input));
+ break;
}
}
/* write output stack offsets */
for (int i = 0; i < node.num_outputs(); ++i) {
- ConstOutputKey key = node.output(i);
+ ConstOutputKey output = node.output(i);
- push_stack_index(output_index.at(key));
+ push_stack_index(output_index.at(output));
}
}
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 7535c06..7ce5406 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -1837,11 +1837,11 @@ static void register_opcode_node_types()
nt->add_output("normal", "FLOAT3");
nt->add_output("tangent", "FLOAT3");
- nt = NodeGraph::add_kernel_node_type("MESH_LOAD");
+ nt = NodeGraph::add_function_node_type("MESH_LOAD");
nt->add_input("base_mesh", "RNAPOINTER", PointerRNA_NULL);
nt->add_output("mesh", "MESH");
- nt = NodeGraph::add_kernel_node_type("MESH_COMBINE");
+ nt = NodeGraph::add_function_node_type("MESH_COMBINE");
nt->add_input("mesh_a", "MESH", __empty_mesh__);
nt->add_input("mesh_b", "MESH", __empty_mesh__);
nt->add_output("mesh_out", "MESH");
@@ -1851,16 +1851,15 @@ static void register_opcode_node_types()
nt->add_input("count", "INT", 1);
nt->add_input(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list