[Bf-blender-cvs] [c7f4433] object_nodes: Splitting the codegen function into a 'symbol resolve' part and a 'codegen' part.
Lukas Tönne
noreply at git.blender.org
Wed Dec 9 10:47:19 CET 2015
Commit: c7f44335faa8d73bea7127ee88699b442bb17178
Author: Lukas Tönne
Date: Wed Dec 9 10:45:12 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBc7f44335faa8d73bea7127ee88699b442bb17178
Splitting the codegen function into a 'symbol resolve' part and a 'codegen' part.
This basically introduces a linker step which will allow the proper use of function calls.
===================================================================
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_codegen.h
M source/blender/blenvm/intern/bvm_api.cc
===================================================================
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 0161d7b..0444172 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -82,35 +82,35 @@ StackIndex BVMCompiler::assign_stack_index(const TypeDesc &typedesc)
return stack_offset;
}
-void BVMCompiler::push_opcode(OpCode op)
+void BVMCompiler::push_opcode(OpCode op) const
{
fn->add_instruction(op);
}
-void BVMCompiler::push_stack_index(StackIndex arg)
+void BVMCompiler::push_stack_index(StackIndex arg) const
{
if (arg != BVM_STACK_INVALID)
fn->add_instruction(arg);
}
-void BVMCompiler::push_jump_address(int address)
+void BVMCompiler::push_jump_address(int address) const
{
fn->add_instruction(int_to_instruction(address));
}
-void BVMCompiler::push_float(float f)
+void BVMCompiler::push_float(float f) const
{
fn->add_instruction(float_to_instruction(f));
}
-void BVMCompiler::push_float3(float3 f)
+void BVMCompiler::push_float3(float3 f) const
{
fn->add_instruction(float_to_instruction(f.x));
fn->add_instruction(float_to_instruction(f.y));
fn->add_instruction(float_to_instruction(f.z));
}
-void BVMCompiler::push_float4(float4 f)
+void BVMCompiler::push_float4(float4 f) const
{
fn->add_instruction(float_to_instruction(f.x));
fn->add_instruction(float_to_instruction(f.y));
@@ -118,12 +118,12 @@ void BVMCompiler::push_float4(float4 f)
fn->add_instruction(float_to_instruction(f.w));
}
-void BVMCompiler::push_int(int i)
+void BVMCompiler::push_int(int i) const
{
fn->add_instruction(int_to_instruction(i));
}
-void BVMCompiler::push_matrix44(matrix44 m)
+void BVMCompiler::push_matrix44(matrix44 m) const
{
fn->add_instruction(float_to_instruction(m.data[0][0]));
fn->add_instruction(float_to_instruction(m.data[0][1]));
@@ -143,7 +143,7 @@ void BVMCompiler::push_matrix44(matrix44 m)
fn->add_instruction(float_to_instruction(m.data[3][3]));
}
-void BVMCompiler::push_pointer(PointerRNA p)
+void BVMCompiler::push_pointer(PointerRNA p) const
{
fn->add_instruction(pointer_to_instruction_hi(p.id.data));
fn->add_instruction(pointer_to_instruction_lo(p.id.data));
@@ -153,122 +153,118 @@ void BVMCompiler::push_pointer(PointerRNA p)
fn->add_instruction(pointer_to_instruction_lo(p.data));
}
-StackIndex BVMCompiler::codegen_value(const Value *value)
+void BVMCompiler::push_constant(const Value *value) const
{
- StackIndex offset = assign_stack_index(value->typedesc());
-
switch (value->typedesc().base_type) {
case BVM_FLOAT: {
float f = 0.0f;
value->get(&f);
- push_opcode(OP_VALUE_FLOAT);
push_float(f);
- push_stack_index(offset);
break;
}
case BVM_FLOAT3: {
float3 f = float3(0.0f, 0.0f, 0.0f);
value->get(&f);
- push_opcode(OP_VALUE_FLOAT3);
push_float3(f);
- push_stack_index(offset);
break;
}
case BVM_FLOAT4: {
float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
value->get(&f);
- push_opcode(OP_VALUE_FLOAT4);
push_float4(f);
- push_stack_index(offset);
break;
}
case BVM_INT: {
int i = 0;
value->get(&i);
- push_opcode(OP_VALUE_INT);
push_int(i);
- push_stack_index(offset);
break;
}
case BVM_MATRIX44: {
matrix44 m = matrix44::identity();
value->get(&m);
- push_opcode(OP_VALUE_MATRIX44);
push_matrix44(m);
- push_stack_index(offset);
break;
}
case BVM_POINTER: {
PointerRNA p = PointerRNA_NULL;
value->get(&p);
- push_opcode(OP_VALUE_POINTER);
push_pointer(p);
- push_stack_index(offset);
break;
}
case BVM_MESH:
- push_opcode(OP_VALUE_MESH);
- push_stack_index(offset);
break;
}
-
- return offset;
}
-void BVMCompiler::codegen_constant(const Value *value)
+void BVMCompiler::codegen_value(const Value *value, StackIndex offset) const
{
switch (value->typedesc().base_type) {
case BVM_FLOAT: {
float f = 0.0f;
value->get(&f);
+ push_opcode(OP_VALUE_FLOAT);
push_float(f);
+ push_stack_index(offset);
break;
}
case BVM_FLOAT3: {
float3 f = float3(0.0f, 0.0f, 0.0f);
value->get(&f);
+ push_opcode(OP_VALUE_FLOAT3);
push_float3(f);
+ push_stack_index(offset);
break;
}
case BVM_FLOAT4: {
float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
value->get(&f);
+ push_opcode(OP_VALUE_FLOAT4);
push_float4(f);
+ push_stack_index(offset);
break;
}
case BVM_INT: {
int i = 0;
value->get(&i);
+ push_opcode(OP_VALUE_INT);
push_int(i);
+ push_stack_index(offset);
break;
}
case BVM_MATRIX44: {
matrix44 m = matrix44::identity();
value->get(&m);
+ push_opcode(OP_VALUE_MATRIX44);
push_matrix44(m);
+ push_stack_index(offset);
break;
}
case BVM_POINTER: {
PointerRNA p = PointerRNA_NULL;
value->get(&p);
+ push_opcode(OP_VALUE_POINTER);
push_pointer(p);
+ push_stack_index(offset);
break;
}
case BVM_MESH:
+ push_opcode(OP_VALUE_MESH);
+ push_stack_index(offset);
break;
}
}
@@ -307,17 +303,14 @@ static OpCode ptr_release_opcode(const TypeDesc &typedesc)
return OP_NOOP;
}
-int BVMCompiler::codegen_subgraph(const NodeList &nodes,
- const SocketUserMap &socket_users,
- SocketIndexMap &output_index)
+void BVMCompiler::resolve_subgraph_symbols(const NodeList &nodes,
+ SocketIndexMap &input_index,
+ SocketIndexMap &output_index)
{
- int entry_point = fn->get_instruction_count();
-
for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
const NodeInstance &node = **it;
/* prepare input stack entries */
- SocketIndexMap input_index;
for (int i = 0; i < node.num_inputs(); ++i) {
const NodeInput *input = node.type->find_input(i);
ConstSocketPair key(&node, input->name);
@@ -332,12 +325,8 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
assert(output_index.find(link_key) != output_index.end());
input_index[key] = output_index[link_key];
}
- else if (node.has_input_value(i)) {
- Value *value = node.find_input_value(i);
- input_index[key] = codegen_value(value);
- }
else {
- input_index[key] = codegen_value(input->default_value);
+ input_index[key] = assign_stack_index(input->typedesc);
}
}
@@ -347,15 +336,49 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
ConstSocketPair key(&node, output->name);
output_index[key] = assign_stack_index(output->typedesc);
+ }
+ }
+}
+
+int BVMCompiler::codegen_subgraph(const NodeList &nodes,
+ const SocketUserMap &socket_users,
+ const SocketIndexMap &input_index,
+ const SocketIndexMap &output_index) const
+{
+ int entry_point = fn->get_instruction_count();
+
+ for (NodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
+ const NodeInstance &node = **it;
+
+ /* store values for unconnected inputs */
+ for (int i = 0; i < node.num_inputs(); ++i) {
+ const NodeInput *input = node.type->find_input(i);
+ ConstSocketPair key(&node, input->name);
+
+ if (node.is_input_constant(i) || node.is_input_function(i)) {
+ /* stored directly in instructions */
+ }
+ else if (node.has_input_link(i)) {
+ /* uses linked output value on the stack */
+ }
+ 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));
+ }
+ }
+ /* 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);
/* if necessary, add a user count initializer */
OpCode init_op = ptr_init_opcode(output->typedesc);
if (init_op != OP_NOOP) {
- assert(socket_users.find(key) != socket_users.end());
int users = socket_users.find(key)->second;
if (users > 0) {
push_opcode(init_op);
- push_stack_index(output_index[key]);
+ push_stack_index(output_index.at(key));
push_int(users);
}
}
@@ -372,26 +395,23 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
if (node.is_input_constant(i)) {
Value *value = node.find_input_value(i);
- codegen_constant(value);
+ push_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];
+ const FunctionInfo &func = func_entry_map.at(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]);
+ push_stack_index(input_index.at(key));
}
}
/* write output stack offsets */
for (int i = 0; i < node.num_outputs(); ++i) {
const NodeOutput *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]);
+ push_stack_index(output_index.at(key));
}
}
@@ -405,13 +425,12 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
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());
OpCode release_op = ptr_release_opcode(input->typedesc);
if (release_op != OP_NOOP) {
push_opcode(release_op);
- push_stack_index(output_index[link_key]);
+ push_stack_index(output_index.at(link_key));
}
}
}
@@ -422,69 +441,63 @@ int BVMCompiler::codegen_subgraph(const NodeList &nodes,
return entry_point;
}
-void BVMCompiler::graph_node_append(const NodeInstance *node,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list