[Bf-blender-cvs] [7663d403565] profiler-editor: draw node rectangles
Jacques Lucke
noreply at git.blender.org
Thu Apr 29 11:30:48 CEST 2021
Commit: 7663d403565cb3bec5d36fb2ae103ab09ba2693e
Author: Jacques Lucke
Date: Tue Apr 27 17:39:58 2021 +0200
Branches: profiler-editor
https://developer.blender.org/rB7663d403565cb3bec5d36fb2ae103ab09ba2693e
draw node rectangles
===================================================================
M source/blender/blenkernel/intern/DerivedMesh.cc
M source/blender/blenkernel/intern/screen.c
M source/blender/editors/space_profiler/profiler_draw.cc
M source/blender/editors/space_profiler/profiler_profile.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index 9f51ef5292f..474bfd0a4ee 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -41,6 +41,7 @@
#include "BLI_float2.hh"
#include "BLI_linklist.h"
#include "BLI_math.h"
+#include "BLI_profile.hh"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
@@ -923,6 +924,7 @@ static Mesh *modifier_modify_mesh_and_geometry_set(ModifierData *md,
Mesh *input_mesh,
GeometrySet &geometry_set)
{
+ BLI_PROFILE_SCOPE(__func__);
Mesh *mesh_output = nullptr;
const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md->type);
if (mti->modifyGeometrySet == nullptr) {
@@ -2059,6 +2061,7 @@ void makeDerivedMesh(struct Depsgraph *depsgraph,
BMEditMesh *em,
const CustomData_MeshMasks *dataMask)
{
+ BLI_PROFILE_SCOPE(__func__);
bool need_mapping;
CustomData_MeshMasks cddata_masks = *dataMask;
object_get_datamask(depsgraph, ob, &cddata_masks, &need_mapping);
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 60e45168dea..7c4517b07f1 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -1764,6 +1764,10 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area)
}
}
}
+ else if (sl->spacetype == SPACE_PROFILER) {
+ SpaceProfiler *sprofiler = (SpaceProfiler *)sl;
+ sprofiler->runtime = NULL;
+ }
}
BLI_listbase_clear(&area->actionzones);
diff --git a/source/blender/editors/space_profiler/profiler_draw.cc b/source/blender/editors/space_profiler/profiler_draw.cc
index 00dde364304..42f4e7c48f2 100644
--- a/source/blender/editors/space_profiler/profiler_draw.cc
+++ b/source/blender/editors/space_profiler/profiler_draw.cc
@@ -26,6 +26,9 @@
#include "BKE_context.h"
+#include "BLI_color.hh"
+#include "BLI_hash.h"
+#include "BLI_math_color.h"
#include "BLI_rect.h"
#include "profiler_draw.hh"
@@ -34,6 +37,8 @@
namespace blender::ed::profiler {
+using profile::Duration;
+
class ProfilerDrawer {
private:
const bContext *C;
@@ -64,6 +69,7 @@ class ProfilerDrawer {
{
UI_ThemeClearColor(TH_BACK);
this->compute_vertical_extends_of_all_nodes();
+ this->draw_all_nodes();
}
void compute_vertical_extends_of_all_nodes()
@@ -95,6 +101,59 @@ class ProfilerDrawer {
node.bottom_y = this->compute_vertical_extends_of_nodes(children, node.bottom_y);
}
}
+
+ void draw_all_nodes()
+ {
+ for (Span<ProfileNode *> nodes : profiler_layout_->root_nodes()) {
+ this->draw_nodes(nodes);
+ }
+ }
+
+ void draw_nodes(Span<ProfileNode *> nodes)
+ {
+ for (ProfileNode *node : nodes) {
+ this->draw_node(*node);
+ }
+ }
+
+ void draw_node(ProfileNode &node)
+ {
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ const Color4f color = this->get_node_color(node);
+ immUniformColor4fv(color);
+
+ const int left_x = this->time_to_x(node.begin_time());
+ const int right_x = std::max(left_x + 1, this->time_to_x(node.end_time()));
+ immRecti(pos, left_x, node.top_y, right_x, node.bottom_y);
+
+ immUnbindProgram();
+ }
+
+ int time_to_x(const TimePoint time) const
+ {
+ const TimePoint begin_time = profiler_layout_->begin_time();
+ const Duration time_since_begin = time - begin_time;
+ const float ms_since_begin = this->duration_to_ms(time_since_begin);
+ return ms_since_begin / 5.0f;
+ }
+
+ Color4f get_node_color(ProfileNode &node)
+ {
+ const uint64_t value = node.begin_time().time_since_epoch().count();
+ const float variation = BLI_hash_int_2d_to_float(value, value >> 32);
+ float r, g, b;
+ hsv_to_rgb(variation * 0.2f, 0.5f, 0.5f, &r, &g, &b);
+ return {r, g, b, 1.0f};
+ }
+
+ float duration_to_ms(const Duration duration) const
+ {
+ return duration.count() / 1000000.0f;
+ }
};
void draw_profiler(const bContext *C, ARegion *region)
diff --git a/source/blender/editors/space_profiler/profiler_profile.cc b/source/blender/editors/space_profiler/profiler_profile.cc
index 5019577e4fe..81c3c7099f9 100644
--- a/source/blender/editors/space_profiler/profiler_profile.cc
+++ b/source/blender/editors/space_profiler/profiler_profile.cc
@@ -18,6 +18,9 @@
#include "DNA_space_types.h"
+#include "WM_api.h"
+#include "WM_types.h"
+
#include "profiler_runtime.hh"
void ED_profiler_profile_enable(SpaceProfiler *sprofiler)
@@ -28,6 +31,7 @@ void ED_profiler_profile_enable(SpaceProfiler *sprofiler)
SpaceProfiler_Runtime &runtime = *sprofiler->runtime;
runtime.profile_listener = std::make_unique<blender::ed::profiler::SpaceProfilerListener>(
runtime);
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_PROFILER, nullptr);
}
void ED_profiler_profile_disable(SpaceProfiler *sprofiler)
@@ -41,7 +45,11 @@ void ED_profiler_profile_disable(SpaceProfiler *sprofiler)
bool ED_profiler_profile_is_enabled(SpaceProfiler *sprofiler)
{
+ if (sprofiler->runtime == nullptr) {
+ return false;
+ }
SpaceProfiler_Runtime &runtime = *sprofiler->runtime;
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_PROFILER, nullptr);
return (bool)runtime.profile_listener;
}
@@ -49,4 +57,5 @@ void ED_profiler_profile_clear(SpaceProfiler *sprofiler)
{
SpaceProfiler_Runtime &runtime = *sprofiler->runtime;
runtime.profiler_layout.reset();
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_PROFILER, nullptr);
}
More information about the Bf-blender-cvs
mailing list