Blender  V3.3
COM_Debug.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. */
3 
4 #pragma once
5 
6 #include <map>
7 #include <string>
8 
9 #include "BLI_vector.hh"
10 
11 #include "COM_ExecutionSystem.h"
12 #include "COM_MemoryBuffer.h"
13 #include "COM_Node.h"
14 
15 namespace blender::compositor {
16 
17 static constexpr bool COM_EXPORT_GRAPHVIZ = false;
18 static constexpr bool COM_GRAPHVIZ_SHOW_NODE_NAME = false;
19 
20 /* Saves operations results to image files. */
21 static constexpr bool COM_EXPORT_OPERATION_BUFFERS = false;
22 
23 class Node;
24 class NodeOperation;
25 class ExecutionSystem;
26 class ExecutionGroup;
27 
28 class DebugInfo {
29  public:
31 
32  typedef std::map<const Node *, std::string> NodeNameMap;
33  typedef std::map<const NodeOperation *, std::string> OpNameMap;
34  typedef std::map<const ExecutionGroup *, GroupState> GroupStateMap;
35 
36  static std::string node_name(const Node *node);
37  static std::string operation_name(const NodeOperation *op);
38 
39  private:
40  static int file_index_;
42  static NodeNameMap node_names_;
44  static OpNameMap op_names_;
46  static std::string current_node_name_;
48  static std::string current_op_name_;
50  static GroupStateMap group_states_;
51 
52  public:
53  static void convert_started()
54  {
55  if (COM_EXPORT_GRAPHVIZ) {
56  op_names_.clear();
57  }
58  }
59 
60  static void execute_started(const ExecutionSystem *system)
61  {
62  if (COM_EXPORT_GRAPHVIZ) {
63  file_index_ = 1;
64  group_states_.clear();
65  for (ExecutionGroup *execution_group : system->groups_) {
66  group_states_[execution_group] = EG_WAIT;
67  }
68  }
71  }
72  };
73 
74  static void node_added(const Node *node)
75  {
76  if (COM_EXPORT_GRAPHVIZ) {
77  node_names_[node] = std::string(node->get_bnode() ? node->get_bnode()->name : "");
78  }
79  }
80 
81  static void node_to_operations(const Node *node)
82  {
83  if (COM_EXPORT_GRAPHVIZ) {
84  current_node_name_ = node_names_[node];
85  }
86  }
87 
88  static void operation_added(const NodeOperation *operation)
89  {
90  if (COM_EXPORT_GRAPHVIZ) {
91  op_names_[operation] = current_node_name_;
92  }
93  };
94 
95  static void operation_read_write_buffer(const NodeOperation *operation)
96  {
97  if (COM_EXPORT_GRAPHVIZ) {
98  current_op_name_ = op_names_[operation];
99  }
100  };
101 
102  static void execution_group_started(const ExecutionGroup *group)
103  {
104  if (COM_EXPORT_GRAPHVIZ) {
105  group_states_[group] = EG_RUNNING;
106  }
107  };
108  static void execution_group_finished(const ExecutionGroup *group)
109  {
110  if (COM_EXPORT_GRAPHVIZ) {
111  group_states_[group] = EG_FINISHED;
112  }
113  };
114 
115  static void operation_rendered(const NodeOperation *op, MemoryBuffer *render)
116  {
117  /* Don't export constant operations as there are too many and it's rarely useful. */
118  if (COM_EXPORT_OPERATION_BUFFERS && render && !render->is_a_single_elem()) {
119  export_operation(op, render);
120  }
121  }
122 
123  static void graphviz(const ExecutionSystem *system, StringRefNull name = "");
124 
125  protected:
126  static int graphviz_operation(const ExecutionSystem *system,
127  NodeOperation *operation,
128  const ExecutionGroup *group,
129  char *str,
130  int maxlen);
131  static int graphviz_legend_color(const char *name, const char *color, char *str, int maxlen);
132  static int graphviz_legend_line(
133  const char *name, const char *color, const char *style, char *str, int maxlen);
134  static int graphviz_legend_group(
135  const char *name, const char *color, const char *style, char *str, int maxlen);
136  static int graphviz_legend(char *str, int maxlen, bool has_execution_groups);
137  static bool graphviz_system(const ExecutionSystem *system, char *str, int maxlen);
138 
139  static void export_operation(const NodeOperation *op, MemoryBuffer *render);
140  static void delete_operation_exports();
141 };
142 
143 } // namespace blender::compositor
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
static std::string node_name(const Node *node)
Definition: COM_Debug.cc:39
static void node_to_operations(const Node *node)
Definition: COM_Debug.h:81
static void operation_read_write_buffer(const NodeOperation *operation)
Definition: COM_Debug.h:95
static void operation_added(const NodeOperation *operation)
Definition: COM_Debug.h:88
static int graphviz_operation(const ExecutionSystem *system, NodeOperation *operation, const ExecutionGroup *group, char *str, int maxlen)
Definition: COM_Debug.cc:57
static void execution_group_started(const ExecutionGroup *group)
Definition: COM_Debug.h:102
static void delete_operation_exports()
Definition: COM_Debug.cc:466
static int graphviz_legend(char *str, int maxlen, bool has_execution_groups)
Definition: COM_Debug.cc:223
static std::string operation_name(const NodeOperation *op)
Definition: COM_Debug.cc:48
static void convert_started()
Definition: COM_Debug.h:53
static int graphviz_legend_line(const char *name, const char *color, const char *style, char *str, int maxlen)
Definition: COM_Debug.cc:200
static bool graphviz_system(const ExecutionSystem *system, char *str, int maxlen)
Definition: COM_Debug.cc:276
static void node_added(const Node *node)
Definition: COM_Debug.h:74
std::map< const Node *, std::string > NodeNameMap
Definition: COM_Debug.h:32
static void export_operation(const NodeOperation *op, MemoryBuffer *render)
Definition: COM_Debug.cc:448
static void operation_rendered(const NodeOperation *op, MemoryBuffer *render)
Definition: COM_Debug.h:115
static void execution_group_finished(const ExecutionGroup *group)
Definition: COM_Debug.h:108
std::map< const NodeOperation *, std::string > OpNameMap
Definition: COM_Debug.h:33
static int graphviz_legend_color(const char *name, const char *color, char *str, int maxlen)
Definition: COM_Debug.cc:189
std::map< const ExecutionGroup *, GroupState > GroupStateMap
Definition: COM_Debug.h:34
static void graphviz(const ExecutionSystem *system, StringRefNull name="")
Definition: COM_Debug.cc:414
static void execute_started(const ExecutionSystem *system)
Definition: COM_Debug.h:60
static int graphviz_legend_group(const char *name, const char *color, const char *style, char *str, int maxlen)
Definition: COM_Debug.cc:209
Class ExecutionGroup is a group of Operations that are executed as one. This grouping is used to comb...
the ExecutionSystem contains the whole compositor tree.
a MemoryBuffer contains access to the data of a chunk
NodeOperation contains calculation logic.
OperationNode * node
#define str(s)
static constexpr bool COM_EXPORT_GRAPHVIZ
Definition: COM_Debug.h:17
static constexpr bool COM_GRAPHVIZ_SHOW_NODE_NAME
Definition: COM_Debug.h:18
static constexpr bool COM_EXPORT_OPERATION_BUFFERS
Definition: COM_Debug.h:21