1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2013 Blender Foundation.
* All rights reserved.
*/
/** \file
* \ingroup depsgraph
*
* Core routines for how the Depsgraph works.
*/
#include "intern/depsgraph_tag.h"
#include <stdio.h>
#include <cstring> /* required for memset */
#include <queue>
#include "BLI_utildefines.h"
#include "BLI_math_bits.h"
#include "BLI_task.h"
extern "C" {
#include "DNA_anim_types.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
#include "BKE_animsys.h"
#include "BKE_global.h"
#include "BKE_idcode.h"
#include "BKE_node.h"
#include "BKE_scene.h"
#include "BKE_workspace.h"
#define new new_
#include "BKE_screen.h"
#undef new
} /* extern "C" */
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_debug.h"
#include "DEG_depsgraph_query.h"
#include "intern/builder/deg_builder.h"
#include "intern/depsgraph.h"
#include "intern/depsgraph_update.h"
#include "intern/depsgraph_registry.h"
#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/eval/deg_eval_flush.h"
#include "intern/node/deg_node.h"
#include "intern/node/deg_node_component.h"
#include "intern/node/deg_node_factory.h"
#include "intern/node/deg_node_id.h"
#include "intern/node/deg_node_operation.h"
/* *********************** */
/* Update Tagging/Flushing */
namespace DEG {
namespace {
void depsgraph_geometry_tag_to_component(const ID *id, NodeType *component_type)
{
const NodeType result = geometry_tag_to_component(id);
if (result != NodeType::UNDEFINED) {
*component_type = result;
}
}
bool is_selectable_data_id_type(const ID_Type id_type)
{
return ELEM(id_type, ID_ME, ID_CU, ID_MB, ID_LT, ID_GD);
}
void depsgraph_select_tag_to_component_opcode(const ID *id,
NodeType *component_type,
OperationCode *operation_code)
{
const ID_Type id_type = GS(id->name);
if (id_type == ID_SCE) {
/* We need to flush base flags to all objects in a scene since we
* don't know which ones changed. However, we don't want to update
* the whole scene, so pick up some operation which will do as less
* as possible.
*
* TODO(sergey): We can introduce explicit exit operation which
* does nothing and which is only used to cascade flush down the
* road. */
*component_type = NodeType::LAYER_COLLECTIONS;
*operation_code = OperationCode::VIEW_LAYER_EVAL;
}
else if (id_type == ID_OB) {
*component_type = NodeType::OBJECT_FROM_LAYER;
*operation_code = OperationCode::OBJECT_BASE_FLAGS;
}
else if (id_type == ID_MC) {
*component_type = NodeType::BATCH_CACHE;
*operation_code = OperationCode::MOVIECLIP_SELECT_UPDATE;
}
else if (is_selectable_data_id_type(id_type)) {
*component_type = NodeType::BATCH_CACHE;
*operation_code = OperationCode::GEOMETRY_SELECT_UPDATE;
}
else {
*component_type = NodeType::COPY_ON_WRITE;
*operation_code = OperationCode::COPY_ON_WRITE;
}
}
void depsgraph_base_flags_tag_to_component_opcode(const ID *id,
NodeType *component_type,
OperationCode *operation_code)
{
const ID_Type id_type = GS(id->name);
if (id_type == ID_SCE) {
*component_type = NodeType::LAYER_COLLECTIONS;
*operation_code = OperationCode::VIEW_LAYER_EVAL;
}
else if (id_type == ID_OB) {
*component_type = NodeType::OBJECT_FROM_LAYER;
*operation_code = OperationCode::OBJECT_BASE_FLAGS;
}
}
OperationCode psysTagToOperationCode(IDRecalcFlag tag)
{
if (tag == ID_RECALC_PSYS_RESET) {
return OperationCode::PARTICLE_SETTINGS_RESET;
}
return OperationCode::OPERATION;
}
void depsgraph_tag_to_component_opcode(const ID *id,
IDRecalcFlag tag,
NodeType *component_type,
OperationCode *operation_code)
{
const ID_Type id_type = GS(id->name);
*component_type = NodeType::UNDEFINED;
*operation_code = OperationCode::OPERATION;
/* Special case for now, in the future we should get rid of this. */
if (tag == 0) {
*component_type = NodeType::ID_REF;
*operation_code = OperationCode::OPERATION;
return;
}
switch (tag) {
case ID_RECALC_TRANSFORM:
*component_type = NodeType::TRANSFORM;
break;
case ID_RECALC_GEOMETRY:
depsgraph_geometry_tag_to_component(id, component_type);
break;
case ID_RECALC_ANIMATION:
*component_type = NodeType::ANIMATION;
break;
case ID_RECALC_PSYS_REDO:
case ID_RECALC_PSYS_RESET:
case ID_RECALC_PSYS_CHILD:
case ID_RECALC_PSYS_PHYS:
if (id_type == ID_PA) {
/* NOTES:
* - For particle settings node we need to use different
* component. Will be nice to get this unified with object,
* but we can survive for now with single exception here.
* Particles needs reconsideration anyway, */
*component_type = NodeType::PARTICLE_SETTINGS;
*operation_code = psysTagToOperationCode(tag);
}
else {
*component_type = NodeType::PARTICLE_SYSTEM;
}
break;
case ID_RECALC_COPY_ON_WRITE:
*component_type = NodeType::COPY_ON_WRITE;
break;
case ID_RECALC_SHADING:
if (id_type == ID_NT) {
*component_type = NodeType::SHADING_PARAMETERS;
}
else {
*component_type = NodeType::SHADING;
}
break;
case ID_RECALC_SELECT:
depsgraph_select_tag_to_component_opcode(id, component_type, operation_code);
break;
case ID_RECALC_BASE_FLAGS:
depsgraph_base_flags_tag_to_component_opcode(id, component_type, operation_code);
break;
case ID_RECALC_POINT_CACHE:
*component_type = NodeType::POINT_CACHE;
break;
case ID_RECALC_EDITORS:
/* There is no such node in depsgraph, this tag is to be handled
* separately. */
break;
case ID_RECALC_SEQUENCER_STRIPS:
*component_type = NodeType::SEQUENCER;
break;
case ID_RECALC_AUDIO_SEEK:
case ID_RECALC_AUDIO_FPS:
case ID_RECALC_AUDIO_VOLUME:
case ID_RECALC_AUDIO_MUTE:
case ID_RECALC_AUDIO_LISTENER:
case ID_RECALC_AUDIO:
*component_type = NodeType::AUDIO;
break;
case ID_RECALC_PARAMETERS:
*component_type = NodeType::PARAMETERS;
break;
case ID_RECALC_SOURCE:
*component_type = NodeType::PARAMETERS;
break;
case ID_RECALC_TIME:
BLI_assert(!"Should be handled outside of this function");
break;
case ID_RECALC_ALL:
case ID_RECALC_PSYS_ALL:
BLI_assert(!"Should not happen");
break;
}
}
void id_tag_update_ntree_special(
Main *bmain, Depsgraph *graph, ID *id, int flag, eUpdateSource update_source)
{
bNodeTree *ntree = ntreeFromID(id);
if (ntree == NULL) {
return;
}
graph_id_tag_update(bmain, graph, &ntree->id, flag, update_source);
}
void depsgraph_update_editors_tag(Main *bmain, Depsgraph *graph, ID *id)
{
/* NOTE: We handle this immediately, without delaying anything, to be
* sure we don't cause threading issues with OpenGL. */
/* TODO(sergey): Make sure this works for CoW-ed datablocks as well. */
DEGEditorUpdateContext update_ctx = {NULL};
update_ctx.bmain = bmain;
update_ctx.depsgraph = (::Depsgraph *)graph;
update_ctx.scene = graph->scene;
update_ctx.view_layer = graph->view_layer;
deg_editors_id_update(&update_ctx, id);
}
void depsgraph_id_tag_copy_on_write(Depsgraph *graph, IDNode *id_node, eUpdateSource update_source)
{
ComponentNode *cow_comp = id_node->find_component(NodeType::COPY_ON_WRITE);
cow_comp->tag_update(graph, update_source);
}
void depsgraph_tag_component(Depsgraph *graph,
IDNode *id_node,
NodeType component_type,
OperationCode operation_code,
eUpdateSource update_source)
{
ComponentNode *component_node = id_node->find_component(component_type);
/* NOTE: Animation component might not be existing yet (which happens when adding new driver or
* adding a new keyframe), so the required copy-on-write tag needs to be taken care explicitly
* here. */
if (component_node == NULL) {
if (component_type == NodeType::ANIMATION) {
depsgraph_id_tag_copy_on_write(graph, id_node, update_source);
}
return;
}
if (operation_code == OperationCode::OPERATION) {
component_node->tag_update(graph, update_source);
}
else {
OperationNode *operation_node = component_node->find_operation(operation_code);
if (operation_node != NULL) {
operation_node->tag_update(graph, update_source);
}
}
/* If component depends on copy-on-write, tag it as well. */
if (component_node->need_tag_cow_before_update()) {
depsgraph_id_tag_copy_on_write(graph, id_node, update_source);
}
}
/* This is a tag compatibility with legacy code.
*
* Mainly, old code was tagging object with ID_RECALC_GEOMETRY tag to inform
* that object's data datablock changed. Now API expects that ID is given
* explicitly, but not all areas are aware of this yet. */
void deg_graph_id_tag_legacy_compat(
Main *bmain, Depsgraph *depsgraph, ID *id, IDRecalcFlag tag, eUpdateSource update_source)
{
if (tag == ID_RECALC_GEOMETRY || tag == 0) {
switch (GS(id->name)) {
case ID_OB: {
Object *object = (Object *)id;
ID *data_id = (ID *)object->data;
if (data_id != NULL) {
graph_id_tag_update(bmain, depsgraph, data_id, 0, update_source);
}
break;
}
/* TODO(sergey): Shape keys are annoying, maybe we should find a
* way to chain geometry evaluation to them, so we don't need extra
* tagging here. */
case ID_ME: {
Mesh *mesh = (Mesh *)id;
if (mesh->key != NULL) {
ID *key_id = &mesh->key->id;
if (key_id != NULL) {
graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
}
}
break;
}
case ID_LT: {
Lattice *lattice = (Lattice *)id;
if (lattice->key != NULL) {
ID *key_id = &lattice->key->id;
if (key_id != NULL) {
graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
}
}
break;
}
case ID_CU: {
Curve *curve = (Curve *)id;
if (curve->key != NULL) {
ID *key_id = &curve->key->id;
if (key_id != NULL) {
graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source);
}
}
break;
}
default:
break;
}
}
}
static void graph_id_tag_update_single_flag(Main *bmain,
Depsgraph *graph,
ID *id,
IDNode *id_node,
IDRecalcFlag tag,
eUpdateSource update_source)
{
if (tag == ID_RECALC_EDITORS) {
if (graph != NULL) {
depsgraph_update_editors_tag(bmain, graph, id);
}
return;
}
else if (tag == ID_RECALC_TIME) {
if (graph != NULL) {
graph->need_update_time = true;
}
return;
}
/* Get description of what is to be tagged. */
NodeType component_type;
OperationCode operation_code;
depsgraph_tag_to_component_opcode(id, tag, &component_type, &operation_code);
/* Check whether we've got something to tag. */
if (component_type == NodeType::UNDEFINED) {
/* Given ID does not support tag. */
/* TODO(sergey): Shall we raise some panic here? */
return;
}
/* Some sanity checks before moving forward. */
if (id_node == NULL) {
/* Happens when object is tagged for update and not yet in the
* dependency graph (but will be after relations update). */
return;
}
/* Tag ID recalc flag. */
DepsNodeFactory *factory = type_get_factory(component_type);
BLI_assert(factory != NULL);
id_node->id_cow->recalc |= factory->id_recalc_tag();
/* Tag corresponding dependency graph operation for update. */
if (component_type == NodeType::ID_REF) {
id_node->tag_update(graph, update_source);
}
else {
depsgraph_tag_component(graph, id_node, component_type, operation_code, update_source);
}
/* TODO(sergey): Get rid of this once all areas are using proper data ID
* for tagging. */
deg_graph_id_tag_legacy_compat(bmain, graph, id, tag, update_source);
}
string stringify_append_bit(const string &str, IDRecalcFlag tag)
{
const char *tag_name = DEG_update_tag_as_string(tag);
if (tag_name == NULL) {
return str;
}
string result = str;
if (!result.empty()) {
result += ", ";
}
result += tag_name;
return result;
}
string stringify_update_bitfield(int flag)
{
if (flag == 0) {
return "LEGACY_0";
}
string result = "";
int current_flag = flag;
/* Special cases to avoid ALL flags form being split into
* individual bits. */
if ((current_flag & ID_RECALC_PSYS_ALL) == ID_RECALC_PSYS_ALL) {
result = stringify_append_bit(result, ID_RECALC_PSYS_ALL);
}
/* Handle all the rest of the flags. */
while (current_flag != 0) {
IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_i(¤t_flag));
result = stringify_append_bit(result, tag);
}
return result;
}
const char *update_source_as_string(eUpdateSource source)
{
switch (source) {
case DEG_UPDATE_SOURCE_TIME:
return "TIME";
case DEG_UPDATE_SOURCE_USER_EDIT:
return "USER_EDIT";
case DEG_UPDATE_SOURCE_RELATIONS:
return "RELATIONS";
case DEG_UPDATE_SOURCE_VISIBILITY:
return "VISIBILITY";
}
BLI_assert(!"Should never happen.");
return "UNKNOWN";
}
int deg_recalc_flags_for_legacy_zero()
{
return ID_RECALC_ALL &
~(ID_RECALC_PSYS_ALL | ID_RECALC_ANIMATION | ID_RECALC_SOURCE | ID_RECALC_TIME);
}
int deg_recalc_flags_effective(Depsgraph *graph, int flags)
{
if (graph != NULL) {
if (!graph->is_active) {
return 0;
}
}
if (flags == 0) {
return deg_recalc_flags_for_legacy_zero();
}
return flags;
}
/* Special tag function which tags all components which needs to be tagged
* for update flag=0.
*
* TODO(sergey): This is something to be avoid in the future, make it more
* explicit and granular for users to tag what they really need. */
void deg_graph_node_tag_zero(Main *bmain,
Depsgraph *graph,
IDNode *id_node,
eUpdateSource update_source)
{
if (id_node == NULL) {
return;
}
ID *id = id_node->id_orig;
/* TODO(sergey): Which recalc flags to set here? */
id_node->id_cow->recalc |= deg_recalc_flags_for_legacy_zero();
GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) {
if (comp_node->type == NodeType::ANIMATION) {
continue;
}
comp_node->tag_update(graph, update_source);
}
GHASH_FOREACH_END();
deg_graph_id_tag_legacy_compat(bmain, graph, id, (IDRecalcFlag)0, update_source);
}
void deg_graph_on_visible_update(Main *bmain, Depsgraph *graph, const bool do_time)
{
/* NOTE: It is possible to have this function called with `do_time=false` first and later (prior
* to evaluation though) with `do_time=true`. This means early output checks should be aware of
* this. */
for (DEG::IDNode *id_node : graph->id_nodes) {
if (!id_node->visible_components_mask) {
/* ID has no components which affects anything visible.
* No need bother with it to tag or anything. */
continue;
}
int flag = 0;
if (!DEG::deg_copy_on_write_is_expanded(id_node->id_cow)) {
flag |= ID_RECALC_COPY_ON_WRITE;
if (do_time) {
if (BKE_animdata_from_id(id_node->id_orig) != NULL) {
flag |= ID_RECALC_ANIMATION;
}
}
}
else {
if (id_node->visible_components_mask == id_node->previously_visible_components_mask) {
/* The ID was already visible and evaluated, all the subsequent
* updates and tags are to be done explicitly. */
continue;
}
}
/* We only tag components which needs an update. Tagging everything is
* not a good idea because that might reset particles cache (or any
* other type of cache).
*
* TODO(sergey): Need to generalize this somehow. */
const ID_Type id_type = GS(id_node->id_orig->name);
if (id_type == ID_OB) {
flag |= ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY;
}
graph_id_tag_update(bmain, graph, id_node->id_orig, flag, DEG_UPDATE_SOURCE_VISIBILITY);
if (id_type == ID_SCE) {
/* Make sure collection properties are up to date. */
id_node->tag_update(graph, DEG_UPDATE_SOURCE_VISIBILITY);
}
/* Now when ID is updated to the new visibility state, prevent it from
* being re-tagged again. Simplest way to do so is to pretend that it
* was already updated by the "previous" dependency graph.
*
* NOTE: Even if the on_visible_update() is called from the state when
* dependency graph is tagged for relations update, it will be fine:
* since dependency graph builder re-schedules entry tags, all the
* tags we request from here will be applied in the updated state of
* dependency graph. */
id_node->previously_visible_components_mask = id_node->visible_components_mask;
}
}
} /* namespace */
NodeType geometry_tag_to_component(const ID *id)
{
const ID_Type id_type = GS(id->name);
switch (id_type) {
case ID_OB: {
const Object *object = (Object *)id;
switch (object->type) {
case OB_MESH:
case OB_CURVE:
case OB_SURF:
case OB_FONT:
case OB_LATTICE:
case OB_MBALL:
case OB_GPENCIL:
return NodeType::GEOMETRY;
case OB_ARMATURE:
return NodeType::EVAL_POSE;
/* TODO(sergey): More cases here? */
}
break;
}
case ID_ME:
case ID_CU:
case ID_LT:
case ID_MB:
return NodeType::GEOMETRY;
case ID_PA: /* Particles */
return NodeType::UNDEFINED;
case ID_LP:
return NodeType::PARAMETERS;
case ID_GD:
return NodeType::GEOMETRY;
case ID_PAL: /* Palettes */
return NodeType::PARAMETERS;
case ID_MSK:
return NodeType::PARAMETERS;
default:
break;
}
return NodeType::UNDEFINED;
}
void id_tag_update(Main *bmain, ID *id, int flag, eUpdateSource update_source)
{
graph_id_tag_update(bmain, NULL, id, flag, update_source);
for (DEG::Depsgraph *depsgraph : DEG::get_all_registered_graphs(bmain)) {
graph_id_tag_update(bmain, depsgraph, id, flag, update_source);
}
}
void graph_id_tag_update(
Main *bmain, Depsgraph *graph, ID *id, int flag, eUpdateSource update_source)
{
const int debug_flags = (graph != NULL) ? DEG_debug_flags_get((::Depsgraph *)graph) : G.debug;
if (debug_flags & G_DEBUG_DEPSGRAPH_TAG) {
printf("%s: id=%s flags=%s source=%s\n",
__func__,
id->name,
stringify_update_bitfield(flag).c_str(),
update_source_as_string(update_source));
}
IDNode *id_node = (graph != NULL) ? graph->find_id_node(id) : NULL;
if (graph != NULL) {
DEG_graph_id_type_tag(reinterpret_cast<::Depsgraph *>(graph), GS(id->name));
}
if (flag == 0) {
deg_graph_node_tag_zero(bmain, graph, id_node, update_source);
}
/* Store original flag in the ID.
* Allows to have more granularity than a node-factory based flags. */
if (id_node != NULL) {
id_node->id_cow->recalc |= flag;
}
/* When ID is tagged for update based on an user edits store the recalc flags in the original ID.
* This way IDs in the undo steps will have this flag preserved, making it possible to restore
* all needed tags when new dependency graph is created on redo.
* This is the only way to ensure modifications to animation data (such as keyframes i.e.)
* properly triggers animation update for the newly constructed dependency graph on redo (while
* usually newly created dependency graph skips animation update to avoid loss of unkeyed
* changes). */
if (update_source == DEG_UPDATE_SOURCE_USER_EDIT) {
id->recalc |= deg_recalc_flags_effective(graph, flag);
}
int current_flag = flag;
while (current_flag != 0) {
IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_i(¤t_flag));
graph_id_tag_update_single_flag(bmain, graph, id, id_node, tag, update_source);
}
/* Special case for nested node tree datablocks. */
id_tag_update_ntree_special(bmain, graph, id, flag, update_source);
/* Direct update tags means that something outside of simulated/cached
* physics did change and that cache is to be invalidated.
* This is only needed if data changes. If it's just a drawing, we keep the
* point cache. */
if (update_source == DEG_UPDATE_SOURCE_USER_EDIT && flag != ID_RECALC_SHADING) {
graph_id_tag_update_single_flag(
bmain, graph, id, id_node, ID_RECALC_POINT_CACHE, update_source);
}
}
} // namespace DEG
const char *DEG_update_tag_as_string(IDRecalcFlag flag)
{
switch (flag) {
case ID_RECALC_TRANSFORM:
return "TRANSFORM";
case ID_RECALC_GEOMETRY:
return "GEOMETRY";
case ID_RECALC_ANIMATION:
return "ANIMATION";
case ID_RECALC_PSYS_REDO:
return "PSYS_REDO";
case ID_RECALC_PSYS_RESET:
return "PSYS_RESET";
case ID_RECALC_PSYS_CHILD:
return "PSYS_CHILD";
case ID_RECALC_PSYS_PHYS:
return "PSYS_PHYS";
case ID_RECALC_PSYS_ALL:
return "PSYS_ALL";
case ID_RECALC_COPY_ON_WRITE:
return "COPY_ON_WRITE";
case ID_RECALC_SHADING:
return "SHADING";
case ID_RECALC_SELECT:
return "SELECT";
case ID_RECALC_BASE_FLAGS:
return "BASE_FLAGS";
case ID_RECALC_POINT_CACHE:
return "POINT_CACHE";
case ID_RECALC_EDITORS:
return "EDITORS";
case ID_RECALC_SEQUENCER_STRIPS:
return "SEQUENCER_STRIPS";
case ID_RECALC_AUDIO_SEEK:
return "AUDIO_SEEK";
case ID_RECALC_AUDIO_FPS:
return "AUDIO_FPS";
case ID_RECALC_AUDIO_VOLUME:
return "AUDIO_VOLUME";
case ID_RECALC_AUDIO_MUTE:
return "AUDIO_MUTE";
case ID_RECALC_AUDIO_LISTENER:
return "AUDIO_LISTENER";
case ID_RECALC_AUDIO:
return "AUDIO";
case ID_RECALC_PARAMETERS:
return "PARAMETERS";
case ID_RECALC_TIME:
return "TIME";
case ID_RECALC_SOURCE:
return "SOURCE";
case ID_RECALC_ALL:
return "ALL";
}
return NULL;
}
/* Data-Based Tagging */
/* Tag given ID for an update in all the dependency graphs. */
void DEG_id_tag_update(ID *id, int flag)
{
DEG_id_tag_update_ex(G.main, id, flag);
}
void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
{
if (id == NULL) {
/* Ideally should not happen, but old depsgraph allowed this. */
return;
}
DEG::id_tag_update(bmain, id, flag, DEG::DEG_UPDATE_SOURCE_USER_EDIT);
}
void DEG_graph_id_tag_update(struct Main *bmain,
struct Depsgraph *depsgraph,
struct ID *id,
int flag)
{
DEG::Depsgraph *graph = (DEG::Depsgraph *)depsgraph;
DEG::graph_id_tag_update(bmain, graph, id, flag, DEG::DEG_UPDATE_SOURCE_USER_EDIT);
}
/* Mark a particular datablock type as having changing. */
void DEG_graph_id_type_tag(Depsgraph *depsgraph, short id_type)
{
if (id_type == ID_NT) {
/* Stupid workaround so parent datablocks of nested nodetree get looped
* over when we loop over tagged datablock types. */
DEG_graph_id_type_tag(depsgraph, ID_MA);
DEG_graph_id_type_tag(depsgraph, ID_TE);
DEG_graph_id_type_tag(depsgraph, ID_LA);
DEG_graph_id_type_tag(depsgraph, ID_WO);
DEG_graph_id_type_tag(depsgraph, ID_SCE);
}
const int id_type_index = BKE_idcode_to_index(id_type);
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
deg_graph->id_type_updated[id_type_index] = 1;
}
void DEG_id_type_tag(Main *bmain, short id_type)
{
for (DEG::Depsgraph *depsgraph : DEG::get_all_registered_graphs(bmain)) {
DEG_graph_id_type_tag(reinterpret_cast<::Depsgraph *>(depsgraph), id_type);
}
}
/* Update dependency graph when visible scenes/layers changes. */
void DEG_graph_on_visible_update(Main *bmain, Depsgraph *depsgraph, const bool do_time)
{
DEG::Depsgraph *graph = (DEG::Depsgraph *)depsgraph;
DEG::deg_graph_on_visible_update(bmain, graph, do_time);
}
void DEG_on_visible_update(Main *bmain, const bool do_time)
{
for (DEG::Depsgraph *depsgraph : DEG::get_all_registered_graphs(bmain)) {
DEG_graph_on_visible_update(bmain, reinterpret_cast<::Depsgraph *>(depsgraph), do_time);
}
}
/* Check if something was changed in the database and inform
* editors about this. */
void DEG_ids_check_recalc(
Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, bool time)
{
bool updated = time || DEG_id_type_any_updated(depsgraph);
DEGEditorUpdateContext update_ctx = {NULL};
update_ctx.bmain = bmain;
update_ctx.depsgraph = depsgraph;
update_ctx.scene = scene;
update_ctx.view_layer = view_layer;
DEG::deg_editors_scene_update(&update_ctx, updated);
}
static void deg_graph_clear_id_recalc_flags(ID *id)
{
id->recalc &= ~ID_RECALC_ALL;
bNodeTree *ntree = ntreeFromID(id);
/* Clear embedded node trees too. */
if (ntree) {
ntree->id.recalc &= ~ID_RECALC_ALL;
}
}
static void deg_graph_clear_id_node_func(void *__restrict data_v,
const int i,
const TaskParallelTLS *__restrict /*tls*/)
{
/* TODO: we clear original ID recalc flags here, but this may not work
* correctly when there are multiple depsgraph with others still using
* the recalc flag. */
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(data_v);
DEG::IDNode *id_node = deg_graph->id_nodes[i];
id_node->is_user_modified = false;
deg_graph_clear_id_recalc_flags(id_node->id_cow);
if (deg_graph->is_active) {
deg_graph_clear_id_recalc_flags(id_node->id_orig);
}
}
void DEG_ids_clear_recalc(Main *UNUSED(bmain), Depsgraph *depsgraph)
{
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
/* TODO(sergey): Re-implement POST_UPDATE_HANDLER_WORKAROUND using entry_tags
* and id_tags storage from the new dependency graph. */
if (!DEG_id_type_any_updated(depsgraph)) {
return;
}
/* Go over all ID nodes nodes, clearing tags. */
const int num_id_nodes = deg_graph->id_nodes.size();
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
settings.min_iter_per_thread = 1024;
BLI_task_parallel_range(0, num_id_nodes, deg_graph, deg_graph_clear_id_node_func, &settings);
memset(deg_graph->id_type_updated, 0, sizeof(deg_graph->id_type_updated));
}
|