[Bf-blender-cvs] [aad781cae1d] temp-geometry-nodes-timings: Change from milliseconds to microseconds Refactored drawing code
Erik
noreply at git.blender.org
Wed Nov 10 14:09:45 CET 2021
Commit: aad781cae1d2204fdb6b847310d05097e6a2835c
Author: Erik
Date: Wed Nov 10 14:07:53 2021 +0100
Branches: temp-geometry-nodes-timings
https://developer.blender.org/rBaad781cae1d2204fdb6b847310d05097e6a2835c
Change from milliseconds to microseconds
Refactored drawing code
===================================================================
M source/blender/editors/space_node/node_draw.cc
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/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 1f06a538f04..3a13e23824c 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -87,6 +87,8 @@
#include "node_intern.h" /* own include */
+#include <iomanip>
+
#ifdef WITH_COMPOSITOR
# include "COM_compositor.h"
#endif
@@ -1577,6 +1579,72 @@ 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)
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+ uint64_t exec_time = 0;
+
+ if (node.type == NODE_GROUP_OUTPUT) {
+ const geo_log::TreeLog *tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context(
+ *snode);
+ if (tree_log) {
+ tree_log->foreach_node_log(
+ [&](const geo_log::NodeLog &node_log) { exec_time += node_log.execution_time(); });
+ }
+ }
+ else if (node.type == NODE_GROUP) {
+ const geo_log::TreeLog *tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context(
+ *snode);
+ if (tree_log) {
+ const geo_log::TreeLog *child_tree_log = tree_log->lookup_child_log(node.name);
+ if (child_tree_log) {
+ child_tree_log->foreach_node_log(
+ [&](const geo_log::NodeLog &node_log) { exec_time += node_log.execution_time(); });
+ }
+ }
+ }
+ else {
+ const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(
+ *snode, node);
+ exec_time = node_log ? node_log->execution_time() : 0;
+ }
+ /* Don't show if time is below 100 microseconds */
+ if (exec_time >= 100) {
+ std::string timing_str;
+ short precision = 0;
+
+ /* Show decimals if value is below 10s */
+ if (exec_time < 10000) {
+ precision = 1;
+ }
+ if (exec_time < 1000) {
+ precision = 2;
+ }
+
+ std::stringstream stream;
+ stream << std::fixed << std::setprecision(precision) << (exec_time / 1000.0f);
+ timing_str = stream.str() + " ms";
+
+ uiBut *but_timing = uiDefBut(node.block,
+ UI_BTYPE_LABEL,
+ 0,
+ timing_str.c_str(),
+ (int)(rect.xmin + NODE_MARGIN_X + 0.4f),
+ (int)(rect.ymax - NODE_DY + (22.0f * U.dpi_fac)),
+ (short)(rect.xmax - rect.xmin),
+ (short)NODE_DY,
+ nullptr,
+ 0,
+ 0,
+ 0,
+ 0,
+ "");
+ if (node.flag & NODE_MUTED) {
+ UI_but_flag_enable(but_timing, UI_BUT_INACTIVE);
+ }
+ }
+}
+
static void node_draw_basis(const bContext *C,
const View2D *v2d,
const SpaceNode *snode,
@@ -1750,29 +1818,9 @@ static void node_draw_basis(const bContext *C,
UI_but_flag_enable(but, UI_BUT_INACTIVE);
}
+ /* Execution time. */
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);
- }
- }
+ node_add_execution_time_label(C, *node, *rct);
}
/* Wire across the node when muted/disabled. */
if (node->flag & NODE_MUTED) {
@@ -1903,6 +1951,11 @@ static void node_draw_hidden(const bContext *C,
/* Shadow. */
node_draw_shadow(snode, node, hiddenrad, 1.0f);
+ /* Execution time. */
+ if (snode->flag & SNODE_SHOW_TIMING) {
+ node_add_execution_time_label(C, *node, *rct);
+ }
+
/* 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/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 67694880c62..6cb345705cc 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -931,7 +931,7 @@ class GeometryNodesEvaluator {
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();
+ int duration = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();
params.execution_time(duration);
}
@@ -939,10 +939,12 @@ class GeometryNodesEvaluator {
const nodes::NodeMultiFunctions::Item &fn_item,
NodeState &node_state)
{
+ NodeParamsProvider params_provider{*this, node, node_state};
+ GeoNodeExecParams params{params_provider};
+ auto begin = std::chrono::high_resolution_clock::now();
+
if (node->idname().find("Legacy") != StringRef::not_found) {
/* Create geometry nodes params just for creating an error message. */
- NodeParamsProvider params_provider{*this, node, node_state};
- GeoNodeExecParams params{params_provider};
params.error_message_add(geo_log::NodeWarningType::Legacy,
TIP_("Legacy node will be removed before Blender 4.0"));
}
@@ -989,6 +991,10 @@ class GeometryNodesEvaluator {
output_state.has_been_computed = true;
output_index++;
}
+
+ auto end = std::chrono::high_resolution_clock::now();
+ int duration = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();
+ params.execution_time(duration);
}
void execute_unknown_node(const DNode node, NodeState &node_state)
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 806c38cf11b..bb3ede0bb29 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -308,7 +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;
+ void execution_time(const uint64_t 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 e75ebeb7c04..2556dd566e6 100644
--- a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
@@ -171,7 +171,7 @@ struct NodeWithWarning {
struct NodeWithExecutionTime {
DNode node;
- int exec_time;
+ uint64_t exec_time;
};
/** The same value can be referenced by multiple sockets when they are linked. */
@@ -207,7 +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);
+ void log_execution_time(DNode node, uint64_t exec_time);
};
/** The root logger class. */
@@ -281,7 +281,7 @@ class NodeLog {
Vector<SocketLog> input_logs_;
Vector<SocketLog> output_logs_;
Vector<NodeWarning, 0> warnings_;
- int exec_time_ = 0;
+ uint64_t exec_time_ = 0;
friend ModifierLog;
diff --git a/source/blender/nodes/intern/geometry_nodes_eval_log.cc b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
index 085a907dbc1..92f8bde2e76 100644
--- a/source/blender/nodes/intern/geometry_nodes_eval_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
@@ -463,7 +463,7 @@ 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)
+void LocalGeoLogger::log_execution_time(DNode node, uint64_t exec_time)
{
node_exec_times_.append({node, exec_time});
}
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 39e22d0eb70..60f7e5eefb7 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -36,7 +36,7 @@ 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
+void GeoNodeExecParams::execution_time(const uint64_t exec_time) const
{
if (provider_->logger == nullptr) {
return;
More information about the Bf-blender-cvs
mailing list