Blender V4.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
9#pragma once
10
15
16#include "BLI_string.h"
17#include "BLI_utildefines.h"
18
19#include "BKE_object.hh"
20
21#include "DNA_object_types.h"
22
23struct ID;
24struct bPoseChannel;
25
26namespace blender::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 const char *name;
39
42 OperationIDKey(OperationCode opcode, const char *name, int name_tag);
43
44 string identifier() const;
45 bool operator==(const OperationIDKey &other) const;
46 uint64_t hash() const;
47 };
48
49 /* Typedef for container of operations */
52
54 void init(const ID *id, const char *subdata) override;
55
56 virtual string identifier() const override;
57
58 /* Find an existing operation, if requested operation does not exist nullptr will be returned.
59 * See #add_operation for the meaning and examples of #name and #name_tag.
60 */
63 const char *name = "",
64 int name_tag = -1) const;
65
66 /* Find an existing operation, will throw an assert() if it does not exist.
67 * See #add_operation for the meaning and examples of #name and #name_tag. */
70 const char *name = "",
71 int name_tag = -1) const;
72
73 /* Check operation exists and return it. */
74 bool has_operation(OperationIDKey key) const;
75 bool has_operation(OperationCode opcode, const char *name = "", int name_tag = -1) const;
76
94 OperationCode opcode,
95 const char *name = "",
96 int name_tag = -1);
97
98 /* Entry/exit operations management.
99 *
100 * Use those instead of direct set since this will perform sanity checks. */
101 void set_entry_operation(OperationNode *op_node);
102 void set_exit_operation(OperationNode *op_node);
103
104 void clear_operations();
105
106 virtual void tag_update(Depsgraph *graph, eUpdateSource source) override;
107
108 virtual OperationNode *get_entry_operation() override;
109 virtual OperationNode *get_exit_operation() override;
110
111 void finalize_build(Depsgraph *graph);
112
114
115 /* ** Inner nodes for this component ** */
116
117 /* Operations stored as a hash map, for faster build.
118 * This hash map will be freed when graph is fully built. */
120
121 /* This is a "normal" list of operations, used by evaluation
122 * and other routines after construction. */
124
127
128 virtual bool depends_on_cow()
129 {
130 return true;
131 }
132
133 /* Denotes whether copy-on-eval component is to be tagged when this component
134 * is tagged for update. */
135 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/)
136 {
137 return true;
138 }
139
140 /* The component has (possibly indirect) effect on a data-block whose node has
141 * is_visible_on_build set to true.
142 *
143 * This field is ensured to be up-to-date prior to `IDNode::finalize_build()`. */
145
146 /* Denotes whether this component actually affects (possibly indirectly) on a directly visible
147 * object. Includes possibly run-time visibility update of ID nodes.
148 *
149 * NOTE: Is only reliable after `deg_graph_flush_visibility()`. */
151};
152
153/* ---------------------------------------- */
154
155#define DEG_COMPONENT_NODE_DEFINE_TYPEINFO(NodeType, type_, type_name_, id_recalc_tag) \
156 const Node::TypeInfo NodeType::typeinfo = Node::TypeInfo(type_, type_name_, id_recalc_tag)
157
158#define DEG_COMPONENT_NODE_DECLARE DEG_DEPSNODE_DECLARE
159
160#define DEG_COMPONENT_NODE_DEFINE(name, NAME, id_recalc_tag) \
161 DEG_COMPONENT_NODE_DEFINE_TYPEINFO( \
162 name##ComponentNode, NodeType::NAME, #name " Component", id_recalc_tag); \
163 static DepsNodeFactoryImpl<name##ComponentNode> DNTI_##NAME
164
165#define DEG_COMPONENT_NODE_DECLARE_GENERIC(name) \
166 struct name##ComponentNode : public ComponentNode { \
167 DEG_COMPONENT_NODE_DECLARE; \
168 }
169
170#define DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(name) \
171 struct name##ComponentNode : public ComponentNode { \
172 DEG_COMPONENT_NODE_DECLARE; \
173 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/) \
174 { \
175 return false; \
176 } \
177 }
178
179#define DEG_COMPONENT_NODE_DECLARE_NO_COW(name) \
180 struct name##ComponentNode : public ComponentNode { \
181 DEG_COMPONENT_NODE_DECLARE; \
182 virtual bool depends_on_cow() \
183 { \
184 return false; \
185 } \
186 }
187
213DEG_COMPONENT_NODE_DECLARE_GENERIC(NTreeGeometryPreprocess);
214
215/* Bone Component */
218 void init(const ID *id, const char *subdata);
219
220 struct bPoseChannel *pchan; /* the bone that this component represents */
221
223};
224
225/* Eventually we would not tag parameters in all cases.
226 * Support for this each ID needs to be added on an individual basis. */
228 virtual bool need_tag_cow_before_update(const IDRecalcFlag /*tag*/) override
229 {
231 /* Disabled as this is not true for newly added objects, needs investigation. */
232 // BLI_assert(deg_eval_copy_is_expanded(owner->id_cow));
233 return false;
234 }
235 return true;
236 }
237
239};
240
241/* Audio component. */
243 virtual bool need_tag_cow_before_update(const IDRecalcFlag tag) override
244 {
245 /* Frame change doesn't require a copy of the scene, doing so can be a heavy operation
246 * especially when the collection contains many objects, see #104798. */
247 return (tag != ID_RECALC_FRAME_CHANGE);
248 }
249
251};
252
254
255} // namespace blender::deg
General operations, lookup, etc. for blender objects.
IDRecalcFlag
Definition DNA_ID.h:1016
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1092
#define ID_TYPE_SUPPORTS_PARAMS_WITHOUT_COW(id_type)
Definition DNA_ID.h:698
Object is a sort of wrapper for general info.
void init()
#define DEG_COMPONENT_NODE_DECLARE_NO_COW_TAG_ON_UPDATE(name)
#define DEG_COMPONENT_NODE_DECLARE_GENERIC(name)
void deg_register_component_depsnodes()
function< void(::Depsgraph *)> DepsEvalOperationCb
unsigned __int64 uint64_t
Definition stdint.h:90
Definition DNA_ID.h:413
virtual bool need_tag_cow_before_update(const IDRecalcFlag tag) override
bool operator==(const OperationIDKey &other) const
virtual OperationNode * get_entry_operation() override
virtual bool need_tag_cow_before_update(const IDRecalcFlag)
OperationNode * get_operation(OperationIDKey key) const
virtual void tag_update(Depsgraph *graph, eUpdateSource source) override
Vector< OperationNode * > operations
OperationNode * find_operation(OperationIDKey key) const
virtual OperationNode * get_exit_operation() override
OperationNode * add_operation(const DepsEvalOperationCb &op, OperationCode opcode, const char *name="", int name_tag=-1)
bool has_operation(OperationIDKey key) const
void set_exit_operation(OperationNode *op_node)
void finalize_build(Depsgraph *graph)
virtual string identifier() const override
Map< ComponentNode::OperationIDKey, OperationNode * > * operations_map
void set_entry_operation(OperationNode *op_node)
virtual bool need_tag_cow_before_update(const IDRecalcFlag) override