Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NOD_geometry_nodes_log.hh « nodes « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 297702bd0b236150cb3bd4c4c24f6d54db9f60ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

#include <chrono>

#include "BLI_compute_context.hh"
#include "BLI_enumerable_thread_specific.hh"
#include "BLI_generic_pointer.hh"
#include "BLI_multi_value_map.hh"

#include "BKE_attribute.h"
#include "BKE_geometry_set.hh"

#include "FN_field.hh"

#include "DNA_node_types.h"

struct SpaceNode;
struct SpaceSpreadsheet;
struct NodesModifierData;

namespace blender::nodes::geo_eval_log {

using fn::GField;

enum class NodeWarningType {
  Error,
  Warning,
  Info,
};

struct NodeWarning {
  NodeWarningType type;
  std::string message;
};

enum class NamedAttributeUsage {
  None = 0,
  Read = 1 << 0,
  Write = 1 << 1,
  Remove = 1 << 2,
};
ENUM_OPERATORS(NamedAttributeUsage, NamedAttributeUsage::Remove);

class ValueLog {
 public:
  virtual ~ValueLog() = default;
};

class GenericValueLog : public ValueLog {
 public:
  GMutablePointer value;

  GenericValueLog(const GMutablePointer value) : value(value)
  {
  }

  ~GenericValueLog()
  {
    this->value.destruct();
  }
};

class FieldInfoLog : public ValueLog {
 public:
  const CPPType &type;
  Vector<std::string> input_tooltips;

  FieldInfoLog(const GField &field);
};

struct GeometryAttributeInfo {
  std::string name;
  /** Can be empty when #name does not actually exist on a geometry yet. */
  std::optional<eAttrDomain> domain;
  std::optional<eCustomDataType> data_type;
};

class GeometryInfoLog : public ValueLog {
 public:
  Vector<GeometryAttributeInfo> attributes;
  Vector<GeometryComponentType> component_types;

  struct MeshInfo {
    int verts_num, edges_num, faces_num;
  };
  struct CurveInfo {
    int splines_num;
  };
  struct PointCloudInfo {
    int points_num;
  };
  struct InstancesInfo {
    int instances_num;
  };
  struct EditDataInfo {
    bool has_deformed_positions;
    bool has_deform_matrices;
  };

  std::optional<MeshInfo> mesh_info;
  std::optional<CurveInfo> curve_info;
  std::optional<PointCloudInfo> pointcloud_info;
  std::optional<InstancesInfo> instances_info;
  std::optional<EditDataInfo> edit_data_info;

  GeometryInfoLog(const GeometrySet &geometry_set);
};

class ViewerNodeLog {
 public:
  GeometrySet geometry;
  GField field;
};

using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;

class GeoTreeLogger {
 public:
  std::optional<ComputeContextHash> parent_hash;
  std::optional<std::string> group_node_name;
  Vector<ComputeContextHash> children_hashes;

  LinearAllocator<> *allocator = nullptr;
  Vector<std::pair<std::string, NodeWarning>> node_warnings;
  Vector<destruct_ptr<ValueLog>> socket_values_owner;
  Vector<std::tuple<std::string, std::string, ValueLog *>> input_socket_values;
  Vector<std::tuple<std::string, std::string, ValueLog *>> output_socket_values;
  Vector<std::tuple<std::string, TimePoint, TimePoint>> node_execution_times;
  Vector<std::tuple<std::string, destruct_ptr<ViewerNodeLog>>, 0> viewer_node_logs_;
  Vector<std::tuple<std::string, std::string, NamedAttributeUsage>, 0> used_named_attributes_;

  GeoTreeLogger();
  ~GeoTreeLogger();
  void log_value(const bNode &node, const bNodeSocket &socket, GPointer value);
  void log_viewer_node(const bNode &viewer_node, const GeometrySet &geometry, const GField &field);
};

class GeoNodeLog {
 public:
  Vector<NodeWarning> warnings;
  std::chrono::nanoseconds run_time{0};
  Map<std::string, ValueLog *> input_values_;
  Map<std::string, ValueLog *> output_values_;
  Map<std::string, NamedAttributeUsage> used_named_attributes;

  GeoNodeLog();
  ~GeoNodeLog();
};

class GeoModifierLog;

class GeoTreeLog {
 private:
  GeoModifierLog *modifier_log_;
  Vector<GeoTreeLogger *> tree_loggers_;
  bool reduced_node_warnings_ = false;
  bool reduced_node_run_times_ = false;
  bool reduced_socket_values_ = false;
  bool reduced_viewer_node_logs_ = false;
  bool reduced_existing_attributes_ = false;
  bool reduced_used_named_attributes_ = false;

 public:
  Map<std::string, GeoNodeLog> nodes;
  Map<std::string, ViewerNodeLog *, 0> viewer_node_logs;
  Vector<NodeWarning> all_warnings;
  std::chrono::nanoseconds run_time_sum{0};
  Vector<const GeometryAttributeInfo *> existing_attributes;
  Map<std::string, NamedAttributeUsage> used_named_attributes;

  GeoTreeLog(GeoModifierLog *modifier_log, Vector<GeoTreeLogger *> tree_loggers);
  ~GeoTreeLog();

  void ensure_node_warnings();
  void ensure_node_run_time();
  void ensure_socket_values();
  void ensure_viewer_node_logs();
  void ensure_existing_attributes();
  void ensure_used_named_attributes();

  ValueLog *find_socket_value_log(const bNodeSocket &query_socket);
};

class GeoModifierLog {
 private:
  struct LocalData {
    LinearAllocator<> allocator;
    Map<ComputeContextHash, destruct_ptr<GeoTreeLogger>> tree_logger_by_context;
  };

  threading::EnumerableThreadSpecific<LocalData> data_per_thread_;
  Map<ComputeContextHash, std::unique_ptr<GeoTreeLog>> tree_logs_;

 public:
  GeoTreeLogger &get_local_tree_logger(const ComputeContext &compute_context);
  GeoTreeLog &get_tree_log(const ComputeContextHash &compute_context_hash);

  struct ObjectAndModifier {
    const Object *object;
    const NodesModifierData *nmd;
  };

  static std::optional<ObjectAndModifier> get_modifier_for_node_editor(const SpaceNode &snode);
  static GeoTreeLog *get_tree_log_for_node_editor(const SpaceNode &snode);
  static const ViewerNodeLog *find_viewer_node_log_for_spreadsheet(
      const SpaceSpreadsheet &sspreadsheet);
};

}  // namespace blender::nodes::geo_eval_log