[Bf-blender-cvs] [df29f2da23e] temp-geometry-nodes-timings: Initial implementation

Erik noreply at git.blender.org
Wed Nov 10 14:09:44 CET 2021


Commit: df29f2da23e625415f78d5f7af943746f8290afb
Author: Erik
Date:   Wed Nov 10 02:20:02 2021 +0100
Branches: temp-geometry-nodes-timings
https://developer.blender.org/rBdf29f2da23e625415f78d5f7af943746f8290afb

Initial implementation

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

M	release/scripts/startup/bl_ui/space_node.py
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/NOD_geometry_nodes_eval_log.hh
M	source/blender/nodes/intern/geometry_nodes_eval_log.cc
M	source/blender/nodes/intern/node_geometry_exec.cc

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

diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index 2fda13184da..34cb82eed1f 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -710,6 +710,10 @@ class NODE_PT_overlay(Panel):
 
         col.prop(snode, "show_annotation", text="Annotations")
 
+        if snode.tree_type == 'GeometryNodeTree':
+            col.separator()
+            col.prop(snode, "show_timing", text="Timings")
+
 
 class NODE_UL_interface_sockets(bpy.types.UIList):
     def draw_item(self, context, layout, _data, item, icon, _active_data, _active_propname, _index):
@@ -775,7 +779,7 @@ class NodeTreeInterfacePanel:
                 "node.tree_socket_change_type",
                 "socket_type",
                 text=active_socket.bl_label if active_socket.bl_label else active_socket.bl_idname
-                )
+            )
             props.in_out = in_out
 
             layout.use_property_split = True
@@ -815,6 +819,7 @@ class NODE_PT_node_tree_interface_inputs(NodeTreeInterfacePanel, Panel):
     def draw(self, context):
         self.draw_socket_list(context, "IN", "inputs", "active_input")
 
+
 class NODE_PT_node_tree_interface_outputs(NodeTreeInterfacePanel, Panel):
     bl_space_type = 'NODE_EDITOR'
     bl_region_type = 'UI'
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 5fdf816339b..1f06a538f04 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1750,6 +1750,30 @@ static void node_draw_basis(const bContext *C,
     UI_but_flag_enable(but, UI_BUT_INACTIVE);
   }
 
+  if (snode->flag & SNODE_SHOW_TIMING) {
+    const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(
+        *snode, *node);
+    if (node_log && node_log->execution_time() > 0) {
+      std::string timing_str = std::to_string(node_log->execution_time()) + " ms";
+      uiBut *but_timing = uiDefBut(node->block,
+                                   UI_BTYPE_LABEL,
+                                   0,
+                                   timing_str.c_str(),
+                                   (int)(rct->xmin + NODE_MARGIN_X + 0.4f),
+                                   (int)(rct->ymax - NODE_DY + (22.0f * U.dpi_fac)),
+                                   (short)(iconofs - rct->xmin - (18.0f * U.dpi_fac)),
+                                   (short)NODE_DY,
+                                   nullptr,
+                                   0,
+                                   0,
+                                   0,
+                                   0,
+                                   "");
+      if (node->flag & NODE_MUTED) {
+        UI_but_flag_enable(but_timing, UI_BUT_INACTIVE);
+      }
+    }
+  }
   /* Wire across the node when muted/disabled. */
   if (node->flag & NODE_MUTED) {
     node_draw_mute_line(C, v2d, snode, node);
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 671cc182d7e..8cf34f99922 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1593,6 +1593,7 @@ typedef enum eSpaceNode_Flag {
   SNODE_PIN = (1 << 12),
   /** automatically offset following nodes in a chain on insertion */
   SNODE_SKIP_INSOFFSET = (1 << 13),
+  SNODE_SHOW_TIMING = (1 << 14),
 } eSpaceNode_Flag;
 
 /* SpaceNode.texfrom */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 03976967e9f..3e4a5c3c12f 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -7243,6 +7243,11 @@ static void rna_def_space_node(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Show Annotation", "Show annotations for this view");
   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
 
+  prop = RNA_def_property(srna, "show_timing", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_SHOW_TIMING);
+  RNA_def_property_ui_text(prop, "Show Timing", "Show node execution time");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
+
   prop = RNA_def_property(srna, "use_auto_render", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_AUTO_RENDER);
   RNA_def_property_ui_text(
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 70d2bd9c7f5..67694880c62 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -35,6 +35,8 @@
 #include "BLI_task.hh"
 #include "BLI_vector_set.hh"
 
+#include <chrono>
+
 namespace blender::modifiers::geometry_nodes {
 
 using fn::CPPType;
@@ -926,7 +928,11 @@ class GeometryNodesEvaluator {
       params.error_message_add(geo_log::NodeWarningType::Legacy,
                                TIP_("Legacy node will be removed before Blender 4.0"));
     }
+    auto begin = std::chrono::high_resolution_clock::now();
     bnode.typeinfo->geometry_node_execute(params);
+    auto end = std::chrono::high_resolution_clock::now();
+    int duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
+    params.execution_time(duration);
   }
 
   void execute_multi_function_node(const DNode node,
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 6e1f21dbae0..806c38cf11b 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -308,6 +308,7 @@ class GeoNodeExecParams {
    * and potentially elsewhere in Blender.
    */
   void error_message_add(const NodeWarningType type, std::string message) const;
+  void execution_time(const int exec_time) const;
 
   /**
    * Creates a read-only attribute based on node inputs. The method automatically detects which
diff --git a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
index 2a118057a03..e75ebeb7c04 100644
--- a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
@@ -169,6 +169,11 @@ struct NodeWithWarning {
   NodeWarning warning;
 };
 
+struct NodeWithExecutionTime {
+  DNode node;
+  int exec_time;
+};
+
 /** The same value can be referenced by multiple sockets when they are linked. */
 struct ValueOfSockets {
   Span<DSocket> sockets;
@@ -189,6 +194,7 @@ class LocalGeoLogger {
   std::unique_ptr<LinearAllocator<>> allocator_;
   Vector<ValueOfSockets> values_;
   Vector<NodeWithWarning> node_warnings_;
+  Vector<NodeWithExecutionTime> node_exec_times_;
 
   friend ModifierLog;
 
@@ -201,6 +207,7 @@ class LocalGeoLogger {
   void log_value_for_sockets(Span<DSocket> sockets, GPointer value);
   void log_multi_value_socket(DSocket socket, Span<GPointer> values);
   void log_node_warning(DNode node, NodeWarningType type, std::string message);
+  void log_execution_time(DNode node, int exec_time);
 };
 
 /** The root logger class. */
@@ -274,12 +281,14 @@ class NodeLog {
   Vector<SocketLog> input_logs_;
   Vector<SocketLog> output_logs_;
   Vector<NodeWarning, 0> warnings_;
+  int exec_time_ = 0;
 
   friend ModifierLog;
 
  public:
   const SocketLog *lookup_socket_log(eNodeSocketInOut in_out, int index) const;
   const SocketLog *lookup_socket_log(const bNode &node, const bNodeSocket &socket) const;
+  void execution_time(int exec_time);
 
   Span<SocketLog> input_logs() const
   {
@@ -296,6 +305,11 @@ class NodeLog {
     return warnings_;
   }
 
+  int execution_time() const
+  {
+    return exec_time_;
+  }
+
   Vector<const GeometryAttributeInfo *> lookup_available_attributes() const;
 };
 
diff --git a/source/blender/nodes/intern/geometry_nodes_eval_log.cc b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
index ddd3c991518..085a907dbc1 100644
--- a/source/blender/nodes/intern/geometry_nodes_eval_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
@@ -63,6 +63,12 @@ ModifierLog::ModifierLog(GeoLogger &logger)
                                                        node_with_warning.node);
       node_log.warnings_.append(node_with_warning.warning);
     }
+
+    for (NodeWithExecutionTime &node_with_exec_time : local_logger.node_exec_times_) {
+      NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context,
+                                                       node_with_exec_time.node);
+      node_log.exec_time_ = node_with_exec_time.exec_time;
+    }
   }
 }
 
@@ -457,4 +463,9 @@ void LocalGeoLogger::log_node_warning(DNode node, NodeWarningType type, std::str
   node_warnings_.append({node, {type, std::move(message)}});
 }
 
+void LocalGeoLogger::log_execution_time(DNode node, int exec_time)
+{
+  node_exec_times_.append({node, exec_time});
+}
+
 }  // namespace blender::nodes::geometry_nodes_eval_log
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 27bc206187d..39e22d0eb70 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -36,6 +36,15 @@ void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::strin
   local_logger.log_node_warning(provider_->dnode, type, std::move(message));
 }
 
+void GeoNodeExecParams::execution_time(const int exec_time) const
+{
+  if (provider_->logger == nullptr) {
+    return;
+  }
+  LocalGeoLogger &local_logger = provider_->logger->local();
+  local_logger.log_execution_time(provider_->dnode, exec_time);
+}
+
 void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
                                                  const GeometrySet &geometry_set) const
 {



More information about the Bf-blender-cvs mailing list