[Bf-blender-cvs] [d165b1b] master: Cycles: Add method to dump current shader graph to the graphiz file

Sergey Sharybin noreply at git.blender.org
Thu Sep 25 13:16:59 CEST 2014


Commit: d165b1b266b9d19775ee73733b63824b8551aea6
Author: Sergey Sharybin
Date:   Fri Sep 19 15:21:32 2014 +0600
Branches: master
https://developer.blender.org/rBd165b1b266b9d19775ee73733b63824b8551aea6

Cycles: Add method to dump current shader graph to the graphiz file

This is rather useful to see how good optimization went and so.

Currently uses quite simple notation: shader nodes are nodes on the
graph, connects between graph nodes are named by the sockets names,
so i.e. connection between BSDF and Mix would be named bsdf:closure1.

Could be improved in the feature to draw fancier graph, but it's good
enough already.

Use in the following way:
- To create graphix file call graph->dump_graph("graph.dot")
- To visualize the grapf call: dot -Tpng graph.dot -o graph.png

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

M	intern/cycles/render/graph.cpp
M	intern/cycles/render/graph.h

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

diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index d90e5c4..45b0883 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -835,5 +835,47 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
 	}
 }
 
+void ShaderGraph::dump_graph(const char *filename)
+{
+	FILE *fd = fopen(filename, "w");
+
+	if(fd == NULL) {
+		printf("Error opening file for dumping the graph: %s\n", filename);
+		return;
+	}
+
+	fprintf(fd, "digraph dependencygraph {\n");
+	fprintf(fd, "ranksep=1.5\n");
+	fprintf(fd, "splines=false\n");
+
+	foreach(ShaderNode *node, nodes) {
+		fprintf(fd, "// NODE: %p\n", node);
+		fprintf(fd,
+		        "\"%p\" [shape=record,label=\"%s\"]\n",
+		        node,
+		        node->name.c_str());
+	}
+
+	foreach(ShaderNode *node, nodes) {
+		foreach(ShaderOutput *output, node->outputs) {
+			foreach(ShaderInput *input, output->links) {
+				fprintf(fd,
+				        "// CONNECTION: %p->%p (%s:%s)\n",
+				        output,
+				        input,
+				        output->name, input->name);
+				fprintf(fd,
+				        "\"%p\":s -> \"%p\":n [label=\"%s:%s\"]\n",
+				        output->parent,
+				        input->parent,
+				        output->name, input->name);
+			}
+		}
+	}
+
+	fprintf(fd, "}\n");
+	fclose(fd);
+}
+
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h
index 7bfd51c..7b95703 100644
--- a/intern/cycles/render/graph.h
+++ b/intern/cycles/render/graph.h
@@ -250,6 +250,8 @@ public:
 	void remove_unneeded_nodes();
 	void finalize(bool do_bump = false, bool do_osl = false);
 
+	void dump_graph(const char *filename);
+
 protected:
 	typedef pair<ShaderNode* const, ShaderNode*> NodePair;




More information about the Bf-blender-cvs mailing list