[Bf-blender-cvs] [affbc6ade2b] temp-geometry-nodes-timings: Add support for frames. Change to show 1 decimal below 1ms and 0 decimals above.

Erik noreply at git.blender.org
Sat Nov 13 00:08:29 CET 2021


Commit: affbc6ade2b399f779e80a7298b396cab50db153
Author: Erik
Date:   Sat Nov 13 00:07:27 2021 +0100
Branches: temp-geometry-nodes-timings
https://developer.blender.org/rBaffbc6ade2b399f779e80a7298b396cab50db153

Add support for frames.
Change to show 1 decimal below 1ms and 0 decimals above.

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

M	source/blender/editors/space_node/drawnode.cc
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_intern.h
M	source/blender/nodes/NOD_geometry_nodes_eval_log.hh

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

diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index d903e9ee984..a6d0acfabf2 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -337,8 +337,9 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
   node->totr = rect;
 }
 
-static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float aspect)
+static void node_draw_frame_label(bNodeTree *ntree, bNode *node, SpaceNode *snode)
 {
+  const float aspect = snode->runtime->aspect;
   /* XXX font id is crap design */
   const int fontid = UI_style_get()->widgetlabel.uifont_id;
   NodeFrame *data = (NodeFrame *)node->storage;
@@ -369,6 +370,24 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
   float x = BLI_rctf_cent_x(rct) - (0.5f * width);
   float y = rct->ymax - label_height;
 
+  /* Draw execution time. */
+  if (snode->flag & SNODE_SHOW_TIMING) {
+    uint64_t exec_time_us = node_get_execution_time(ntree, node, snode);
+
+    if (exec_time_us > 0) {
+      std::string timing_str;
+      if (exec_time_us < 1000) {
+        timing_str = "<1 ms";
+      }
+      else {
+        int exec_time_ms = static_cast<int>((exec_time_us / 1000.0f) + 0.5f);
+        timing_str = std::to_string(exec_time_ms) + " ms";
+      }
+      BLF_position(fontid, rct->xmin + U.widget_unit * 0.5f, y, 0);
+      BLF_draw(fontid, timing_str.c_str(), timing_str.length());
+    }
+  }
+
   /* label */
   const bool has_label = node->label[0] != '\0';
   if (has_label) {
@@ -468,7 +487,7 @@ static void node_draw_frame(const bContext *C,
   }
 
   /* label and text */
-  node_draw_frame_label(ntree, node, snode->runtime->aspect);
+  node_draw_frame_label(ntree, node, snode);
 
   UI_block_end(C, node->block);
   UI_block_draw(C, node->block);
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index db4f7ab9694..9bca6c3592c 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1579,44 +1579,87 @@ static void node_add_error_message_button(
   UI_block_emboss_set(node.block, UI_EMBOSS);
 }
 
-static void node_add_execution_time_label(const bContext *C, bNode &node, const rctf &rect)
+uint64_t node_get_execution_time(bNodeTree *ntree, bNode *node, SpaceNode *snode)
 {
-  SpaceNode *snode = CTX_wm_space_node(C);
   uint64_t exec_time_us = 0;
 
-  if (node.type == NODE_GROUP_OUTPUT) {
+  if (node->type == NODE_GROUP_OUTPUT) {
     auto *tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context(*snode);
 
     if (tree_log == nullptr) {
-      return;
+      return 0;
     }
     tree_log->foreach_node_log(
         [&](const geo_log::NodeLog &node_log) { exec_time_us += node_log.execution_time(); });
   }
-  else if (node.type == NODE_GROUP) {
+  else if (node->type == NODE_FRAME) {
+    LISTBASE_FOREACH (bNode *, tnode, &ntree->nodes) {
+      if (tnode->parent != node) {
+        continue;
+      }
+
+      if (tnode->type == NODE_FRAME) {
+        exec_time_us += node_get_execution_time(ntree, tnode, snode);
+      }
+      else if (tnode->type == NODE_GROUP) {
+        auto *root_tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context(*snode);
+        if (root_tree_log == nullptr) {
+          continue;
+        }
+        auto *tree_log = root_tree_log->lookup_child_log(tnode->name);
+        if (tree_log == nullptr) {
+          continue;
+        }
+        tree_log->foreach_node_log(
+            [&](const geo_log::NodeLog &node_log) { exec_time_us += node_log.execution_time(); });
+      }
+      else {
+        auto *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(*snode, *tnode);
+        if (node_log) {
+          exec_time_us += node_log->execution_time();
+        }
+      }
+    }
+  }
+  else if (node->type == NODE_GROUP) {
     auto *root_tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context(*snode);
     if (root_tree_log == nullptr) {
-      return;
+      return 0;
     }
-    auto *tree_log = root_tree_log->lookup_child_log(node.name);
+    auto *tree_log = root_tree_log->lookup_child_log(node->name);
     if (tree_log == nullptr) {
-      return;
+      return 0;
     }
     tree_log->foreach_node_log(
         [&](const geo_log::NodeLog &node_log) { exec_time_us += node_log.execution_time(); });
   }
   else {
-    auto *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(*snode, node);
+    auto *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(*snode, *node);
     exec_time_us = node_log ? node_log->execution_time() : 0;
   }
+  return exec_time_us;
+}
+
+static void node_add_execution_time_label(const bContext *C, bNode &node, const rctf &rect)
+{
+  SpaceNode *snode = CTX_wm_space_node(C);
+
+  uint64_t exec_time_us = node_get_execution_time(nullptr, &node, snode);
+  short precision = 0;
 
   /* Don't show the label if execution time is 0 microseconds. */
   if (exec_time_us == 0) {
     return;
   }
 
-  int exec_time_ms = static_cast<int>((exec_time_us / 1000.0f) + 0.5f);
-  std::string timing_str = (exec_time_us < 1000 ? "<1" : std::to_string(exec_time_ms)) + " ms";
+  /* Show decimal if value is below 1ms */
+  if (exec_time_us < 1000) {
+    precision = 1;
+  }
+
+  std::stringstream stream;
+  stream << std::fixed << std::setprecision(precision) << (exec_time_us / 1000.0f);
+  std::string timing_str = stream.str() + " ms";
 
   uiBut *but_timing = uiDefBut(node.block,
                                UI_BTYPE_LABEL,
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 383fe5afdf9..168bbc87180 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -101,6 +101,9 @@ void node_link_calculate_multi_input_position(const float socket_x,
                                               float r[2]);
 
 int node_get_colorid(struct bNode *node);
+uint64_t node_get_execution_time(struct bNodeTree *ntree,
+                                 struct bNode *node,
+                                 struct SpaceNode *snode);
 int node_get_resize_cursor(int directions);
 void node_draw_shadow(const struct SpaceNode *snode,
                       const struct bNode *node,
diff --git a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
index 2556dd566e6..7013b8a996e 100644
--- a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
@@ -288,7 +288,7 @@ class NodeLog {
  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);
+  void execution_time(uint64_t exec_time);
 
   Span<SocketLog> input_logs() const
   {
@@ -305,7 +305,7 @@ class NodeLog {
     return warnings_;
   }
 
-  int execution_time() const
+  uint64_t execution_time() const
   {
     return exec_time_;
   }



More information about the Bf-blender-cvs mailing list