Blender  V3.3
depsgraph_build.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
10 #include "MEM_guardedalloc.h"
11 
12 #include "BLI_listbase.h"
13 #include "BLI_utildefines.h"
14 
15 #include "PIL_time.h"
16 #include "PIL_time_utildefines.h"
17 
18 #include "DNA_cachefile_types.h"
19 #include "DNA_collection_types.h"
20 #include "DNA_node_types.h"
21 #include "DNA_object_types.h"
22 #include "DNA_scene_types.h"
23 #include "DNA_simulation_types.h"
24 
25 #include "BKE_collection.h"
26 #include "BKE_main.h"
27 #include "BKE_scene.h"
28 
29 #include "DEG_depsgraph.h"
30 #include "DEG_depsgraph_build.h"
31 #include "DEG_depsgraph_debug.h"
32 
39 
40 #include "intern/debug/deg_debug.h"
41 
42 #include "intern/node/deg_node.h"
46 
49 #include "intern/depsgraph_tag.h"
50 #include "intern/depsgraph_type.h"
51 
52 /* ****************** */
53 /* External Build API */
54 
55 namespace deg = blender::deg;
56 
58 {
59  switch (component) {
61  return deg::NodeType::PARAMETERS;
63  return deg::NodeType::ANIMATION;
65  return deg::NodeType::SEQUENCER;
66  }
68 }
69 
70 static deg::DepsNodeHandle *get_node_handle(DepsNodeHandle *node_handle)
71 {
72  return reinterpret_cast<deg::DepsNodeHandle *>(node_handle);
73 }
74 
75 void DEG_add_scene_relation(DepsNodeHandle *node_handle,
76  Scene *scene,
78  const char *description)
79 {
81  deg::ComponentKey comp_key(&scene->id, type);
82  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
83  deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
84 }
85 
86 void DEG_add_object_relation(DepsNodeHandle *node_handle,
87  Object *object,
89  const char *description)
90 {
92  deg::ComponentKey comp_key(&object->id, type);
93  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
94  deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
95 }
96 
98 {
100 }
101 
102 void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle,
103  Collection *collection,
104  const char *description)
105 {
106  deg::OperationKey operation_key{
107  &collection->id, deg::NodeType::GEOMETRY, deg::OperationCode::GEOMETRY_EVAL_DONE};
108  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
109  deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
110 }
111 
112 void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle,
113  Collection *collection,
114  const CustomData_MeshMasks *masks)
115 {
117  DEG_add_customdata_mask(node_handle, ob, masks);
118  if (ob->type == OB_EMPTY && ob->instance_collection != nullptr) {
119  DEG_add_collection_geometry_customdata_mask(node_handle, ob->instance_collection, masks);
120  }
121  }
123 }
124 
125 void DEG_add_simulation_relation(DepsNodeHandle *node_handle,
127  const char *description)
128 {
129  deg::OperationKey operation_key(
130  &simulation->id, deg::NodeType::SIMULATION, deg::OperationCode::SIMULATION_EVAL);
131  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
132  deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
133 }
134 
135 void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle,
137  const char *description)
138 {
139  deg::OperationKey ntree_output_key(
140  &node_tree->id, deg::NodeType::NTREE_OUTPUT, deg::OperationCode::NTREE_OUTPUT);
141  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
142  deg_node_handle->builder->add_node_handle_relation(
143  ntree_output_key, deg_node_handle, description);
144 }
145 
146 void DEG_add_object_cache_relation(DepsNodeHandle *node_handle,
147  CacheFile *cache_file,
149  const char *description)
150 {
152  deg::ComponentKey comp_key(&cache_file->id, type);
153  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
154  deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
155 }
156 
157 void DEG_add_bone_relation(DepsNodeHandle *node_handle,
158  Object *object,
159  const char *bone_name,
161  const char *description)
162 {
164  deg::ComponentKey comp_key(&object->id, type, bone_name);
165  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
166  deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
167 }
168 
169 void DEG_add_object_pointcache_relation(struct DepsNodeHandle *node_handle,
170  struct Object *object,
172  const char *description)
173 {
175  deg::ComponentKey comp_key(&object->id, type);
176  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
177  deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
178  /* Add relation from source to the node handle. */
179  relation_builder->add_node_handle_relation(comp_key, deg_node_handle, description);
180  /* Node deduct point cache component and connect source to it. */
181  ID *id = DEG_get_id_from_handle(node_handle);
182  deg::ComponentKey point_cache_key(id, deg::NodeType::POINT_CACHE);
183  deg::Relation *rel = relation_builder->add_relation(comp_key, point_cache_key, "Point Cache");
184  if (rel != nullptr) {
186  }
187  else {
188  fprintf(stderr, "Error in point cache relation from %s to ^%s.\n", object->id.name, id->name);
189  }
190 }
191 
192 void DEG_add_generic_id_relation(struct DepsNodeHandle *node_handle,
193  struct ID *id,
194  const char *description)
195 {
196  deg::OperationKey operation_key(
197  id, deg::NodeType::GENERIC_DATABLOCK, deg::OperationCode::GENERIC_DATABLOCK_UPDATE);
198  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
199  deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
200 }
201 
202 void DEG_add_modifier_to_transform_relation(struct DepsNodeHandle *node_handle,
203  const char *description)
204 {
205  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
206  deg_node_handle->builder->add_modifier_to_transform_relation(deg_node_handle, description);
207 }
208 
209 void DEG_add_special_eval_flag(struct DepsNodeHandle *node_handle, ID *id, uint32_t flag)
210 {
211  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
212  deg_node_handle->builder->add_special_eval_flag(id, flag);
213 }
214 
215 void DEG_add_customdata_mask(struct DepsNodeHandle *node_handle,
216  struct Object *object,
217  const CustomData_MeshMasks *masks)
218 {
219  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
220  deg_node_handle->builder->add_customdata_mask(object, deg::DEGCustomDataMeshMasks(masks));
221 }
222 
223 struct ID *DEG_get_id_from_handle(struct DepsNodeHandle *node_handle)
224 {
225  deg::DepsNodeHandle *deg_handle = get_node_handle(node_handle);
226  return deg_handle->node->owner->owner->id_orig;
227 }
228 
229 struct Depsgraph *DEG_get_graph_from_handle(struct DepsNodeHandle *node_handle)
230 {
231  deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
232  deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
233  return reinterpret_cast<Depsgraph *>(relation_builder->getGraph());
234 }
235 
236 /* ******************** */
237 /* Graph Building API's */
238 
240 {
242  builder.build();
243 }
244 
246 {
248  builder.build();
249 }
250 
252 {
254  builder.build();
255 }
256 
258 {
259  deg::CompositorBuilderPipeline builder(graph, nodetree);
260  builder.build();
261 }
262 
263 void DEG_graph_build_from_ids(Depsgraph *graph, ID **ids, const int num_ids)
264 {
265  deg::FromIDsBuilderPipeline builder(graph, blender::Span(ids, num_ids));
266  builder.build();
267 }
268 
270 {
271  DEG_DEBUG_PRINTF(graph, TAG, "%s: Tagging relations for update.\n", __func__);
272  deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
273  deg_graph->need_update_relations = true;
274  /* NOTE: When relations are updated, it's quite possible that
275  * we've got new bases in the scene. This means, we need to
276  * re-create flat array of bases in view layer.
277  *
278  * TODO(sergey): Try to make it so we don't flush updates
279  * to the whole depsgraph. */
280  deg::IDNode *id_node = deg_graph->find_id_node(&deg_graph->scene->id);
281  if (id_node != nullptr) {
282  id_node->tag_update(deg_graph, deg::DEG_UPDATE_SOURCE_RELATIONS);
283  }
284 }
285 
287 {
288  deg::Depsgraph *deg_graph = (deg::Depsgraph *)graph;
289  if (!deg_graph->need_update_relations) {
290  /* Graph is up to date, nothing to do. */
291  return;
292  }
294 }
295 
297 {
298  DEG_GLOBAL_DEBUG_PRINTF(TAG, "%s: Tagging relations for update.\n", __func__);
300  DEG_graph_tag_relations_update(reinterpret_cast<Depsgraph *>(depsgraph));
301  }
302 }
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
eDepsSceneComponentType
@ DEG_SCENE_COMP_ANIMATION
@ DEG_SCENE_COMP_PARAMETERS
@ DEG_SCENE_COMP_SEQUENCER
eDepsObjectComponentType
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
@ OB_EMPTY
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Platform independent time functions.
Utility defines for timing/benchmarks.
void add_customdata_mask(Object *object, const DEGCustomDataMeshMasks &customdata_masks)
Relation * add_node_handle_relation(const KeyType &key_from, const DepsNodeHandle *handle, const char *description, int flags=0)
void add_special_eval_flag(ID *id, uint32_t flag)
Relation * add_relation(const KeyFrom &key_from, const KeyTo &key_to, const char *description, int flags=0)
void add_modifier_to_transform_relation(const DepsNodeHandle *handle, const char *description)
Depsgraph * graph
#define DEG_GLOBAL_DEBUG_PRINTF(type,...)
Definition: deg_debug.h:59
#define DEG_DEBUG_PRINTF(depsgraph, type,...)
Definition: deg_debug.h:51
const IDNode * id_node
Scene scene
Simulation simulation
const Depsgraph * depsgraph
static deg::DepsNodeHandle * get_node_handle(DepsNodeHandle *node_handle)
void DEG_relations_tag_update(Main *bmain)
void DEG_graph_build_for_compositor_preview(Depsgraph *graph, bNodeTree *nodetree)
void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle, Collection *collection, const char *description)
void DEG_add_object_cache_relation(DepsNodeHandle *node_handle, CacheFile *cache_file, eDepsObjectComponentType component, const char *description)
void DEG_graph_tag_relations_update(Depsgraph *graph)
void DEG_add_modifier_to_transform_relation(struct DepsNodeHandle *node_handle, const char *description)
void DEG_add_generic_id_relation(struct DepsNodeHandle *node_handle, struct ID *id, const char *description)
void DEG_add_scene_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsSceneComponentType component, const char *description)
void DEG_add_customdata_mask(struct DepsNodeHandle *node_handle, struct Object *object, const CustomData_MeshMasks *masks)
void DEG_add_special_eval_flag(struct DepsNodeHandle *node_handle, ID *id, uint32_t flag)
bool DEG_object_has_geometry_component(Object *object)
void DEG_graph_build_from_ids(Depsgraph *graph, ID **ids, const int num_ids)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
struct ID * DEG_get_id_from_handle(struct DepsNodeHandle *node_handle)
void DEG_add_bone_relation(DepsNodeHandle *node_handle, Object *object, const char *bone_name, eDepsObjectComponentType component, const char *description)
void DEG_graph_build_for_all_objects(struct Depsgraph *graph)
void DEG_graph_build_for_render_pipeline(Depsgraph *graph)
void DEG_add_object_pointcache_relation(struct DepsNodeHandle *node_handle, struct Object *object, eDepsObjectComponentType component, const char *description)
void DEG_graph_relations_update(Depsgraph *graph)
void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle, Collection *collection, const CustomData_MeshMasks *masks)
void DEG_graph_build_from_view_layer(Depsgraph *graph)
void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle, bNodeTree *node_tree, const char *description)
struct Depsgraph * DEG_get_graph_from_handle(struct DepsNodeHandle *node_handle)
static deg::NodeType deg_build_scene_component_type(eDepsSceneComponentType component)
void DEG_add_simulation_relation(DepsNodeHandle *node_handle, Simulation *simulation, const char *description)
Span< Depsgraph * > get_all_registered_graphs(Main *bmain)
NodeType geometry_tag_to_component(const ID *id)
@ RELATION_FLAG_FLUSH_USER_EDIT_ONLY
NodeType nodeTypeFromObjectComponent(eDepsObjectComponentType component_type)
Definition: deg_node.cc:171
@ DEG_UPDATE_SOURCE_RELATIONS
unsigned int uint32_t
Definition: stdint.h:80
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378
Definition: BKE_main.h:121
DepsgraphRelationBuilder * builder
IDNode * find_id_node(const ID *id) const
Definition: depsgraph.cc:101