Blender V4.5
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
37
39#include "BKE_geometry_set.hh"
40#include "BKE_node.hh"
43
47
48#include "FN_field.hh"
49
50#include "DNA_node_types.h"
51
52struct SpaceNode;
54struct Report;
55
57
58using fn::GField;
59
62 std::string message;
63
65 NodeWarning(const Report &report);
66
67 uint64_t hash() const
68 {
69 return get_default_hash(this->type, this->message);
70 }
71
73};
74
76 None = 0,
77 Read = 1 << 0,
78 Write = 1 << 1,
79 Remove = 1 << 2,
80};
82
90class ValueLog {
91 public:
92 virtual ~ValueLog() = default;
93};
94
99class GenericValueLog : public ValueLog {
100 public:
105
107
108 ~GenericValueLog() override;
109};
110
115class FieldInfoLog : public ValueLog {
116 public:
117 const CPPType &type;
119
120 FieldInfoLog(const GField &field);
121};
122
123struct StringLog : public ValueLog {
126 StringLog(StringRef string, LinearAllocator<> &allocator);
127};
128
130 std::string name;
132 std::optional<bke::AttrDomain> domain;
133 std::optional<eCustomDataType> data_type;
134};
135
140class GeometryInfoLog : public ValueLog {
141 public:
142 std::string name;
145
149 struct CurveInfo {
152 };
155 };
162 };
168 struct VolumeInfo {
170 };
171 struct GridInfo {
173 };
174
175 std::optional<MeshInfo> mesh_info;
176 std::optional<CurveInfo> curve_info;
177 std::optional<PointCloudInfo> pointcloud_info;
178 std::optional<GreasePencilInfo> grease_pencil_info;
179 std::optional<InstancesInfo> instances_info;
180 std::optional<EditDataInfo> edit_data_info;
181 std::optional<VolumeInfo> volume_info;
182 std::optional<GridInfo> grid_info;
183
184 GeometryInfoLog(const bke::GeometrySet &geometry_set);
185 GeometryInfoLog(const bke::GVolumeGrid &grid);
186};
187
199
200class ClosureValueLog : public ValueLog {
201 public:
206
216
219 std::optional<Source> source;
220 std::shared_ptr<ClosureEvalLog> eval_log;
221
224 const std::optional<ClosureSourceLocation> &source_location,
225 std::shared_ptr<ClosureEvalLog> eval_log);
226};
227
233 public:
235};
236
237using Clock = std::chrono::steady_clock;
238using TimePoint = Clock::time_point;
239
245 public:
246 std::optional<ComputeContextHash> parent_hash;
247 std::optional<int32_t> parent_node_id;
253 std::optional<uint32_t> tree_orig_session_uid;
255 std::chrono::nanoseconds execution_time{};
256
258
289
299
302
303 void log_value(const bNode &node, const bNodeSocket &socket, GPointer value);
304 void log_viewer_node(const bNode &viewer_node, bke::GeometrySet geometry);
305};
306
332
333class GeoNodesLog;
334
343 private:
344 GeoNodesLog *root_log_;
345 Vector<GeoTreeLogger *> tree_loggers_;
346 VectorSet<ComputeContextHash> children_hashes_;
347 bool reduced_node_warnings_ = false;
348 bool reduced_execution_times_ = false;
349 bool reduced_socket_values_ = false;
350 bool reduced_viewer_node_logs_ = false;
351 bool reduced_existing_attributes_ = false;
352 bool reduced_used_named_attributes_ = false;
353 bool reduced_debug_messages_ = false;
354 bool reduced_evaluated_gizmo_nodes_ = false;
355 bool reduced_layer_names_ = false;
356
357 public:
361 std::chrono::nanoseconds execution_time{0};
366
367 GeoTreeLog(GeoNodesLog *root_log, Vector<GeoTreeLogger *> tree_loggers);
369
376 void ensure_node_warnings(const Main &bmain);
377 void ensure_node_warnings(const Map<uint32_t, const bNodeTree *> &orig_tree_by_session_uid);
378
386 void ensure_layer_names();
387
388 ValueLog *find_socket_value_log(const bNodeSocket &query_socket);
389 [[nodiscard]] bool try_convert_primitive_socket_value(const GenericValueLog &value_log,
390 const CPPType &dst_type,
391 void *dst);
392
393 template<typename T>
394 std::optional<T> find_primitive_socket_value(const bNodeSocket &query_socket)
395 {
396 if (auto *value_log = dynamic_cast<GenericValueLog *>(
397 this->find_socket_value_log(query_socket)))
398 {
399 T value;
400 if (this->try_convert_primitive_socket_value(*value_log, CPPType::get<T>(), &value)) {
401 return value;
402 }
403 }
404 return std::nullopt;
405 }
406};
407
409 private:
411
412 public:
414
419 GeoTreeLog *get_main_tree_log(const bNode &node) const;
420 GeoTreeLog *get_main_tree_log(const bNodeSocket &socket) const;
421
425 void foreach_tree_log(FunctionRef<void(GeoTreeLog &)> callback) const;
426};
427
434 private:
436 struct LocalData {
438 LinearAllocator<> allocator;
444 };
445
452
453 public:
456
460 GeoTreeLogger &get_local_tree_logger(const ComputeContext &compute_context);
461
465 GeoTreeLog &get_tree_log(const ComputeContextHash &compute_context_hash);
466
472 bke::ComputeContextCache &compute_context_cache);
473
475 static const ViewerNodeLog *find_viewer_node_log_for_path(const ViewerPath &viewer_path);
476};
477
478} // namespace blender::nodes::geo_eval_log
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
#define ENUM_OPERATORS(_type, _max)
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
void log_viewer_node(const bNode &viewer_node, bke::GeometrySet geometry)
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
#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
Defines a socket type.
Definition BKE_node.hh:152
NodeWarning(NodeWarningType type, StringRef message)
StringLog(StringRef string, LinearAllocator<> &allocator)