Blender V5.3
deg_node_component.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_span.hh"
12#include "BLI_string_ref.hh"
17
18#include "BLI_map.hh"
19#include "BLI_vector.hh"
20
21namespace blender {
22
23struct ID;
24struct bPoseChannel;
25
26namespace deg {
27
28struct Depsgraph;
29struct IDNode;
30struct OperationNode;
31
32/* ID Component - Base type for all components */
33struct ComponentNode : public Node {
34 /* Key used to look up operations within a component */
37 int name_tag = -1;
39
40 OperationIDKey() = default;
46
47 std::string identifier() const;
48 friend bool operator==(const OperationIDKey &a, const OperationIDKey &b) = default;
49 uint64_t hash() const
50 {
52 }
53 };
54
55 /* Typedef for container of operations */
57 ~ComponentNode() override;
58
60 void init(const ID *id, const char *subdata) override;
61
62 std::string identifier() const override;
63
64 /* Find an existing operation, if requested operation does not exist nullptr will be returned.
65 * See #add_operation for the meaning and examples of #name and #name_tag.
66 */
67 OperationNode *find_operation(OperationIDKey key) const;
69 StringRef name = "",
70 int name_tag = -1) const;
71
72 /* Find an existing operation, will throw an assert() if it does not exist.
73 * See #add_operation for the meaning and examples of #name and #name_tag. */
74 OperationNode *get_operation(OperationIDKey key) const;
75 OperationNode *get_operation(OperationCode opcode, StringRef name = "", int name_tag = -1) const;
76
77 /* Check operation exists and return it. */
78 bool has_operation(OperationIDKey key) const;
79 bool has_operation(OperationCode opcode, StringRef name = "", int name_tag = -1) const;
80
98 OperationCode opcode,
99 const StringRef name = "",
100 int name_tag = -1);
101
102 /* Entry/exit operations management.
103 *
104 * Use those instead of direct set since this will perform sanity checks. */
105 void set_entry_operation(OperationNode *op_node);
106 void set_exit_operation(OperationNode *op_node);
107
108 void clear_operations();
109
110 void tag_update(Depsgraph *graph, eUpdateSource source) override;
111
114
115 void finalize_build(Depsgraph *graph);
116
118
119 /* ** Inner nodes for this component ** */
120
121 /* Operations stored as a hash map, for faster build.
122 * This hash map will be freed when graph is fully built. */
124
125 /* This is a "normal" list of operations, used by evaluation
126 * and other routines after construction. */
128
131
132 virtual bool depends_on_cow()
133 {
134 return true;
135 }
136
137 /* Denotes whether copy-on-eval component is to be tagged when this component
138 * is tagged for update. */
139 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/)
140 {
141 return true;
142 }
143
144 /* The component has (possibly indirect) effect on a data-block whose node has
145 * is_visible_on_build set to true.
146 *
147 * This field is ensured to be up-to-date prior to `IDNode::finalize_build()`. */
149
150 /* Denotes whether this component actually affects (possibly indirectly) on a directly visible
151 * object. Includes possibly run-time visibility update of ID nodes.
152 *
153 * NOTE: Is only reliable after `deg_graph_flush_visibility()`. */
155
156 /* Accumulated flag from operations. Is initialized and used during updates flush. */
158};
159
160/* ---------------------------------------- */
161
162#define DEG_COMPONENT_NODE_DEFINE_TYPEINFO(NodeType, type_, type_name_, id_recalc_tag) \
163 const Node::TypeInfo NodeType::typeinfo = Node::TypeInfo(type_, type_name_, id_recalc_tag)
164
165#define DEG_COMPONENT_NODE_DECLARE DEG_DEPSNODE_DECLARE
166
167#define DEG_COMPONENT_NODE_DEFINE(name, NAME, id_recalc_tag) \
168 DEG_COMPONENT_NODE_DEFINE_TYPEINFO( \
169 name##ComponentNode, NodeType::NAME, #name " Component", id_recalc_tag); \
170 static DepsNodeFactoryImpl<name##ComponentNode> DNTI_##NAME
171
172#define DEG_COMPONENT_NODE_DECLARE_GENERIC(name) \
173 struct name##ComponentNode : public ComponentNode { \
174 DEG_COMPONENT_NODE_DECLARE; \
175 }
176
177#define DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(name) \
178 struct name##ComponentNode : public ComponentNode { \
179 DEG_COMPONENT_NODE_DECLARE; \
180 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/) \
181 { \
182 return false; \
183 } \
184 }
185
186#define DEG_COMPONENT_NODE_DECLARE_NO_COW(name) \
187 struct name##ComponentNode : public ComponentNode { \
188 DEG_COMPONENT_NODE_DECLARE; \
189 virtual bool depends_on_cow() \
190 { \
191 return false; \
192 } \
193 }
194
221DEG_COMPONENT_NODE_DECLARE_GENERIC(NTreeGeometryPreprocess);
222
223/* Bone Component */
226 void init(const ID *id, const char *subdata) override;
227
228 struct bPoseChannel *pchan; /* the bone that this component represents */
229
231};
232
233/* Eventually we would not tag parameters in all cases.
234 * Support for this each ID needs to be added on an individual basis. */
236 bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/) override
237 {
239 /* Disabled as this is not true for newly added objects, needs investigation. */
240 // BLI_assert(deg_eval_copy_is_expanded(owner->id_cow));
241 return false;
242 }
243 return true;
244 }
245
247};
248
249/* Audio component. */
252 {
253 /* Frame change doesn't require a copy of the scene, doing so can be a heavy operation
254 * especially when the collection contains many objects, see #104798. */
255 return (tag != ID_RECALC_FRAME_CHANGE);
256 }
257
259};
260
262
263} // namespace deg
264} // namespace blender
#define ID_TYPE_SUPPORTS_PARAMS_WITHOUT_COW(id_type)
Definition DNA_ID.h:751
DEG_COMPONENT_NODE_DECLARE_GENERIC(Animation)
void deg_register_component_depsnodes()
DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(BatchCache)
std::function< void(blender::Depsgraph *)> DepsEvalOperationCb
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
IDRecalcFlag
Definition DNA_ID.h:1049
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
bool need_tag_cow_before_update(const IDRecalcFlag tag) override
void init(const ID *id, const char *subdata) override
friend bool operator==(const OperationIDKey &a, const OperationIDKey &b)=default
OperationIDKey(const OperationCode opcode, const StringRef name, const int name_tag)
OperationNode * get_entry_operation() override
virtual bool need_tag_cow_before_update(const IDRecalcFlag)
std::string identifier() const override
OperationNode * get_operation(OperationIDKey key) const
void tag_update(Depsgraph *graph, eUpdateSource source) override
Vector< OperationNode * > operations
OperationNode * find_operation(OperationIDKey key) const
OperationNode * add_operation(const DepsEvalOperationCb &op, OperationCode opcode, const StringRef name="", int name_tag=-1)
OperationNode * get_exit_operation() override
bool has_operation(OperationIDKey key) const
void set_exit_operation(OperationNode *op_node)
void finalize_build(Depsgraph *graph)
Map< ComponentNode::OperationIDKey, OperationNode * > * operations_map
void set_entry_operation(OperationNode *op_node)
std::string name
Definition deg_node.hh:186
bool need_tag_cow_before_update(const IDRecalcFlag) override