[Bf-blender-cvs] [1074abc] object_nodes: Node graph optimization: skip over 'pass' nodes.

Lukas Tönne noreply at git.blender.org
Tue Nov 24 09:44:41 CET 2015


Commit: 1074abc47010837e943d00e4ad291922c080398b
Author: Lukas Tönne
Date:   Fri Nov 20 17:01:43 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB1074abc47010837e943d00e4ad291922c080398b

Node graph optimization: skip over 'pass' nodes.

These nodes don't have opcodes any more, they are merely placeholders
to simplify node graph construction. Ultimately they will be removed
in the 'finalize' function, along with any other unreachable nodes.

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

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_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 098002b..9d1aba0 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -110,48 +110,6 @@ static void eval_op_int_to_float(float *stack, StackIndex offset_from, StackInde
 	stack_store_float(stack, offset_to, (float)i);
 }
 
-static void eval_op_pass_float(float *stack, StackIndex offset_from, StackIndex offset_to)
-{
-	float f = stack_load_float(stack, offset_from);
-	stack_store_float(stack, offset_to, f);
-}
-
-static void eval_op_pass_float3(float *stack, StackIndex offset_from, StackIndex offset_to)
-{
-	float3 f = stack_load_float3(stack, offset_from);
-	stack_store_float3(stack, offset_to, f);
-}
-
-static void eval_op_pass_float4(float *stack, StackIndex offset_from, StackIndex offset_to)
-{
-	float4 f = stack_load_float4(stack, offset_from);
-	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_pass_mesh(float *stack, StackIndex offset_from, StackIndex offset_to)
-{
-	mesh_ptr p = stack_load_mesh(stack, offset_from);
-	stack_store_mesh(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);
@@ -535,48 +493,6 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
 				eval_op_int_to_float(stack, offset_from, offset_to);
 				break;
 			}
-			case OP_PASS_FLOAT: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_float(stack, offset_from, offset_to);
-				break;
-			}
-			case OP_PASS_FLOAT3: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_float3(stack, offset_from, offset_to);
-				break;
-			}
-			case OP_PASS_FLOAT4: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_float4(stack, offset_from, offset_to);
-				break;
-			}
-			case OP_PASS_INT: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_int(stack, offset_from, offset_to);
-				break;
-			}
-			case OP_PASS_MATRIX44: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_matrix44(stack, offset_from, offset_to);
-				break;
-			}
-			case OP_PASS_POINTER: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_pointer(stack, offset_from, offset_to);
-				break;
-			}
-			case OP_PASS_MESH: {
-				StackIndex offset_from = fn->read_stack_index(&instr);
-				StackIndex offset_to = fn->read_stack_index(&instr);
-				eval_op_pass_mesh(stack, offset_from, offset_to);
-				break;
-			}
 			case OP_SET_FLOAT3: {
 				StackIndex offset_x = fn->read_stack_index(&instr);
 				StackIndex offset_y = fn->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 0f18b54..3680ac1 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -45,13 +45,6 @@ enum OpCode {
 	OP_VALUE_MESH,
 	OP_FLOAT_TO_INT,
 	OP_INT_TO_FLOAT,
-	OP_PASS_FLOAT,
-	OP_PASS_FLOAT3,
-	OP_PASS_FLOAT4,
-	OP_PASS_INT,
-	OP_PASS_MATRIX44,
-	OP_PASS_POINTER,
-	OP_PASS_MESH,
 	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 3c51cee..3145231 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -311,6 +311,10 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 	for (NodeList::const_iterator it = sorted_nodes.begin(); it != sorted_nodes.end(); ++it) {
 		const NodeInstance &node = **it;
 		
+		OpCode op = get_opcode_from_node_type(node.type->name);
+		if (op == OP_NOOP)
+			continue;
+		
 		for (int i = 0; i < node.type->inputs.size(); ++i) {
 			const NodeSocket &input = node.type->inputs[i];
 			SocketPair key(&node, &input);
@@ -335,7 +339,6 @@ Function *BVMCompiler::codegen_function(const NodeGraph &graph)
 			}
 		}
 		
-		OpCode op = get_opcode_from_node_type(node.type->name);
 		push_opcode(op);
 		
 		for (int i = 0; i < node.type->inputs.size(); ++i) {
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 2617f27..2735174 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -55,7 +55,8 @@ NodeSocket::~NodeSocket()
 /* ------------------------------------------------------------------------- */
 
 NodeType::NodeType(const string &name) :
-    name(name)
+    name(name),
+    is_pass(false)
 {
 }
 
@@ -517,6 +518,184 @@ void NodeGraph::set_output_link(const string &name, NodeInstance *link_node, con
 	}
 }
 
+/* ------------------------------------------------------------------------- */
+/* Link Type Converters */
+
+SocketPair NodeGraph::add_float_converter(const SocketPair &from, BVMType to_type)
+{
+	SocketPair result(NULL, "");
+	switch (to_type) {
+		case BVM_FLOAT3: {
+			NodeInstance *node = add_node("SET_FLOAT3");
+			add_link(from.node, from.socket, node, "value_x");
+			add_link(from.node, from.socket, node, "value_y");
+			add_link(from.node, from.socket, node, "value_z");
+			result = SocketPair(node, "value");
+			break;
+		}
+		case BVM_FLOAT4: {
+			NodeInstance *node = add_node("SET_FLOAT4");
+			add_link(from.node, from.socket, node, "value_x");
+			add_link(from.node, from.socket, node, "value_y");
+			add_link(from.node, from.socket, node, "value_z");
+			add_link(from.node, from.socket, node, "value_w");
+			result = SocketPair(node, "value");
+			break;
+		}
+		case BVM_INT: {
+			NodeInstance *node = add_node("FLOAT_TO_INT");
+			add_link(from.node, from.socket, node, "value");
+			result = SocketPair(node, "value");
+			break;
+		}
+		default:
+			break;
+	}
+	return result;
+}
+
+SocketPair NodeGraph::add_float3_converter(const SocketPair &from, BVMType to_type)
+{
+	SocketPair result(NULL, "");
+	switch (to_type) {
+		case BVM_FLOAT4: {
+			NodeInstance *node_x = add_node("GET_ELEM_FLOAT3");
+			node_x->set_input_value("index", 0);
+			add_link(from.node, from.socket, node_x, "value");
+			NodeInstance *node_y = add_node("GET_ELEM_FLOAT3");
+			node_y->set_input_value("index", 1);
+			add_link(from.node, from.socket, node_y, "value");
+			NodeInstance *node_z = add_node("GET_ELEM_FLOAT3");
+			node_z->set_input_value("index", 2);
+			add_link(from.node, from.socket, node_z, "value");
+			
+			NodeInstance *node = add_node("SET_FLOAT4");
+			add_link(node_x, "value", node, "value_x");
+			add_link(node_y, "value", node, "value_y");
+			add_link(node_z, "value", node, "value_z");
+			node->set_input_value("value_w", 1.0f);
+			result = SocketPair(node, "value");
+			break;
+		}
+		default:
+			break;
+	}
+	return result;
+}
+
+SocketPair NodeGraph::add_float4_converter(const SocketPair &from, BVMType to_type)
+{
+	SocketPair result(NULL, "");
+	switch (to_type) {
+		case BVM_FLOAT3: {
+			NodeInstance *node_x = add_node("GET_ELEM_FLOAT4");
+			node_x->set_input_value("index", 0);
+			add_link(from.node, from.socket, node_x, "value");
+			NodeInstance *node_y = add_node("GET_ELEM_FLOAT4");
+			node_y->set_input_value("index", 1);
+			add_link(from.node, from.socket, node_y, "value");
+			NodeInstance *node_z = add_node("GET_ELEM_FLOAT4");
+			node_z->set_input_value("index", 2);
+			add_link(from.node, from.socket, node_z, "value");
+			
+			NodeInstance *node = add_node("SET_FLOAT3");
+			add_link(node_x, "value", node, "value_x");
+			add_link(node_y, "value", node, "value_y");
+			add_link(node_z, "value", node, "value_z");
+			result = SocketPair(node, "value");
+			break;
+		}
+		default:
+			break;
+	}
+	return result;
+}
+
+SocketPair NodeGraph::add_int_converter(const SocketPair &/*from*/, BVMType /*to_type*/)
+{
+	SocketPair result(NULL, "");
+	return result;
+}
+
+SocketPair NodeGraph::add_matrix44_converter(const SocketPair &/*from*/, BVMType /*to_type*/)
+{
+	SocketPair result(NULL, "");
+	return result;
+}
+
+SocketPair NodeGraph::add_type_converter(const SocketPair &from, const TypeDesc &to_typedesc)
+{
+	SocketPair result(NULL, "");
+	const NodeSocket *from_socket = from.node->type->find_output(from.socket);
+	/* TODO only uses base type so far */
+	BVMType to_type = to_typedesc.base_type;
+	BVMType from_type = from_socket->typedesc.base_type;
+	
+	if (from_type == to_type) {
+		result = from;
+	}
+	else {
+		switch (from_type) {
+			case BVM_FLOAT: result = add_float_converter(from, to_type); break;
+			case BVM_FLOAT3: result = add_float3_converter(from, to_type); break;
+			case BVM_FLOAT4: result = add_float4_converter(from, to_type); break;
+			case BVM_INT: result = add_int_converter(from, to_type); break;
+			case BVM_MATRIX44: result = add_matrix44_converter(from, to_type); break;
+			default: break;
+		}
+	}
+	return result;
+}
+
+/* ------------------------------------------------------------------------- */
+/* Optimization */
+
+void NodeGraph::skip_pass_nodes()
+{
+	/* redirect links to skip over 'pass'-type nodes */
+	for (NodeInstanceMap::iterator it = nodes.begin(); it != nodes.end(); ++it) {
+		NodeInstance &node = it->second;
+		
+		if (no

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list