[Bf-blender-cvs] [60779ad] object_nodes: Added an 'entry point' instruction number to functions.
Lukas Tönne
noreply at git.blender.org
Wed Nov 25 15:22:41 CET 2015
Commit: 60779ad90e255db43fb1281d0461f4ff259406fb
Author: Lukas Tönne
Date: Wed Nov 25 11:27:37 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB60779ad90e255db43fb1281d0461f4ff259406fb
Added an 'entry point' instruction number to functions.
This is currently always 0, but will be used in the future to allow
storing per-element functions along with the main code. These can then
be called within kernels.
===================================================================
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_function.cc
M source/blender/blenvm/bvm/bvm_function.h
M source/blender/blenvm/compile/bvm_codegen.cc
===================================================================
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index b6d9014..76ed42b 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -465,7 +465,7 @@ static void eval_op_effector_closest_point(float *stack, StackIndex offset_objec
void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *data, const Function *fn, float *stack) const
{
- int instr = 0;
+ int instr = fn->entry_point();
while (true) {
OpCode op = fn->read_opcode(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_function.cc b/source/blender/blenvm/bvm/bvm_function.cc
index 44a86c6..8a93910 100644
--- a/source/blender/blenvm/bvm/bvm_function.cc
+++ b/source/blender/blenvm/bvm/bvm_function.cc
@@ -33,7 +33,8 @@
namespace bvm {
-Function::Function()
+Function::Function() :
+ m_entry_point(0)
{
}
@@ -43,31 +44,36 @@ Function::~Function()
void Function::add_instruction(Instruction v)
{
- instructions.push_back(v);
+ m_instructions.push_back(v);
+}
+
+void Function::set_entry_point(int entry_point)
+{
+ m_entry_point = entry_point;
}
ReturnValue &Function::add_return_value(const TypeDesc &typedesc, const string &name)
{
- return_values.push_back(ReturnValue(typedesc, name));
- return return_values.back();
+ m_return_values.push_back(ReturnValue(typedesc, name));
+ return m_return_values.back();
}
size_t Function::return_values_size() const
{
- return return_values.size();
+ return m_return_values.size();
}
const ReturnValue &Function::return_value(size_t index) const
{
- return return_values[index];
+ return m_return_values[index];
}
const ReturnValue &Function::return_value(const string &name) const
{
- for (ReturnValueList::const_iterator it = return_values.begin(); it != return_values.end(); ++it)
+ for (ReturnValueList::const_iterator it = m_return_values.begin(); it != m_return_values.end(); ++it)
if ((*it).name == name)
return *it;
- return *(return_values.end());
+ return *(m_return_values.end());
}
} /* namespace bvm */
diff --git a/source/blender/blenvm/bvm/bvm_function.h b/source/blender/blenvm/bvm/bvm_function.h
index 8317d62..2822ed7 100644
--- a/source/blender/blenvm/bvm/bvm_function.h
+++ b/source/blender/blenvm/bvm/bvm_function.h
@@ -120,21 +120,21 @@ struct Function {
OpCode read_opcode(int *instr) const
{
- OpCode op = (OpCode)instructions[*instr];
+ OpCode op = (OpCode)m_instructions[*instr];
++(*instr);
return op;
}
StackIndex read_stack_index(int *instr) const
{
- StackIndex index = instructions[*instr];
+ StackIndex index = m_instructions[*instr];
++(*instr);
return index;
}
float read_float(int *instr) const
{
- float f = instruction_to_float(instructions[*instr]);
+ float f = instruction_to_float(m_instructions[*instr]);
++(*instr);
return f;
}
@@ -142,9 +142,9 @@ struct Function {
float3 read_float3(int *instr) const
{
float3 f;
- f.x = instruction_to_float(instructions[*instr + 0]);
- f.y = instruction_to_float(instructions[*instr + 1]);
- f.z = instruction_to_float(instructions[*instr + 2]);
+ f.x = instruction_to_float(m_instructions[*instr + 0]);
+ f.y = instruction_to_float(m_instructions[*instr + 1]);
+ f.z = instruction_to_float(m_instructions[*instr + 2]);
(*instr) += 3;
return f;
}
@@ -152,17 +152,17 @@ struct Function {
float4 read_float4(int *instr) const
{
float4 f;
- f.x = instruction_to_float(instructions[*instr + 0]);
- f.y = instruction_to_float(instructions[*instr + 1]);
- f.z = instruction_to_float(instructions[*instr + 2]);
- f.w = instruction_to_float(instructions[*instr + 3]);
+ f.x = instruction_to_float(m_instructions[*instr + 0]);
+ f.y = instruction_to_float(m_instructions[*instr + 1]);
+ f.z = instruction_to_float(m_instructions[*instr + 2]);
+ f.w = instruction_to_float(m_instructions[*instr + 3]);
(*instr) += 4;
return f;
}
int read_int(int *instr) const
{
- int i = instruction_to_int(instructions[*instr]);
+ int i = instruction_to_int(m_instructions[*instr]);
++(*instr);
return i;
}
@@ -170,31 +170,31 @@ struct Function {
matrix44 read_matrix44(int *instr) const
{
matrix44 m;
- m.data[0][0] = instruction_to_float(instructions[*instr + 0]);
- m.data[0][1] = instruction_to_float(instructions[*instr + 1]);
- m.data[0][2] = instruction_to_float(instructions[*instr + 2]);
- m.data[0][3] = instruction_to_float(instructions[*instr + 3]);
- m.data[1][0] = instruction_to_float(instructions[*instr + 4]);
- m.data[1][1] = instruction_to_float(instructions[*instr + 5]);
- m.data[1][2] = instruction_to_float(instructions[*instr + 6]);
- m.data[1][3] = instruction_to_float(instructions[*instr + 7]);
- m.data[2][0] = instruction_to_float(instructions[*instr + 8]);
- m.data[2][1] = instruction_to_float(instructions[*instr + 9]);
- m.data[2][2] = instruction_to_float(instructions[*instr + 10]);
- m.data[2][3] = instruction_to_float(instructions[*instr + 11]);
- m.data[3][0] = instruction_to_float(instructions[*instr + 12]);
- m.data[3][1] = instruction_to_float(instructions[*instr + 13]);
- m.data[3][2] = instruction_to_float(instructions[*instr + 14]);
- m.data[3][3] = instruction_to_float(instructions[*instr + 15]);
+ m.data[0][0] = instruction_to_float(m_instructions[*instr + 0]);
+ m.data[0][1] = instruction_to_float(m_instructions[*instr + 1]);
+ m.data[0][2] = instruction_to_float(m_instructions[*instr + 2]);
+ m.data[0][3] = instruction_to_float(m_instructions[*instr + 3]);
+ m.data[1][0] = instruction_to_float(m_instructions[*instr + 4]);
+ m.data[1][1] = instruction_to_float(m_instructions[*instr + 5]);
+ m.data[1][2] = instruction_to_float(m_instructions[*instr + 6]);
+ m.data[1][3] = instruction_to_float(m_instructions[*instr + 7]);
+ m.data[2][0] = instruction_to_float(m_instructions[*instr + 8]);
+ m.data[2][1] = instruction_to_float(m_instructions[*instr + 9]);
+ m.data[2][2] = instruction_to_float(m_instructions[*instr + 10]);
+ m.data[2][3] = instruction_to_float(m_instructions[*instr + 11]);
+ m.data[3][0] = instruction_to_float(m_instructions[*instr + 12]);
+ m.data[3][1] = instruction_to_float(m_instructions[*instr + 13]);
+ m.data[3][2] = instruction_to_float(m_instructions[*instr + 14]);
+ m.data[3][3] = instruction_to_float(m_instructions[*instr + 15]);
(*instr) += 16;
return m;
}
PointerRNA read_pointer(int *instr) const
{
- ID *id = (ID *)instruction_to_pointer(instructions[*instr + 0], instructions[*instr + 1]);
- StructRNA *type = (StructRNA *)instruction_to_pointer(instructions[*instr + 2], instructions[*instr + 3]);
- void *data = instruction_to_pointer(instructions[*instr + 4], instructions[*instr + 5]);
+ ID *id = (ID *)instruction_to_pointer(m_instructions[*instr + 0], m_instructions[*instr + 1]);
+ StructRNA *type = (StructRNA *)instruction_to_pointer(m_instructions[*instr + 2], m_instructions[*instr + 3]);
+ void *data = instruction_to_pointer(m_instructions[*instr + 4], m_instructions[*instr + 5]);
(*instr) += 6;
PointerRNA ptr;
@@ -204,14 +204,18 @@ struct Function {
void add_instruction(Instruction v);
+ int entry_point() const { return m_entry_point; }
+ void set_entry_point(int m_entry_point);
+
ReturnValue &add_return_value(const TypeDesc &typedesc, const string &name = "");
size_t return_values_size() const;
const ReturnValue &return_value(size_t index) const;
const ReturnValue &return_value(const string &name) const;
private:
- ReturnValueList return_values;
- InstructionList instructions;
+ ReturnValueList m_return_values;
+ InstructionList m_instructions;
+ int m_entry_point;
MEM_CXX_CLASS_ALLOC_FUNCS("BVM:Function")
};
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 3deb9d7..5cd4d3d 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -373,6 +373,7 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
typedef std::map<ConstSocketPair, StackIndex> SocketIndexMap;
fn = new Function();
+ int entry_point = 0;
NodeList sorted_nodes;
sort_nodes(graph, sorted_nodes);
@@ -500,6 +501,8 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
push_opcode(OP_END);
+ fn->set_entry_point(entry_point);
+
Function *result = fn;
fn = NULL;
return result;
More information about the Bf-blender-cvs
mailing list