Blender V5.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
10
11#include "BLI_listbase.hh"
12#include "BLI_utildefines.hh"
13
14#include "DNA_cachefile_types.h"
15#include "DNA_camera_types.h"
17#include "DNA_layer_types.h"
18#include "DNA_node_types.h"
19#include "DNA_object_types.h"
20#include "DNA_scene_types.h"
21#include "DNA_vfont_types.h"
22
23#include "BKE_collection.hh"
24#include "BKE_global.hh"
25#include "BKE_main.hh"
26#include "BKE_scene.hh"
27
28#include "DEG_depsgraph.hh"
31
39
41
46
51
52namespace blender {
53
54/* ****************** */
55/* External Build API */
56
71
72static deg::DepsNodeHandle *get_node_handle(DepsNodeHandle *node_handle)
73{
74 return reinterpret_cast<deg::DepsNodeHandle *>(node_handle);
75}
76
77void DEG_add_scene_relation(DepsNodeHandle *node_handle,
78 Scene *scene,
80 const char *description)
81{
83 deg::ComponentKey comp_key(&scene->id, type);
84 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
85 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
86}
87
88static void add_camera_parameters_relation(DepsNodeHandle *node_handle,
90 const char *description)
91{
92 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
94 deg_node_handle->builder->add_node_handle_relation(parameters_key, deg_node_handle, description);
95}
96
97void DEG_add_scene_camera_relation(DepsNodeHandle *node_handle,
98 Scene *scene,
100 const char *description)
101{
102 if (scene->camera != nullptr) {
103 DEG_add_object_relation(node_handle, scene->camera, component, description);
104 if (scene->camera->type == OB_CAMERA) {
106 node_handle, reinterpret_cast<Camera *>(scene->camera->data), description);
107 }
108 }
109
110 /* Like DepsgraphNodeBuilder::build_scene_camera(), we also need to account for other cameras
111 * referenced by markers. */
112 for (TimeMarker &marker : scene->markers) {
113 if (!ELEM(marker.camera, nullptr, scene->camera)) {
114 DEG_add_object_relation(node_handle, marker.camera, component, description);
115 if (marker.camera->type == OB_CAMERA) {
117 node_handle, reinterpret_cast<Camera *>(marker.camera->data), description);
118 }
119 }
120 }
121}
122
123void DEG_add_object_relation(DepsNodeHandle *node_handle,
124 Object *object,
125 eDepsObjectComponentType component,
126 const char *description)
127{
129 deg::ComponentKey comp_key(&object->id, type);
130 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
131 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
132}
133
138
139void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle,
140 Collection *collection,
141 const char *description)
142{
143 deg::OperationKey operation_key{
145 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
146 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
147}
148
149void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle,
150 Collection *collection,
151 const CustomData_MeshMasks *masks)
152{
154 DEG_add_customdata_mask(node_handle, ob, masks);
155 if (ob->type == OB_EMPTY && ob->instance_collection != nullptr) {
156 DEG_add_collection_geometry_customdata_mask(node_handle, ob->instance_collection, masks);
157 }
158 }
160}
161
162void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle,
163 bNodeTree *node_tree,
164 const char *description)
165{
166 deg::OperationKey ntree_output_key(
168 deg::OperationKey ntree_preprocess_key(&node_tree->id,
171 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
172 deg_node_handle->builder->add_node_handle_relation(
173 ntree_output_key, deg_node_handle, description);
174 deg_node_handle->builder->add_node_handle_relation(
175 ntree_preprocess_key, deg_node_handle, description, deg::RELATION_FLAG_NO_FLUSH);
176}
177
178void DEG_add_object_cache_relation(DepsNodeHandle *node_handle,
179 CacheFile *cache_file,
180 eDepsObjectComponentType component,
181 const char *description)
182{
184 deg::ComponentKey comp_key(&cache_file->id, type);
185 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
186 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
187}
188
189void DEG_add_bone_relation(DepsNodeHandle *node_handle,
190 Object *object,
191 const char *bone_name,
192 eDepsObjectComponentType component,
193 const char *description)
194{
196 deg::ComponentKey comp_key(&object->id, type, bone_name);
197 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
198 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
199}
200
201void DEG_add_vfont_relation(DepsNodeHandle *handle, VFont *vfont, const char *description)
202{
203 deg::OperationKey operation_key(
205 deg::DepsNodeHandle *deg_node_handle = get_node_handle(handle);
206 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
207}
208
209void DEG_add_object_pointcache_relation(DepsNodeHandle *node_handle,
210 Object *object,
211 eDepsObjectComponentType component,
212 const char *description)
213{
215 deg::ComponentKey comp_key(&object->id, type);
216 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
217 deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
218 /* Add relation from source to the node handle. */
219 relation_builder->add_node_handle_relation(comp_key, deg_node_handle, description);
220 /* Node deduct point cache component and connect source to it. */
221 ID *id = DEG_get_id_from_handle(node_handle);
223 deg::Relation *rel = relation_builder->add_relation(comp_key, point_cache_key, "Point Cache");
224 if (rel != nullptr) {
226 }
227 else {
228 fprintf(stderr, "Error in point cache relation from %s to ^%s.\n", object->id.name, id->name);
229 }
230}
231
232void DEG_add_generic_id_relation(DepsNodeHandle *node_handle, ID *id, const char *description)
233{
234 deg::OperationKey operation_key(
236 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
237 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
238}
239
240void DEG_add_depends_on_transform_relation(DepsNodeHandle *node_handle, const char *description)
241{
242 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
243 deg_node_handle->builder->add_depends_on_transform_relation(deg_node_handle, description);
244}
245
246void DEG_add_time_source_relation(DepsNodeHandle *node_handle, const char *description)
247{
248 const deg::TimeSourceKey time_src_key;
249 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
250 deg_node_handle->builder->add_node_handle_relation(time_src_key, deg_node_handle, description);
251}
252
253void DEG_add_special_eval_flag(DepsNodeHandle *node_handle, ID *id, uint32_t flag)
254{
255 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
256 deg_node_handle->builder->add_special_eval_flag(id, flag);
257}
258
259void DEG_add_customdata_mask(DepsNodeHandle *node_handle,
260 Object *object,
261 const CustomData_MeshMasks *masks)
262{
263 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
264 deg_node_handle->builder->add_customdata_mask(object, deg::DEGCustomDataMeshMasks(masks));
265}
266
267ID *DEG_get_id_from_handle(DepsNodeHandle *node_handle)
268{
269 deg::DepsNodeHandle *deg_handle = get_node_handle(node_handle);
270 return deg_handle->node->owner->owner->id_orig;
271}
272
273Depsgraph *DEG_get_graph_from_handle(DepsNodeHandle *node_handle)
274{
275 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
276 deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
277 return reinterpret_cast<Depsgraph *>(relation_builder->getGraph());
278}
279
280/* ******************** */
281/* Graph Building API's */
282
284{
285 deg::ViewLayerBuilderPipeline builder(graph);
286 builder.build();
287}
288
290{
291 deg::AllObjectsBuilderPipeline builder(graph);
292 builder.build();
293}
294
296{
297 deg::RenderBuilderPipeline builder(graph);
298 builder.build();
299}
300
302{
303 deg::CompositorBuilderPipeline builder(graph);
304 builder.build();
305}
306
307void DEG_graph_build_from_ids(Depsgraph *graph, Span<ID *> ids)
308{
309 deg::FromIDsBuilderPipeline builder(graph, ids);
310 builder.build();
311}
312
313void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
314{
315 deg::FromCollectionBuilderPipeline builder(graph, collection);
316 builder.build();
317}
318
319void DEG_graph_tag_relations_update(Depsgraph *graph)
320{
321 DEG_DEBUG_PRINTF(graph, TAG, "%s: Tagging relations for update.\n", __func__);
322 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
323 deg_graph->need_update_relations = true;
324
325 /* NOTE: When relations are updated, it's quite possible that we've got new bases in the scene.
326 * This means, we need to re-create flat array of bases in view layer. */
327 /* TODO(sergey): It is expected that bases manipulation tags scene for update to tag bases array
328 * for re-creation. Once it is ensured to happen from all places this implicit tag can be
329 * removed. */
330 deg::IDNode *id_node = deg_graph->find_id_node(&deg_graph->scene->id);
331 if (id_node != nullptr) {
332 graph_id_tag_update(deg_graph->bmain,
333 deg_graph,
334 &deg_graph->scene->id,
337 }
338}
339
340void DEG_graph_relations_update(Depsgraph *graph)
341{
342 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
343 if (!deg_graph->need_update_relations) {
344 /* Graph is up to date, nothing to do. */
345 return;
346 }
348}
349
351{
352 DEG_GLOBAL_DEBUG_PRINTF(TAG, "%s: Tagging relations for update.\n", __func__);
353 for (deg::Depsgraph *depsgraph : deg::get_all_registered_graphs(bmain)) {
354 DEG_graph_tag_relations_update(reinterpret_cast<Depsgraph *>(depsgraph));
355 }
356}
357
358} // namespace blender
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define ELEM(...)
Relation * add_node_handle_relation(const KeyType &key_from, const DepsNodeHandle *handle, const char *description, int flags=0)
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)
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)
#define DEG_GLOBAL_DEBUG_PRINTF(type,...)
Definition deg_debug.h:55
#define DEG_DEBUG_PRINTF(depsgraph, type,...)
Definition deg_debug.h:47
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
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:179
BMesh Iterators.
void DEG_graph_tag_relations_update(Depsgraph *graph)
void DEG_graph_build_from_view_layer(Depsgraph *graph)
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
void DEG_add_generic_id_relation(DepsNodeHandle *node_handle, ID *id, const char *description)
Depsgraph * DEG_get_graph_from_handle(DepsNodeHandle *node_handle)
void DEG_add_special_eval_flag(DepsNodeHandle *handle, ID *id, uint32_t flag)
void DEG_add_object_pointcache_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
void DEG_add_bone_relation(DepsNodeHandle *handle, Object *object, const char *bone_name, eDepsObjectComponentType component, const char *description)
void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle, Collection *collection, const char *description)
void DEG_add_depends_on_transform_relation(DepsNodeHandle *node_handle, const char *description)
static deg::NodeType deg_build_scene_component_type(eDepsSceneComponentType component)
void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle, bNodeTree *node_tree, const char *description)
void DEG_graph_build_for_render_pipeline(Depsgraph *graph)
static void add_camera_parameters_relation(DepsNodeHandle *node_handle, Camera *camera, const char *description)
void DEG_add_object_cache_relation(DepsNodeHandle *handle, CacheFile *cache_file, eDepsObjectComponentType component, const char *description)
unsigned int uint32_t
Definition BKE_text.h:81
void DEG_add_time_source_relation(DepsNodeHandle *node_handle, const char *description)
void DEG_graph_build_from_ids(Depsgraph *graph, Span< ID * > ids)
void DEG_graph_build_for_all_objects(Depsgraph *graph)
void DEG_graph_build_for_compositor_preview(Depsgraph *graph)
static deg::DepsNodeHandle * get_node_handle(DepsNodeHandle *node_handle)
void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle, Collection *collection, const CustomData_MeshMasks *masks)
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1158
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
bool DEG_object_has_geometry_component(Object *object)
void DEG_graph_relations_update(Depsgraph *graph)
void DEG_relations_tag_update(Main *bmain)
void DEG_add_scene_camera_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsObjectComponentType component, const char *description)
ID * DEG_get_id_from_handle(DepsNodeHandle *node_handle)
void DEG_add_scene_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsSceneComponentType component, const char *description)
void DEG_add_vfont_relation(DepsNodeHandle *handle, VFont *vfont, const char *description)
void DEG_add_customdata_mask(DepsNodeHandle *handle, Object *object, const CustomData_MeshMasks *masks)
struct Object * camera
ListBaseT< TimeMarker > markers
struct Object * camera
DepsgraphRelationBuilder * builder
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:102