Blender V5.0
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"
18
19#include "BLI_map.hh"
20#include "BLI_vector.hh"
21
22struct ID;
23struct bPoseChannel;
24
25namespace blender::deg {
26
27struct Depsgraph;
28struct IDNode;
29struct OperationNode;
30
31/* ID Component - Base type for all components */
32struct ComponentNode : public Node {
33 /* Key used to look up operations within a component */
53
54 /* Typedef for container of operations */
56 ~ComponentNode() override;
57
59 void init(const ID *id, const char *subdata) override;
60
61 std::string identifier() const override;
62
63 /* Find an existing operation, if requested operation does not exist nullptr will be returned.
64 * See #add_operation for the meaning and examples of #name and #name_tag.
65 */
66 OperationNode *find_operation(OperationIDKey key) const;
68 StringRef name = "",
69 int name_tag = -1) const;
70
71 /* Find an existing operation, will throw an assert() if it does not exist.
72 * See #add_operation for the meaning and examples of #name and #name_tag. */
73 OperationNode *get_operation(OperationIDKey key) const;
74 OperationNode *get_operation(OperationCode opcode, StringRef name = "", int name_tag = -1) const;
75
76 /* Check operation exists and return it. */
77 bool has_operation(OperationIDKey key) const;
78 bool has_operation(OperationCode opcode, StringRef name = "", int name_tag = -1) const;
79
97 OperationCode opcode,
98 const StringRef name = "",
99 int name_tag = -1);
100
101 /* Entry/exit operations management.
102 *
103 * Use those instead of direct set since this will perform sanity checks. */
104 void set_entry_operation(OperationNode *op_node);
105 void set_exit_operation(OperationNode *op_node);
106
107 void clear_operations();
108
109 void tag_update(Depsgraph *graph, eUpdateSource source) override;
110
113
114 void finalize_build(Depsgraph *graph);
115
117
118 /* ** Inner nodes for this component ** */
119
120 /* Operations stored as a hash map, for faster build.
121 * This hash map will be freed when graph is fully built. */
123
124 /* This is a "normal" list of operations, used by evaluation
125 * and other routines after construction. */
127
130
131 virtual bool depends_on_cow()
132 {
133 return true;
134 }
135
136 /* Denotes whether copy-on-eval component is to be tagged when this component
137 * is tagged for update. */
138 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/)
139 {
140 return true;
141 }
142
143 /* The component has (possibly indirect) effect on a data-block whose node has
144 * is_visible_on_build set to true.
145 *
146 * This field is ensured to be up-to-date prior to `IDNode::finalize_build()`. */
148
149 /* Denotes whether this component actually affects (possibly indirectly) on a directly visible
150 * object. Includes possibly run-time visibility update of ID nodes.
151 *
152 * NOTE: Is only reliable after `deg_graph_flush_visibility()`. */
154};
155
156/* ---------------------------------------- */
157
158#define DEG_COMPONENT_NODE_DEFINE_TYPEINFO(NodeType, type_, type_name_, id_recalc_tag) \
159 const Node::TypeInfo NodeType::typeinfo = Node::TypeInfo(type_, type_name_, id_recalc_tag)
160
161#define DEG_COMPONENT_NODE_DECLARE DEG_DEPSNODE_DECLARE
162
163#define DEG_COMPONENT_NODE_DEFINE(name, NAME, id_recalc_tag) \
164 DEG_COMPONENT_NODE_DEFINE_TYPEINFO( \
165 name##ComponentNode, NodeType::NAME, #name " Component", id_recalc_tag); \
166 static DepsNodeFactoryImpl<name##ComponentNode> DNTI_##NAME
167
168#define DEG_COMPONENT_NODE_DECLARE_GENERIC(name) \
169 struct name##ComponentNode : public ComponentNode { \
170 DEG_COMPONENT_NODE_DECLARE; \
171 }
172
173#define DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(name) \
174 struct name##ComponentNode : public ComponentNode { \
175 DEG_COMPONENT_NODE_DECLARE; \
176 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/) \
177 { \
178 return false; \
179 } \
180 }
181
182#define DEG_COMPONENT_NODE_DECLARE_NO_COW(name) \
183 struct name##ComponentNode : public ComponentNode { \
184 DEG_COMPONENT_NODE_DECLARE; \
185 virtual bool depends_on_cow() \
186 { \
187 return false; \
188 } \
189 }
190
216DEG_COMPONENT_NODE_DECLARE_GENERIC(NTreeGeometryPreprocess);
217
218/* Bone Component */
221 void init(const ID *id, const char *subdata) override;
222
223 struct bPoseChannel *pchan; /* the bone that this component represents */
224
226};
227
228/* Eventually we would not tag parameters in all cases.
229 * Support for this each ID needs to be added on an individual basis. */
231 bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/) override
232 {
234 /* Disabled as this is not true for newly added objects, needs investigation. */
235 // BLI_assert(deg_eval_copy_is_expanded(owner->id_cow));
236 return false;
237 }
238 return true;
239 }
240
242};
243
244/* Audio component. */
247 {
248 /* Frame change doesn't require a copy of the scene, doing so can be a heavy operation
249 * especially when the collection contains many objects, see #104798. */
250 return (tag != ID_RECALC_FRAME_CHANGE);
251 }
252
254};
255
257
258} // namespace blender::deg
IDRecalcFlag
Definition DNA_ID.h:1049
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
#define ID_TYPE_SUPPORTS_PARAMS_WITHOUT_COW(id_type)
Definition DNA_ID.h:745
void init()
unsigned long long int uint64_t
#define DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(name)
#define DEG_COMPONENT_NODE_DECLARE_GENERIC(name)
void deg_register_component_depsnodes()
std::function< void(::Depsgraph *)> DepsEvalOperationCb
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233
const char * name
Definition DNA_ID.h:414
bool need_tag_cow_before_update(const IDRecalcFlag tag) override
OperationIDKey(const OperationCode opcode, const StringRef name, const int name_tag)
BLI_STRUCT_EQUALITY_OPERATORS_3(OperationIDKey, opcode, name_tag, name)
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)
bool need_tag_cow_before_update(const IDRecalcFlag) override