Blender V5.3
NOD_eval_log.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
28
29#pragma once
30
31#include <chrono>
32
33#include "BLI_cache_mutex.hh"
35#include "BLI_enum_flags.hh"
39#include "BLI_ustring.hh"
40
42#include "BKE_geometry_set.hh"
43#include "BKE_node.hh"
47
50#include "NOD_warning.hh"
51
52#include "DNA_node_types.h"
53
54namespace blender {
55
56struct SpaceNode;
58struct Report;
59struct ImBuf;
60
61namespace fn {
62class GField;
63}
64
65namespace nodes::eval_log {
66
67using fn::GField;
68
70 None = 0,
71 Read = 1 << 0,
72 Write = 1 << 1,
73 Remove = 1 << 2,
74};
76
84class ValueLog {
85 public:
86 virtual ~ValueLog() = default;
87};
88
93class GenericValueLog : public ValueLog {
94 public:
99
101
102 ~GenericValueLog() override;
103};
104
109class FieldInfoLog : public ValueLog {
110 public:
111 const CPPType &type;
113
114 FieldInfoLog(const GField &field);
115};
116
117struct StringLog : public ValueLog {
120 StringLog(StringRef string, LinearAllocator<> &allocator);
121};
122
124 std::string name;
126 std::optional<bke::AttrDomain> domain;
127 std::optional<bke::AttrType> data_type;
128};
129
134
139class GeometryInfoLog : public ValueLog {
140 public:
141 std::string name;
144
148 struct CurveInfo {
151 };
154 };
161 };
170
171 std::optional<MeshInfo> mesh_info;
172 std::optional<CurveInfo> curve_info;
173 std::optional<PointCloudInfo> pointcloud_info;
174 std::optional<GreasePencilInfo> grease_pencil_info;
175 std::optional<InstancesInfo> instances_info;
176 std::optional<EditDataInfo> edit_data_info;
177 std::optional<VolumeInfo> volume_info;
178
179 GeometryInfoLog(const bke::GeometrySet &geometry_set);
180};
181
182class GridInfoLog : public ValueLog {
183 public:
184 bool is_empty = false;
185
186 GridInfoLog(const bke::GVolumeGrid &grid);
187};
188
189class BundleValueLog : public ValueLog {
190 public:
191 struct Item {
193 std::variant<const bke::bNodeSocketType *, StringRefNull> type;
194 };
195
197
199};
200
201class ClosureValueLog : public ValueLog {
202 public:
203 struct Item {
204 std::string key;
206 };
207
217
220 std::optional<Source> source;
221 std::shared_ptr<ClosureEvalLog> eval_log;
222
225 const std::optional<ClosureSourceLocation> &source_location,
226 std::shared_ptr<ClosureEvalLog> eval_log);
227};
228
229class ListInfoLog : public ValueLog {
230 public:
232
233 ListInfoLog(const GListPtr &list);
234};
235
240 mutable CacheMutex main_geometry_cache_mutex_;
241 mutable std::optional<bke::GeometrySet> main_geometry_cache_;
242
243 public:
249
251 int operator()(const Item &item) const
252 {
253 return item.identifier;
254 }
255 };
256
258
259 const bke::GeometrySet *main_geometry() const;
260};
261
262/* Compositor image result. */
263class ImageInfoLog : public ValueLog {
264 public:
265 /* Stores compositor::Domain information. */
270
271 /* Stores compositor::RealizationOptions information in a textual representation. */
275
276 /* Stores compositor::Result.precision in a textual representation. */
278
287};
288
289using Clock = std::chrono::steady_clock;
290using TimePoint = Clock::time_point;
291
297 public:
298 std::optional<ComputeContextHash> parent_hash;
299 std::optional<int32_t> parent_node_id;
305 std::optional<uint32_t> tree_orig_session_uid;
307 std::chrono::nanoseconds execution_time{};
308
310
346
357
360
361 void log_value(const bNode &node, const bNodeSocket &socket, GPointer value);
362};
363
391
392class NodesEvalLog;
393
402 private:
403 LinearAllocator<> allocator_;
404 NodesEvalLog *root_log_;
405 Vector<NodeTreeLogger *> tree_loggers_;
406 VectorSet<ComputeContextHash> children_hashes_;
407 bool reduced_node_warnings_ = false;
408 bool reduced_execution_times_ = false;
409 bool reduced_socket_values_ = false;
410 bool reduced_viewer_node_logs_ = false;
411 bool reduced_existing_attributes_ = false;
412 bool reduced_used_named_attributes_ = false;
413 bool reduced_debug_messages_ = false;
414 bool reduced_evaluated_gizmo_nodes_ = false;
415 bool reduced_layer_names_ = false;
416 bool reduced_node_image_previews_ = false;
417
418 public:
422 std::chrono::nanoseconds execution_time{0};
427
428 NodeTreeLog(NodesEvalLog *root_log, Vector<NodeTreeLogger *> tree_loggers);
430
437 void ensure_node_warnings(const Main &bmain);
438 void ensure_node_warnings(const Map<uint32_t, const bNodeTree *> &orig_tree_by_session_uid);
439
447 void ensure_layer_names();
449
450 NodeLog *find_node_log(int32_t identifier) const;
451 NodeLog &lookup_or_add_node_log(const int32_t identifier);
452
453 ValueLog *find_socket_value_log(const bNodeSocket &query_socket);
454 [[nodiscard]] bool try_convert_primitive_socket_value(const GenericValueLog &value_log,
455 const CPPType &dst_type,
456 void *dst);
457
458 template<typename T>
459 std::optional<T> find_primitive_socket_value(const bNodeSocket &query_socket)
460 {
461 if (auto *value_log = dynamic_cast<GenericValueLog *>(
462 this->find_socket_value_log(query_socket)))
463 {
464 T value;
465 if (this->try_convert_primitive_socket_value(*value_log, CPPType::get<T>(), &value)) {
466 return value;
467 }
468 }
469 return std::nullopt;
470 }
471};
472
474 private:
476
477 public:
479
485 NodeTreeLog *get_main_tree_log(const bNodeSocket &socket) const;
486
490 void foreach_tree_log(FunctionRef<void(NodeTreeLog &)> callback) const;
491};
492
498 private:
500 struct LocalData {
502 LinearAllocator<> allocator;
508 };
509
516
517 public:
520
524 NodeTreeLogger &get_local_tree_logger(const ComputeContext &compute_context);
525
529 NodeTreeLog &get_tree_log(const ComputeContextHash &compute_context_hash);
530
536 bke::ComputeContextCache &compute_context_cache);
537
539 static const ViewerNodeLog *find_viewer_node_log_for_path(const ViewerPath &viewer_path);
540};
541
542} // namespace nodes::eval_log
543
544} // namespace blender
static const CPPType & get()
GeometryInfoLog(const bke::GeometrySet &geometry_set)
Definition eval_log.cc:99
NodeTreeLog(NodesEvalLog *root_log, Vector< NodeTreeLogger * > tree_loggers)
Definition eval_log.cc:307
std::shared_ptr< ClosureEvalLog > eval_log
ClosureValueLog(Vector< Item > inputs, Vector< Item > outputs, const std::optional< ClosureSourceLocation > &source_location, std::shared_ptr< ClosureEvalLog > eval_log)
Definition eval_log.cc:243
NodeTreeLog * get_main_tree_log(const bke::bNodeTreeZone *zone) const
Definition eval_log.cc:1116
ContextualNodeTreeLogs(Map< const bke::bNodeTreeZone *, NodeTreeLog * > tree_logs_by_zone={})
Definition eval_log.cc:1110
void foreach_tree_log(FunctionRef< void(NodeTreeLog &)> callback) const
Definition eval_log.cc:1143
FieldInfoLog(const GField &field)
Definition eval_log.cc:80
GenericValueLog(const GMutablePointer value)
std::optional< GreasePencilInfo > grease_pencil_info
GeometryInfoLog(const bke::GeometrySet &geometry_set)
Definition eval_log.cc:99
std::optional< VolumeInfo > volume_info
std::optional< CurveInfo > curve_info
std::optional< PointCloudInfo > pointcloud_info
Vector< bke::GeometryComponent::Type > component_types
Vector< GeometryAttributeInfo > attributes
std::optional< EditDataInfo > edit_data_info
std::optional< InstancesInfo > instances_info
GridInfoLog(const bke::GVolumeGrid &grid)
Definition eval_log.cc:221
ImageInfoLog(int2 data_size, int2 display_size, int2 data_offset, float3x3 transformation, StringRefNull interpolation, StringRefNull extension_x, StringRefNull extension_y, StringRefNull precision)
Definition eval_log.cc:268
ListInfoLog(const GListPtr &list)
Definition eval_log.cc:259
Map< StringRefNull, NamedAttributeUsage > used_named_attributes
std::chrono::nanoseconds execution_time
VectorSet< NodeWarning > warnings
Map< int, ValueLog * > output_values_
Map< int, ValueLog * > input_values_
Vector< StringRefNull > debug_messages
std::chrono::nanoseconds execution_time
Map< int32_t, destruct_ptr< NodeLog > > nodes
void ensure_node_warnings(const NodesModifierData &nmd)
Definition eval_log.cc:438
std::optional< T > find_primitive_socket_value(const bNodeSocket &query_socket)
Map< int32_t, ViewerNodeLog *, 0 > viewer_node_logs
NodeLog & lookup_or_add_node_log(const int32_t identifier)
Definition eval_log.cc:727
Vector< const GeometryAttributeInfo * > existing_attributes
NodeTreeLog(NodesEvalLog *root_log, Vector< NodeTreeLogger * > tree_loggers)
Definition eval_log.cc:307
VectorSet< NodeWarning > all_warnings
Map< StringRefNull, NamedAttributeUsage > used_named_attributes
NodeLog * find_node_log(int32_t identifier) const
Definition eval_log.cc:718
bool try_convert_primitive_socket_value(const GenericValueLog &value_log, const CPPType &dst_type, void *dst)
Definition eval_log.cc:819
ValueLog * find_socket_value_log(const bNodeSocket &query_socket)
Definition eval_log.cc:734
linear_allocator::ChunkedList< ViewerNodeLogWithNode > viewer_node_logs
linear_allocator::ChunkedList< SocketValueLog, 16 > input_socket_values
std::optional< ComputeContextHash > parent_hash
linear_allocator::ChunkedList< NodeImagePreview, 16 > node_image_previews
linear_allocator::ChunkedList< DebugMessage > debug_messages
Vector< ComputeContextHash > children_hashes
linear_allocator::ChunkedList< WarningWithNode > node_warnings
linear_allocator::ChunkedList< NodeExecutionTime, 16 > node_execution_times
linear_allocator::ChunkedList< SocketValueLog, 16 > output_socket_values
linear_allocator::ChunkedList< EvaluatedGizmoNode > evaluated_gizmo_nodes
std::optional< uint32_t > tree_orig_session_uid
void log_value(const bNode &node, const bNodeSocket &socket, GPointer value)
Definition eval_log.cc:319
linear_allocator::ChunkedList< AttributeUsageWithNode > used_named_attributes
std::optional< int32_t > parent_node_id
std::chrono::nanoseconds execution_time
NodeTreeLogger & get_local_tree_logger(const ComputeContext &compute_context)
Definition eval_log.cc:851
static ContextualNodeTreeLogs get_contextual_tree_logs(const SpaceNode &snode)
Definition eval_log.cc:1048
static Map< const bke::bNodeTreeZone *, ComputeContextHash > get_context_hash_by_zone_for_node_editor(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
Definition eval_log.cc:972
NodeTreeLog & get_tree_log(const ComputeContextHash &compute_context_hash)
Definition eval_log.cc:939
static const ViewerNodeLog * find_viewer_node_log_for_path(const ViewerPath &viewer_path)
Definition eval_log.cc:1065
const bke::GeometrySet * main_geometry() const
Definition eval_log.cc:415
CustomIDVectorSet< Item, ItemIdentifierGetter > items
#define T
ENUM_OPERATORS(NamedAttributeUsage)
std::chrono::steady_clock Clock
Clock::time_point TimePoint
BMesh Iterators.
__int64 int64_t
Definition BKE_text.h:90
std::unique_ptr< T, DestructValueAtAddress< T > > destruct_ptr
unsigned int uint32_t
Definition BKE_text.h:81
VecBase< int32_t, 2 > int2
VectorSet< T, InlineBufferCapacity, DefaultProbingStrategy, CustomIDHash< T, GetIDFn >, CustomIDEqual< T, GetIDFn > > CustomIDVectorSet
MatBase< float, 3, 3 > float3x3
signed int int32_t
Definition BKE_text.h:78
Defines a socket type.
Definition BKE_node.hh:163
std::variant< const bke::bNodeSocketType *, StringRefNull > type
std::optional< bke::AttrDomain > domain
StringLog(StringRef string, LinearAllocator<> &allocator)
Definition eval_log.cc:67