[Bf-blender-cvs] [09f875e] object_nodes: Pointer type for passing opaque DNA references and the like through the VM.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:43:45 CET 2015
Commit: 09f875e164d3e39a659c6c555f1a2aaf4a4f0e9d
Author: Lukas Tönne
Date: Mon Nov 2 12:44:12 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB09f875e164d3e39a659c6c555f1a2aaf4a4f0e9d
Pointer type for passing opaque DNA references and the like through the VM.
===================================================================
M source/blender/blenvm/BVM_types.h
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_eval_common.h
M source/blender/blenvm/bvm/bvm_expression.h
M source/blender/blenvm/bvm/bvm_opcode.h
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_codegen.h
M source/blender/blenvm/compile/bvm_nodegraph.cc
M source/blender/blenvm/util/bvm_util_typedesc.h
===================================================================
diff --git a/source/blender/blenvm/BVM_types.h b/source/blender/blenvm/BVM_types.h
index 7a2ecbe..aed28fb 100644
--- a/source/blender/blenvm/BVM_types.h
+++ b/source/blender/blenvm/BVM_types.h
@@ -42,6 +42,7 @@ typedef enum BVMType {
BVM_FLOAT4,
BVM_INT,
BVM_MATRIX44,
+ BVM_POINTER,
} BVMType;
#ifdef __cplusplus
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index a24cadf..72db2e1 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -81,6 +81,11 @@ static void eval_op_value_matrix44(float *stack, matrix44 value, StackIndex offs
stack_store_matrix44(stack, offset, value);
}
+static void eval_op_value_pointer(float *stack, PointerRNA value, StackIndex offset)
+{
+ stack_store_pointer(stack, offset, value);
+}
+
static void eval_op_pass_float(float *stack, StackIndex offset_from, StackIndex offset_to)
{
float f = stack_load_float(stack, offset_from);
@@ -99,6 +104,24 @@ static void eval_op_pass_float4(float *stack, StackIndex offset_from, StackIndex
stack_store_float4(stack, offset_to, f);
}
+static void eval_op_pass_int(float *stack, StackIndex offset_from, StackIndex offset_to)
+{
+ int i = stack_load_int(stack, offset_from);
+ stack_store_int(stack, offset_to, i);
+}
+
+static void eval_op_pass_matrix44(float *stack, StackIndex offset_from, StackIndex offset_to)
+{
+ matrix44 m = stack_load_matrix44(stack, offset_from);
+ stack_store_matrix44(stack, offset_to, m);
+}
+
+static void eval_op_pass_pointer(float *stack, StackIndex offset_from, StackIndex offset_to)
+{
+ PointerRNA p = stack_load_pointer(stack, offset_from);
+ stack_store_pointer(stack, offset_to, p);
+}
+
static void eval_op_set_float3(float *stack, StackIndex offset_x, StackIndex offset_y, StackIndex offset_z, StackIndex offset_to)
{
float x = stack_load_float(stack, offset_x);
@@ -406,6 +429,12 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_value_matrix44(stack, value, offset);
break;
}
+ case OP_VALUE_POINTER: {
+ PointerRNA value = expr->read_pointer(&instr);
+ StackIndex offset = expr->read_stack_index(&instr);
+ eval_op_value_pointer(stack, value, offset);
+ break;
+ }
case OP_PASS_FLOAT: {
StackIndex offset_from = expr->read_stack_index(&instr);
StackIndex offset_to = expr->read_stack_index(&instr);
@@ -424,6 +453,24 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_pass_float4(stack, offset_from, offset_to);
break;
}
+ case OP_PASS_INT: {
+ StackIndex offset_from = expr->read_stack_index(&instr);
+ StackIndex offset_to = expr->read_stack_index(&instr);
+ eval_op_pass_int(stack, offset_from, offset_to);
+ break;
+ }
+ case OP_PASS_MATRIX44: {
+ StackIndex offset_from = expr->read_stack_index(&instr);
+ StackIndex offset_to = expr->read_stack_index(&instr);
+ eval_op_pass_matrix44(stack, offset_from, offset_to);
+ break;
+ }
+ case OP_PASS_POINTER: {
+ StackIndex offset_from = expr->read_stack_index(&instr);
+ StackIndex offset_to = expr->read_stack_index(&instr);
+ eval_op_pass_pointer(stack, offset_from, offset_to);
+ break;
+ }
case OP_SET_FLOAT3: {
StackIndex offset_x = expr->read_stack_index(&instr);
StackIndex offset_y = expr->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval_common.h b/source/blender/blenvm/bvm/bvm_eval_common.h
index 98f8aef..494f9aa 100644
--- a/source/blender/blenvm/bvm/bvm_eval_common.h
+++ b/source/blender/blenvm/bvm/bvm_eval_common.h
@@ -62,6 +62,11 @@ inline static matrix44 stack_load_matrix44(float *stack, StackIndex offset)
return *(matrix44 *)(&stack[offset]);
}
+inline static PointerRNA stack_load_pointer(float *stack, StackIndex offset)
+{
+ return *(PointerRNA *)(&stack[offset]);
+}
+
inline static void stack_store_float(float *stack, StackIndex offset, float f)
{
*(float *)(&stack[offset]) = f;
@@ -87,6 +92,11 @@ inline static void stack_store_matrix44(float *stack, StackIndex offset, matrix4
*(matrix44 *)(&stack[offset]) = m;
}
+inline static void stack_store_pointer(float *stack, StackIndex offset, PointerRNA p)
+{
+ *(PointerRNA *)(&stack[offset]) = p;
+}
+
} /* namespace bvm */
#endif /* __BVM_EVAL_COMMON_H__ */
diff --git a/source/blender/blenvm/bvm/bvm_expression.h b/source/blender/blenvm/bvm/bvm_expression.h
index f4010bd..3a3f8ea 100644
--- a/source/blender/blenvm/bvm/bvm_expression.h
+++ b/source/blender/blenvm/bvm/bvm_expression.h
@@ -59,6 +59,20 @@ static inline Instruction int_to_instruction(int v)
return u.i;
}
+static inline Instruction pointer_to_instruction_lo(void *v)
+{
+ union { uint32_t i[2]; void *v; } u;
+ u.v = v;
+ return u.i[1];
+}
+
+static inline Instruction pointer_to_instruction_hi(void *v)
+{
+ union { uint32_t i[2]; void *v; } u;
+ u.v = v;
+ return u.i[0];
+}
+
static inline float instruction_to_float(Instruction i)
{
union { uint32_t i; float f; } u;
@@ -73,6 +87,14 @@ static inline int instruction_to_int(Instruction i)
return u.v;
}
+static inline void *instruction_to_pointer(Instruction hi, Instruction lo)
+{
+ union { uint32_t i[2]; void *v; } u;
+ u.i[0] = hi;
+ u.i[1] = lo;
+ return u.v;
+}
+
struct ReturnValue {
ReturnValue(const TypeDesc &typedesc, const string &name) :
typedesc(typedesc),
@@ -164,6 +186,18 @@ struct Expression {
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]);
+ (*instr) += 6;
+
+ PointerRNA ptr;
+ RNA_pointer_create(id, type, data, &ptr);
+ return ptr;
+ }
+
void add_instruction(Instruction v);
ReturnValue &add_return_value(const TypeDesc &typedesc, const string &name = "");
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 8d31f71..53250af 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -41,9 +41,13 @@ enum OpCode {
OP_VALUE_FLOAT4,
OP_VALUE_INT,
OP_VALUE_MATRIX44,
+ OP_VALUE_POINTER,
OP_PASS_FLOAT,
OP_PASS_FLOAT3,
OP_PASS_FLOAT4,
+ OP_PASS_INT,
+ OP_PASS_MATRIX44,
+ OP_PASS_POINTER,
OP_SET_FLOAT3,
OP_GET_ELEM_FLOAT3,
OP_SET_FLOAT4,
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 2211ef4..004dee7 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -137,6 +137,16 @@ void BVMCompiler::push_matrix44(matrix44 m)
expr->add_instruction(float_to_instruction(m.data[3][3]));
}
+void BVMCompiler::push_pointer(PointerRNA p)
+{
+ expr->add_instruction(pointer_to_instruction_hi(p.id.data));
+ expr->add_instruction(pointer_to_instruction_lo(p.id.data));
+ expr->add_instruction(pointer_to_instruction_hi(p.type));
+ expr->add_instruction(pointer_to_instruction_lo(p.type));
+ expr->add_instruction(pointer_to_instruction_hi(p.data));
+ expr->add_instruction(pointer_to_instruction_lo(p.data));
+}
+
StackIndex BVMCompiler::codegen_value(const Value *value)
{
StackIndex offset = assign_stack_index(value->typedesc());
@@ -187,6 +197,15 @@ StackIndex BVMCompiler::codegen_value(const Value *value)
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;
+ }
}
return offset;
@@ -230,6 +249,13 @@ void BVMCompiler::codegen_constant(const Value *value)
push_matrix44(m);
break;
}
+ case BVM_POINTER: {
+ PointerRNA p = PointerRNA_NULL;
+ value->get(&p);
+
+ push_pointer(p);
+ break;
+ }
}
}
diff --git a/source/blender/blenvm/compile/bvm_codegen.h b/source/blender/blenvm/compile/bvm_codegen.h
index 981f6df..846235d 100644
--- a/source/blender/blenvm/compile/bvm_codegen.h
+++ b/source/blender/blenvm/compile/bvm_codegen.h
@@ -62,6 +62,7 @@ struct BVMCompiler {
void push_float4(float4 f);
void push_int(int i);
void push_matrix44(matrix44 m);
+ void push_pointer(PointerRNA p);
StackIndex codegen_value(const Value *value);
void codegen_constant(const Value *value);
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 06c56d8..5e60f23 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -557,6 +557,9 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(PASS_FLOAT);
NODETYPE(PASS_FLOAT3);
NODETYPE(PASS_FLOAT4);
+ NODETYPE(PASS_INT);
+ NODETYPE(PASS_MATRIX44);
+ NODETYPE(PASS_POINTER);
NODETYPE(SET_FLOAT3);
NODETYPE(GET_ELEM_FLOAT3);
@@ -619,6 +622,18 @@ void register_opcode_node_types()
nt->add_input("value", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 0.0f));
nt->add_output("value", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 0.0f));
+ nt = NodeGraph::add_node_type("PASS_INT");
+ nt->add_input("value", BVM_INT, 0);
+ nt->add_output("value", BVM_INT, 0);
+
+ nt = NodeGraph::add_node_type("PASS_MATRIX44");
+ nt->add_input("value", BVM_MATRIX44, matrix44::identity());
+ nt->add_output("value", BVM_MATRIX44, matrix44::identity());
+
+ nt = NodeGraph::add_node_type("PASS_POINTER");
+ nt->add_input("value", BVM_POINTER, PointerRNA_NULL);
+ nt->add_output("value", BVM_POINTER, PointerRNA_NULL);
+
nt = NodeGraph::add_node_type("GET_ELEM_FLOAT3");
nt->add_input("index", BVM_INT, 0, true);
nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h b/source/blender/blenvm/util/bvm_util_typedesc.h
index 17cb834..5b8f827 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -34,13 +34,16 @@
#include <cassert>
+extern "C" {
+#include "RNA_access.h"
+}
+
#include "BVM_types.h"
namespa
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list