[Bf-blender-cvs] [bd9f268] object_nodes: Support for constants as internal node socket inputs.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:43:22 CET 2015
Commit: bd9f26871eced16fb681db83beb3b3727fc8edd7
Author: Lukas Tönne
Date: Thu Oct 22 14:14:04 2015 +0200
Branches: object_nodes
https://developer.blender.org/rBbd9f26871eced16fb681db83beb3b3727fc8edd7
Support for constants as internal node socket inputs.
Constants should never be linked to other nodes (will be ignored).
===================================================================
M source/blender/blenvm/bvm/bvm_eval.cc
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/compile/bvm_nodegraph.h
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 e6e879a..77ea21d 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -58,6 +58,11 @@ inline static float3 stack_load_float3(float *stack, StackIndex offset)
return *(float3 *)(&stack[offset]);
}
+inline static int stack_load_int(float *stack, StackIndex offset)
+{
+ return *(int *)(&stack[offset]);
+}
+
inline static void stack_store_float(float *stack, StackIndex offset, float f)
{
*(float *)(&stack[offset]) = f;
@@ -68,6 +73,11 @@ inline static void stack_store_float3(float *stack, StackIndex offset, float3 f)
*(float3 *)(&stack[offset]) = f;
}
+inline static void stack_store_int(float *stack, StackIndex offset, int i)
+{
+ *(int *)(&stack[offset]) = i;
+}
+
/* ------------------------------------------------------------------------- */
static void eval_op_value_float(float *stack, float value, StackIndex offset)
@@ -80,6 +90,11 @@ static void eval_op_value_float3(float *stack, float3 value, StackIndex offset)
stack_store_float3(stack, offset, value);
}
+static void eval_op_value_int(float *stack, int value, StackIndex offset)
+{
+ stack_store_int(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);
@@ -284,6 +299,12 @@ void EvalContext::eval_instructions(const EvalData *data, const Expression &expr
eval_op_value_float3(stack, value, offset);
break;
}
+ case OP_VALUE_INT: {
+ int value = expr.read_int(&instr);
+ StackIndex offset = expr.read_stack_index(&instr);
+ eval_op_value_int(stack, value, offset);
+ break;
+ }
case OP_PASS_FLOAT: {
StackIndex offset_from = expr.read_stack_index(&instr);
StackIndex offset_to = expr.read_stack_index(&instr);
@@ -304,22 +325,11 @@ void EvalContext::eval_instructions(const EvalData *data, const Expression &expr
eval_op_set_float3(stack, offset_x, offset_y, offset_z, offset_to);
break;
}
- case OP_GET_ELEM0_FLOAT3: {
- StackIndex offset_from = expr.read_stack_index(&instr);
- StackIndex offset_to = expr.read_stack_index(&instr);
- eval_op_get_elem_float3(stack, 0, offset_from, offset_to);
- break;
- }
- case OP_GET_ELEM1_FLOAT3: {
- StackIndex offset_from = expr.read_stack_index(&instr);
- StackIndex offset_to = expr.read_stack_index(&instr);
- eval_op_get_elem_float3(stack, 1, offset_from, offset_to);
- break;
- }
- case OP_GET_ELEM2_FLOAT3: {
+ case OP_GET_ELEM_FLOAT3: {
+ int index = expr.read_int(&instr);
StackIndex offset_from = expr.read_stack_index(&instr);
StackIndex offset_to = expr.read_stack_index(&instr);
- eval_op_get_elem_float3(stack, 2, offset_from, offset_to);
+ eval_op_get_elem_float3(stack, index, offset_from, offset_to);
break;
}
case OP_EFFECTOR_POSITION: {
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 459d512..b67bfaf 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -38,12 +38,11 @@ enum OpCode {
OP_NOOP = 0,
OP_VALUE_FLOAT,
OP_VALUE_FLOAT3,
+ OP_VALUE_INT,
OP_PASS_FLOAT,
OP_PASS_FLOAT3,
OP_SET_FLOAT3,
- OP_GET_ELEM0_FLOAT3,
- OP_GET_ELEM1_FLOAT3,
- OP_GET_ELEM2_FLOAT3,
+ OP_GET_ELEM_FLOAT3,
OP_EFFECTOR_POSITION,
OP_EFFECTOR_VELOCITY,
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 7462191..7f51283 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -104,6 +104,11 @@ void BVMCompiler::push_float3(float3 f)
expr->add_instruction(float_to_instruction(f.z));
}
+void BVMCompiler::push_int(int i)
+{
+ expr->add_instruction(int_to_instruction(i));
+}
+
StackIndex BVMCompiler::codegen_value(const Value *value)
{
StackIndex offset = assign_stack_index(value->typedesc());
@@ -127,11 +132,47 @@ StackIndex BVMCompiler::codegen_value(const Value *value)
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;
+ }
}
return offset;
}
+void BVMCompiler::codegen_constant(const Value *value)
+{
+ switch (value->typedesc().base_type) {
+ case BVM_FLOAT: {
+ float f = 0.0f;
+ value->get(&f);
+
+ push_float(f);
+ break;
+ }
+ case BVM_FLOAT3: {
+ float3 f = float3(0.0f, 0.0f, 0.0f);
+ value->get(&f);
+
+ push_float3(f);
+ break;
+ }
+ case BVM_INT: {
+ int i = 0;
+ value->get(&i);
+
+ push_int(i);
+ break;
+ }
+ }
+}
+
#if 0
StackIndex BVMCompiler::codegen_link(const TypeDesc &from, StackIndex stack_from,
const TypeDesc &to, StackIndex stack_to)
@@ -198,7 +239,12 @@ Expression *BVMCompiler::codegen_expression(const NodeGraph &graph)
const NodeSocket &input = node.type->inputs[i];
SocketPair key(&node, &input);
- if (node.has_input_link(i)) {
+ if (node.is_input_constant(i)) {
+ /* value is stored directly in the instructions list,
+ * after the opcode
+ */
+ }
+ else if (node.has_input_link(i)) {
const NodeInstance *link_node = node.find_input_link_node(i);
const NodeSocket *link_socket = node.find_input_link_socket(i);
SocketPair link_key(link_node, link_socket);
@@ -220,7 +266,13 @@ Expression *BVMCompiler::codegen_expression(const NodeGraph &graph)
const NodeSocket &input = node.type->inputs[i];
SocketPair key(&node, &input);
- push_stack_index(socket_index[key]);
+ if (node.is_input_constant(i)) {
+ Value *value = node.find_input_value(i);
+ codegen_constant(value);
+ }
+ else {
+ push_stack_index(socket_index[key]);
+ }
}
for (int i = 0; i < node.type->outputs.size(); ++i) {
const NodeSocket &output = node.type->outputs[i];
diff --git a/source/blender/blenvm/compile/bvm_codegen.h b/source/blender/blenvm/compile/bvm_codegen.h
index dfa8374..acf8cab 100644
--- a/source/blender/blenvm/compile/bvm_codegen.h
+++ b/source/blender/blenvm/compile/bvm_codegen.h
@@ -59,8 +59,10 @@ struct BVMCompiler {
void push_stack_index(StackIndex arg);
void push_float(float f);
void push_float3(float3 f);
+ void push_int(int i);
StackIndex codegen_value(const Value *value);
+ void codegen_constant(const Value *value);
Expression *codegen_expression(const NodeGraph &graph);
private:
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 546201b..1afb99b 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -38,10 +38,11 @@
namespace bvm {
-NodeSocket::NodeSocket(const string &name, BVMType type, Value *default_value) :
+NodeSocket::NodeSocket(const string &name, BVMType type, Value *default_value, bool constant) :
name(name),
type(type),
- default_value(default_value)
+ default_value(default_value),
+ constant(constant)
{
}
@@ -179,17 +180,17 @@ bool NodeType::verify_arguments(Module *module, LLVMContext &context, raw_ostrea
}
#endif
-const NodeSocket *NodeType::add_input(const string &name, BVMType type, Value *default_value)
+const NodeSocket *NodeType::add_input(const string &name, BVMType type, Value *default_value, bool constant)
{
BLI_assert(!find_input(name));
- inputs.push_back(NodeSocket(name, type, default_value));
+ inputs.push_back(NodeSocket(name, type, default_value, constant));
return &inputs.back();
}
const NodeSocket *NodeType::add_output(const string &name, BVMType type, Value *default_value)
{
BLI_assert(!find_output(name));
- outputs.push_back(NodeSocket(name, type, default_value));
+ outputs.push_back(NodeSocket(name, type, default_value, false));
return &outputs.back();
}
@@ -345,6 +346,18 @@ bool NodeInstance::has_input_value(int index) const
return socket ? has_input_value(socket->name) : false;
}
+bool NodeInstance::is_input_constant(const string &name) const
+{
+ const NodeSocket *socket = type->find_input(name);
+ return socket ? socket->constant : false;
+}
+
+bool NodeInstance::is_input_constant(int index) const
+{
+ const NodeSocket *socket = type->find_input(index);
+ return socket ? socket->constant : false;
+}
+
bool NodeInstance::set_output_value(const string &name, Value *value)
{
OutputInstance &output = outputs[name];
@@ -544,9 +557,7 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(PASS_FLOAT);
NODETYPE(PASS_FLOAT3);
NODETYPE(SET_FLOAT3);
- NODETYPE(GET_ELEM0_FLOAT3);
- NODETYPE(GET_ELEM1_FLOAT3);
- NODETYPE(GET_ELEM2_FLOAT3);
+ NODETYPE(GET_ELEM_FLOAT3);
NODETYPE(EFFECTOR_POSITION);
NODETYPE(EFFECTOR_VELOCITY);
@@ -593,15 +604,8 @@ void register_opcode_node_types()
nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
- nt = NodeGraph::add_node_type("GET_ELEM0_FLOAT3");
- nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
- nt->add_output("value", BVM_FLOAT, 0.0f);
-
- nt = NodeGraph::add_node_type("GET_ELEM1_FLOAT3");
- nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
- nt->add_output("value", BVM_FLOAT, 0.0f);
-
- nt = NodeGraph::add_node_type("GET_ELEM2_FLOAT3");
+ 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));
nt->add_output("value", BVM_FLOAT, 0.0f);
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.h b/source/blender/blenvm/compile/bvm_nodegraph.h
index 425f8c0..0857fa9 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.h
+++ b/source/blender/blenvm/compile/bvm_nodegraph.h
@@ -57,12 +57,13 @@ struct NodeGraphInput;
struct NodeType;
struct NodeSocket {
- NodeSocket(const string &name, BVMType type, Value *default_value);
+ NodeSocket(const string &name, BVMType type, Value *default_value, bool constant);
~NodeSocket();
string name;
BVMType type;
Value
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list