Blender V5.3
deg_builder_nodes.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
12
13#include <algorithm>
14#include <cstdio>
15#include <cstdlib>
16
17#include "MEM_guardedalloc.h"
18
19#include "BLI_listbase.hh"
20#include "BLI_span.hh"
21#include "BLI_utildefines.hh"
22
23#include "DNA_action_types.h"
24#include "DNA_anim_types.h"
25#include "DNA_armature_types.h"
26#include "DNA_cachefile_types.h"
27#include "DNA_camera_types.h"
30#include "DNA_curve_types.h"
31#include "DNA_curves_types.h"
32#include "DNA_key_types.h"
33#include "DNA_light_types.h"
35#include "DNA_linestyle_types.h"
36#include "DNA_mask_types.h"
37#include "DNA_material_types.h"
38#include "DNA_mesh_types.h"
39#include "DNA_movieclip_types.h"
40#include "DNA_node_types.h"
41#include "DNA_object_types.h"
42#include "DNA_particle_types.h"
43#include "DNA_rigidbody_types.h"
44#include "DNA_scene_types.h"
45#include "DNA_sequence_types.h"
46#include "DNA_sound_types.h"
47#include "DNA_speaker_types.h"
48#include "DNA_texture_types.h"
49#include "DNA_vfont_types.h"
50#include "DNA_world_types.h"
51
52#include "BKE_action.hh"
53#include "BKE_anim_data.hh"
54#include "BKE_animsys.hh"
55#include "BKE_armature.hh"
57#include "BKE_cachefile.hh"
58#include "BKE_collection.hh"
59#include "BKE_constraint.h"
60#include "BKE_curve.hh"
61#include "BKE_fcurve_driver.h"
62#include "BKE_grease_pencil.hh"
64#include "BKE_idprop.hh"
65#include "BKE_image.hh"
66#include "BKE_key.hh"
67#include "BKE_lattice.hh"
68#include "BKE_layer.hh"
69#include "BKE_lib_id.hh"
70#include "BKE_lib_query.hh"
71#include "BKE_light.h"
72#include "BKE_mask.hh"
73#include "BKE_material.hh"
74#include "BKE_mesh.hh"
75#include "BKE_modifier.hh"
76#include "BKE_movieclip.hh"
77#include "BKE_nla.hh"
78#include "BKE_node.hh"
79#include "BKE_node_runtime.hh"
80#include "BKE_object.hh"
81#include "BKE_particle.h"
82#include "BKE_pointcache.h"
83#include "BKE_rigidbody.h"
84#include "BKE_scene.hh"
85#include "BKE_shader_fx.hh"
86#include "BKE_sound.hh"
87#include "BKE_volume.hh"
88#include "BKE_world.h"
89
90#include "RNA_access.hh"
91#include "RNA_path.hh"
92#include "RNA_prototypes.hh"
93#include "RNA_types.hh"
94
95#include "DEG_depsgraph.hh"
97
98#include "SEQ_iterator.hh"
99#include "SEQ_sequencer.hh"
100
105#include "intern/depsgraph.hh"
115
116namespace blender::deg {
117
118/* ************ */
119/* Node Builder */
120
121/* **** General purpose functions **** */
122
133
135{
136 /* Cannot be in an IDInfo destructor, as these COW IDs do not belong to the IDInfo data. */
137 for (IDInfo &id_info : id_info_hash_.values()) {
138 if (id_info.id_cow != nullptr) {
139 deg_free_eval_copy_datablock(id_info.id_cow);
140 MEM_delete(id_info.id_cow);
141 }
142 }
143}
144
146{
147 BLI_assert(id->session_uid != MAIN_ID_SESSION_UID_UNSET);
148
149 const ID_Type id_type = id->id_type();
150 IDNode *id_node = nullptr;
151 ID *id_cow = nullptr;
152 IDComponentsMask previously_visible_components_mask = 0;
153 uint32_t previous_eval_flags = 0;
154 DEGCustomDataMeshMasks previous_customdata_masks;
155 IDInfo *id_info = id_info_hash_.lookup_ptr(id->session_uid);
156 if (id_info != nullptr) {
157 id_cow = id_info->id_cow;
158 previously_visible_components_mask = id_info->previously_visible_components_mask;
159 previous_eval_flags = id_info->previous_eval_flags;
160 previous_customdata_masks = id_info->previous_customdata_masks;
161 /* Tag ID info to not free the evaluated ID pointer. */
162 id_info->id_cow = nullptr;
163 }
164 id_node = graph_->add_id_node(id, id_cow);
165 id_node->previously_visible_components_mask = previously_visible_components_mask;
166 id_node->previous_eval_flags = previous_eval_flags;
167 id_node->previous_customdata_masks = previous_customdata_masks;
168
169 /* NOTE: Zero number of components indicates that ID node was just created. */
170 const bool is_newly_created = id_node->components.is_empty();
171
172 if (is_newly_created) {
173 if (deg_eval_copy_is_needed(id_type)) {
175 OperationNode *op_cow = comp_cow->add_operation(
176 [id_node](blender::Depsgraph *depsgraph) { deg_create_eval_copy(depsgraph, id_node); },
178 graph_->operations.append(op_cow);
179 }
180
181 ComponentNode *visibility_component = id_node->add_component(NodeType::VISIBILITY);
182 OperationNode *visibility_operation;
183
184 /* Optimization: currently only objects need a special visibility evaluation. For the rest ID
185 * types keep the node as a NO-OP so that relations can still be routed, but without penalty
186 * during the graph evaluation. */
187 if (id_type == ID_OB) {
188 visibility_operation = visibility_component->add_operation(
189 [id_node](blender::Depsgraph *depsgraph) {
190 deg_evaluate_object_node_visibility(depsgraph, id_node);
191 },
193 }
194 else {
195 visibility_operation = visibility_component->add_operation(nullptr,
197 }
198
199 /* Pin the node so that it and its relations are preserved by the unused nodes/relations
200 * deletion. This is mainly to make it easier to debug visibility. */
201 visibility_operation->flag |= (OperationFlag::DEPSOP_FLAG_PINNED |
203 graph_->operations.append(visibility_operation);
204 }
205 return id_node;
206}
207
209{
210 return graph_->find_id_node(id);
211}
212
217
219 NodeType comp_type,
220 const char *comp_name)
221{
222 IDNode *id_node = add_id_node(id);
223 ComponentNode *comp_node = id_node->add_component(comp_type, comp_name);
224 comp_node->owner = id_node;
225 return comp_node;
226}
227
229 const NodeType comp_type,
230 const char *comp_name)
231{
232 IDNode *id_node = find_id_node(id);
233 if (id_node == nullptr) {
234 return nullptr;
235 }
236 return id_node->find_component(comp_type, comp_name);
237}
238
240 OperationCode opcode,
241 const DepsEvalOperationCb &op,
242 const char *name,
243 int name_tag)
244{
245 OperationNode *op_node = comp_node->find_operation(opcode, name, name_tag);
246 if (op_node == nullptr) {
247 op_node = comp_node->add_operation(op, opcode, name, name_tag);
248 graph_->operations.append(op_node);
249 }
250 else {
251 fprintf(stderr,
252 "add_operation: Operation already exists - %s has %s at %p\n",
253 comp_node->identifier().c_str(),
254 op_node->identifier().c_str(),
255 op_node);
256 BLI_assert_msg(0, "Should not happen!");
257 }
258 return op_node;
259}
260
262 NodeType comp_type,
263 const char *comp_name,
264 OperationCode opcode,
265 const DepsEvalOperationCb &op,
266 const char *name,
267 int name_tag)
268{
269 ComponentNode *comp_node = add_component_node(id, comp_type, comp_name);
270 return add_operation_node(comp_node, opcode, op, name, name_tag);
271}
272
274 NodeType comp_type,
275 OperationCode opcode,
276 const DepsEvalOperationCb &op,
277 const char *name,
278 int name_tag)
279{
280 return add_operation_node(id, comp_type, "", opcode, op, name, name_tag);
281}
282
284 NodeType comp_type,
285 const char *comp_name,
286 OperationCode opcode,
287 const DepsEvalOperationCb &op,
288 const char *name,
289 int name_tag)
290{
291 OperationNode *operation = find_operation_node(id, comp_type, comp_name, opcode, name, name_tag);
292 if (operation != nullptr) {
293 return operation;
294 }
295 return add_operation_node(id, comp_type, comp_name, opcode, op, name, name_tag);
296}
297
299 NodeType comp_type,
300 OperationCode opcode,
301 const DepsEvalOperationCb &op,
302 const char *name,
303 int name_tag)
304{
305 OperationNode *operation = find_operation_node(id, comp_type, opcode, name, name_tag);
306 if (operation != nullptr) {
307 return operation;
308 }
309 return add_operation_node(id, comp_type, opcode, op, name, name_tag);
310}
311
313 NodeType comp_type,
314 const char *comp_name,
315 OperationCode opcode,
316 const char *name,
317 int name_tag)
318{
319 return find_operation_node(id, comp_type, comp_name, opcode, name, name_tag) != nullptr;
320}
321
323 const NodeType comp_type,
324 const OperationCode opcode)
325{
326 return find_operation_node(id, comp_type, opcode) != nullptr;
327}
328
330 NodeType comp_type,
331 const char *comp_name,
332 OperationCode opcode,
333 const char *name,
334 int name_tag)
335{
336 ComponentNode *comp_node = find_component_node(id, comp_type, comp_name);
337 if (comp_node == nullptr) {
338 return nullptr;
339 }
340 return comp_node->find_operation(opcode, name, name_tag);
341}
342
344 const ID *id, NodeType comp_type, OperationCode opcode, const char *name, int name_tag)
345{
346 return find_operation_node(id, comp_type, "", opcode, name, name_tag);
347}
348
354
356{
357 return graph_->get_cow_id(id_orig);
358}
359
361{
362 if (id_orig->tag & ID_TAG_COPIED_ON_EVAL) {
363 /* ID is already remapped to copy-on-evaluation. */
364 return id_orig;
365 }
366 IDNode *id_node = add_id_node(id_orig);
367 return id_node->id_cow;
368}
369
370/* **** Build functions for entity nodes **** */
371
373{
374 /* Store existing evaluated versions of datablock, so we can re-use
375 * them for new ID nodes. */
376 for (IDNode *id_node : graph_->id_nodes) {
377 /* It is possible that the ID does not need to have evaluated version in which case id_cow is
378 * the same as id_orig. Additionally, such ID might have been removed, which makes the check
379 * for whether id_cow is expanded to access freed memory. In order to deal with this we
380 * check whether an evaluated copy is needed based on a scalar value which does not lead to
381 * access of possibly deleted memory. */
382 IDInfo id_info{};
383 if (deg_eval_copy_is_needed(id_node->id_type) && id_node->id_orig != id_node->id_cow) {
384 if (deg_eval_copy_is_expanded(id_node->id_cow)) {
385 id_info.id_cow = id_node->id_cow;
386 }
387 else {
388 /* This ID has not been expanded yet. Don't reuse it like already expanded IDs. */
389 MEM_SAFE_DELETE(id_node->id_cow);
390 }
391 }
393 id_info.previous_eval_flags = id_node->eval_flags;
395 BLI_assert(!id_info_hash_.contains(id_node->id_orig_session_uid));
396 id_info_hash_.add_new(id_node->id_orig_session_uid, std::move(id_info));
397 id_node->id_cow = nullptr;
398 }
399
400 for (const OperationNode *op_node : graph_->entry_tags) {
401 saved_entry_tags_.append_as(op_node);
402 }
403
404 for (const OperationNode *op_node : graph_->operations) {
405 if (op_node->flag & DEPSOP_FLAG_NEEDS_UPDATE) {
406 needs_update_operations_.append_as(op_node);
407 }
408 }
409
410 /* Make sure graph has no nodes left from previous state. */
413 graph_->entry_tags.clear();
414}
415
416/* Utility callbacks for `BKE_library_foreach_ID_link`, used to detect when an evaluated ID is
417 * using ID pointers that are either:
418 * - evaluated ID pointers that do not exist anymore in current depsgraph.
419 * - Orig ID pointers that do have now an evaluated version in current depsgraph.
420 * In both cases, it means the evaluated ID user needs to be flushed, to ensure its pointers are
421 * properly remapped.
422 *
423 * NOTE: This is split in two, a static function and a public method of the node builder, to allow
424 * the code to access the builder's data more easily. */
425
427 ID *id_pointer)
428{
429 if (id_pointer->orig_id == nullptr) {
430 /* `id_cow_self` uses a non-cow ID, if that ID has an evaluated copy in current depsgraph its
431 * owner needs to be remapped, i.e. copy-on-eval-flushed. */
432 IDNode *id_node = find_id_node(id_pointer);
433 if (id_node != nullptr && id_node->id_cow != nullptr) {
435 graph_,
436 id_cow_self->orig_id,
440 }
441 }
442 else {
443 /* `id_cow_self` uses an evaluated ID, if that evaluated copy is removed from current depsgraph
444 * its owner needs to be remapped, i.e. copy-on-eval-flushed. */
445 /* NOTE: at that stage, old existing evaluated copies that are to be removed from current state
446 * of evaluated depsgraph are still valid pointers, they are freed later (typically during
447 * destruction of the builder itself). */
448 IDNode *id_node = find_id_node(id_pointer->orig_id);
449 if (id_node == nullptr) {
451 graph_,
452 id_cow_self->orig_id,
456 }
457 }
458 return IDWALK_RET_NOP;
459}
460
462{
463 ID *id = *cb_data->id_pointer;
464 if (id == nullptr) {
465 return IDWALK_RET_NOP;
466 }
467 if (!ID_TYPE_USE_COPY_ON_EVAL(id->id_type())) {
468 /* No need to go further if the id never had an evaluated copy in the depsgraph. This function
469 * is only concerned with keeping the mapping between original and evaluated IDs intact. */
470 return IDWALK_RET_NOP;
471 }
472
473 DepsgraphNodeBuilder *builder = static_cast<DepsgraphNodeBuilder *>(cb_data->user_data);
474 ID *id_cow_self = cb_data->self_id;
475
476 return builder->foreach_id_cow_detect_need_for_update_callback(id_cow_self, id);
477}
478
480{
481 /* NOTE: Currently the only ID types that depsgraph may decide to not evaluate/generate evaluated
482 * copies for, even though they are referenced by other data-blocks, are Collections and Objects
483 * (through their various visibility flags, and the ones from #LayerCollections too). However,
484 * this code is kept generic as it makes it more future-proof, and optimization here would give
485 * negligible performance improvements in typical cases.
486 *
487 * NOTE: This mechanism may also 'fix' some missing update tagging from non-depsgraph code in
488 * some cases. This is slightly unfortunate (as it may hide issues in other parts of Blender
489 * code), but cannot really be avoided currently. */
490
491 for (const IDNode *id_node : graph_->id_nodes) {
492 if (ELEM(id_node->id_cow, id_node->id_orig, nullptr)) {
493 /* Node/ID with no copy-on-eval data, no need to check it. */
494 continue;
495 }
496 if (!deg_eval_copy_is_expanded(id_node->id_cow)) {
497 /* Copy-on-eval data is not expanded yet, so this is a newly added node/ID that has not been
498 * evaluated yet. */
499 continue;
500 }
501 if ((id_node->id_cow->recalc & ID_RECALC_SYNC_TO_EVAL) != 0) {
502 /* Node/ID already tagged for copy-on-eval flush, no need to check it. */
503 continue;
504 }
505 if ((id_node->id_cow->flag & ID_FLAG_EMBEDDED_DATA) != 0) {
506 /* For now, we assume embedded data are managed by their owner IDs and do not need to be
507 * checked here.
508 *
509 * NOTE: This exception somewhat weak, and ideally should not be needed. Currently however,
510 * embedded data are handled as full local (private) data of their owner IDs in part of
511 * Blender (like read/write code, including undo/redo), while depsgraph generally treat them
512 * as regular independent IDs. This leads to inconsistencies that can lead to bad level
513 * memory accesses.
514 *
515 * E.g. when undoing creation/deletion of a collection directly child of a scene's master
516 * collection, the scene itself is re-read in place, but its master collection becomes a
517 * completely new different pointer, and the existing copy-on-eval of the old master
518 * collection in the matching deg node is therefore pointing to fully invalid (freed) memory.
519 */
520 continue;
521 }
523 id_node->id_cow,
525 this,
527 }
528}
529
531{
532 for (const OperationKey &operation_key : saved_entry_tags_) {
533 OperationNode *operation_node = find_operation_node(operation_key);
534 if (operation_node == nullptr) {
535 continue;
536 }
537
538 /* Since the tag is coming from a saved copy of entry tags, this means
539 * that originally node was explicitly tagged for user update. */
541 }
542
543 /* Restore needs-update flags since the previous state of the dependency graph, ensuring the
544 * previously-skipped operations are properly re-evaluated when needed. */
545 for (const OperationKey &operation_key : needs_update_operations_) {
546 OperationNode *operation_node = find_operation_node(operation_key);
547 if (operation_node == nullptr) {
548 continue;
549 }
550 operation_node->flag |= DEPSOP_FLAG_NEEDS_UPDATE;
551 }
552}
553
560
561void DepsgraphNodeBuilder::build_id(ID *id, const bool force_be_visible)
562{
563 if (id == nullptr) {
564 return;
565 }
566
567 const ID_Type id_type = id->id_type();
568 switch (id_type) {
569 case ID_AC:
570 build_action(id_cast<bAction *>(id));
571 break;
572 case ID_AR:
573 build_armature(id_cast<bArmature *>(id));
574 break;
575 case ID_CA:
576 build_camera(id_cast<Camera *>(id));
577 break;
578 case ID_GR:
579 build_collection(nullptr, id_cast<Collection *>(id));
580 break;
581 case ID_OB:
582 /* TODO(sergey): Get visibility from a "parent" somehow.
583 *
584 * NOTE: Using `false` visibility here should be fine, since if this
585 * driver affects on something invisible we don't really care if the
586 * driver gets evaluated (and even don't want this to force object
587 * to become visible).
588 *
589 * If this happened to be affecting visible object, then it is up to
590 * deg_graph_build_flush_visibility() to ensure visibility of the
591 * object is true. */
592 build_object(-1, id_cast<Object *>(id), DEG_ID_LINKED_INDIRECTLY, force_be_visible);
593 break;
594 case ID_KE:
595 build_shapekeys(id_cast<Key *>(id));
596 break;
597 case ID_LA:
598 build_light(id_cast<Light *>(id));
599 break;
600 case ID_LP:
601 build_lightprobe(id_cast<LightProbe *>(id));
602 break;
603 case ID_NT:
604 build_nodetree(id_cast<bNodeTree *>(id));
605 break;
606 case ID_MA:
607 build_material(id_cast<Material *>(id));
608 break;
609 case ID_TE:
610 build_texture(id_cast<Tex *>(id));
611 break;
612 case ID_IM:
613 build_image(id_cast<Image *>(id));
614 break;
615 case ID_WO:
616 build_world(id_cast<World *>(id));
617 break;
618 case ID_MSK:
619 build_mask(id_cast<Mask *>(id));
620 break;
621 case ID_LS:
622 build_freestyle_linestyle(id_cast<FreestyleLineStyle *>(id));
623 break;
624 case ID_MC:
625 build_movieclip(id_cast<MovieClip *>(id));
626 break;
627 case ID_ME:
628 case ID_MB:
629 case ID_CU_LEGACY:
630 case ID_LT:
631 case ID_GD_LEGACY:
632 case ID_CV:
633 case ID_PT:
634 case ID_VO:
635 case ID_GP:
637 break;
638 case ID_SPK:
639 build_speaker(id_cast<Speaker *>(id));
640 break;
641 case ID_SO:
642 build_sound(id_cast<bSound *>(id));
643 break;
644 case ID_TXT:
645 /* Not a part of dependency graph. */
646 break;
647 case ID_CF:
648 build_cachefile(id_cast<CacheFile *>(id));
649 break;
650 case ID_SCE:
651 build_scene_parameters(id_cast<Scene *>(id));
652 break;
653 case ID_PA:
654 build_particle_settings(id_cast<ParticleSettings *>(id));
655 break;
656 case ID_VF:
657 build_vfont((VFont *)id);
658 break;
659
660 case ID_LI:
661 case ID_SCR:
662 case ID_BR:
663 case ID_WM:
664 case ID_PAL:
665 case ID_PC:
666 case ID_WS:
669 break;
670 }
671}
672
674{
676 return;
677 }
678
679 build_idproperties(id->properties);
680 build_idproperties(id->system_properties);
681 build_animdata(id);
683}
684
686{
687 IDP_foreach_property(id_property, IDP_TYPE_FILTER_ID, [&](IDProperty *id_property) {
688 this->build_id(static_cast<ID *>(id_property->data.pointer));
689 });
690}
691
693 Collection *collection)
694{
695 const int visibility_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? COLLECTION_HIDE_VIEWPORT :
697 const bool is_collection_restricted = (collection->flag & visibility_flag);
698 const bool is_collection_visible = !is_collection_restricted && is_parent_collection_visible_;
699 IDNode *id_node;
700 if (built_map_.check_is_built_and_tag(collection)) {
701 id_node = find_id_node(&collection->id);
702 if (is_collection_visible && id_node->is_visible_on_build == false &&
703 id_node->is_collection_fully_expanded == true)
704 {
705 /* Collection became visible, make sure nested collections and
706 * objects are poked with the new visibility flag, since they
707 * might become visible too. */
708 }
709 else if (from_layer_collection == nullptr && !id_node->is_collection_fully_expanded) {
710 /* Initially collection was built from layer now, and was requested
711 * to not recurse into object. But now it's asked to recurse into all objects. */
712 }
713 else {
714 return;
715 }
716 }
717 else {
718 /* Collection itself. */
719 id_node = add_id_node(&collection->id);
720 id_node->is_visible_on_build = is_collection_visible;
721
723
724 build_idproperties(collection->id.properties);
726 build_parameters(&collection->id);
728 }
729 if (from_layer_collection != nullptr) {
730 /* If we came from layer collection we don't go deeper, view layer
731 * builder takes care of going deeper. */
732 return;
733 }
734 /* Backup state. */
735 const bool is_current_parent_collection_visible = is_parent_collection_visible_;
736 /* Modify state as we've entered new collection/ */
737 is_parent_collection_visible_ = is_collection_visible;
738 /* Build collection objects. */
739 for (CollectionObject &cob : collection->gobject) {
740 build_object(-1, cob.ob, DEG_ID_LINKED_INDIRECTLY, is_collection_visible);
741 }
742 /* Build child collections. */
743 for (CollectionChild &child : collection->children) {
744 build_collection(nullptr, child.collection);
745 }
746 /* Restore state. */
747 is_parent_collection_visible_ = is_current_parent_collection_visible;
748 id_node->is_collection_fully_expanded = true;
749}
750
752 Object *object,
753 eDepsNode_LinkedState_Type linked_state,
754 bool is_visible)
755{
756 const bool has_object = built_map_.check_is_built_and_tag(object);
757
758 /* When there is already object in the dependency graph accumulate visibility an linked state
759 * flags. Only do it on the object itself (apart from very special cases) and leave dealing with
760 * visibility of dependencies to the visibility flush step which happens at the end of the build
761 * process. */
762 if (has_object) {
763 IDNode *id_node = find_id_node(&object->id);
764 if (id_node->linked_state == DEG_ID_LINKED_INDIRECTLY) {
765 build_object_flags(base_index, object, linked_state);
766 }
767 id_node->linked_state = std::max(id_node->linked_state, linked_state);
768 id_node->is_visible_on_build |= is_visible;
769 id_node->has_base |= (base_index != -1);
770
771 /* There is no relation path which will connect current object with all the ones which come
772 * via the instanced collection, so build the collection again. Note that it will do check
773 * whether visibility update is needed on its own. */
774 build_object_instance_collection(object, is_visible);
775
776 return;
777 }
778
779 /* Create ID node for object and begin init. */
780 IDNode *id_node = add_id_node(&object->id);
781 Object *object_cow = get_cow_datablock(object);
782 id_node->linked_state = linked_state;
783 /* NOTE: Scene is nullptr when building dependency graph for render pipeline.
784 * Probably need to assign that to something non-nullptr, but then the logic here will still be
785 * somewhat weird. */
786 if (scene_ != nullptr && object == scene_->camera) {
787 id_node->is_visible_on_build = true;
788 }
789 else {
790 id_node->is_visible_on_build = is_visible;
791 }
792 id_node->has_base |= (base_index != -1);
793
795
796 /* Various flags, flushing from bases/collections. */
797 build_object_from_layer(base_index, object, linked_state);
798 /* Transform. */
800 /* Parent. */
801 if (object->parent != nullptr) {
802 build_object(-1, object->parent, DEG_ID_LINKED_INDIRECTLY, is_visible);
803 }
804 /* Modifiers. */
806 /* Grease Pencil Modifiers. */
807 if (object->greasepencil_modifiers.first() != nullptr) {
809 data.builder = this;
811 }
812 /* Shader FX. */
813 if (object->shader_fx.first() != nullptr) {
815 data.builder = this;
817 }
818 /* Constraints. */
819 if (object->constraints.first() != nullptr) {
821 data.builder = this;
823 }
824 /* Object data. */
825 build_object_data(object);
826 /* Parameters, used by both drivers/animation and also to inform dependency
827 * from object's data. */
829 build_idproperties(object->id.properties);
830 build_idproperties(object->id.system_properties);
831 /* Build animation data,
832 *
833 * Do it now because it's possible object data will affect
834 * on object's level animation, for example in case of rebuilding
835 * pose for proxy. */
837 /* Particle systems. */
838 if (object->particlesystem.first() != nullptr) {
839 build_particle_systems(object, is_visible);
840 }
841 /* Force field Texture. */
842 if ((object->pd != nullptr) && (object->pd->forcefield == PFIELD_TEXTURE) &&
843 (object->pd->tex != nullptr))
844 {
845 build_texture(object->pd->tex);
846 }
847
848 /* Object instancing. */
849 if (object->instance_collection != nullptr) {
850 build_object_instance_collection(object, is_visible);
851
852 OperationNode *instancer_node = add_operation_node(
854 instancer_node->flag |= OperationFlag::DEPSOP_FLAG_PINNED;
855 }
856 OperationNode *instance_node = add_operation_node(
858 instance_node->flag |= OperationFlag::DEPSOP_FLAG_PINNED;
859
860 OperationNode *instance_geometry_node = add_operation_node(
862 instance_geometry_node->flag |= OperationFlag::DEPSOP_FLAG_PINNED;
863
865
866 build_object_shading(object);
867
868 /* Synchronization back to original object. */
872 [object_cow](blender::Depsgraph *depsgraph) {
873 BKE_object_sync_to_original(depsgraph, object_cow);
874 });
875}
876
878 Object *object,
879 eDepsNode_LinkedState_Type linked_state)
880{
881
882 OperationNode *entry_node = add_operation_node(
884 entry_node->set_as_entry();
887 exit_node->set_as_exit();
888
889 build_object_flags(base_index, object, linked_state);
890}
891
893 Object *object,
894 eDepsNode_LinkedState_Type linked_state)
895{
896 if (base_index == -1) {
897 return;
898 }
899 Scene *scene_cow = get_cow_datablock(scene_);
900 Object *object_cow = get_cow_datablock(object);
901 const bool is_from_set = (linked_state == DEG_ID_LINKED_VIA_SET);
902 /* TODO(sergey): Is this really best component to be used? */
904 &object->id,
907 [view_layer_index = view_layer_index_, scene_cow, object_cow, base_index, is_from_set](
908 blender::Depsgraph *depsgraph) {
909 BKE_object_eval_eval_base_flags(
910 depsgraph, scene_cow, view_layer_index, object_cow, base_index, is_from_set);
911 });
912}
913
915{
916 if (object->instance_collection == nullptr) {
917 return;
918 }
919 const bool is_current_parent_collection_visible = is_parent_collection_visible_;
920 is_parent_collection_visible_ = is_object_visible;
921 build_collection(nullptr, object->instance_collection);
922 is_parent_collection_visible_ = is_current_parent_collection_visible;
923}
924
926{
927 if (object->modifiers.is_empty()) {
928 return;
929 }
930
931 const ModifierMode modifier_mode = (graph_->mode == DAG_EVAL_VIEWPORT) ? eModifierMode_Realtime :
933
934 IDNode *id_node = find_id_node(&object->id);
935
939 [id_node](blender::Depsgraph *depsgraph) {
940 deg_evaluate_object_modifiers_mode_node_visibility(depsgraph, id_node);
941 });
942
943 for (const auto [modifier_index, modifier] : object->modifiers.enumerate()) {
944 OperationNode *modifier_node = add_operation_node(
946 if (modifier.type == eModifierType_Nodes) {
947 modifier_node->evaluate = [id_node, modifier_index = modifier_index, modifier_node](
948 blender::Depsgraph * /*depsgraph*/) {
949 Object *ob_eval = reinterpret_cast<Object *>(id_node->id_cow);
950 ModifierData *md_eval = reinterpret_cast<ModifierData *>(
951 BLI_findlink(&ob_eval->modifiers, modifier_index));
952 if (!md_eval) {
953 /* The modifiers may not be available on the evaluated object if the object has an
954 * error that turned it into an Empty. Modifiers are not copied on this object type.
955 * Also see #142290. */
956 return;
957 }
958 /* Set flag that the modifier can check when it is evaluated. */
959 const bool is_user_modified = modifier_node->flag & DEPSOP_FLAG_USER_MODIFIED;
960 SET_FLAG_FROM_TEST(md_eval->flag, is_user_modified, eModifierFlag_UserModified);
961 };
962 }
963
964 /* Mute modifier mode if the modifier is not enabled for the dependency graph mode.
965 * This handles static (non-animated) mode of the modifier. */
966 if ((modifier.mode & modifier_mode) == 0) {
967 modifier_node->flag |= DEPSOP_FLAG_MUTE;
968 }
969
972 }
973 }
974
976 data.builder = this;
977
978 /* Temporarily set the collection visibility to false, relying on the visibility flushing code
979 * to flush the visibility from a modifier into collections it depends on. */
980 const bool is_current_parent_collection_visible = is_parent_collection_visible_;
983 is_parent_collection_visible_ = is_current_parent_collection_visible;
984}
985
987{
988 if (object->type != OB_EMPTY && object->data == nullptr) {
989 return;
990 }
991 /* type-specific data. */
992 switch (object->type) {
993 case OB_EMPTY:
994 build_empty_object(object);
995 break;
996 case OB_MESH:
997 case OB_CURVES_LEGACY:
998 case OB_FONT:
999 case OB_SURF:
1000 case OB_MBALL:
1001 case OB_LATTICE:
1002 case OB_CURVES:
1003 case OB_POINTCLOUD:
1004 case OB_VOLUME:
1006 break;
1007 case OB_GREASE_PENCIL:
1009 break;
1010 case OB_ARMATURE:
1011 build_rig(object);
1012 break;
1013 case OB_LAMP:
1015 break;
1016 case OB_CAMERA:
1018 break;
1019 case OB_LIGHTPROBE:
1021 break;
1022 case OB_SPEAKER:
1024 break;
1025 default: {
1026 ID *obdata = object->data;
1027 if (!built_map_.check_is_built(obdata)) {
1028 build_animdata(obdata);
1029 }
1030 break;
1031 }
1032 }
1033 /* Materials. */
1034 Material ***materials_ptr = BKE_object_material_array_p(object);
1035 if (materials_ptr != nullptr) {
1036 short *num_materials_ptr = BKE_object_material_len_p(object);
1037 build_materials(*materials_ptr, *num_materials_ptr);
1038 }
1039}
1040
1042{
1043 Camera *camera = id_cast<Camera *>(object->data);
1045}
1046
1048{
1049 Light *lamp = id_cast<Light *>(object->data);
1050 build_light(lamp);
1051}
1052
1059
1061{
1062 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
1063 /* Build the layer parents. */
1064 for (const bke::greasepencil::Layer *layer : grease_pencil.layers()) {
1065 Object *parent = layer->parent;
1066 if (parent == nullptr) {
1067 continue;
1068 }
1069 build_object(-1, parent, DEG_ID_LINKED_INDIRECTLY, false);
1070 }
1072}
1073
1075{
1076 Speaker *speaker = id_cast<Speaker *>(object->data);
1077 build_speaker(speaker);
1079}
1080
1082{
1083 OperationNode *op_node;
1084 Object *ob_cow = get_cow_datablock(object);
1085 /* Transform entry operation. */
1087 op_node->set_as_entry();
1088 /* Local transforms (from transform channels - loc/rot/scale + deltas). */
1092 [ob_cow](blender::Depsgraph *depsgraph) {
1093 BKE_object_eval_local_transform(depsgraph, ob_cow);
1094 });
1095 /* Object parent. */
1096 if (object->parent != nullptr) {
1098 &object->id,
1101 [ob_cow](blender::Depsgraph *depsgraph) { BKE_object_eval_parent(depsgraph, ob_cow); });
1102 }
1103 /* Object constraints. */
1104 if (object->constraints.first() != nullptr) {
1106 }
1107 /* Rest of transformation update. */
1111 [ob_cow](blender::Depsgraph *depsgraph) {
1112 BKE_object_eval_uber_transform(depsgraph, ob_cow);
1113 });
1114 /* Operation to take of rigid body simulation. soft bodies and other friends
1115 * in the context of point cache invalidation. */
1117 /* Object transform is done. */
1118 op_node = add_operation_node(&object->id,
1121 [ob_cow](blender::Depsgraph *depsgraph) {
1122 BKE_object_eval_transform_final(depsgraph, ob_cow);
1123 });
1124 op_node->set_as_exit();
1125}
1126
1145{
1146 /* create node for constraint stack */
1147 Scene *scene_cow = get_cow_datablock(scene_);
1148 Object *object_cow = get_cow_datablock(object);
1152 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
1153 BKE_object_eval_constraints(depsgraph, scene_cow, object_cow);
1154 });
1155}
1156
1158{
1159 if (!BKE_ptcache_object_has(scene_, object, 0)) {
1160 return;
1161 }
1162 Scene *scene_cow = get_cow_datablock(scene_);
1163 Object *object_cow = get_cow_datablock(object);
1167 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
1168 BKE_object_eval_ptcache_reset(depsgraph, scene_cow, object_cow);
1169 });
1170}
1171
1173{
1174 /* For objects put the light linking update callback to the same component as the base flags.
1175 * This way the light linking is updated on the view layer hierarchy change (which does not seem
1176 * to have a dedicated tag). */
1177 Object *object_cow = get_cow_datablock(object);
1181 [object_cow](blender::Depsgraph *depsgraph) {
1182 BKE_object_eval_light_linking(depsgraph, object_cow);
1183 });
1184
1186
1187 if (object->light_linking) {
1188 build_light_linking_collection(object->light_linking->receiver_collection);
1189 build_light_linking_collection(object->light_linking->blocker_collection);
1190 }
1191}
1192
1194{
1195 if (collection == nullptr) {
1196 return;
1197 }
1198
1199 /* TODO(sergey): Support some sort of weak referencing, so that receiver objects which are
1200 * specified by this collection but not in the scene do not use extra memory.
1201 *
1202 * Until the better solution is implemented pull the objects indirectly, and keep them
1203 * invisible. This has penalty of higher memory usage, but not a performance penalty. */
1204
1205 const bool is_current_parent_collection_visible = is_parent_collection_visible_;
1207
1208 build_collection(nullptr, collection);
1209
1210 is_parent_collection_visible_ = is_current_parent_collection_visible;
1211
1212 /* Ensure the light linking component is created for the collection.
1213 *
1214 * Note that it is not possible to have early output check based on regular built flags because
1215 * the collection might have been first built for the non-light-linking purposes. */
1216 /* TODO(sergey): Can optimize this out by explicitly separating the different built tags. This
1217 * needs to be done in all places where the collection is built (is not something that can be
1218 * easily solved from just adding the light linking functionality). */
1219 if (!has_operation_node(
1221 {
1223 }
1224}
1225
1227{
1228 Object *object_cow = get_cow_datablock(object);
1232 [object_cow](blender::Depsgraph *depsgraph) {
1233 BKE_object_eval_shading(depsgraph, object_cow);
1234 });
1235
1236 OperationNode *done_node = add_operation_node(
1238 done_node->set_as_exit();
1239}
1240
1242{
1243 /* Special handling for animated images/sequences. */
1245 /* Regular animation. */
1246 AnimData *adt = BKE_animdata_from_id(id);
1247 if (adt == nullptr) {
1248 return;
1249 }
1250 if (adt->action != nullptr) {
1251 build_action(adt->action);
1252 }
1253 /* Make sure ID node exists. */
1254 (void)add_id_node(id);
1255 ID *id_cow = get_cow_id(id);
1256 if (adt->action != nullptr || !adt->nla_tracks.is_empty()) {
1257 OperationNode *operation_node;
1258 /* Explicit entry operation. */
1260 operation_node->set_as_entry();
1261 /* All the evaluation nodes. */
1263 id,
1266 [id_cow](blender::Depsgraph *depsgraph) { BKE_animsys_eval_animdata(depsgraph, id_cow); });
1267 /* Explicit exit operation. */
1269 operation_node->set_as_exit();
1270 }
1271 /* NLA strips contain actions. */
1272 for (NlaTrack &nlt : adt->nla_tracks) {
1273 if (!BKE_nlatrack_is_enabled(*adt, nlt)) {
1274 continue;
1275 }
1277 }
1278 /* Drivers. */
1279 build_animdata_drivers(id, adt);
1280}
1281
1283{
1284 for (NlaStrip &strip : *strips) {
1285 if (strip.act != nullptr) {
1286 build_action(strip.act);
1287 }
1288 else if (strip.strips.first() != nullptr) {
1289 build_animdata_nlastrip_targets(&strip.strips);
1290 }
1291 }
1292}
1293
1295{
1296 /* GPU materials might use an animated image. However, these materials have no been built yet so
1297 * we have to check if they might be created during evaluation. */
1298 bool has_image_animation = false;
1299 if (ELEM(id->id_type(), ID_MA, ID_WO)) {
1301 if (ntree != nullptr && ntree->runtime->runtime_flag & NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION)
1302 {
1303 has_image_animation = true;
1304 }
1305 }
1306
1307 if (has_image_animation || BKE_image_user_id_has_animation(id)) {
1308 ID *id_cow = get_cow_id(id);
1312 [id_cow](blender::Depsgraph *depsgraph) {
1313 BKE_image_user_id_eval_animation(depsgraph, id_cow);
1314 });
1315 }
1316}
1317
1319{
1320 if (built_map_.check_is_built_and_tag(action)) {
1321 return;
1322 }
1323
1324 /* To make it possible to use animation data as a variable for drivers: */
1325 build_parameters(&action->id);
1326
1329
1330 for (TimeMarker &marker : action->markers) {
1331 build_idproperties(marker.prop);
1332 }
1333
1335}
1336
1338{
1339 bool needs_unshare = false;
1340
1341 /* Drivers. */
1342
1343 for (const auto [driver_index, fcu] : adt->drivers.enumerate()) {
1344 build_driver(id, &fcu, driver_index);
1345 needs_unshare = needs_unshare || data_path_maybe_shared(*id, fcu.rna_path());
1346 }
1347
1348 if (!needs_unshare) {
1349 return;
1350 }
1351
1352 ID *id_cow = get_cow_id(id);
1356 [id_cow](blender::Depsgraph *depsgraph) {
1357 BKE_animsys_eval_driver_unshare(depsgraph, id_cow);
1358 });
1359}
1360
1361void DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcurve, int driver_index)
1362{
1363 /* Create data node for this driver */
1364 ID *id_cow = get_cow_id(id);
1365
1366 /* TODO(sergey): ideally we could pass the copy-on-eval of fcu, but since it
1367 * has not yet been allocated at this point we can't. As a workaround
1368 * the animation systems allocates an array so we can do a fast lookup
1369 * with the driver index. */
1371 id,
1374 [id_cow, driver_index, fcurve](blender::Depsgraph *depsgraph) {
1375 BKE_animsys_eval_driver(depsgraph, id_cow, driver_index, fcurve);
1376 },
1377 fcurve->rna_path().c_str(),
1378 fcurve->array_index);
1379 build_driver_variables(id, fcurve);
1380}
1381
1383{
1384 PointerRNA id_ptr = RNA_id_pointer_create(id);
1385
1386 build_driver_id_property(id_ptr, fcurve->rna_path().c_str());
1387
1388 DriverTargetContext driver_target_context;
1389 driver_target_context.scene = graph_->scene;
1390 driver_target_context.view_layer = graph_->view_layer;
1391
1392 for (DriverVar &dvar : fcurve->driver->variables) {
1394 PointerRNA target_prop;
1395 if (!driver_get_target_property(&driver_target_context, &dvar, dtar, &target_prop)) {
1396 continue;
1397 }
1398
1399 /* Property is always expected to be resolved to a non-null RNA property, which is always
1400 * relative to some ID. */
1401 BLI_assert(target_prop.owner_id);
1402
1403 ID *target_id = target_prop.owner_id;
1404
1405 build_id(target_id);
1406 build_driver_id_property(target_prop, dtar->rna_path);
1407
1408 /* For rna_path based variables: */
1409 if ((dtar->flag & DTAR_FLAG_STRUCT_REF) == 0) {
1410 /* Handle all other cameras used by the scene timeline if applicable. */
1411 if (const char *camera_path = get_rna_path_relative_to_scene_camera(
1412 scene_, target_prop, dtar->rna_path))
1413 {
1415 }
1416 }
1417 }
1419 }
1420}
1421
1423 const char *camera_path)
1424{
1425 /* This skips scene->camera, which was already handled by the caller. */
1426 for (TimeMarker &marker : scene->markers) {
1427 if (!ELEM(marker.camera, nullptr, scene->camera)) {
1428 PointerRNA camera_ptr = RNA_id_pointer_create(&marker.camera->id);
1429 build_driver_id_property(camera_ptr, camera_path);
1430 }
1431 }
1432}
1433
1435 const char *rna_path_from_target_prop)
1436{
1437 if (rna_path_from_target_prop == nullptr || rna_path_from_target_prop[0] == '\0') {
1438 return;
1439 }
1440
1441 PointerRNA ptr;
1442 PropertyRNA *prop;
1443 int index;
1444 if (!RNA_path_resolve_full(&target_prop, rna_path_from_target_prop, &ptr, &prop, &index)) {
1445 return;
1446 }
1447 if (prop == nullptr) {
1448 return;
1449 }
1450 if (!rna_prop_affects_parameters_node(&ptr, prop)) {
1451 return;
1452 }
1453 if (ptr.owner_id) {
1454 build_id(ptr.owner_id);
1455 }
1456 const char *prop_identifier = RNA_property_identifier(prop);
1457 /* Custom properties of bones are placed in their components to improve granularity. */
1458 if (RNA_struct_is_a(ptr.type, RNA_PoseBone)) {
1459 const bPoseChannel *pchan = static_cast<const bPoseChannel *>(ptr.data);
1462 pchan->name,
1464 nullptr,
1465 prop_identifier);
1466 }
1467 else {
1469 ptr.owner_id, NodeType::PARAMETERS, OperationCode::ID_PROPERTY, nullptr, prop_identifier);
1470 }
1471}
1472
1474{
1475 (void)add_id_node(id);
1476 OperationNode *op_node;
1477 /* Explicit entry. */
1479 op_node->set_as_entry();
1480 /* Generic evaluation node. */
1481
1482 if (ID_TYPE_SUPPORTS_PARAMS_WITHOUT_COW(id->id_type())) {
1483 ID *id_cow = get_cow_id(id);
1487 [id_cow, id](blender::Depsgraph * /*depsgraph*/) {
1488 BKE_id_eval_properties_copy(id_cow, id);
1489 });
1490 }
1491 else {
1493 }
1494
1495 /* Explicit exit operation. */
1497 op_node->set_as_exit();
1498}
1499
1501{
1502 /* Object dimensions (bounding box) node. Will depend on both geometry and transform. */
1504}
1505
1507{
1509 return;
1510 }
1511 /* World itself. */
1512 add_id_node(&world->id);
1513 World *world_cow = get_cow_datablock(world);
1514 /* Shading update. */
1516 &world->id,
1519 [world_cow](blender::Depsgraph *depsgraph) { BKE_world_eval(depsgraph, world_cow); });
1520 build_idproperties(world->id.properties);
1521 build_idproperties(world->id.system_properties);
1522 /* Animation. */
1523 build_animdata(&world->id);
1524 build_parameters(&world->id);
1525 /* World's nodetree. */
1526 build_nodetree(world->nodetree);
1527}
1528
1529/* Rigidbody Simulation - Scene Level */
1531{
1532 RigidBodyWorld *rbw = scene->rigidbody_world;
1533 Scene *scene_cow = get_cow_datablock(scene);
1534
1550
1551 /* Create nodes --------------------------------------------------------- */
1552
1553 /* XXX: is this the right component, or do we want to use another one
1554 * instead? */
1555
1556 /* Init/rebuild operation. */
1557 add_operation_node(&scene->id,
1560 [scene_cow](blender::Depsgraph *depsgraph) {
1561 BKE_rigidbody_rebuild_sim(depsgraph, scene_cow);
1562 });
1563 /* Do-sim operation. */
1564 OperationNode *sim_node = add_operation_node(&scene->id,
1567 [scene_cow](blender::Depsgraph *depsgraph) {
1568 BKE_rigidbody_eval_simulation(depsgraph,
1569 scene_cow);
1570 });
1571 sim_node->set_as_entry();
1572 sim_node->set_as_exit();
1573 sim_node->owner->entry_operation = sim_node;
1574 /* Objects - simulation participants. */
1575 if (rbw->group != nullptr) {
1576 build_collection(nullptr, rbw->group);
1578 if (object->type != OB_MESH) {
1579 continue;
1580 }
1581 if (object->rigidbody_object == nullptr) {
1582 continue;
1583 }
1584
1585 if (object->rigidbody_object->type == RBO_TYPE_PASSIVE) {
1586 continue;
1587 }
1588
1589 /* Create operation for flushing results. */
1590 /* Object's transform component - where the rigidbody operation
1591 * lives. */
1592 Object *object_cow = get_cow_datablock(object);
1596 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
1597 BKE_rigidbody_object_sync_transforms(depsgraph, scene_cow, object_cow);
1598 });
1599 }
1601 }
1602 /* Constraints. */
1603 if (rbw->constraints != nullptr) {
1605 RigidBodyCon *rbc = object->rigidbody_constraint;
1606 if (rbc == nullptr || rbc->ob1 == nullptr || rbc->ob2 == nullptr) {
1607 /* When either ob1 or ob2 is nullptr, the constraint doesn't work. */
1608 continue;
1609 }
1610 /* Make sure indirectly linked objects are fully built. */
1611 build_object(-1, object, DEG_ID_LINKED_INDIRECTLY, false);
1612 build_object(-1, rbc->ob1, DEG_ID_LINKED_INDIRECTLY, false);
1613 build_object(-1, rbc->ob2, DEG_ID_LINKED_INDIRECTLY, false);
1614 }
1616 }
1617}
1618
1619void DepsgraphNodeBuilder::build_particle_systems(Object *object, bool is_object_visible)
1620{
1621 /* Particle Systems Nodes
1622 * ======================
1623 *
1624 * There are two types of nodes associated with representing
1625 * particle systems:
1626 * 1) Component (EVAL_PARTICLES) - This is the particle-system
1627 * evaluation context for an object. It acts as the container
1628 * for all the nodes associated with a particular set of particle
1629 * systems.
1630 * 2) Particle System Evaluation Operation - This operation node acts as a
1631 * black-box evaluation step for one particle system referenced by
1632 * the particle systems stack. All dependencies link to this operation. */
1633 /* Component for all particle systems. */
1635
1636 Object *ob_cow = get_cow_datablock(object);
1637 OperationNode *op_node;
1638 op_node = add_operation_node(
1639 psys_comp, OperationCode::PARTICLE_SYSTEM_INIT, [ob_cow](blender::Depsgraph *depsgraph) {
1640 BKE_particle_system_eval_init(depsgraph, ob_cow);
1641 });
1642 op_node->set_as_entry();
1643 /* Build all particle systems. */
1644 for (ParticleSystem &psys : object->particlesystem) {
1645 ParticleSettings *part = psys.part;
1646 /* Build particle settings operations.
1647 *
1648 * NOTE: The call itself ensures settings are only build once. */
1650 /* Particle system evaluation. */
1652 /* Keyed particle targets. */
1654 for (ParticleTarget &particle_target : psys.targets) {
1655 if (ELEM(particle_target.ob, nullptr, object)) {
1656 continue;
1657 }
1658 build_object(-1, particle_target.ob, DEG_ID_LINKED_INDIRECTLY, is_object_visible);
1659 }
1660 }
1661 /* Visualization of particle system. */
1662 switch (part->ren_as) {
1663 case PART_DRAW_OB:
1664 if (part->instance_object != nullptr) {
1665 build_object(-1, part->instance_object, DEG_ID_LINKED_INDIRECTLY, is_object_visible);
1666 }
1667 break;
1668 case PART_DRAW_GR:
1669 if (part->instance_collection != nullptr) {
1670 build_collection(nullptr, part->instance_collection);
1671 }
1672 break;
1673 default:
1674 break;
1675 }
1676 }
1678 op_node->set_as_exit();
1679}
1680
1682{
1683 if (built_map_.check_is_built_and_tag(particle_settings)) {
1684 return;
1685 }
1686 /* Make sure we've got proper copied ID pointer. */
1687 add_id_node(&particle_settings->id);
1688 ParticleSettings *particle_settings_cow = get_cow_datablock(particle_settings);
1689 /* Animation data. */
1690 build_animdata(&particle_settings->id);
1691 build_parameters(&particle_settings->id);
1692 /* Parameters change. */
1693 OperationNode *op_node;
1694 op_node = add_operation_node(
1696 op_node->set_as_entry();
1697 add_operation_node(&particle_settings->id,
1700 [particle_settings_cow](blender::Depsgraph *depsgraph) {
1701 BKE_particle_settings_eval_reset(depsgraph, particle_settings_cow);
1702 });
1703 op_node = add_operation_node(
1705 op_node->set_as_exit();
1706 /* Texture slots. */
1707 for (MTex *mtex : particle_settings->mtex) {
1708 if (mtex == nullptr || mtex->tex == nullptr) {
1709 continue;
1710 }
1711 build_texture(mtex->tex);
1712 }
1713}
1714
1716{
1718 return;
1719 }
1722 build_animdata(&key->id);
1723 build_parameters(&key->id);
1724 /* This is an exit operation for the entire key datablock, is what is used
1725 * as dependency for modifiers evaluation. */
1727 /* Create per-key block properties, allowing tricky inter-dependencies for
1728 * drivers evaluation. */
1729 for (KeyBlock &key_block : key->block) {
1731 &key->id, NodeType::PARAMETERS, OperationCode::PARAMETERS_EVAL, nullptr, key_block.name);
1732 }
1733}
1734
1736{
1737 OperationNode *op_node;
1738 Scene *scene_cow = get_cow_datablock(scene_);
1739 Object *object_cow = get_cow_datablock(object);
1740
1741 const bool has_modifiers = !BLI_listbase_is_empty(&object->modifiers);
1742 if (!has_modifiers) {
1743 if (deg_eval_copy_is_expanded(&object_cow->id)) {
1744 /* The empty might have had modifiers previously, so it might still have cached evaluated
1745 * geometry. Usually this would be freed by #BKE_object_eval_uber_data during the next
1746 * evaluation. However, since the geometry evaluation is fully skipped, we need to free the
1747 * data here already. */
1749 }
1750 return;
1751 }
1752 /* Entry operation, takes care of initialization, and some other
1753 * relations which needs to be run prior actual geometry evaluation. */
1755 op_node->set_as_entry();
1756 /* Geometry evaluation. */
1757 /* The empty object type doesn't contain any original geometry, but it can have a geometry nodes
1758 * modifier that creates geometry dynamically. */
1759 op_node = add_operation_node(&object->id,
1762 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
1763 BKE_object_eval_uber_data(depsgraph, scene_cow, object_cow);
1764 });
1765 op_node->set_as_exit();
1766}
1767
1768/* ObData Geometry Evaluation */
1769/* XXX: what happens if the datablock is shared! */
1771{
1772 OperationNode *op_node;
1773 Scene *scene_cow = get_cow_datablock(scene_);
1774 Object *object_cow = get_cow_datablock(object);
1775 /* Entry operation, takes care of initialization, and some other
1776 * relations which needs to be run prior actual geometry evaluation. */
1778 op_node->set_as_entry();
1779 /* Geometry evaluation. */
1780 op_node = add_operation_node(&object->id,
1783 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
1784 BKE_object_eval_uber_data(depsgraph, scene_cow, object_cow);
1785 });
1786 op_node->set_as_exit();
1787 /* Materials. */
1788 build_materials(object->mat, object->totcol);
1789 /* Point caches. */
1791 /* Geometry. */
1793 build_dimensions(object);
1794 /* Batch cache. */
1798 [object_cow](blender::Depsgraph *depsgraph) {
1799 BKE_object_select_update(depsgraph, object_cow);
1800 });
1801}
1802
1804{
1805 if (built_map_.check_is_built_and_tag(obdata)) {
1806 return;
1807 }
1808 OperationNode *op_node;
1809 /* Make sure we've got an ID node before requesting evaluated pointer. */
1810 (void)add_id_node(obdata);
1811 ID *obdata_cow = get_cow_id(obdata);
1814 /* Animation. */
1815 build_animdata(obdata);
1816 /* ShapeKeys */
1817 Key *key = BKE_key_from_id(obdata);
1818 if (key) {
1819 build_shapekeys(key);
1820 }
1821 /* Nodes for result of obdata's evaluation, and geometry
1822 * evaluation on object. */
1823 const ID_Type id_type = obdata->id_type();
1824 switch (id_type) {
1825 case ID_ME: {
1826 op_node = add_operation_node(obdata,
1829 [obdata_cow](blender::Depsgraph *depsgraph) {
1830 BKE_mesh_eval_geometry(depsgraph,
1831 id_cast<Mesh *>(obdata_cow));
1832 });
1833 op_node->set_as_entry();
1834 break;
1835 }
1836 case ID_MB: {
1838 op_node->set_as_entry();
1839 break;
1840 }
1841 case ID_CU_LEGACY: {
1842 op_node = add_operation_node(obdata,
1845 [obdata_cow](blender::Depsgraph *depsgraph) {
1846 BKE_curve_eval_geometry(depsgraph,
1847 id_cast<Curve *>(obdata_cow));
1848 });
1849 op_node->set_as_entry();
1850 Curve *cu = id_cast<Curve *>(obdata);
1851 if (cu->bevobj != nullptr) {
1853 }
1854 if (cu->taperobj != nullptr) {
1856 }
1857 if (cu->textoncurve != nullptr) {
1859 }
1860 break;
1861 }
1862 case ID_LT: {
1863 op_node = add_operation_node(obdata,
1866 [obdata_cow](blender::Depsgraph *depsgraph) {
1868 depsgraph, reinterpret_cast<Lattice *>(obdata_cow));
1869 });
1870 op_node->set_as_entry();
1871 break;
1872 }
1873
1874 case ID_CV: {
1875 Curves *curves_id = reinterpret_cast<Curves *>(obdata);
1876
1878 op_node->set_as_entry();
1879
1880 if (curves_id->surface != nullptr) {
1881 build_object(-1, curves_id->surface, DEG_ID_LINKED_INDIRECTLY, false);
1882 }
1883 break;
1884 }
1885 case ID_PT: {
1887 op_node->set_as_entry();
1888 break;
1889 }
1890 case ID_VO: {
1891 /* Volume frame update. */
1892 op_node = add_operation_node(obdata,
1895 [obdata_cow](blender::Depsgraph *depsgraph) {
1896 BKE_volume_eval_geometry(depsgraph,
1897 id_cast<Volume *>(obdata_cow));
1898 });
1899 op_node->set_as_entry();
1900 break;
1901 }
1902 case ID_GP: {
1903 op_node = add_operation_node(obdata,
1906 [obdata_cow](blender::Depsgraph *depsgraph) {
1908 depsgraph, reinterpret_cast<GreasePencil *>(obdata_cow));
1909 });
1910 op_node->set_as_entry();
1911 break;
1912 }
1913 default:
1914 BLI_assert_msg(0, "Should not happen");
1915 break;
1916 }
1918 op_node->set_as_exit();
1919 /* Parameters for driver sources. */
1920 build_parameters(obdata);
1921 /* Batch cache. */
1922 add_operation_node(obdata,
1925 [obdata_cow](blender::Depsgraph *depsgraph) {
1926 BKE_object_data_select_update(depsgraph, obdata_cow);
1927 });
1928 /* Shading (No-Op).
1929 * Needed to allow the Material shading updates reach the Object. */
1931}
1932
1934{
1935 if (built_map_.check_is_built_and_tag(armature)) {
1936 return;
1937 }
1938 build_idproperties(armature->id.properties);
1940 build_animdata(&armature->id);
1941 build_parameters(&armature->id);
1942 /* This operation is no longer necessary, as it was updating things with the bone layers (which
1943 * got replaced by bone collections). However, it's still used by other depsgraph components as a
1944 * dependency, so for now the node itself is kept as a no-op.
1945 * TODO: remove this node & the references to it, if eventually it turns out we really don't need
1946 * this.
1947 */
1948 add_operation_node(&armature->id,
1951 [](blender::Depsgraph *) {});
1952 build_armature_bones(&armature->bonebase);
1953 build_armature_bone_collections(armature->collections_span());
1954}
1955
1957{
1958 for (Bone &bone : *bones) {
1959 build_idproperties(bone.prop);
1960 build_idproperties(bone.system_properties);
1961 build_armature_bones(&bone.childbase);
1962 }
1963}
1964
1966{
1967 for (BoneCollection *bcoll : collections) {
1968 build_idproperties(bcoll->prop);
1969 build_idproperties(bcoll->system_properties);
1970 }
1971}
1972
1974{
1976 return;
1977 }
1978 build_idproperties(camera->id.properties);
1979 build_idproperties(camera->id.system_properties);
1980 build_animdata(&camera->id);
1982 if (camera->dof.focus_object != nullptr) {
1983 build_object(-1, camera->dof.focus_object, DEG_ID_LINKED_INDIRECTLY, false);
1984 }
1985}
1986
1988{
1990 return;
1991 }
1992 build_idproperties(lamp->id.properties);
1993 build_idproperties(lamp->id.system_properties);
1994 build_animdata(&lamp->id);
1995 build_parameters(&lamp->id);
1996 /* light's nodetree */
1997 build_nodetree(lamp->nodetree);
1998
1999 Light *lamp_cow = get_cow_datablock(lamp);
2001 &lamp->id,
2004 [lamp_cow](blender::Depsgraph *depsgraph) { BKE_light_eval(depsgraph, lamp_cow); });
2005}
2006
2008{
2009 build_idproperties(socket->prop);
2010
2011 if (socket->type == SOCK_OBJECT) {
2012 build_id(id_cast<ID *>((static_cast<bNodeSocketValueObject *>(socket->default_value))->value));
2013 }
2014 else if (socket->type == SOCK_IMAGE) {
2015 build_id(id_cast<ID *>((static_cast<bNodeSocketValueImage *>(socket->default_value))->value));
2016 }
2017 else if (socket->type == SOCK_COLLECTION) {
2018 build_id(
2019 id_cast<ID *>((static_cast<bNodeSocketValueCollection *>(socket->default_value))->value));
2020 }
2021 else if (socket->type == SOCK_TEXTURE) {
2022 build_id(
2023 id_cast<ID *>((static_cast<bNodeSocketValueTexture *>(socket->default_value))->value));
2024 }
2025 else if (socket->type == SOCK_MATERIAL) {
2026 build_id(
2027 id_cast<ID *>((static_cast<bNodeSocketValueMaterial *>(socket->default_value))->value));
2028 }
2029 else if (socket->type == SOCK_FONT) {
2030 build_id(id_cast<ID *>((static_cast<bNodeSocketValueFont *>(socket->default_value))->value));
2031 }
2032 else if (socket->type == SOCK_SCENE) {
2033 build_id(id_cast<ID *>((static_cast<bNodeSocketValueScene *>(socket->default_value))->value));
2034 }
2035 else if (socket->type == SOCK_TEXT_ID) {
2036 /* Text data-blocks don't use the depsgraph. */
2037 }
2038 else if (socket->type == SOCK_MASK) {
2039 build_id(id_cast<ID *>((static_cast<bNodeSocketValueMask *>(socket->default_value))->value));
2040 }
2041 else if (socket->type == SOCK_SOUND) {
2042 build_id(id_cast<ID *>((static_cast<bNodeSocketValueSound *>(socket->default_value))->value));
2043 }
2044}
2045
2047{
2048 if (ntree == nullptr) {
2049 return;
2050 }
2052 return;
2053 }
2054 /* nodetree itself */
2055 add_id_node(&ntree->id);
2056 /* General parameters. */
2057 build_parameters(&ntree->id);
2060 /* Animation, */
2061 build_animdata(&ntree->id);
2062 /* Output update. */
2064 if (ntree->type == NTREE_GEOMETRY) {
2065 ID *id_cow = get_cow_id(&ntree->id);
2066 add_operation_node(&ntree->id,
2069 [id_cow](blender::Depsgraph * /*depsgraph*/) {
2070 bNodeTree *ntree_cow = reinterpret_cast<bNodeTree *>(id_cow);
2071 bke::node_tree_runtime::preprocess_geometry_node_tree_for_evaluation(
2072 *ntree_cow);
2073 });
2074 }
2075
2076 /* nodetree's nodes... */
2077 for (bNode *bnode : ntree->all_nodes()) {
2078 build_idproperties(bnode->prop);
2079 for (bNodeSocket &socket : bnode->inputs) {
2080 build_nodetree_socket(&socket);
2081 }
2082 for (bNodeSocket &socket : bnode->outputs) {
2083 build_nodetree_socket(&socket);
2084 }
2085
2086 ID *id = bnode->id;
2087 if (id == nullptr) {
2088 continue;
2089 }
2090 ID_Type id_type = id->id_type();
2091 if (id_type == ID_MA) {
2092 build_material(id_cast<Material *>(id));
2093 }
2094 else if (id_type == ID_TE) {
2095 build_texture(id_cast<Tex *>(id));
2096 }
2097 else if (id_type == ID_IM) {
2098 build_image(id_cast<Image *>(id));
2099 }
2100 else if (id_type == ID_OB) {
2101 /* TODO(sergey): Use visibility of owner of the node tree. */
2102 build_object(-1, id_cast<Object *>(id), DEG_ID_LINKED_INDIRECTLY, true);
2103 }
2104 else if (id_type == ID_SCE) {
2105 Scene *node_scene = id_cast<Scene *>(id);
2106 build_scene_parameters(node_scene);
2107 /* Camera is used by defocus node.
2108 *
2109 * On the one hand it's annoying to always pull it in, but on another hand it's also annoying
2110 * to have hardcoded node-type exception here. */
2111 if (node_scene->camera != nullptr) {
2112 /* TODO(sergey): Use visibility of owner of the node tree. */
2113 build_object(-1, node_scene->camera, DEG_ID_LINKED_INDIRECTLY, true);
2114 }
2115 }
2116 else if (id_type == ID_TXT) {
2117 /* Ignore script nodes. */
2118 }
2119 else if (id_type == ID_MSK) {
2120 build_mask(id_cast<Mask *>(id));
2121 }
2122 else if (id_type == ID_MC) {
2123 build_movieclip(id_cast<MovieClip *>(id));
2124 }
2125 else if (id_type == ID_VF) {
2126 build_vfont(id_cast<VFont *>(id));
2127 }
2128 else if (id_type == ID_GR) {
2129 build_collection(nullptr, reinterpret_cast<Collection *>(id));
2130 }
2131 else if (bnode->is_group()) {
2132 bNodeTree *group_ntree = id_cast<bNodeTree *>(id);
2133 build_nodetree(group_ntree);
2134 }
2135 else {
2136 /* Ignore this case. It can happen when the node type is not known currently. Either because
2137 * it belongs to an add-on or because it comes from a different Blender version that does
2138 * support the ID type here already. */
2139 }
2140 }
2141
2142 /* Needed for interface cache. */
2143 ntree->ensure_interface_cache();
2144 for (bNodeTreeInterfaceSocket *socket : ntree->interface_inputs()) {
2145 build_idproperties(socket->properties);
2146 }
2147 for (bNodeTreeInterfaceSocket *socket : ntree->interface_outputs()) {
2148 build_idproperties(socket->properties);
2149 }
2150
2151 /* TODO: link from nodetree to owner_component? */
2152}
2153
2155{
2156 if (built_map_.check_is_built_and_tag(material)) {
2157 return;
2158 }
2159 /* Material itself. */
2160 add_id_node(&material->id);
2161 Material *material_cow = get_cow_datablock(material);
2162 /* Shading update. */
2163 add_operation_node(&material->id,
2166 [material_cow](blender::Depsgraph *depsgraph) {
2167 BKE_material_eval(depsgraph, material_cow);
2168 });
2169 build_idproperties(material->id.properties);
2170 build_idproperties(material->id.system_properties);
2171 /* Material animation. */
2172 build_animdata(&material->id);
2173 build_parameters(&material->id);
2174 /* Material's nodetree. */
2175 build_nodetree(material->nodetree);
2176}
2177
2178void DepsgraphNodeBuilder::build_materials(Material **materials, int num_materials)
2179{
2180 for (int i = 0; i < num_materials; i++) {
2181 if (materials[i] == nullptr) {
2182 continue;
2183 }
2184 build_material(materials[i]);
2185 }
2186}
2187
2189{
2191 return;
2192 }
2193 /* Texture itself. */
2194 add_id_node(&texture->id);
2195 Tex *texture_cow = get_cow_datablock(texture);
2196 build_idproperties(texture->id.properties);
2197 build_idproperties(texture->id.system_properties);
2198 build_animdata(&texture->id);
2200 /* Texture's nodetree. */
2201 build_nodetree(texture->nodetree);
2202 /* Special cases for different IDs which texture uses. */
2203 if (texture->type == TEX_IMAGE) {
2204 if (texture->ima != nullptr) {
2205 build_image(texture->ima);
2206 }
2207 }
2211 [texture_cow](blender::Depsgraph *depsgraph) {
2212 texture_cow->runtime.last_update = DEG_get_update_count(depsgraph);
2213 });
2214}
2215
2227
2229{
2230 if (built_map_.check_is_built_and_tag(cache_file)) {
2231 return;
2232 }
2233 ID *cache_file_id = &cache_file->id;
2234 add_id_node(cache_file_id);
2235 CacheFile *cache_file_cow = get_cow_datablock(cache_file);
2236 build_idproperties(cache_file_id->properties);
2237 build_idproperties(cache_file_id->system_properties);
2238 /* Animation, */
2239 build_animdata(cache_file_id);
2240 build_parameters(cache_file_id);
2241 /* Cache evaluation itself. */
2242 add_operation_node(cache_file_id,
2245 [bmain = bmain_, cache_file_cow](blender::Depsgraph *depsgraph) {
2246 BKE_cachefile_eval(bmain, depsgraph, cache_file_cow);
2247 });
2248}
2249
2251{
2253 return;
2254 }
2255 ID *mask_id = &mask->id;
2256 Mask *mask_cow = reinterpret_cast<Mask *>(ensure_cow_id(mask_id));
2257 build_idproperties(mask->id.properties);
2258 build_idproperties(mask->id.system_properties);
2259 /* F-Curve based animation. */
2260 build_animdata(mask_id);
2261 build_parameters(mask_id);
2262 /* Animation based on mask's shapes. */
2264 mask_id,
2267 [mask_cow](blender::Depsgraph *depsgraph) { BKE_mask_eval_animation(depsgraph, mask_cow); });
2268 /* Final mask evaluation. */
2270 mask_id,
2273 [mask_cow](blender::Depsgraph *depsgraph) { BKE_mask_eval_update(depsgraph, mask_cow); });
2274 /* Build parents. */
2275 for (MaskLayer &mask_layer : mask->masklayers) {
2276 for (MaskSpline &spline : mask_layer.splines) {
2277 for (int i = 0; i < spline.tot_point; i++) {
2278 MaskSplinePoint *point = &spline.points[i];
2279 MaskParent *parent = &point->parent;
2280 if (parent == nullptr || parent->id == nullptr) {
2281 continue;
2282 }
2283 build_id(parent->id);
2284 }
2285 }
2286 }
2287}
2288
2290{
2291 if (built_map_.check_is_built_and_tag(linestyle)) {
2292 return;
2293 }
2294
2295 ID *linestyle_id = &linestyle->id;
2296 build_parameters(linestyle_id);
2297 build_idproperties(linestyle->id.properties);
2299 build_animdata(linestyle_id);
2300 build_nodetree(linestyle->nodetree);
2301}
2302
2304{
2306 return;
2307 }
2308 ID *clip_id = &clip->id;
2309 MovieClip *clip_cow = reinterpret_cast<MovieClip *>(ensure_cow_id(clip_id));
2312 /* Animation. */
2313 build_animdata(clip_id);
2314 build_parameters(clip_id);
2315 /* Movie clip evaluation. */
2316 add_operation_node(clip_id,
2319 [bmain = bmain_, clip_cow](blender::Depsgraph *depsgraph) {
2320 BKE_movieclip_eval_update(depsgraph, bmain, clip_cow);
2321 });
2322}
2323
2325{
2327 return;
2328 }
2329 /* Placeholder so we can add relations and tag ID node for update. */
2331 build_idproperties(probe->id.properties);
2332 build_idproperties(probe->id.system_properties);
2333 build_animdata(&probe->id);
2334 build_parameters(&probe->id);
2335}
2336
2338{
2339 if (built_map_.check_is_built_and_tag(speaker)) {
2340 return;
2341 }
2342 /* Placeholder so we can add relations and tag ID node for update. */
2346 build_animdata(&speaker->id);
2347 build_parameters(&speaker->id);
2348 if (speaker->sound != nullptr) {
2349 build_sound(speaker->sound);
2350 }
2351}
2352
2354{
2356 return;
2357 }
2358 add_id_node(&sound->id);
2359 bSound *sound_cow = get_cow_datablock(sound);
2360 add_operation_node(&sound->id,
2363 [bmain = bmain_, sound_cow](blender::Depsgraph *depsgraph) {
2364 BKE_sound_evaluate(depsgraph, bmain, sound_cow);
2365 });
2368 build_animdata(&sound->id);
2369 build_parameters(&sound->id);
2370}
2371
2373{
2375 return;
2376 }
2377 build_parameters(&vfont->id);
2380}
2381
2382static bool strip_node_build_cb(Strip *strip, void *user_data)
2383{
2384 DepsgraphNodeBuilder *nb = static_cast<DepsgraphNodeBuilder *>(user_data);
2385 nb->build_idproperties(strip->prop);
2386 nb->build_idproperties(strip->system_properties);
2387 if (strip->sound != nullptr) {
2388 nb->build_sound(strip->sound);
2389 }
2390 if (strip->scene != nullptr) {
2391 nb->build_scene_parameters(strip->scene);
2392 }
2393 if (strip->type == STRIP_TYPE_SCENE && strip->scene != nullptr) {
2394 BLI_assert(strip->scene_view_layer_name != nullptr);
2395 if (strip->flag & SEQ_SCENE_STRIPS) {
2396 nb->build_scene_sequencer(strip->scene);
2397 }
2398 ViewLayer *strip_view_layer = BKE_view_layer_find(strip->scene, strip->scene_view_layer_name);
2399 nb->build_scene_speakers(strip->scene, strip_view_layer);
2400 }
2401
2402 if (strip->type == STRIP_TYPE_COMPOSITOR && strip->effectdata) {
2403 CompositorEffectVars *comp_data = static_cast<CompositorEffectVars *>(strip->effectdata);
2404 if (comp_data->node_group) {
2405 nb->build_nodetree(comp_data->node_group);
2406 }
2407 }
2408 for (StripModifierData &modifier : strip->modifiers) {
2410 continue;
2411 }
2412
2413 const SequencerCompositorModifierData *modifier_data =
2414 reinterpret_cast<SequencerCompositorModifierData *>(&modifier);
2415 if (!modifier_data->node_group) {
2416 continue;
2417 }
2418 nb->build_nodetree(modifier_data->node_group);
2419 }
2420 /* TODO(sergey): Movie clip, scene, camera, mask. */
2421 return true;
2422}
2423
2425{
2426 if (scene->ed == nullptr) {
2427 return;
2428 }
2430 return;
2431 }
2432 build_scene_audio(scene);
2433 Scene *scene_cow = get_cow_datablock(scene);
2434 add_operation_node(&scene->id,
2437 [scene_cow](blender::Depsgraph *depsgraph) {
2438 seq::eval_strips(depsgraph, scene_cow, &scene_cow->ed->seqbase);
2439 });
2440 /* Make sure data for sequences is in the graph. */
2442}
2443
2445{
2447 return;
2448 }
2449
2450 OperationNode *audio_entry_node = add_operation_node(
2452 audio_entry_node->set_as_entry();
2453
2455
2456 Scene *scene_cow = get_cow_datablock(scene);
2457 add_operation_node(&scene->id,
2460 [scene_cow](blender::Depsgraph *depsgraph) {
2461 BKE_scene_update_tag_audio_volume(depsgraph, scene_cow);
2462 });
2463}
2464
2466{
2467 BKE_view_layer_synced_ensure(*bmain_, scene, view_layer);
2468 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
2469 Object *object = base.object;
2470 if (object->type != OB_SPEAKER || !need_pull_base_into_graph(&base)) {
2471 continue;
2472 }
2473 /* NOTE: Can not use base because it does not belong to a current view layer. */
2474 build_object(-1, base.object, DEG_ID_LINKED_INDIRECTLY, true);
2475 }
2476}
2477
2478/* **** ID traversal callbacks functions **** */
2479
2481 Object * /*object*/,
2482 ID **idpoin,
2483 LibraryForeachIDCallbackFlag /*cb_flag*/)
2484{
2485 BuilderWalkUserData *data = static_cast<BuilderWalkUserData *>(user_data);
2486 ID *id = *idpoin;
2487 if (id == nullptr) {
2488 return;
2489 }
2490 switch (id->id_type()) {
2491 case ID_OB:
2492 data->builder->build_object(-1, id_cast<Object *>(id), DEG_ID_LINKED_INDIRECTLY, false);
2493 break;
2494 default:
2495 data->builder->build_id(id);
2496 break;
2497 }
2498}
2499
2501 ID **idpoin,
2502 bool /*is_reference*/,
2503 void *user_data)
2504{
2505 BuilderWalkUserData *data = static_cast<BuilderWalkUserData *>(user_data);
2506 ID *id = *idpoin;
2507 if (id == nullptr) {
2508 return;
2509 }
2510 switch (id->id_type()) {
2511 case ID_OB:
2512 data->builder->build_object(-1, id_cast<Object *>(id), DEG_ID_LINKED_INDIRECTLY, false);
2513 break;
2514 default:
2515 data->builder->build_id(id);
2516 break;
2517 }
2518}
2519
2524
2525} // namespace blender::deg
Blender kernel action and pose functionality.
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
#define DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
#define DRIVER_TARGETS_LOOPER_END
Low-level operations for grease pencil.
#define MAIN_ID_SESSION_UID_UNSET
General operations, lookup, etc. for blender lights.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
API for Blender-side Rigid Body stuff.
Volume data-block.
#define ID_TYPE_USE_COPY_ON_EVAL(_id_type)
Definition DNA_ID.h:746
#define ID_TYPE_SUPPORTS_PARAMS_WITHOUT_COW(id_type)
Definition DNA_ID.h:751
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
Read Blender memory allocation and freeing.
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
void append(const T &value)
bool check_is_built(ID *id, int tag=TAG_COMPLETE) const
bool check_is_built_and_tag(ID *id, int tag=TAG_COMPLETE)
Set< const ID * > get_ids() const
virtual bool need_pull_base_into_graph(const Base *base)
static const char * get_rna_path_relative_to_scene_camera(const Scene *scene, const PointerRNA &target_prop, const char *rna_path)
DepsgraphBuilder(Main *bmain, Depsgraph *graph, DepsgraphBuilderCache *cache)
virtual bool is_modifier_visibility_animated(const Object *object, const ModifierData *modifier)
ComponentNode * find_component_node(const ID *id, NodeType comp_type, const char *comp_name="")
virtual void build_scene_parameters(Scene *scene)
virtual void build_scene_sequencer(Scene *scene)
virtual void build_object_data_camera(Object *object)
virtual void build_object_data_geometry(Object *object)
virtual void build_object_pointcache(Object *object)
virtual void build_world(World *world)
virtual void build_object(int base_index, Object *object, eDepsNode_LinkedState_Type linked_state, bool is_visible)
OperationNode * ensure_operation_node(ID *id, NodeType comp_type, const char *comp_name, OperationCode opcode, const DepsEvalOperationCb &op=nullptr, const char *name="", int name_tag=-1)
virtual void build_id(ID *id, bool force_be_visible=false)
virtual void build_freestyle_linestyle(FreestyleLineStyle *linestyle)
virtual void build_scene_speakers(Scene *scene, ViewLayer *view_layer)
virtual void build_cachefile(CacheFile *cache_file)
virtual void build_object_instance_collection(Object *object, bool is_object_visible)
virtual void build_object_data_speaker(Object *object)
OperationNode * add_operation_node(ComponentNode *comp_node, OperationCode opcode, const DepsEvalOperationCb &op=nullptr, const char *name="", int name_tag=-1)
virtual void build_vfont(VFont *vfont)
OperationNode * find_operation_node(const ID *id, NodeType comp_type, const char *comp_name, OperationCode opcode, const char *name="", int name_tag=-1)
virtual void build_object_data(Object *object)
virtual void build_particle_settings(ParticleSettings *part)
static void constraint_walk(bConstraint *constraint, ID **idpoin, bool is_reference, void *user_data)
virtual void build_driver_id_property(const PointerRNA &target_prop, const char *rna_path_from_target_prop)
virtual void build_particle_systems(Object *object, bool is_object_visible)
virtual void build_dimensions(Object *object)
virtual void build_armature(bArmature *armature)
virtual void build_scene_audio(Scene *scene)
ComponentNode * add_component_node(ID *id, NodeType comp_type, const char *comp_name="")
virtual void build_armature_bone_collections(Span< BoneCollection * > collections)
virtual void build_driver_variables(ID *id, FCurve *fcurve)
virtual void build_action(bAction *action)
virtual void build_armature_bones(ListBaseT< Bone > *bones)
virtual void build_driver_scene_camera_variable(Scene *scene, const char *camera_path)
virtual Set< const ID * > get_built_ids() const
virtual void build_material(Material *ma)
virtual void build_animdata_nlastrip_targets(ListBaseT< NlaStrip > *strips)
virtual void build_materials(Material **materials, int num_materials)
virtual void build_collection(LayerCollection *from_layer_collection, Collection *collection)
virtual void build_rigidbody(Scene *scene)
virtual void build_empty_object(Object *object)
virtual void build_object_transform(Object *object)
virtual void build_light_linking_collection(Collection *collection)
static void modifier_walk(void *user_data, struct Object *object, struct ID **idpoin, LibraryForeachIDCallbackFlag cb_flag)
virtual void build_movieclip(MovieClip *clip)
T * get_cow_datablock(const T *orig) const
virtual void build_object_data_light(Object *object)
virtual void build_image(Image *image)
virtual void build_speaker(Speaker *speaker)
virtual void build_sound(bSound *sound)
Vector< PersistentOperationKey > needs_update_operations_
virtual void build_object_data_geometry_datablock(ID *obdata)
DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph, DepsgraphBuilderCache *cache)
Vector< PersistentOperationKey > saved_entry_tags_
virtual void build_object_flags(int base_index, Object *object, eDepsNode_LinkedState_Type linked_state)
ID * get_cow_id(const ID *id_orig) const
virtual void build_rig(Object *object)
virtual void build_lightprobe(LightProbe *probe)
int foreach_id_cow_detect_need_for_update_callback(ID *id_cow_self, ID *id_pointer)
virtual void build_nodetree(bNodeTree *ntree)
virtual void build_idproperties(IDProperty *id_property)
virtual void build_camera(Camera *camera)
virtual void build_light(Light *lamp)
virtual void build_driver(ID *id, FCurve *fcurve, int driver_index)
virtual void build_object_light_linking(Object *object)
bool has_operation_node(ID *id, NodeType comp_type, const char *comp_name, OperationCode opcode, const char *name="", int name_tag=-1)
virtual void build_nodetree_socket(bNodeSocket *socket)
virtual void build_object_data_lightprobe(Object *object)
virtual void build_animdata_drivers(ID *id, AnimData *adt)
virtual void build_object_data_grease_pencil(Object *object)
virtual void build_object_constraints(Object *object)
virtual void build_object_shading(Object *object)
virtual void build_object_modifiers(Object *object)
virtual void build_object_from_layer(int base_index, Object *object, eDepsNode_LinkedState_Type linked_state)
void add_emitter(const Scene &scene, const Object &emitter)
#define layer
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
bNodeTree ** node_tree_ptr_from_id(ID *id)
Definition node.cc:5312
uint64_t IDComponentsMask
bool rna_prop_affects_parameters_node(const PointerRNA *ptr, const PropertyRNA *prop)
std::function< void(blender::Depsgraph *)> DepsEvalOperationCb
static bool strip_node_build_cb(Strip *strip, void *user_data)
bool deg_eval_copy_is_expanded(const ID *id_cow)
void deg_free_eval_copy_datablock(ID *id_cow)
bool deg_eval_copy_is_needed(const ID *id_orig)
bool data_path_maybe_shared(const ID &id, const StringRef data_path)
@ DEG_ID_LINKED_INDIRECTLY
static int foreach_id_cow_detect_need_for_update_callback(LibraryIDLinkCallbackData *cb_data)
void deg_create_eval_copy(blender::Depsgraph *graph, const IDNode *id_node)
void graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, uint flags, eUpdateSource update_source)
void deg_evaluate_object_node_visibility(blender::Depsgraph *depsgraph, IDNode *id_node)
void foreach_strip(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
Definition iterator.cc:60
void BKE_particle_system_eval_init(struct Depsgraph *depsgraph, struct Object *object)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_curve_eval_geometry(Depsgraph *depsgraph, Curve *curve)
Definition curve.cc:5517
void BKE_animsys_eval_driver_unshare(Depsgraph *depsgraph, ID *id)
Definition anim_sys.cc:3812
void BKE_id_eval_properties_copy(ID *id_cow, ID *id)
void BKE_shaderfx_foreach_ID_link(Object *ob, ShaderFxIDWalkFunc walk, void *user_data)
Definition shader_fx.cc:239
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
@ NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION
short * BKE_object_material_len_p(Object *ob)
Material *** BKE_object_material_array_p(Object *ob)
PointerRNA RNA_id_pointer_create(ID *id)
const char * RNA_property_identifier(const PropertyRNA *prop)
@ IDWALK_IGNORE_EMBEDDED_ID
void BKE_mask_eval_update(Depsgraph *depsgraph, Mask *mask)
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
void void void BKE_modifiers_foreach_ID_link(Object *ob, IDWalkFunc walk, void *user_data)
void BKE_image_user_id_eval_animation(Depsgraph *depsgraph, ID *id)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
bool BKE_ptcache_object_has(struct Scene *scene, struct Object *ob, int duplis)
void BKE_lattice_eval_geometry(Depsgraph *depsgraph, Lattice *latt)
Definition lattice.cc:711
void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
bool driver_get_target_property(const DriverTargetContext *driver_target_context, struct DriverVar *dvar, struct DriverTarget *dtar, struct PointerRNA *r_prop)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
unsigned int uint32_t
Definition BKE_text.h:81
void BKE_grease_pencil_eval_geometry(Depsgraph *depsgraph, GreasePencil *grease_pencil)
Key * BKE_key_from_id(ID *id)
Definition key.cc:1291
bool BKE_nlatrack_is_enabled(const AnimData &adt, const NlaTrack &nlt)
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
BMesh const char void * data
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
@ DAG_EVAL_VIEWPORT
void BKE_volume_eval_geometry(Depsgraph *depsgraph, Volume *volume)
void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
ViewLayer * BKE_view_layer_find(const Scene *scene, const char *layer_name)
@ IDWALK_RET_STOP_ITER
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_TAG_COPIED_ON_EVAL
Definition DNA_ID.h:1000
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
void BKE_grease_pencil_modifiers_foreach_ID_link(struct Object *ob, GreasePencilIDWalkFunc walk, void *user_data)
void BKE_movieclip_eval_update(Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
void BKE_constraints_id_loop(ListBaseT< bConstraint > *list, ConstraintIDFunc func, const int flag, void *userdata)
void BKE_mask_eval_animation(Depsgraph *depsgraph, Mask *mask)
LibraryForeachIDCallbackFlag
@ DTAR_FLAG_STRUCT_REF
@ eSeqModifierType_Compositor
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:449
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file)
Definition cachefile.cc:328
void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, int driver_index, FCurve *fcu_orig)
Definition anim_sys.cc:3844
@ IDP_TYPE_FILTER_ID
void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id)
Definition anim_sys.cc:3777
bool RNA_path_resolve_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition rna_path.cc:548
ListBaseT< FCurve > drivers
ListBaseT< NlaTrack > nla_tracks
ListBaseT< DriverVar > variables
ListBaseT< CollectionChild > children
ListBaseT< CollectionObject > gobject
struct Object * textoncurve
struct Object * bevobj
struct Object * taperobj
ListBaseT< Strip > seqbase
ChannelDriver * driver
IDPropertyData data
Definition DNA_ID.h:157
IDProperty * system_properties
Definition DNA_ID.h:490
short flag
Definition DNA_ID.h:439
IDProperty * properties
Definition DNA_ID.h:481
unsigned int recalc
Definition DNA_ID.h:446
struct ID * orig_id
Definition DNA_ID.h:502
ListBaseT< KeyBlock > block
ListBaseT< MaskSpline > splines
MaskSplinePoint * points
ListBaseT< NlaStrip > strips
ListBaseT< ModifierData > modifiers
eParticlePhysicsType phystype
struct Collection * instance_collection
ListBaseT< ParticleTarget > targets
StructRNA * type
Definition RNA_types.hh:63
struct Collection * constraints
struct Editing * ed
struct Object * camera
ListBaseT< TimeMarker > markers
struct RigidBodyWorld * rigidbody_world
struct bSound * sound
struct Object * camera
struct IDProperty * prop
ListBaseT< struct TimeMarker > markers
ListBaseT< Bone > bonebase
eNodeSocketDatatype type
eNodeTree_Type type
bke::bNodeTreeRuntime * runtime
std::string identifier() const override
OperationNode * find_operation(OperationIDKey key) const
OperationNode * add_operation(const DepsEvalOperationCb &op, OperationCode opcode, const StringRef name="", int name_tag=-1)
ID * get_cow_id(const ID *id_orig) const
Definition depsgraph.cc:248
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:102
light_linking::Cache light_linking_cache
Definition depsgraph.hh:187
IDNode * add_id_node(ID *id, ID *id_cow_hint=nullptr)
Definition depsgraph.cc:107
OperationNodes operations
Definition depsgraph.hh:135
eEvaluationMode mode
Definition depsgraph.hh:145
TimeSourceNode * add_time_source()
Definition depsgraph.cc:83
Set< OperationNode * > entry_tags
Definition depsgraph.hh:129
IDComponentsMask previously_visible_components_mask
DEGCustomDataMeshMasks customdata_masks
DEGCustomDataMeshMasks previous_customdata_masks
ComponentNode * add_component(NodeType type, StringRef name="")
IDComponentsMask visible_components_mask
Map< ComponentIDKey, ComponentNode * > components
eDepsNode_LinkedState_Type linked_state
ComponentNode * find_component(NodeType type, StringRef name="") const
uint32_t previous_eval_flags
void tag_update(Depsgraph *graph, eUpdateSource source) override
std::string identifier() const override