[Bf-blender-cvs] [1a246af] master: Cycles: Use different approach for SVM summary report

Sergey Sharybin noreply at git.blender.org
Mon Dec 28 15:42:41 CET 2015


Commit: 1a246afe0330546a9fb526558d24b47c69e678d4
Author: Sergey Sharybin
Date:   Mon Dec 28 19:30:43 2015 +0500
Branches: master
https://developer.blender.org/rB1a246afe0330546a9fb526558d24b47c69e678d4

Cycles: Use different approach for SVM summary report

Use Summary structure to collect all summary related on the shader compilation
process which then could be either simply reported to the log or be passed to
some user interface or so.

This is type of the summary / report which is most flexible and useful and
something we could use for other parts like shader optimization.

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

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

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

diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp
index 5b085d7..cfc961a 100644
--- a/intern/cycles/render/svm.cpp
+++ b/intern/cycles/render/svm.cpp
@@ -76,9 +76,14 @@ void SVMShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
 		if(shader->use_mis && shader->has_surface_emission)
 			scene->light_manager->need_update = true;
 
+		SVMCompiler::Summary summary;
 		SVMCompiler compiler(scene->shader_manager, scene->image_manager);
 		compiler.background = ((int)i == scene->default_background);
-		compiler.compile(scene, shader, svm_nodes, i);
+		compiler.compile(scene, shader, svm_nodes, i, &summary);
+
+		VLOG(1) << "Compilation summary:\n"
+		        << "Shader name: " << shader->name << "\n"
+		        << summary.full_report();
 	}
 
 	dscene->svm_nodes.copy((uint4*)&svm_nodes[0], svm_nodes.size());
@@ -706,10 +711,12 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
 void SVMCompiler::compile(Scene *scene,
                           Shader *shader,
                           vector<int4>& global_svm_nodes,
-                          int index)
+                          int index,
+                          Summary *summary)
 {
 	/* copy graph for shader with bump mapping */
 	ShaderNode *node = shader->graph->output();
+	int start_num_svm_nodes = global_svm_nodes.size();
 
 	if(node->input("Surface")->link && node->input("Displacement")->link)
 		if(!shader->graph_bump)
@@ -764,10 +771,27 @@ void SVMCompiler::compile(Scene *scene,
 	global_svm_nodes[index*2 + 1].w = global_svm_nodes.size();
 	global_svm_nodes.insert(global_svm_nodes.end(), svm_nodes.begin(), svm_nodes.end());
 
-	/* TODO(sergey): Consider making it more generic compile report. */
-	VLOG(1) << "Statistics for compiled shader " << shader->name << ":";
-	VLOG(1) << "  Number of SVM nodes: " << global_svm_nodes.size();
-	VLOG(1) << "  Maximum stack usage: " << max_stack_use;
+	/* Fill in summary information. */
+	if(summary != NULL) {
+		summary->peak_stack_usage = max_stack_use;
+		summary->num_svm_nodes = global_svm_nodes.size() - start_num_svm_nodes;
+	}
+}
+
+/* Compiler summary implementation. */
+
+SVMCompiler::Summary::Summary()
+	: num_svm_nodes(0),
+	  peak_stack_usage(0)
+{
+}
+
+string SVMCompiler::Summary::full_report() const
+{
+	string report = "";
+	report += string_printf("Number of SVM nodes: %d\n", num_svm_nodes);
+	report += string_printf("Peak stack usage:    %d", peak_stack_usage);
+	return report;
 }
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/render/svm.h b/intern/cycles/render/svm.h
index 02855f2..bc641d2 100644
--- a/intern/cycles/render/svm.h
+++ b/intern/cycles/render/svm.h
@@ -52,11 +52,27 @@ public:
 
 class SVMCompiler {
 public:
+	struct Summary {
+		Summary();
+
+		/* Number of SVM nodes shader was compiled into. */
+		int num_svm_nodes;
+
+		/* Peak stack usage during shader evaluation. */
+		int peak_stack_usage;
+
+		/* A full multiline description of the state of the compiler after
+		 * compilation.
+		 */
+		string full_report() const;
+	};
+
 	SVMCompiler(ShaderManager *shader_manager, ImageManager *image_manager);
 	void compile(Scene *scene,
 	             Shader *shader,
 	             vector<int4>& svm_nodes,
-	             int index);
+	             int index,
+	             Summary *summary = NULL);
 
 	void stack_assign(ShaderOutput *output);
 	void stack_assign(ShaderInput *input);




More information about the Bf-blender-cvs mailing list