[Bf-blender-cvs] [a4108eb] object_nodes: Redefinition of the meaning of "value type" for sockets (intermediate commit).

Lukas Tönne noreply at git.blender.org
Tue Jan 26 12:16:43 CET 2016


Commit: a4108eba7fbe8f3b7524691b3b7c8c5c90f37c5a
Author: Lukas Tönne
Date:   Tue Jan 26 11:51:40 2016 +0100
Branches: object_nodes
https://developer.blender.org/rBa4108eba7fbe8f3b7524691b3b7c8c5c90f37c5a

Redefinition of the meaning of "value type" for sockets (intermediate commit).

The use of "expressions" for node inputs must be generalized to support array-like
data and a level of functional programming. Inputs are now expressions *by default*.

A node can also have "variables" as inputs, which are implicitly defined in the base node
graph and should not be bounded in the first compiler step (i.e. are not defined by
pynodes). Variables instead are defined as outputs of other nodes (currently still called
"kernel" nodes), which would mostly constitute loops over such variables.

The concepts being worked on here are loosely based on those found in the Halide language
http://halide-lang.org/index.html

===================================================================

M	release/scripts/nodes/common_nodes.py
M	release/scripts/nodes/geometry_nodes.py
M	source/blender/blenvm/BVM_types.h
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_debug.cc
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/compile/bvm_nodegraph.h
M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/blenvm/util/bvm_util_debug.h
M	source/blender/makesrna/intern/rna_blenvm.c

===================================================================

diff --git a/release/scripts/nodes/common_nodes.py b/release/scripts/nodes/common_nodes.py
index b5ef3b1..c80754e 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -177,6 +177,31 @@ class CommonNodeBase(NodeBase):
     def poll(cls, ntree):
         return isinstance(ntree, NodeTreeBase)
 
+class RangeNode(CommonNodeBase, ObjectNode):
+    '''Generate a range of numbers'''
+    bl_idname = 'ObjectRangeNode'
+    bl_label = 'Range'
+
+    start = IntProperty(name="Start", default=0)
+    end = IntProperty(name="End", default=10)
+    step = IntProperty(name="Step", default=1)
+
+    def draw_buttons(self, context, layout):
+        row = layout.row(align=True)
+        row.prop(self, "start")
+        row.prop(self, "end")
+        layout.prop(self, "step")
+
+    def init(self, context):
+        self.outputs.new('NodeSocketInt', "Value")
+
+    def compile(self, compiler):
+        node = compiler.add_node("RANGE_INT")
+        node.inputs[1].set_value(self.start)
+        node.inputs[2].set_value(self.end)
+        node.inputs[3].set_value(self.step)
+        compiler.map_output(0, node.outputs[0])
+
 class ValueFloatNode(CommonNodeBase, ObjectNode):
     '''Floating point number'''
     bl_idname = 'ObjectValueFloatNode'
diff --git a/release/scripts/nodes/geometry_nodes.py b/release/scripts/nodes/geometry_nodes.py
index 7ddc266..aed09b6 100644
--- a/release/scripts/nodes/geometry_nodes.py
+++ b/release/scripts/nodes/geometry_nodes.py
@@ -430,6 +430,7 @@ def register():
 
     node_categories = [
         GeometryNodeCategory("GEO_INPUT", "Input", items=[
+            NodeItem("ObjectRangeNode"),
             NodeItem("ObjectIterationNode"),
             NodeItem("GeometryMeshLoadNode"),
             NodeItem("GeometryObjectFinalMeshNode"),
diff --git a/source/blender/blenvm/BVM_types.h b/source/blender/blenvm/BVM_types.h
index 3293aa2..5c2b778 100644
--- a/source/blender/blenvm/BVM_types.h
+++ b/source/blender/blenvm/BVM_types.h
@@ -55,13 +55,13 @@ typedef enum BVMBufferType {
 
 typedef enum BVMInputValueType {
 	INPUT_CONSTANT,
-	INPUT_VARIABLE,
 	INPUT_EXPRESSION,
+	INPUT_VARIABLE,
 } BVMInputValueType;
 
 typedef enum BVMOutputValueType {
+	OUTPUT_EXPRESSION,
 	OUTPUT_VARIABLE,
-	OUTPUT_LOCAL,
 } BVMOutputValueType;
 
 #ifdef __cplusplus
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 916844c..549238d 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -194,6 +194,15 @@ static void eval_op_value_duplis(EvalStack *stack, StackIndex offset)
 	stack_store_duplis(stack, offset, new DupliList());
 }
 
+static void eval_op_range_int(EvalStack *stack,
+                              int start, int /*end*/, int step,
+                              StackIndex offset_index,
+                              StackIndex offset_value)
+{
+	int index = stack_load_int(stack, offset_index);
+	stack_store_int(stack, offset_value, start + index * step);
+}
+
 static void eval_op_float_to_int(EvalStack *stack, StackIndex offset_from, StackIndex offset_to)
 {
 	float f = stack_load_float(stack, offset_from);
@@ -446,6 +455,15 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const Instructio
 				eval_op_value_duplis(stack, offset);
 				break;
 			}
+			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);
+				StackIndex offset_value = fn->read_stack_index(&instr);
+				eval_op_range_int(stack, offset_index, offset_start, offset_end, offset_step, offset_value);
+				break;
+			}
 			case OP_FLOAT_TO_INT: {
 				StackIndex offset_from = fn->read_stack_index(&instr);
 				StackIndex offset_to = fn->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index abaad0d..9949085 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -54,6 +54,8 @@ namespace bvm {
 	DEF_OPCODE(VALUE_MESH) \
 	DEF_OPCODE(VALUE_DUPLIS) \
 	\
+	DEF_OPCODE(RANGE_INT) \
+	\
 	DEF_OPCODE(FLOAT_TO_INT) \
 	DEF_OPCODE(INT_TO_FLOAT) \
 	DEF_OPCODE(SET_FLOAT3) \
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index acdd081..58daa45 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -78,7 +78,7 @@ void Compiler::calc_node_dependencies(const NodeInstance *node, BlockDependencyM
 				block_deps.insert(input.link());
 			}
 			
-			if (input.is_expression()) {
+			if (input.value_type() == INPUT_EXPRESSION) {
 				if (link_node->block != node->block) {
 					calc_block_dependencies(link_node->block, block_deps_map);
 					
@@ -165,7 +165,7 @@ void Compiler::get_local_arg_indices(const NodeInstance *node, const NodeBlock *
 	for (int i = 0; i < node->num_outputs(); ++i) {
 		ConstOutputKey output = node->output(i);
 		
-		if (output.socket->value_type == OUTPUT_LOCAL) {
+		if (output.socket->value_type == OUTPUT_VARIABLE) {
 			ConstOutputKey local_output = local_block->local_arg(output.socket->name);
 			output_index[local_output] = output_index.at(output);
 		}
@@ -200,10 +200,10 @@ void Compiler::resolve_node_block_symbols(const NodeBlock *block)
 			ConstInputKey input = node.input(i);
 			assert(input_index.find(input) == input_index.end());
 			
-			if (input.is_constant()) {
+			if (input.value_type() == INPUT_CONSTANT) {
 				/* stored directly in the instructions list after creating values */
 			}
-			else if (input.is_expression()) {
+			else if (input.value_type() == INPUT_EXPRESSION) {
 				ConstOutputKey link = input.link();
 				const NodeBlock *expr_block = link.node->block;
 				
@@ -425,7 +425,8 @@ int Compiler::codegen_node_block(const NodeBlock &block)
 		for (int i = 0; i < node.num_inputs(); ++i) {
 			ConstInputKey key = node.input(i);
 			
-			if (key.is_constant() || key.is_expression()) {
+			if (key.value_type() == INPUT_CONSTANT ||
+			    key.value_type() == INPUT_EXPRESSION) {
 				/* stored directly in instructions */
 			}
 			else if (key.link()) {
@@ -461,11 +462,11 @@ int Compiler::codegen_node_block(const NodeBlock &block)
 			for (int i = 0; i < node.num_inputs(); ++i) {
 				ConstInputKey key = node.input(i);
 				
-				if (key.is_constant()) {
+				if (key.value_type() == INPUT_CONSTANT) {
 					push_constant(key.value());
 				}
 				else {
-					if (key.is_expression()) {
+					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);
diff --git a/source/blender/blenvm/compile/bvm_codegen_debug.cc b/source/blender/blenvm/compile/bvm_codegen_debug.cc
index 157c708..614b6e8 100644
--- a/source/blender/blenvm/compile/bvm_codegen_debug.cc
+++ b/source/blender/blenvm/compile/bvm_codegen_debug.cc
@@ -40,13 +40,9 @@
 
 namespace bvm {
 
-#define NL "\r\n"
+using namespace debug;
 
-static const char *fontname = "helvetica";
-static const char *color_opcode = "firebrick1";
-static const char *color_stack_index = "dodgerblue1";
-static const char *color_jump_address = "forestgreen";
-static const char *color_value = "gold1";
+#define NL "\r\n"
 
 static void debug_fprintf(FILE *f, const char *fmt, ...) ATTR_PRINTF_FORMAT(2, 3);
 static void debug_fprintf(FILE *f, const char *fmt, ...)
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 17751f2..737d7b7 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -217,8 +217,6 @@ const NodeInput *NodeType::add_input(const string &name,
 {
 	BLI_assert(!find_input(name));
 	BLI_assert(NodeGraph::has_typedef(type));
-	/* function inputs only allowed for kernel nodes */
-	BLI_assert(m_is_kernel_node || value_type != INPUT_EXPRESSION);
 	m_inputs.push_back(NodeInput(name, NodeGraph::find_typedef(type), default_value, value_type));
 	return &m_inputs.back();
 }
@@ -230,7 +228,7 @@ const NodeOutput *NodeType::add_output(const string &name,
 	BLI_assert(!find_output(name));
 	BLI_assert(NodeGraph::has_typedef(type));
 	/* local outputs only allowed for kernel nodes */
-	BLI_assert(m_is_kernel_node || value_type != OUTPUT_LOCAL);
+	BLI_assert(m_is_kernel_node || value_type != OUTPUT_VARIABLE);
 	m_outputs.push_back(NodeOutput(name, NodeGraph::find_typedef(type), value_type));
 	return &m_outputs.back();
 }
@@ -264,6 +262,11 @@ ConstOutputKey::operator bool() const
 	return node != NULL && socket != NULL;
 }
 
+BVMOutputValueType ConstOutputKey::value_type() const
+{
+	return socket->value_type;
+}
+
 /*****/
 
 OutputKey::OutputKey() :
@@ -298,6 +301,11 @@ OutputKey::operator bool() const
 	return node != NULL && socket != NULL;
 }
 
+BVMOutputValueType OutputKey::value_type() const
+{
+	return socket->value_type;
+}
+
 /*****/
 
 ConstInputKey::ConstInputKey() :
@@ -340,14 +348,9 @@ const Value *ConstInputKey::value() const
 	return node->input_value(socket->name);
 }
 
-bool ConstInputKey::is_constant() const
+BVMInputValueType ConstInputKey::value_type() const
 {
-	return socket->value_type == INPUT_CONSTANT;
-}
-
-bool ConstInputKey::is_expression() const
-{
-	return socket->value_type == INPUT_EXPRESSION;
+	return socket->value_type;
 }
 
 /*****/
@@ -407,14 +410,9 @@ void InputKey::value_set(Value *value) const
 	node->input_value_set(socket->name, value);
 }
 
-bool InputKey::is_constant() const
+BVMInputValueType InputKey::value_type() const
 {
-	return socket->value_type == INPUT_CONSTANT;
-}
-
-bool InputKey::is_expression() const
-{
-	return socket->value_type == INPUT_EXPRESSION;
+	return socket->value_type;
 }
 
 /* ------------------------------------------------------------------------- */
@@ -732,11 +730,8 @@ NodeInstance *NodeGraph::add_node(const string &type, const string &name)
 	make_unique_name(final, nodes);
 	
 	NodeInstance *node = new NodeInstance(node

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list