[Bf-blender-cvs] [468765d29e7] master: Compositor: Export operation results as debug option

Manuel Castilla noreply at git.blender.org
Mon Jul 19 22:06:47 CEST 2021


Commit: 468765d29e783e0983a607310788dbbedc912570
Author: Manuel Castilla
Date:   Mon Jul 19 19:55:15 2021 +0200
Branches: master
https://developer.blender.org/rB468765d29e783e0983a607310788dbbedc912570

Compositor: Export operation results as debug option

When fixing issues, seeing operation results can be helpful for
detecting which operation went wrong.

This commit adds an option for exporting all operations results to
image files.
Exceptions are:
- Output operations: They are already exported or can be seen in UI.
- Constant operations: There are too many and is rarely useful.

They are exported to "<temp session folder>/COM_operations/"
with filenames "<operation class name>_<operation id>.png".
Only works on full frame execution mode.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D11722

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

M	source/blender/compositor/intern/COM_Debug.cc
M	source/blender/compositor/intern/COM_Debug.h
M	source/blender/compositor/intern/COM_FullFrameExecutionModel.cc

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

diff --git a/source/blender/compositor/intern/COM_Debug.cc b/source/blender/compositor/intern/COM_Debug.cc
index abef4517b3e..c0460aed4a4 100644
--- a/source/blender/compositor/intern/COM_Debug.cc
+++ b/source/blender/compositor/intern/COM_Debug.cc
@@ -31,6 +31,8 @@ extern "C" {
 #include "BKE_appdir.h"
 #include "BKE_node.h"
 #include "DNA_node_types.h"
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
 }
 
 #include "COM_ExecutionSystem.h"
@@ -50,7 +52,7 @@ std::string DebugInfo::m_current_node_name;
 std::string DebugInfo::m_current_op_name;
 DebugInfo::GroupStateMap DebugInfo::m_group_states;
 
-static std::string operation_class_name(NodeOperation *op)
+static std::string operation_class_name(const NodeOperation *op)
 {
   std::string full_name = typeid(*op).name();
   /* Remove name-spaces. */
@@ -452,4 +454,45 @@ void DebugInfo::graphviz(const ExecutionSystem *system, StringRefNull name)
   }
 }
 
+static std::string get_operations_export_dir()
+{
+  return std::string(BKE_tempdir_session()) + "COM_operations" + SEP_STR;
+}
+
+void DebugInfo::export_operation(const NodeOperation *op, MemoryBuffer *render)
+{
+  ImBuf *ibuf = IMB_allocFromBuffer(nullptr,
+                                    render->getBuffer(),
+                                    render->getWidth(),
+                                    render->getHeight(),
+                                    render->get_num_channels());
+
+  const std::string file_name = operation_class_name(op) + "_" + std::to_string(op->get_id()) +
+                                ".png";
+  const std::string path = get_operations_export_dir() + file_name;
+  BLI_make_existing_file(path.c_str());
+  IMB_saveiff(ibuf, path.c_str(), ibuf->flags);
+  IMB_freeImBuf(ibuf);
+}
+
+void DebugInfo::delete_operation_exports()
+{
+  const std::string dir = get_operations_export_dir();
+  if (BLI_exists(dir.c_str())) {
+    struct direntry *file_list;
+    int num_files = BLI_filelist_dir_contents(dir.c_str(), &file_list);
+    for (int i = 0; i < num_files; i++) {
+      direntry *file = &file_list[i];
+      const eFileAttributes file_attrs = BLI_file_attributes(file->path);
+      if (file_attrs & FILE_ATTR_ANY_LINK) {
+        continue;
+      }
+
+      if (BLI_is_file(file->path) && BLI_path_extension_check(file->path, ".png")) {
+        BLI_delete(file->path, false, false);
+      }
+    }
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_Debug.h b/source/blender/compositor/intern/COM_Debug.h
index 53461e13f48..23d99c7e529 100644
--- a/source/blender/compositor/intern/COM_Debug.h
+++ b/source/blender/compositor/intern/COM_Debug.h
@@ -30,6 +30,9 @@ namespace blender::compositor {
 static constexpr bool COM_EXPORT_GRAPHVIZ = false;
 static constexpr bool COM_GRAPHVIZ_SHOW_NODE_NAME = false;
 
+/* Saves operations results to image files. */
+static constexpr bool COM_EXPORT_OPERATION_BUFFERS = false;
+
 class Node;
 class ExecutionSystem;
 class ExecutionGroup;
@@ -75,6 +78,9 @@ class DebugInfo {
         m_group_states[execution_group] = EG_WAIT;
       }
     }
+    if (COM_EXPORT_OPERATION_BUFFERS) {
+      delete_operation_exports();
+    }
   };
 
   static void node_added(const Node *node)
@@ -118,6 +124,14 @@ class DebugInfo {
     }
   };
 
+  static void operation_rendered(const NodeOperation *op, MemoryBuffer *render)
+  {
+    /* Don't export constant operations as there are too many and it's rarely useful. */
+    if (COM_EXPORT_OPERATION_BUFFERS && render && !render->is_a_single_elem()) {
+      export_operation(op, render);
+    }
+  }
+
   static void graphviz(const ExecutionSystem *system, StringRefNull name = "");
 
  protected:
@@ -133,6 +147,9 @@ class DebugInfo {
       const char *name, const char *color, const char *style, char *str, int maxlen);
   static int graphviz_legend(char *str, int maxlen, bool has_execution_groups);
   static bool graphviz_system(const ExecutionSystem *system, char *str, int maxlen);
+
+  static void export_operation(const NodeOperation *op, MemoryBuffer *render);
+  static void delete_operation_exports();
 };
 
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
index 3b0a9172871..9f6904bb306 100644
--- a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
+++ b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
@@ -104,6 +104,7 @@ void FullFrameExecutionModel::render_operation(NodeOperation *op)
   op->render(op_buf, areas, input_bufs);
   active_buffers_.set_rendered_buffer(op, std::unique_ptr<MemoryBuffer>(op_buf));
 
+  DebugInfo::operation_rendered(op, op_buf);
   operation_finished(op);
 }



More information about the Bf-blender-cvs mailing list