[Bf-blender-cvs] [f2d5295] master: Cycles: log how many nodes were deduplicated for use in tests.

Alexander Gavrilov noreply at git.blender.org
Tue Aug 2 18:28:22 CEST 2016


Commit: f2d5295abf7a5285cd851de45c8beff276e84d3a
Author: Alexander Gavrilov
Date:   Tue Aug 2 19:26:57 2016 +0300
Branches: master
https://developer.blender.org/rBf2d5295abf7a5285cd851de45c8beff276e84d3a

Cycles: log how many nodes were deduplicated for use in tests.

To make the number more meaningful, also skip deduplicating
obviously unused nodes with no outgoing links.

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

M	intern/cycles/render/graph.cpp
M	intern/cycles/test/render_graph_finalize_test.cpp

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

diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 3eeb7ff..6e795ef 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -24,6 +24,7 @@
 #include "util_debug.h"
 #include "util_foreach.h"
 #include "util_queue.h"
+#include "util_logging.h"
 
 CCL_NAMESPACE_BEGIN
 
@@ -543,6 +544,7 @@ void ShaderGraph::deduplicate_nodes()
 	ShaderNodeSet scheduled, done;
 	map<ustring, ShaderNodeSet> candidates;
 	queue<ShaderNode*> traverse_queue;
+	int num_deduplicated = 0;
 
 	/* Schedule nodes which doesn't have any dependencies. */
 	foreach(ShaderNode *node, nodes) {
@@ -557,8 +559,10 @@ void ShaderGraph::deduplicate_nodes()
 		traverse_queue.pop();
 		done.insert(node);
 		/* Schedule the nodes which were depending on the current node. */
+		bool has_output_links = false;
 		foreach(ShaderOutput *output, node->outputs) {
 			foreach(ShaderInput *input, output->links) {
+				has_output_links = true;
 				if(scheduled.find(input->parent) != scheduled.end()) {
 					/* Node might not be optimized yet but scheduled already
 					 * by other dependencies. No need to re-schedule it.
@@ -572,6 +576,10 @@ void ShaderGraph::deduplicate_nodes()
 				}
 			}
 		}
+		/* Only need to care about nodes that are actually used */
+		if(!has_output_links) {
+			continue;
+		}
 		/* Try to merge this node with another one. */
 		ShaderNode *merge_with = NULL;
 		foreach(ShaderNode *other_node, candidates[node->type->name]) {
@@ -585,11 +593,16 @@ void ShaderGraph::deduplicate_nodes()
 			for(int i = 0; i < node->outputs.size(); ++i) {
 				relink(node, node->outputs[i], merge_with->outputs[i]);
 			}
+			num_deduplicated++;
 		}
 		else {
 			candidates[node->type->name].insert(node);
 		}
 	}
+
+	if(num_deduplicated > 0) {
+		VLOG(1) << "Deduplicated " << num_deduplicated << " nodes.";
+	}
 }
 
 void ShaderGraph::break_cycles(ShaderNode *node, vector<bool>& visited, vector<bool>& on_stack)
diff --git a/intern/cycles/test/render_graph_finalize_test.cpp b/intern/cycles/test/render_graph_finalize_test.cpp
index f84ddc3..633e517 100644
--- a/intern/cycles/test/render_graph_finalize_test.cpp
+++ b/intern/cycles/test/render_graph_finalize_test.cpp
@@ -184,6 +184,7 @@ TEST(render_graph, deduplicate_deep)
 	EXPECT_ANY_MESSAGE(log);
 	CORRECT_INFO_MESSAGE(log, "Folding Value1::Value to constant (0.8).");
 	CORRECT_INFO_MESSAGE(log, "Folding Value2::Value to constant (0.8).");
+	CORRECT_INFO_MESSAGE(log, "Deduplicated 2 nodes.");
 
 	builder
 		.add_node(ShaderNodeBuilder<GeometryNode>("Geometry1"))




More information about the Bf-blender-cvs mailing list