Blender V5.0
NOD_geometry_nodes_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"
38
40#include "BKE_geometry_set.hh"
41#include "BKE_node.hh"
45
49
50#include "FN_field.hh"
51
52#include "DNA_node_types.h"
53
54struct SpaceNode;
56struct Report;
57
59
60using fn::GField;
61
64 std::string message;
65
67 NodeWarning(const Report &report);
68
69 uint64_t hash() const
70 {
71 return get_default_hash(this->type, this->message);
72 }
73
75};
76
78 None = 0,
79 Read = 1 << 0,
80 Write = 1 << 1,
81 Remove = 1 << 2,
82};
84
92class ValueLog {
93 public:
94 virtual ~ValueLog() = default;
95};
96
101class GenericValueLog : public ValueLog {
102 public:
107
109
110 ~GenericValueLog() override;
111};
112
117class FieldInfoLog : public ValueLog {
118 public:
119 const CPPType &type;
121
122 FieldInfoLog(const GField &field);
123};
124
125struct StringLog : public ValueLog {
128 StringLog(StringRef string, LinearAllocator<> &allocator);
129};
130
132 std::string name;
134 std::optional<bke::AttrDomain> domain;
135 std::optional<bke::AttrType> data_type;
136};
137
142
147class GeometryInfoLog : public ValueLog {
148 public:
149 std::string name;
152
156 struct CurveInfo {
159 };
162 };
169 };
178
179 std::optional<MeshInfo> mesh_info;
180 std::optional<CurveInfo> curve_info;
181 std::optional<PointCloudInfo> pointcloud_info;
182 std::optional<GreasePencilInfo> grease_pencil_info;
183 std::optional<InstancesInfo> instances_info;
184 std::optional<EditDataInfo> edit_data_info;
185 std::optional<VolumeInfo> volume_info;
186
187 GeometryInfoLog(const bke::GeometrySet &geometry_set);
188};
189
190class GridInfoLog : public ValueLog {
191 public:
192 bool is_empty = false;
193
194 GridInfoLog(const bke::GVolumeGrid &grid);
195};
196
197class BundleValueLog : public ValueLog {
198 public:
199 struct Item {
200 std::string key;
201 std::variant<const bke::bNodeSocketType *, StringRefNull> type;
202 };
203
205
207};
208
209class ClosureValueLog : public ValueLog {
210 public:
211 struct Item {
212 std::string key;
214 };
215
225
228 std::optional<Source> source;
229 std::shared_ptr<ClosureEvalLog> eval_log;
230
233 const std::optional<ClosureSourceLocation> &source_location,
234 std::shared_ptr<ClosureEvalLog> eval_log);
235};
236
237class ListInfoLog : public ValueLog {
238 public:
240
241 ListInfoLog(const List *list);
242};
243
248 mutable CacheMutex main_geometry_cache_mutex_;
249 mutable std::optional<bke::GeometrySet> main_geometry_cache_;
250
251 public:
257
259 int operator()(const Item &item) const
260 {
261 return item.identifier;
262 }
263 };
264
266
267 const bke::GeometrySet *main_geometry() const;
268};
269
270using Clock = std::chrono::steady_clock;
271using TimePoint = Clock::time_point;
272
278 public:
279 std::optional<ComputeContextHash> parent_hash;
280 std::optional<int32_t> parent_node_id;
286 std::optional<uint32_t> tree_orig_session_uid;
288 std::chrono::nanoseconds execution_time{};
289
291
322
332
335
336 void log_value(const bNode &node, const bNodeSocket &socket, GPointer value);
337};
338
364
365class GeoNodesLog;
366
375 private:
376 GeoNodesLog *root_log_;
377 Vector<GeoTreeLogger *> tree_loggers_;
378 VectorSet<ComputeContextHash> children_hashes_;
379 bool reduced_node_warnings_ = false;
380 bool reduced_execution_times_ = false;
381 bool reduced_socket_values_ = false;
382 bool reduced_viewer_node_logs_ = false;
383 bool reduced_existing_attributes_ = false;
384 bool reduced_used_named_attributes_ = false;
385 bool reduced_debug_messages_ = false;
386 bool reduced_evaluated_gizmo_nodes_ = false;
387 bool reduced_layer_names_ = false;
388
389 public:
393 std::chrono::nanoseconds execution_time{0};
398
399 GeoTreeLog(GeoNodesLog *root_log, Vector<GeoTreeLogger *> tree_loggers);
401
408 void ensure_node_warnings(const Main &bmain);
409 void ensure_node_warnings(const Map<uint32_t, const bNodeTree *> &orig_tree_by_session_uid);
410
418 void ensure_layer_names();
419
420 ValueLog *find_socket_value_log(const bNodeSocket &query_socket);
421 [[nodiscard]] bool try_convert_primitive_socket_value(const GenericValueLog &value_log,
422 const CPPType &dst_type,
423 void *dst);
424
425 template<typename T>
426 std::optional<T> find_primitive_socket_value(const bNodeSocket &query_socket)
427 {
428 if (auto *value_log = dynamic_cast<GenericValueLog *>(
429 this->find_socket_value_log(query_socket)))
430 {
431 T value;
432 if (this->try_convert_primitive_socket_value(*value_log, CPPType::get<T>(), &value)) {
433 return value;
434 }
435 }
436 return std::nullopt;
437 }
438};
439
441 private:
443
444 public:
446
451 GeoTreeLog *get_main_tree_log(const bNode &node) const;
452 GeoTreeLog *get_main_tree_log(const bNodeSocket &socket) const;
453
457 void foreach_tree_log(FunctionRef<void(GeoTreeLog &)> callback) const;
458};
459
466 private:
468 struct LocalData {
470 LinearAllocator<> allocator;
476 };
477
484
485 public:
488
492 GeoTreeLogger &get_local_tree_logger(const ComputeContext &compute_context);
493
497 GeoTreeLog &get_tree_log(const ComputeContextHash &compute_context_hash);
498
504 bke::ComputeContextCache &compute_context_cache);
505
507 static const ViewerNodeLog *find_viewer_node_log_for_path(const ViewerPath &viewer_path);
508};
509
510} // namespace blender::nodes::geo_eval_log
VolumeGridType
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
#define ENUM_OPERATORS(_type, _max)
long long int int64_t
unsigned long long int uint64_t
static const CPPType & get()
ClosureValueLog(Vector< Item > inputs, Vector< Item > outputs, const std::optional< ClosureSourceLocation > &source_location, std::shared_ptr< ClosureEvalLog > eval_log)
GeoTreeLog * get_main_tree_log(const bke::bNodeTreeZone *zone) const
ContextualGeoTreeLogs(Map< const bke::bNodeTreeZone *, GeoTreeLog * > tree_logs_by_zone={})
void foreach_tree_log(FunctionRef< void(GeoTreeLog &)> callback) const
Map< StringRefNull, NamedAttributeUsage > used_named_attributes
static ContextualGeoTreeLogs get_contextual_tree_logs(const SpaceNode &snode)
static Map< const bke::bNodeTreeZone *, ComputeContextHash > get_context_hash_by_zone_for_node_editor(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
static const ViewerNodeLog * find_viewer_node_log_for_path(const ViewerPath &viewer_path)
GeoTreeLogger & get_local_tree_logger(const ComputeContext &compute_context)
GeoTreeLog & get_tree_log(const ComputeContextHash &compute_context_hash)
Vector< const GeometryAttributeInfo * > existing_attributes
void ensure_node_warnings(const NodesModifierData &nmd)
bool try_convert_primitive_socket_value(const GenericValueLog &value_log, const CPPType &dst_type, void *dst)
Map< int32_t, ViewerNodeLog *, 0 > viewer_node_logs
std::optional< T > find_primitive_socket_value(const bNodeSocket &query_socket)
Map< StringRefNull, NamedAttributeUsage > used_named_attributes
GeoTreeLog(GeoNodesLog *root_log, Vector< GeoTreeLogger * > tree_loggers)
ValueLog * find_socket_value_log(const bNodeSocket &query_socket)
linear_allocator::ChunkedList< EvaluatedGizmoNode > evaluated_gizmo_nodes
linear_allocator::ChunkedList< AttributeUsageWithNode > used_named_attributes
linear_allocator::ChunkedList< NodeExecutionTime, 16 > node_execution_times
linear_allocator::ChunkedList< ViewerNodeLogWithNode > viewer_node_logs
std::optional< ComputeContextHash > parent_hash
linear_allocator::ChunkedList< WarningWithNode > node_warnings
linear_allocator::ChunkedList< DebugMessage > debug_messages
linear_allocator::ChunkedList< SocketValueLog, 16 > input_socket_values
void log_value(const bNode &node, const bNodeSocket &socket, GPointer value)
linear_allocator::ChunkedList< SocketValueLog, 16 > output_socket_values
GeometryInfoLog(const bke::GeometrySet &geometry_set)
std::optional< GreasePencilInfo > grease_pencil_info
Vector< bke::GeometryComponent::Type > component_types
const bke::GeometrySet * main_geometry() const
CustomIDVectorSet< Item, ItemIdentifierGetter > items
#define T
std::unique_ptr< T, DestructValueAtAddress< T > > destruct_ptr
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233
VectorSet< T, InlineBufferCapacity, DefaultProbingStrategy, CustomIDHash< T, GetIDFn >, CustomIDEqual< T, GetIDFn > > CustomIDVectorSet
Defines a socket type.
Definition BKE_node.hh:158
std::variant< const bke::bNodeSocketType *, StringRefNull > type
NodeWarning(NodeWarningType type, StringRef message)
StringLog(StringRef string, LinearAllocator<> &allocator)