Cycles: Use different approach for SVM summary report
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 28 Dec 2015 14:30:43 +0000 (19:30 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 28 Dec 2015 14:42:37 +0000 (19:42 +0500)
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.

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

index 5b085d74857b9f8739d9fad444e992e39950735c..cfc961ab33085978564d8edc8bd62f22342dde73 100644 (file)
@@ -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
index 02855f22fb364c4e1c8b15b1e736a7cd8da09370..bc641d2e00ad0aeb3181c614f48e26e422463169 100644 (file)
@@ -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);