Blender V4.3
depsgraph_build.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include "MEM_guardedalloc.h"
12
13#include "BLI_listbase.h"
14#include "BLI_utildefines.h"
15
16#include "BLI_time.h"
18
19#include "DNA_cachefile_types.h"
21#include "DNA_node_types.h"
22#include "DNA_object_types.h"
23#include "DNA_scene_types.h"
24
25#include "BKE_collection.hh"
26#include "BKE_main.hh"
27#include "BKE_scene.hh"
28
29#include "DEG_depsgraph.hh"
32
40
42
47
52
53/* ****************** */
54/* External Build API */
55
56namespace deg = blender::deg;
57
59{
60 switch (component) {
62 return deg::NodeType::PARAMETERS;
64 return deg::NodeType::ANIMATION;
66 return deg::NodeType::SEQUENCER;
67 }
68 return deg::NodeType::UNDEFINED;
69}
70
71static deg::DepsNodeHandle *get_node_handle(DepsNodeHandle *node_handle)
72{
73 return reinterpret_cast<deg::DepsNodeHandle *>(node_handle);
74}
75
76void DEG_add_scene_relation(DepsNodeHandle *node_handle,
77 Scene *scene,
79 const char *description)
80{
82 deg::ComponentKey comp_key(&scene->id, type);
83 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
84 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
85}
86
87void DEG_add_scene_camera_relation(DepsNodeHandle *node_handle,
88 Scene *scene,
90 const char *description)
91{
92 if (scene->camera != nullptr) {
93 DEG_add_object_relation(node_handle, scene->camera, component, description);
94 }
95
96 /* Like DepsgraphNodeBuilder::build_scene_camera(), we also need to account for other cameras
97 * referenced by markers. */
98 LISTBASE_FOREACH (TimeMarker *, marker, &scene->markers) {
99 if (!ELEM(marker->camera, nullptr, scene->camera)) {
100 DEG_add_object_relation(node_handle, marker->camera, component, description);
101 }
102 }
103}
104
105void DEG_add_object_relation(DepsNodeHandle *node_handle,
106 Object *object,
107 eDepsObjectComponentType component,
108 const char *description)
109{
111 deg::ComponentKey comp_key(&object->id, type);
112 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
113 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
114}
115
117{
118 return deg::geometry_tag_to_component(&object->id) == deg::NodeType::GEOMETRY;
119}
120
121void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle,
122 Collection *collection,
123 const char *description)
124{
125 deg::OperationKey operation_key{
126 &collection->id, deg::NodeType::GEOMETRY, deg::OperationCode::GEOMETRY_EVAL_DONE};
127 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
128 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
129}
130
131void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle,
132 Collection *collection,
133 const CustomData_MeshMasks *masks)
134{
136 DEG_add_customdata_mask(node_handle, ob, masks);
137 if (ob->type == OB_EMPTY && ob->instance_collection != nullptr) {
138 DEG_add_collection_geometry_customdata_mask(node_handle, ob->instance_collection, masks);
139 }
140 }
142}
143
144void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle,
146 const char *description)
147{
148 deg::OperationKey ntree_output_key(
149 &node_tree->id, deg::NodeType::NTREE_OUTPUT, deg::OperationCode::NTREE_OUTPUT);
150 deg::OperationKey ntree_preprocess_key(&node_tree->id,
151 deg::NodeType::NTREE_GEOMETRY_PREPROCESS,
152 deg::OperationCode::NTREE_GEOMETRY_PREPROCESS);
153 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
154 deg_node_handle->builder->add_node_handle_relation(
155 ntree_output_key, deg_node_handle, description);
156 deg_node_handle->builder->add_node_handle_relation(
157 ntree_preprocess_key, deg_node_handle, description, deg::RELATION_FLAG_NO_FLUSH);
158}
159
160void DEG_add_object_cache_relation(DepsNodeHandle *node_handle,
161 CacheFile *cache_file,
162 eDepsObjectComponentType component,
163 const char *description)
164{
166 deg::ComponentKey comp_key(&cache_file->id, type);
167 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
168 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
169}
170
171void DEG_add_bone_relation(DepsNodeHandle *node_handle,
172 Object *object,
173 const char *bone_name,
174 eDepsObjectComponentType component,
175 const char *description)
176{
178 deg::ComponentKey comp_key(&object->id, type, bone_name);
179 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
180 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
181}
182
183void DEG_add_object_pointcache_relation(DepsNodeHandle *node_handle,
184 Object *object,
185 eDepsObjectComponentType component,
186 const char *description)
187{
189 deg::ComponentKey comp_key(&object->id, type);
190 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
191 deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
192 /* Add relation from source to the node handle. */
193 relation_builder->add_node_handle_relation(comp_key, deg_node_handle, description);
194 /* Node deduct point cache component and connect source to it. */
195 ID *id = DEG_get_id_from_handle(node_handle);
196 deg::ComponentKey point_cache_key(id, deg::NodeType::POINT_CACHE);
197 deg::Relation *rel = relation_builder->add_relation(comp_key, point_cache_key, "Point Cache");
198 if (rel != nullptr) {
200 }
201 else {
202 fprintf(stderr, "Error in point cache relation from %s to ^%s.\n", object->id.name, id->name);
203 }
204}
205
206void DEG_add_generic_id_relation(DepsNodeHandle *node_handle, ID *id, const char *description)
207{
208 deg::OperationKey operation_key(
209 id, deg::NodeType::GENERIC_DATABLOCK, deg::OperationCode::GENERIC_DATABLOCK_UPDATE);
210 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
211 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
212}
213
214void DEG_add_depends_on_transform_relation(DepsNodeHandle *node_handle, const char *description)
215{
216 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
217 deg_node_handle->builder->add_depends_on_transform_relation(deg_node_handle, description);
218}
219
220void DEG_add_special_eval_flag(DepsNodeHandle *node_handle, ID *id, uint32_t flag)
221{
222 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
223 deg_node_handle->builder->add_special_eval_flag(id, flag);
224}
225
226void DEG_add_customdata_mask(DepsNodeHandle *node_handle,
227 Object *object,
228 const CustomData_MeshMasks *masks)
229{
230 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
231 deg_node_handle->builder->add_customdata_mask(object, deg::DEGCustomDataMeshMasks(masks));
232}
233
234ID *DEG_get_id_from_handle(DepsNodeHandle *node_handle)
235{
236 deg::DepsNodeHandle *deg_handle = get_node_handle(node_handle);
237 return deg_handle->node->owner->owner->id_orig;
238}
239
240Depsgraph *DEG_get_graph_from_handle(DepsNodeHandle *node_handle)
241{
242 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
243 deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
244 return reinterpret_cast<Depsgraph *>(relation_builder->getGraph());
245}
246
247/* ******************** */
248/* Graph Building API's */
249
251{
252 deg::ViewLayerBuilderPipeline builder(graph);
253 builder.build();
254}
255
257{
258 deg::AllObjectsBuilderPipeline builder(graph);
259 builder.build();
260}
261
263{
264 deg::RenderBuilderPipeline builder(graph);
265 builder.build();
266}
267
268void DEG_graph_build_for_compositor_preview(Depsgraph *graph, bNodeTree *nodetree)
269{
270 deg::CompositorBuilderPipeline builder(graph, nodetree);
271 builder.build();
272}
273
275{
276 deg::FromIDsBuilderPipeline builder(graph, ids);
277 builder.build();
278}
279
280void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
281{
282 deg::FromCollectionBuilderPipeline builder(graph, collection);
283 builder.build();
284}
285
286void DEG_graph_tag_relations_update(Depsgraph *graph)
287{
288 DEG_DEBUG_PRINTF(graph, TAG, "%s: Tagging relations for update.\n", __func__);
289 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
290 deg_graph->need_update_relations = true;
291
292 /* NOTE: When relations are updated, it's quite possible that we've got new bases in the scene.
293 * This means, we need to re-create flat array of bases in view layer. */
294 /* TODO(sergey): It is expected that bases manipulation tags scene for update to tag bases array
295 * for re-creation. Once it is ensured to happen from all places this implicit tag can be
296 * removed. */
297 deg::IDNode *id_node = deg_graph->find_id_node(&deg_graph->scene->id);
298 if (id_node != nullptr) {
299 graph_id_tag_update(deg_graph->bmain,
300 deg_graph,
301 &deg_graph->scene->id,
304 }
305}
306
307void DEG_graph_relations_update(Depsgraph *graph)
308{
309 deg::Depsgraph *deg_graph = (deg::Depsgraph *)graph;
310 if (!deg_graph->need_update_relations) {
311 /* Graph is up to date, nothing to do. */
312 return;
313 }
315}
316
318{
319 DEG_GLOBAL_DEBUG_PRINTF(TAG, "%s: Tagging relations for update.\n", __func__);
321 DEG_graph_tag_relations_update(reinterpret_cast<Depsgraph *>(depsgraph));
322 }
323}
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
#define LISTBASE_FOREACH(type, var, list)
Platform independent time functions.
Utility defines for timing/benchmarks.
#define ELEM(...)
eDepsSceneComponentType
@ DEG_SCENE_COMP_ANIMATION
@ DEG_SCENE_COMP_PARAMETERS
@ DEG_SCENE_COMP_SEQUENCER
eDepsObjectComponentType
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1125
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1071
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
@ OB_EMPTY
Read Guarded memory(de)allocation.
Relation * add_depends_on_transform_relation(ID *id, const KeyTo &key_to, const char *description, int flags=0)
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)
Depsgraph * graph
#define DEG_GLOBAL_DEBUG_PRINTF(type,...)
Definition deg_debug.h:53
#define DEG_DEBUG_PRINTF(depsgraph, type,...)
Definition deg_debug.h:45
const IDNode * id_node
const Depsgraph * depsgraph
void DEG_add_scene_camera_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsObjectComponentType component, const char *description)
void DEG_add_generic_id_relation(DepsNodeHandle *node_handle, ID *id, const char *description)
ID * DEG_get_id_from_handle(DepsNodeHandle *node_handle)
void DEG_relations_tag_update(Main *bmain)
void DEG_add_customdata_mask(DepsNodeHandle *node_handle, Object *object, const CustomData_MeshMasks *masks)
void DEG_graph_build_for_compositor_preview(Depsgraph *graph, bNodeTree *nodetree)
void DEG_add_special_eval_flag(DepsNodeHandle *node_handle, ID *id, uint32_t flag)
static deg::DepsNodeHandle * get_node_handle(DepsNodeHandle *node_handle)
void DEG_add_depends_on_transform_relation(DepsNodeHandle *node_handle, const char *description)
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
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_build_from_ids(Depsgraph *graph, blender::Span< ID * > ids)
void DEG_graph_tag_relations_update(Depsgraph *graph)
void DEG_add_scene_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsSceneComponentType component, const char *description)
void DEG_add_object_pointcache_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
bool DEG_object_has_geometry_component(Object *object)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
void DEG_graph_build_for_all_objects(Depsgraph *graph)
void DEG_add_bone_relation(DepsNodeHandle *node_handle, Object *object, const char *bone_name, eDepsObjectComponentType component, const char *description)
void DEG_graph_build_for_render_pipeline(Depsgraph *graph)
Depsgraph * DEG_get_graph_from_handle(DepsNodeHandle *node_handle)
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)
static deg::NodeType deg_build_scene_component_type(eDepsSceneComponentType component)
Span< Depsgraph * > get_all_registered_graphs(Main *bmain)
NodeType geometry_tag_to_component(const ID *id)
NodeType nodeTypeFromObjectComponent(eDepsObjectComponentType component_type)
Definition deg_node.cc:178
unsigned int uint32_t
Definition stdint.h:80
Definition DNA_ID.h:413
DepsgraphRelationBuilder * builder
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:105
uint8_t flag
Definition wm_window.cc:138