Blender V5.3
depsgraph_tag.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 <atomic>
14#include <cstdint>
15#include <cstdio>
16#include <cstring> /* required for memset */
17
18#include "BLI_index_range.hh"
19#include "BLI_math_bits.hh"
20#include "BLI_utildefines.hh"
21
22#include "DNA_curve_types.h"
23#include "DNA_key_types.h"
24#include "DNA_lattice_types.h"
25#include "DNA_mesh_types.h"
26#include "DNA_object_types.h"
27
28#include "BKE_anim_data.hh"
29#include "BKE_global.hh"
30#include "BKE_idtype.hh"
31#include "BKE_image.hh"
32#include "BKE_lib_override.hh"
33#include "BKE_node.hh"
34#include "BKE_scene.hh"
35#include "BKE_workspace.hh"
36
37#include "DEG_depsgraph.hh"
40
42#include "intern/depsgraph.hh"
52
53namespace blender {
54
55/* *********************** */
56/* Update Tagging/Flushing */
57
58namespace deg {
59
60namespace {
61
62void depsgraph_geometry_tag_to_component(const ID *id, NodeType *component_type)
63{
66 *component_type = result;
67 }
68}
69
70bool is_selectable_data_id_type(const ID_Type id_type)
71{
73}
74
75void depsgraph_select_tag_to_component_opcode(const ID *id,
76 NodeType *component_type,
77 OperationCode *operation_code)
78{
79 const ID_Type id_type = GS(id->name);
80 if (id_type == ID_SCE) {
81 /* We need to flush base flags to all objects in a scene since we
82 * don't know which ones changed. However, we don't want to update
83 * the whole scene, so pick up some operation which will do as less
84 * as possible.
85 *
86 * TODO(sergey): We can introduce explicit exit operation which
87 * does nothing and which is only used to cascade flush down the
88 * road. */
89 *component_type = NodeType::LAYER_COLLECTIONS;
90 *operation_code = OperationCode::VIEW_LAYER_EVAL;
91 }
92 else if (id_type == ID_OB) {
93 *component_type = NodeType::OBJECT_FROM_LAYER;
95 }
96 else if (is_selectable_data_id_type(id_type)) {
97 *component_type = NodeType::BATCH_CACHE;
99 }
100 else {
101 *component_type = NodeType::COPY_ON_EVAL;
102 *operation_code = OperationCode::COPY_ON_EVAL;
103 }
104}
105
106void depsgraph_base_flags_tag_to_component_opcode(const ID *id,
107 NodeType *component_type,
108 OperationCode *operation_code)
109{
110 const ID_Type id_type = GS(id->name);
111 if (id_type == ID_SCE) {
112 *component_type = NodeType::LAYER_COLLECTIONS;
113 *operation_code = OperationCode::VIEW_LAYER_EVAL;
114 }
115 else if (id_type == ID_OB) {
116 *component_type = NodeType::OBJECT_FROM_LAYER;
117 *operation_code = OperationCode::OBJECT_BASE_FLAGS;
118 }
119}
120
121OperationCode psysTagToOperationCode(IDRecalcFlag tag)
122{
123 if (tag == ID_RECALC_PSYS_RESET) {
125 }
127}
128
129void depsgraph_tag_to_component_opcode(const ID *id,
130 IDRecalcFlag tag,
131 NodeType *component_type,
132 OperationCode *operation_code)
133{
134 const ID_Type id_type = GS(id->name);
135 *component_type = NodeType::UNDEFINED;
136 *operation_code = OperationCode::OPERATION;
137 /* Special case for now, in the future we should get rid of this. */
138 if (tag == 0) {
139 *component_type = NodeType::ID_REF;
140 *operation_code = OperationCode::OPERATION;
141 return;
142 }
143 switch (tag) {
145 *component_type = NodeType::TRANSFORM;
146 break;
148 depsgraph_geometry_tag_to_component(id, component_type);
149 break;
151 *component_type = NodeType::ANIMATION;
152 break;
157 if (id_type == ID_PA) {
158 /* NOTES:
159 * - For particle settings node we need to use different
160 * component. Will be nice to get this unified with object,
161 * but we can survive for now with single exception here.
162 * Particles needs reconsideration anyway, */
163 *component_type = NodeType::PARTICLE_SETTINGS;
164 *operation_code = psysTagToOperationCode(tag);
165 }
166 else {
167 *component_type = NodeType::PARTICLE_SYSTEM;
168 }
169 break;
171 *component_type = NodeType::COPY_ON_EVAL;
172 break;
174 *component_type = NodeType::SHADING;
175 break;
176 case ID_RECALC_SELECT:
177 depsgraph_select_tag_to_component_opcode(id, component_type, operation_code);
178 break;
180 depsgraph_base_flags_tag_to_component_opcode(id, component_type, operation_code);
181 break;
183 *component_type = NodeType::POINT_CACHE;
184 break;
186 /* There is no such node in depsgraph, this tag is to be handled
187 * separately. */
188 break;
190 *component_type = NodeType::SEQUENCER;
191 break;
197 case ID_RECALC_AUDIO:
198 *component_type = NodeType::AUDIO;
199 break;
201 *component_type = NodeType::PARAMETERS;
202 break;
203 case ID_RECALC_SOURCE:
204 *component_type = NodeType::PARAMETERS;
205 break;
207 case ID_RECALC_ALL:
209 BLI_assert_msg(0, "Should not happen");
210 break;
212 break; /* Must be ignored by depsgraph. */
214 *component_type = NodeType::NTREE_OUTPUT;
215 *operation_code = OperationCode::NTREE_OUTPUT;
216 break;
218 *component_type = NodeType::HIERARCHY;
219 *operation_code = OperationCode::HIERARCHY;
220 break;
222 *component_type = NodeType::COMPOSITOR;
223 *operation_code = OperationCode::COMPOSITOR_EVAL;
224 break;
225
230 /* Silently ignore.
231 * The bits might be passed here from ID_RECALC_ALL. This is not a code-mistake, but just the
232 * way how the recalc flags are handled. */
233 break;
234 }
235}
236
237void id_tag_update_ntree_special(
238 Main *bmain, Depsgraph *graph, ID *id, uint flags, eUpdateSource update_source)
239{
240 bNodeTree *ntree = bke::node_tree_from_id(id);
241 if (ntree == nullptr) {
242 return;
243 }
244 graph_id_tag_update(bmain, graph, &ntree->id, flags, update_source);
245}
246
247void depsgraph_update_editors_tag(Main *bmain, Depsgraph *graph, ID *id)
248{
249 /* NOTE: We handle this immediately, without delaying anything, to be
250 * sure we don't cause threading issues with OpenGL. */
251 /* TODO(sergey): Make sure this works for evaluated data-blocks as well. */
252 DEGEditorUpdateContext update_ctx = {nullptr};
253 update_ctx.bmain = bmain;
254 update_ctx.depsgraph = reinterpret_cast<::blender::Depsgraph *>(graph);
255 update_ctx.scene = graph->scene;
256 update_ctx.view_layer = graph->view_layer;
257 deg_editors_id_update(&update_ctx, id);
258}
259
260void depsgraph_id_tag_copy_on_write(Depsgraph *graph, IDNode *id_node, eUpdateSource update_source)
261{
262 ComponentNode *cow_comp = id_node->find_component(NodeType::COPY_ON_EVAL);
263 if (cow_comp == nullptr) {
264 BLI_assert(!deg_eval_copy_is_needed(GS(id_node->id_orig->name)));
265 return;
266 }
267 cow_comp->tag_update(graph, update_source);
268}
269
270void depsgraph_tag_component(Depsgraph *graph,
271 IDNode *id_node,
272 NodeType component_type,
273 OperationCode operation_code,
274 eUpdateSource update_source)
275{
276 ComponentNode *component_node = id_node->find_component(component_type);
277 /* NOTE: Animation component might not be existing yet (which happens when adding new driver or
278 * adding a new keyframe), so the required copy-on-evaluation tag needs to be taken care
279 * explicitly here. */
280 if (component_node == nullptr) {
281 if (component_type == NodeType::ANIMATION) {
282 id_node->is_cow_explicitly_tagged = true;
283 depsgraph_id_tag_copy_on_write(graph, id_node, update_source);
284 }
285 return;
286 }
287 if (operation_code == OperationCode::OPERATION) {
288 component_node->tag_update(graph, update_source);
289 }
290 else {
291 OperationNode *operation_node = component_node->find_operation(operation_code);
292 if (operation_node != nullptr) {
293 operation_node->tag_update(graph, update_source);
294 }
295 }
296 /* If component depends on copy-on-evaluation, tag it as well. */
297 if (component_node->need_tag_cow_before_update(IDRecalcFlag(id_node->id_cow->recalc))) {
298 depsgraph_id_tag_copy_on_write(graph, id_node, update_source);
299 }
300 if (component_type == NodeType::COPY_ON_EVAL) {
301 id_node->is_cow_explicitly_tagged = true;
302 }
303}
304
305/* This is a tag compatibility with legacy code.
306 *
307 * Mainly, old code was tagging object with ID_RECALC_GEOMETRY tag to inform
308 * that object's data data-block changed. Now API expects that ID is given
309 * explicitly, but not all areas are aware of this yet. */
310void deg_graph_id_tag_legacy_compat(
311 Main *bmain, Depsgraph *depsgraph, ID *id, IDRecalcFlag tag, eUpdateSource update_source)
312{
313 if (ELEM(tag, ID_RECALC_GEOMETRY, 0)) {
314 switch (GS(id->name)) {
315 case ID_OB: {
316 Object *object = id_cast<Object *>(id);
317 ID *data_id = object->data;
318 if (data_id != nullptr) {
319 graph_id_tag_update(bmain, depsgraph, data_id, 0, update_source);
320 }
321 break;
322 }
323 /* TODO(sergey): Shape keys are annoying, maybe we should find a
324 * way to chain geometry evaluation to them, so we don't need extra
325 * tagging here. */
326 case ID_ME: {
327 Mesh *mesh = id_cast<Mesh *>(id);
328 if (mesh->key != nullptr) {
329 ID *key_id = &mesh->key->id;
330 if (key_id != nullptr) {
331 graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
332 }
333 }
334 break;
335 }
336 case ID_LT: {
337 Lattice *lattice = id_cast<Lattice *>(id);
338 if (lattice->key != nullptr) {
339 ID *key_id = &lattice->key->id;
340 if (key_id != nullptr) {
341 graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
342 }
343 }
344 break;
345 }
346 case ID_CU_LEGACY: {
347 Curve *curve = id_cast<Curve *>(id);
348 if (curve->key != nullptr) {
349 ID *key_id = &curve->key->id;
350 if (key_id != nullptr) {
351 graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
352 }
353 }
354 break;
355 }
356 default:
357 break;
358 }
359 }
360}
361
362void graph_id_tag_update_single_flag(Main *bmain,
363 Depsgraph *graph,
364 ID *id,
365 IDNode *id_node,
366 IDRecalcFlag tag,
367 eUpdateSource update_source)
368{
369 if (tag == ID_RECALC_EDITORS) {
370 if (graph != nullptr && graph->is_active) {
371 depsgraph_update_editors_tag(bmain, graph, id);
372 }
373 return;
374 }
375 /* Get description of what is to be tagged. */
376 NodeType component_type;
377 OperationCode operation_code;
378 depsgraph_tag_to_component_opcode(id, tag, &component_type, &operation_code);
379 /* Check whether we've got something to tag. */
380 if (component_type == NodeType::UNDEFINED) {
381 /* Given ID does not support tag. */
382 /* TODO(sergey): Shall we raise some panic here? */
383 return;
384 }
385 /* Some sanity checks before moving forward. */
386 if (id_node == nullptr) {
387 /* Happens when object is tagged for update and not yet in the
388 * dependency graph (but will be after relations update). */
389 return;
390 }
391 /* Tag ID recalc flag. */
392 DepsNodeFactory *factory = type_get_factory(component_type);
393 BLI_assert(factory != nullptr);
394 id_node->id_cow->recalc |= factory->id_recalc_tag();
395 /* Tag corresponding dependency graph operation for update. */
396 if (component_type == NodeType::ID_REF) {
397 id_node->tag_update(graph, update_source);
398 }
399 else {
400 depsgraph_tag_component(graph, id_node, component_type, operation_code, update_source);
401 }
402 /* TODO(sergey): Get rid of this once all areas are using proper data ID
403 * for tagging. */
404 deg_graph_id_tag_legacy_compat(bmain, graph, id, tag, update_source);
405}
406
407std::string stringify_update_bitfield(uint flags)
408{
409 if (flags == 0) {
410 return "LEGACY_0";
411 }
412 return DEG_stringify_recalc_flags(flags);
413}
414
415const char *update_source_as_string(eUpdateSource source)
416{
417 switch (source) {
419 return "TIME";
421 return "USER_EDIT";
423 return "RELATIONS";
425 return "VISIBILITY";
427 return "SIDE_EFFECT_REQUEST";
428 }
429 BLI_assert_msg(0, "Should never happen.");
430 return "UNKNOWN";
431}
432
433int deg_recalc_flags_for_legacy_zero()
434{
435 const uint ID_RECALC_PROVISION_ALL = (ID_RECALC_PROVISION_28 | ID_RECALC_PROVISION_29 |
438 ID_RECALC_SOURCE | ID_RECALC_EDITORS | ID_RECALC_PROVISION_ALL);
439}
440
441int deg_recalc_flags_effective(Depsgraph *graph, uint flags)
442{
443 if (graph != nullptr) {
444 if (!graph->is_active) {
445 return 0;
446 }
447 }
448 if (flags == 0) {
449 return deg_recalc_flags_for_legacy_zero();
450 }
451 return flags;
452}
453
454/* Special tag function which tags all components which needs to be tagged
455 * for update flag=0.
456 *
457 * TODO(sergey): This is something to be avoid in the future, make it more
458 * explicit and granular for users to tag what they really need. */
459void deg_graph_node_tag_zero(Main *bmain,
460 Depsgraph *graph,
461 IDNode *id_node,
462 eUpdateSource update_source)
463{
464 if (id_node == nullptr) {
465 return;
466 }
467 ID *id = id_node->id_orig;
468 /* TODO(sergey): Which recalc flags to set here? */
469 id_node->id_cow->recalc |= deg_recalc_flags_for_legacy_zero();
470
471 for (ComponentNode *comp_node : id_node->components.values()) {
472 if (comp_node->type == NodeType::ANIMATION) {
473 continue;
474 }
475 if (comp_node->type == NodeType::COPY_ON_EVAL) {
476 id_node->is_cow_explicitly_tagged = true;
477 }
478
479 comp_node->tag_update(graph, update_source);
480 }
481 deg_graph_id_tag_legacy_compat(bmain, graph, id, IDRecalcFlag(0), update_source);
482}
483
484/* Implicit tagging of the parameters component on other changes.
485 *
486 * This takes care of ensuring that if a change made in C side on parameters which affect,
487 * say, geometry and explicit tag only done for geometry, parameters are also tagged to give
488 * drivers a chance to re-evaluate for the new values. */
489void deg_graph_tag_parameters_if_needed(Main *bmain,
490 Depsgraph *graph,
491 ID *id,
492 IDNode *id_node,
493 const uint flags,
494 const eUpdateSource update_source)
495{
496 if (flags == 0) {
497 /* Tagging for 0 flags is handled in deg_graph_node_tag_zero(), and parameters are handled
498 * there as well. */
499 return;
500 }
501
502 if (flags & ID_RECALC_PARAMETERS) {
503 /* Parameters are already tagged for update explicitly, no need to run extra logic here. */
504 return;
505 }
506
507 /* Clear flags which are known to not affect parameters usable by drivers. */
508 const uint clean_flags = flags &
511 /* While drivers may use the current-frame, this value is assigned
512 * explicitly and doesn't require the scene to be copied again. */
514
515 if (clean_flags == 0) {
516 /* Changes are limited to only things which are not usable by drivers. */
517 return;
518 }
519
520 graph_id_tag_update_single_flag(bmain, graph, id, id_node, ID_RECALC_PARAMETERS, update_source);
521}
522
523void graph_tag_on_visible_update(Depsgraph *graph, const bool do_time)
524{
525 graph->need_tag_id_on_graph_visibility_update = true;
526 graph->need_tag_id_on_graph_visibility_time_update |= do_time;
527}
528
529} /* namespace */
530
532{
534 return;
535 }
536
537 const bool do_time = graph->need_tag_id_on_graph_visibility_time_update;
538 Main *bmain = graph->bmain;
539
540 /* NOTE: It is possible to have this function called with `do_time=false` first and later (prior
541 * to evaluation though) with `do_time=true`. This means early output checks should be aware of
542 * this. */
543 for (deg::IDNode *id_node : graph->id_nodes) {
544 const ID_Type id_type = GS(id_node->id_orig->name);
545
546 if (!id_node->visible_components_mask) {
547 /* ID has no components which affects anything visible.
548 * No need bother with it to tag or anything. */
549 continue;
550 }
551 uint flags = 0;
552 if (!deg::deg_eval_copy_is_expanded(id_node->id_cow)) {
553 flags |= ID_RECALC_SYNC_TO_EVAL;
554 if (do_time) {
555 if (BKE_animdata_from_id(id_node->id_orig) != nullptr) {
556 flags |= ID_RECALC_ANIMATION;
557 }
558 }
559 }
560 else {
562 /* The ID was already visible and evaluated, all the subsequent
563 * updates and tags are to be done explicitly. */
564 continue;
565 }
566 }
567 /* We only tag components which needs an update. Tagging everything is
568 * not a good idea because that might reset particles cache (or any
569 * other type of cache).
570 *
571 * TODO(sergey): Need to generalize this somehow. */
572 if (id_type == ID_OB) {
574 }
575 /* For non-copy-on-eval datablocks like images, there is no need to update when
576 * they just got added to the depsgraph and there is no flag indicating
577 * a specific change that was made to them. Unlike evaluated datablocks which
578 * have just been copied.
579 * This helps preserve cached image draw data for the compositor. */
580 if (ID_TYPE_USE_COPY_ON_EVAL(id_type) || flags != 0) {
581 graph_id_tag_update(bmain, graph, id_node->id_orig, flags, DEG_UPDATE_SOURCE_VISIBILITY);
582 }
583 if (id_type == ID_SCE) {
584 /* Make sure collection properties are up to date. */
586 }
587 /* Now when ID is updated to the new visibility state, prevent it from
588 * being re-tagged again. Simplest way to do so is to pretend that it
589 * was already updated by the "previous" dependency graph.
590 *
591 * NOTE: Even if the on_visible_update() is called from the state when
592 * dependency graph is tagged for relations update, it will be fine:
593 * since dependency graph builder re-schedules entry tags, all the
594 * tags we request from here will be applied in the updated state of
595 * dependency graph. */
597 }
598
601}
602
604{
605 const ID_Type id_type = GS(id->name);
606 switch (id_type) {
607 case ID_OB: {
608 const Object *object = id_cast<Object *>(const_cast<ID *>(id));
609 switch (object->type) {
610 /* Empties don't contain original geometry, but can have evaluated geometry if there are
611 * modifiers. */
612 case OB_EMPTY: {
613 if (!BLI_listbase_is_empty(&object->modifiers)) {
614 return NodeType::GEOMETRY;
615 }
616 break;
617 }
618 case OB_MESH:
619 case OB_CURVES_LEGACY:
620 case OB_SURF:
621 case OB_FONT:
622 case OB_LATTICE:
623 case OB_MBALL:
624 case OB_CURVES:
625 case OB_POINTCLOUD:
626 case OB_VOLUME:
627 case OB_GREASE_PENCIL:
628 return NodeType::GEOMETRY;
629 case OB_ARMATURE:
630 return NodeType::EVAL_POSE;
631 /* TODO(sergey): More cases here? */
632 default:
633 break;
634 }
635 break;
636 }
637 case ID_ME:
638 case ID_CU_LEGACY:
639 case ID_LT:
640 case ID_MB:
641 case ID_CV:
642 case ID_PT:
643 case ID_VO:
644 case ID_GR:
645 return NodeType::GEOMETRY;
646 case ID_PA: /* Particles */
647 return NodeType::UNDEFINED;
648 case ID_LP:
650 case ID_GD_LEGACY:
651 return NodeType::GEOMETRY;
652 case ID_PAL: /* Palettes */
654 case ID_MSK:
656 case ID_GP:
657 return NodeType::GEOMETRY;
658 default:
659 break;
660 }
661 return NodeType::UNDEFINED;
662}
663
664void id_tag_update(Main *bmain, ID *id, uint flags, eUpdateSource update_source)
665{
666 graph_id_tag_update(bmain, nullptr, id, flags, update_source);
667 for (deg::Depsgraph *depsgraph : deg::get_all_registered_graphs(bmain)) {
668 graph_id_tag_update(bmain, depsgraph, id, flags, update_source);
669 }
670
671 if (update_source & DEG_UPDATE_SOURCE_USER_EDIT) {
673 }
674
675 /* Accumulate all tags for an ID between two undo steps, so they can be
676 * replayed for undo. */
677 id->recalc_after_undo_push |= deg_recalc_flags_effective(nullptr, flags);
678}
679
680/* IDs that are not covered by the copy-on-evaluation system track updates by storing a runtime
681 * update count that gets updated every time the ID is tagged for update. The updated value is the
682 * value of a global atomic that is initially zero and gets incremented every time *any* ID of the
683 * same type gets updated.
684 *
685 * The update counts can be used to check if the ID was changed since the last time it was cached
686 * by comparing its current update count with the one stored at the moment the ID was cached.
687 *
688 * A global atomic is used as opposed to incrementing the update count per ID to protect against
689 * the case where the ID is destroyed and a new one is created taking its same pointer location,
690 * which could be perceived as no update even though the ID was recreated entirely.
691 *
692 * Only Image IDs are considered for now, but other IDs could be supported if needed. */
693static void set_id_update_count(ID *id)
694{
695 if (GS(id->name) == ID_IM) {
696 Image *image = reinterpret_cast<Image *>(id);
697 static std::atomic<uint64_t> global_image_update_count = 0;
698 image->runtime->update_count = global_image_update_count.fetch_add(1) + 1;
699 }
700}
701
703 Main *bmain, Depsgraph *graph, ID *id, uint flags, eUpdateSource update_source)
704{
705 const int debug_flags = (graph != nullptr) ?
707 reinterpret_cast<::blender::Depsgraph *>(graph)) :
708 G.debug;
709 if (graph != nullptr && graph->is_evaluating) {
710 if (debug_flags & G_DEBUG_DEPSGRAPH_TAG) {
711 printf("ID tagged for update during dependency graph evaluation.\n");
712 }
713 return;
714 }
715 if (debug_flags & G_DEBUG_DEPSGRAPH_TAG) {
716 printf("%s: id=%s flags=%s source=%s\n",
717 __func__,
718 id->name,
719 stringify_update_bitfield(flags).c_str(),
720 update_source_as_string(update_source));
721 }
722
724
725 IDNode *id_node = (graph != nullptr) ? graph->find_id_node(id) : nullptr;
726 if (graph != nullptr) {
727 DEG_graph_id_type_tag(reinterpret_cast<::blender::Depsgraph *>(graph), GS(id->name));
728 }
729 if (flags == 0) {
730 deg_graph_node_tag_zero(bmain, graph, id_node, update_source);
731 }
732 /* Store original flag in the ID.
733 * Allows to have more granularity than a node-factory based flags. */
734 if (id_node != nullptr) {
735 id_node->id_cow->recalc |= flags;
736 }
737 /* When ID is tagged for update based on an user edits store the recalc flags in the original ID.
738 * This way IDs in the undo steps will have this flag preserved, making it possible to restore
739 * all needed tags when new dependency graph is created on redo.
740 * This is the only way to ensure modifications to animation data (such as keyframes i.e.)
741 * properly triggers animation update for the newly constructed dependency graph on redo (while
742 * usually newly created dependency graph skips animation update to avoid loss of unkeyed
743 * changes). */
744 if (update_source == DEG_UPDATE_SOURCE_USER_EDIT) {
745 id->recalc |= deg_recalc_flags_effective(graph, flags);
746 }
747 uint current_flag = flags;
748 while (current_flag != 0) {
749 IDRecalcFlag tag = IDRecalcFlag(1 << bitscan_forward_clear_uint(&current_flag));
750 graph_id_tag_update_single_flag(bmain, graph, id, id_node, tag, update_source);
751 }
752 /* Special case for nested node tree data-blocks. */
753 id_tag_update_ntree_special(bmain, graph, id, flags, update_source);
754 /* Direct update tags means that something outside of simulated/cached
755 * physics did change and that cache is to be invalidated.
756 * This is only needed if data changes. If it's just a drawing, we keep the
757 * point cache. */
758 if (update_source == DEG_UPDATE_SOURCE_USER_EDIT && flags != ID_RECALC_SHADING) {
759 graph_id_tag_update_single_flag(
760 bmain, graph, id, id_node, ID_RECALC_POINT_CACHE, update_source);
761 }
762 deg_graph_tag_parameters_if_needed(bmain, graph, id, id_node, flags, update_source);
763}
764
765} // namespace deg
766
768{
769 switch (flag) {
771 return "TRANSFORM";
773 return "GEOMETRY";
775 return "GEOMETRY_ALL_MODES";
777 return "ANIMATION";
779 return "PSYS_REDO";
781 return "PSYS_RESET";
783 return "PSYS_CHILD";
785 return "PSYS_PHYS";
787 return "PSYS_ALL";
789 return "COPY_ON_EVAL";
791 return "SHADING";
792 case ID_RECALC_SELECT:
793 return "SELECT";
795 return "BASE_FLAGS";
797 return "POINT_CACHE";
799 return "EDITORS";
801 return "SEQUENCER_STRIPS";
803 return "FRAME_CHANGE";
805 return "AUDIO_FPS";
807 return "AUDIO_VOLUME";
809 return "AUDIO_MUTE";
811 return "AUDIO_LISTENER";
812 case ID_RECALC_AUDIO:
813 return "AUDIO";
815 return "PARAMETERS";
816 case ID_RECALC_SOURCE:
817 return "SOURCE";
818 case ID_RECALC_ALL:
819 return "ALL";
821 return "TAG_FOR_UNDO";
823 return "ID_RECALC_NTREE_OUTPUT";
825 return "ID_RECALC_HIERARCHY";
827 return "ID_RECALC_COMPOSITOR";
828
833 /* Silently return nullptr, indicating that there is no string representation.
834 *
835 * This is needed due to the way how logging for ID_RECALC_ALL works: it iterates over all
836 * bits and converts then to string. */
837 return nullptr;
838 }
839 return nullptr;
840}
841
842/* Data-Based Tagging. */
843
844void DEG_id_tag_update(ID *id, uint flags)
845{
846 DEG_id_tag_update_ex(G.main, id, flags);
847}
848
849void DEG_id_tag_update_ex(Main *bmain, ID *id, uint flags)
850{
851 if (id == nullptr) {
852 /* Ideally should not happen, but old depsgraph allowed this. */
853 return;
854 }
856}
857
858void DEG_id_tag_update_for_side_effect_request(Depsgraph *depsgraph, ID *id, uint flags)
859{
860 BLI_assert(depsgraph != nullptr);
861 BLI_assert(id != nullptr);
862 deg::Depsgraph *graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
863 Main *bmain = DEG_get_bmain(depsgraph);
865}
866
867void DEG_graph_id_tag_update(Main *bmain, Depsgraph *depsgraph, ID *id, uint flags)
868{
869 deg::Depsgraph *graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
871}
872
874{
875 for (deg::Depsgraph *depsgraph : deg::get_all_registered_graphs(bmain)) {
876 DEG_graph_time_tag_update(reinterpret_cast<::blender::Depsgraph *>(depsgraph));
877 }
878}
879
880void DEG_graph_time_tag_update(Depsgraph *depsgraph)
881{
882 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
883 deg_graph->tag_time_source();
884}
885
886void DEG_graph_id_type_tag(Depsgraph *depsgraph, short id_type)
887{
888 if (id_type == ID_NT) {
889 /* Stupid workaround so parent data-blocks of nested node-tree get looped
890 * over when we loop over tagged data-block types. */
891 DEG_graph_id_type_tag(depsgraph, ID_MA);
892 DEG_graph_id_type_tag(depsgraph, ID_TE);
893 DEG_graph_id_type_tag(depsgraph, ID_LA);
894 DEG_graph_id_type_tag(depsgraph, ID_WO);
895 DEG_graph_id_type_tag(depsgraph, ID_SCE);
896 }
897 const int id_type_index = BKE_idtype_idcode_to_index(id_type);
898 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
899 deg_graph->id_type_updated[id_type_index] = 1;
900}
901
902void DEG_id_type_tag(Main *bmain, short id_type)
903{
904 for (deg::Depsgraph *depsgraph : deg::get_all_registered_graphs(bmain)) {
905 DEG_graph_id_type_tag(reinterpret_cast<Depsgraph *>(depsgraph), id_type);
906 }
907}
908
909void DEG_graph_tag_on_visible_update(Depsgraph *depsgraph, const bool do_time)
910{
911 deg::Depsgraph *graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
912 deg::graph_tag_on_visible_update(graph, do_time);
913}
914
915void DEG_tag_on_visible_update(Main *bmain, const bool do_time)
916{
917 for (deg::Depsgraph *depsgraph : deg::get_all_registered_graphs(bmain)) {
918 deg::graph_tag_on_visible_update(depsgraph, do_time);
919 }
920}
921
922void DEG_enable_editors_update(Depsgraph *depsgraph)
923{
924 deg::Depsgraph *graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
925 graph->use_editors_update = true;
926}
927
928void DEG_editors_update(Depsgraph *depsgraph, bool time)
929{
930 deg::Depsgraph *graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
931 if (!graph->use_editors_update) {
932 return;
933 }
934
935 Scene *scene = DEG_get_input_scene(depsgraph);
936 ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
937 Main *bmain = DEG_get_bmain(depsgraph);
938 bool updated = time || DEG_id_type_any_updated(depsgraph);
939
940 DEGEditorUpdateContext update_ctx = {nullptr};
941 update_ctx.bmain = bmain;
942 update_ctx.depsgraph = depsgraph;
943 update_ctx.scene = scene;
944 update_ctx.view_layer = view_layer;
945 deg::deg_editors_scene_update(&update_ctx, updated);
946}
947
949{
950 id->recalc &= ~ID_RECALC_ALL;
952 /* Clear embedded node trees too. */
953 if (ntree) {
954 ntree->id.recalc &= ~ID_RECALC_ALL;
955 }
956 /* XXX And what about scene's master collection here? */
957}
958
959void DEG_ids_clear_recalc(Depsgraph *depsgraph, const bool backup)
960{
961 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
962 /* TODO(sergey): Re-implement POST_UPDATE_HANDLER_WORKAROUND using entry_tags
963 * and id_tags storage from the new dependency graph. */
964 if (!DEG_id_type_any_updated(depsgraph)) {
965 return;
966 }
967 /* Go over all ID nodes, clearing tags. */
968 for (deg::IDNode *id_node : deg_graph->id_nodes) {
969 if (backup) {
970 id_node->id_cow_recalc_backup |= id_node->id_cow->recalc;
971 }
972 /* TODO: we clear original ID recalc flags here, but this may not work
973 * correctly when there are multiple depsgraph with others still using
974 * the recalc flag. */
975 id_node->is_user_modified = false;
976 id_node->is_cow_explicitly_tagged = false;
977 for (deg::ComponentNode *component_node : id_node->components.values()) {
978 component_node->is_user_modified = false;
979 }
981 if (deg_graph->is_active) {
983 }
984 }
985
986 if (backup) {
987 for (const int64_t i : IndexRange(INDEX_ID_MAX)) {
988 if (deg_graph->id_type_updated[i] != 0) {
989 deg_graph->id_type_updated_backup[i] = 1;
990 }
991 }
992 }
993 memset(deg_graph->id_type_updated, 0, sizeof(deg_graph->id_type_updated));
994}
995
996void DEG_ids_restore_recalc(Depsgraph *depsgraph)
997{
998 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(depsgraph);
999
1000 for (deg::IDNode *id_node : deg_graph->id_nodes) {
1001 id_node->id_cow->recalc |= id_node->id_cow_recalc_backup;
1002 id_node->id_cow_recalc_backup = 0;
1003 }
1004
1005 for (const int64_t i : IndexRange(INDEX_ID_MAX)) {
1006 if (deg_graph->id_type_updated_backup[i] != 0) {
1007 deg_graph->id_type_updated[i] = 1;
1008 }
1009 }
1010 memset(deg_graph->id_type_updated_backup, 0, sizeof(deg_graph->id_type_updated_backup));
1011}
1012
1013} // namespace blender
#define ID_TYPE_USE_COPY_ON_EVAL(_id_type)
Definition DNA_ID.h:746
#define INDEX_ID_MAX
Definition DNA_ID.h:1362
Object is a sort of wrapper for general info.
#define BLI_assert(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
constexpr IndexRange()=default
bNodeTree * node_tree_from_id(ID *id)
Definition node.cc:5337
Span< Depsgraph * > get_all_registered_graphs(Main *bmain)
NodeType geometry_tag_to_component(const ID *id)
static void set_id_update_count(ID *id)
void deg_editors_id_update(const DEGEditorUpdateContext *update_ctx, ID *id)
void deg_editors_scene_update(const DEGEditorUpdateContext *update_ctx, bool updated)
void graph_tag_ids_for_visible_update(Depsgraph *graph)
bool deg_eval_copy_is_expanded(const ID *id_cow)
bool deg_eval_copy_is_needed(const ID *id_orig)
DepsNodeFactory * type_get_factory(const NodeType type)
void id_tag_update(Main *bmain, ID *id, uint flags, eUpdateSource update_source)
void graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, uint flags, eUpdateSource update_source)
@ DEG_UPDATE_SOURCE_SIDE_EFFECT_REQUEST
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void DEG_time_tag_update(Main *bmain)
__int64 int64_t
Definition BKE_text.h:90
void DEG_enable_editors_update(Depsgraph *depsgraph)
unsigned int uint
Definition BKE_text.h:55
void DEG_graph_id_tag_update(Main *bmain, Depsgraph *depsgraph, ID *id, unsigned int flags)
static void deg_graph_clear_id_recalc_flags(ID *id)
void BKE_lib_override_id_tag_on_deg_tag_from_user(ID *id)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void DEG_ids_clear_recalc(Depsgraph *depsgraph, bool backup)
void DEG_tag_on_visible_update(Main *bmain, bool do_time)
@ G_DEBUG_DEPSGRAPH_TAG
Global G
Definition blender.cc:57
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a)
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
bool DEG_id_type_any_updated(const Depsgraph *depsgraph)
Main * DEG_get_bmain(const Depsgraph *graph)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_id_type_tag(Main *bmain, short id_type)
int BKE_idtype_idcode_to_index(short idcode)
Definition idtype.cc:338
void DEG_ids_restore_recalc(Depsgraph *depsgraph)
void DEG_editors_update(Depsgraph *depsgraph, bool time)
void DEG_id_tag_update_for_side_effect_request(Depsgraph *depsgraph, ID *id, unsigned int flags)
void DEG_graph_time_tag_update(Depsgraph *depsgraph)
void DEG_graph_id_type_tag(Depsgraph *depsgraph, short id_type)
IDRecalcFlag
Definition DNA_ID.h:1049
@ ID_RECALC_PSYS_PHYS
Definition DNA_ID.h:1087
@ ID_RECALC_PROVISION_28
Definition DNA_ID.h:1167
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1143
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_ALL
Definition DNA_ID.h:1190
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_AUDIO_LISTENER
Definition DNA_ID.h:1130
@ ID_RECALC_PSYS_RESET
Definition DNA_ID.h:1083
@ ID_RECALC_GEOMETRY_ALL_MODES
Definition DNA_ID.h:1183
@ ID_RECALC_AUDIO_FPS
Definition DNA_ID.h:1127
@ ID_RECALC_PSYS_CHILD
Definition DNA_ID.h:1085
@ ID_RECALC_PSYS_REDO
Definition DNA_ID.h:1081
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1158
@ ID_RECALC_AUDIO
Definition DNA_ID.h:1132
@ ID_RECALC_TAG_FOR_UNDO
Definition DNA_ID.h:1152
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_RECALC_PROVISION_30
Definition DNA_ID.h:1169
@ ID_RECALC_PROVISION_29
Definition DNA_ID.h:1168
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
@ ID_RECALC_SEQUENCER_STRIPS
Definition DNA_ID.h:1122
@ ID_RECALC_COMPOSITOR
Definition DNA_ID.h:1161
@ ID_RECALC_AUDIO_MUTE
Definition DNA_ID.h:1129
@ ID_RECALC_EDITORS
Definition DNA_ID.h:1111
@ ID_RECALC_NTREE_OUTPUT
Definition DNA_ID.h:1155
@ ID_RECALC_POINT_CACHE
Definition DNA_ID.h:1105
@ ID_RECALC_PROVISION_31
Definition DNA_ID.h:1170
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
@ ID_RECALC_AUDIO_VOLUME
Definition DNA_ID.h:1128
@ ID_RECALC_PSYS_ALL
Definition DNA_ID.h:1193
ID_Type GS(const char *name)
Definition DNA_ID.h:410
Scene * DEG_get_input_scene(const Depsgraph *graph)
int DEG_debug_flags_get(const Depsgraph *depsgraph)
const char * DEG_update_tag_as_string(IDRecalcFlag flag)
void DEG_graph_tag_on_visible_update(Depsgraph *depsgraph, bool do_time)
std::string DEG_stringify_recalc_flags(unsigned int flags)
char name[258]
Definition DNA_ID.h:433
unsigned int recalc
Definition DNA_ID.h:446
void tag_update(Depsgraph *graph, eUpdateSource source) override
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:102
char id_type_updated[INDEX_ID_MAX]
Definition depsgraph.hh:119
bool need_tag_id_on_graph_visibility_time_update
Definition depsgraph.hh:116
bool need_tag_id_on_graph_visibility_update
Definition depsgraph.hh:115
char id_type_updated_backup[INDEX_ID_MAX]
Definition depsgraph.hh:121
IDComponentsMask previously_visible_components_mask
IDComponentsMask visible_components_mask
Map< ComponentIDKey, ComponentNode * > components
void tag_update(Depsgraph *graph, eUpdateSource source) override