Move ID recalc flags into dedicated field in ID
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 15 Dec 2017 08:43:18 +0000 (09:43 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 15 Dec 2017 08:43:18 +0000 (09:43 +0100)
Currently this is a no-visible-changes change, but the idea is to use this
dedicated flag to tell which exact components of ID changed, make it more
granular than just OBJECT and OBJECT_DATA. Allow setting this field based
on what components new dependency graph flushed on evaluation.

13 files changed:
source/blender/blenkernel/intern/anim_sys.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/mask.c
source/blender/blenkernel/intern/object_dupli.c
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/depsgraph/intern/builder/deg_builder.cc
source/blender/depsgraph/intern/depsgraph.cc
source/blender/depsgraph/intern/depsgraph_tag.cc
source/blender/depsgraph/intern/eval/deg_eval_flush.cc
source/blender/makesdna/DNA_ID.h
source/blender/makesrna/intern/rna_ID.c
source/blender/modifiers/intern/MOD_correctivesmooth.c

index 6107bb1e32e75ef8d1c39f65447c489c7568537b..ba8f454aa47cdee4fcdbe0421c0a96300043c17d 100644 (file)
@@ -74,6 +74,8 @@
 
 #include "nla_private.h"
 
+#include "atomic_ops.h"
+
 /* ***************************************** */
 /* AnimData API */
 
@@ -1663,8 +1665,11 @@ static bool animsys_write_rna_setting(PathResolvedRNA *anim_rna, const float val
 
                /* for cases like duplifarmes it's only a temporary so don't
                 * notify anyone of updates */
-               if (!(id->tag & LIB_TAG_ANIM_NO_RECALC)) {
-                       BKE_id_tag_set_atomic(id, LIB_TAG_ID_RECALC);
+               if (!(id->recalc & ID_RECALC_SKIP_ANIM_TAG)) {
+                       /* NOTE: This is a bit annoying to use atomic API here, but this
+                        * code is at it's EOL and removed already in 2.8 branch.
+                        */
+                       atomic_fetch_and_or_int32(&id->recalc, ID_RECALC);
                        DAG_id_type_tag(G.main, GS(id->name));
                }
        }
@@ -2618,8 +2623,8 @@ static void animsys_evaluate_nla(ListBase *echannels, PointerRNA *ptr, AnimData
         */
        if (ptr->id.data != NULL) {
                ID *id = ptr->id.data;
-               if (!(id->tag & LIB_TAG_ANIM_NO_RECALC)) {
-                       id->tag |= LIB_TAG_ID_RECALC;
+               if (!(id->recalc & ID_RECALC_SKIP_ANIM_TAG)) {
+                       id->recalc |= ID_RECALC;
                        DAG_id_type_tag(G.main, GS(id->name));
                }
        }
index e9b83b27ef2175886e0524494c7824a1e3970f92..81e88bd3019b3c4a35186f66751d35c79d392aa8 100644 (file)
@@ -1532,7 +1532,7 @@ static bool check_object_tagged_for_update(Object *object)
 
        if (ELEM(object->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
                ID *data_id = object->data;
-               return (data_id->tag & LIB_TAG_ID_RECALC_ALL) != 0;
+               return (data_id->recalc & ID_RECALC_ALL) != 0;
        }
 
        return false;
@@ -1780,13 +1780,13 @@ void DAG_scene_free(Scene *sce)
 
 static void lib_id_recalc_tag(Main *bmain, ID *id)
 {
-       id->tag |= LIB_TAG_ID_RECALC;
+       id->recalc |= ID_RECALC;
        DAG_id_type_tag(bmain, GS(id->name));
 }
 
 static void lib_id_recalc_data_tag(Main *bmain, ID *id)
 {
-       id->tag |= LIB_TAG_ID_RECALC_DATA;
+       id->recalc |= ID_RECALC_DATA;
        DAG_id_type_tag(bmain, GS(id->name));
 }
 
@@ -2825,7 +2825,7 @@ void DAG_ids_flush_tagged(Main *bmain)
 
                if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
                        for (; id; id = id->next) {
-                               if (id->tag & LIB_TAG_ID_RECALC_ALL) {
+                               if (id->recalc & ID_RECALC_ALL) {
                                        for (dsl = listbase.first; dsl; dsl = dsl->next)
                                                dag_id_flush_update(bmain, dsl->scene, id);
                                        
@@ -2945,12 +2945,12 @@ void DAG_ids_clear_recalc(Main *bmain)
 
                if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
                        for (; id; id = id->next) {
-                               id->tag &= ~LIB_TAG_ID_RECALC_ALL;
+                               id->recalc &= ~ID_RECALC_ALL;
 
                                /* some ID's contain semi-datablock nodetree */
                                ntree = ntreeFromID(id);
                                if (ntree)
-                                       ntree->id.tag &= ~LIB_TAG_ID_RECALC_ALL;
+                                       ntree->id.recalc &= ~ID_RECALC_ALL;
                        }
                }
        }
index cd697cadc0e0acf3243b98a8f6505e60ffc23d35..ff4e7f36018b5d3b4917233f96c1696a69849465 100644 (file)
@@ -1463,8 +1463,8 @@ void BKE_mask_update_scene(Main *bmain, Scene *scene)
        Mask *mask;
 
        for (mask = bmain->mask.first; mask; mask = mask->id.next) {
-               if (mask->id.tag & LIB_TAG_ID_RECALC_ALL) {
-                       bool do_new_frame = (mask->id.tag & LIB_TAG_ID_RECALC_DATA) != 0;
+               if (mask->id.recalc & ID_RECALC_ALL) {
+                       bool do_new_frame = (mask->id.recalc & ID_RECALC_DATA) != 0;
                        BKE_mask_evaluate_all_masks(bmain, CFRA, do_new_frame);
                }
        }
index b49e481b068325acbd84826756b49dda0fa44d3c..93bc79095d7460df38800c51142f82a3fa53d445 100644 (file)
@@ -379,7 +379,7 @@ static void make_duplis_frames(const DupliContext *ctx)
 
        /* special flag to avoid setting recalc flags to notify the depsgraph of
         * updates, as this is not a permanent change to the object */
-       ob->id.tag |= LIB_TAG_ANIM_NO_RECALC;
+       ob->id.recalc |= ID_RECALC_SKIP_ANIM_TAG;
 
        for (scene->r.cfra = ob->dupsta; scene->r.cfra <= dupend; scene->r.cfra++) {
                int ok = 1;
index 9ce578a9105d27c34c88de6d735687348bc06128..e45d2887250ee8f0dda2cc6fb80297db35d105e1 100644 (file)
@@ -1841,8 +1841,8 @@ static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
        if (obedit) {
                Mesh *mesh = obedit->data;
                if ((obedit->type == OB_MESH) &&
-                   ((obedit->id.tag & LIB_TAG_ID_RECALC_ALL) ||
-                    (mesh->id.tag & LIB_TAG_ID_RECALC_ALL)))
+                   ((obedit->id.recalc & ID_RECALC_ALL) ||
+                    (mesh->id.recalc & ID_RECALC_ALL)))
                {
                        if (check_rendered_viewport_visible(bmain)) {
                                BMesh *bm = mesh->edit_btmesh->bm;
index b6543fc8662e3bb79ee0236e700d257395fb0e38..f43eecffe60906f8757e76e98280b4c825ced90d 100644 (file)
@@ -3077,7 +3077,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        ntree->adt = newdataadr(fd, ntree->adt);
        direct_link_animdata(fd, ntree->adt);
        
-       ntree->id.tag &= ~LIB_TAG_ID_RECALC_ALL;
+       ntree->id.recalc &= ~ID_RECALC_ALL;
 
        link_list(fd, &ntree->nodes);
        for (node = ntree->nodes.first; node; node = node->next) {
index e3494e4756eb36433e410a90298df37ce1c4015d..26f729a16d769838d7c2429ff6e0cc23390eaa47 100644 (file)
@@ -153,7 +153,7 @@ void deg_graph_build_finalize(Depsgraph *graph)
 
                if ((id_node->layers & graph->layers) != 0 || graph->layers == 0) {
                        ID *id = id_node->id;
-                       if ((id->tag & LIB_TAG_ID_RECALC_ALL) &&
+                       if ((id->recalc & ID_RECALC_ALL) &&
                            (id->tag & LIB_TAG_DOIT))
                        {
                                id_node->tag_update(graph);
index 7e9b2f5c58c919dc116da504254707b95b9b48a9..dd7284eb629f798e4ba1b73935bb5cef60e3ecab 100644 (file)
@@ -312,7 +312,7 @@ DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from,
        if (comp_node->type == DEG_NODE_TYPE_GEOMETRY) {
                IDDepsNode *id_to = to->owner->owner;
                IDDepsNode *id_from = from->owner->owner;
-               if (id_to != id_from && (id_to->id->tag & LIB_TAG_ID_RECALC_ALL)) {
+               if (id_to != id_from && (id_to->id->recalc & ID_RECALC_ALL)) {
                        if ((id_from->eval_flags & DAG_EVAL_NEED_CPU) == 0) {
                                id_from->tag_update(this);
                                id_from->eval_flags |= DAG_EVAL_NEED_CPU;
index 8f91a82676007ac7f2a9e3c4473c8f42a7ddb029..79c30e7904d7c188c0caed80b3204aecafae64df 100644 (file)
@@ -83,13 +83,13 @@ namespace {
 
 void lib_id_recalc_tag(Main *bmain, ID *id)
 {
-       id->tag |= LIB_TAG_ID_RECALC;
+       id->recalc |= ID_RECALC;
        DEG_id_type_tag(bmain, GS(id->name));
 }
 
 void lib_id_recalc_data_tag(Main *bmain, ID *id)
 {
-       id->tag |= LIB_TAG_ID_RECALC_DATA;
+       id->recalc |= ID_RECALC_DATA;
        DEG_id_type_tag(bmain, GS(id->name));
 }
 
@@ -295,7 +295,7 @@ void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
                GHASH_FOREACH_BEGIN(DEG::IDDepsNode *, id_node, graph->id_hash)
                {
                        ID *id = id_node->id;
-                       if ((id->tag & LIB_TAG_ID_RECALC_ALL) != 0 ||
+                       if ((id->recalc & ID_RECALC_ALL) != 0 ||
                            (id_node->layers & scene->lay_updated) == 0)
                        {
                                id_node->tag_update(graph);
@@ -307,7 +307,7 @@ void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
                         */
                        if (GS(id->name) == ID_OB) {
                                Object *object = (Object *)id;
-                               if ((id->tag & LIB_TAG_ID_RECALC_ALL) == 0 &&
+                               if ((id->recalc & ID_RECALC_ALL) == 0 &&
                                    (object->recalc & OB_RECALC_ALL) != 0)
                                {
                                        id_node->tag_update(graph);
@@ -409,12 +409,12 @@ void DEG_ids_clear_recalc(Main *bmain)
 
                if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
                        for (; id; id = (ID *)id->next) {
-                               id->tag &= ~LIB_TAG_ID_RECALC_ALL;
+                               id->recalc &= ~ID_RECALC_ALL;
 
                                /* Some ID's contain semi-datablock nodetree */
                                ntree = ntreeFromID(id);
                                if (ntree != NULL) {
-                                       ntree->id.tag &= ~LIB_TAG_ID_RECALC_ALL;
+                                       ntree->id.recalc &= ~ID_RECALC_ALL;
                                }
                        }
                }
index dcd9a17761de84a07754ce7916a00dea5bb229f7..107bbda1030df405743fb2171be857091b02c4c8 100644 (file)
@@ -65,13 +65,13 @@ namespace {
 // TODO(sergey): De-duplicate with depsgraph_tag,cc
 void lib_id_recalc_tag(Main *bmain, ID *id)
 {
-       id->tag |= LIB_TAG_ID_RECALC;
+       id->recalc |= ID_RECALC;
        DEG_id_type_tag(bmain, GS(id->name));
 }
 
 void lib_id_recalc_data_tag(Main *bmain, ID *id)
 {
-       id->tag |= LIB_TAG_ID_RECALC_DATA;
+       id->recalc |= ID_RECALC_DATA;
        DEG_id_type_tag(bmain, GS(id->name));
 }
 
index f0fc651353f04eb0c090726f950818a4e7c35f31..c1c4d6c5376c4d3915f2f730c037d6f64a619294 100644 (file)
@@ -348,18 +348,20 @@ enum {
        /* RESET_AFTER_USE tag existing data before linking so we know what is new. */
        LIB_TAG_PRE_EXISTING    = 1 << 11,
 
-       /* RESET_AFTER_USE, used by update code (depsgraph). */
-       LIB_TAG_ID_RECALC       = 1 << 12,
-       LIB_TAG_ID_RECALC_DATA  = 1 << 13,
-       LIB_TAG_ANIM_NO_RECALC  = 1 << 14,
-       LIB_TAG_ID_RECALC_ALL   = (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA),
-
        /* RESET_NEVER tag datablock for freeing etc. behavior (usually set when copying real one into temp/runtime one). */
-       LIB_TAG_NO_MAIN          = 1 << 16,  /* Datablock is not listed in Main database. */
-       LIB_TAG_NO_USER_REFCOUNT = 1 << 17,  /* Datablock does not refcount usages of other IDs. */
+       LIB_TAG_NO_MAIN          = 1 << 11,  /* Datablock is not listed in Main database. */
+       LIB_TAG_NO_USER_REFCOUNT = 1 << 13,  /* Datablock does not refcount usages of other IDs. */
        /* Datablock was not allocated by standard system (BKE_libblock_alloc), do not free its memory
         * (usual type-specific freeing is called though). */
-       LIB_TAG_NOT_ALLOCATED     = 1 << 18,
+       LIB_TAG_NOT_ALLOCATED     = 1 << 14,
+};
+
+enum {
+       /* RESET_AFTER_USE, used by update code (depsgraph). */
+       ID_RECALC       = 1 << 0,
+       ID_RECALC_DATA  = 1 << 1,
+       ID_RECALC_SKIP_ANIM_TAG  = 1 << 2,
+       ID_RECALC_ALL   = (ID_RECALC | ID_RECALC_DATA),
 };
 
 /* To filter ID types (filter_id) */
index 9205e15671b43da22b25b5977aee7aa81f83934d..a9e34247cbd6614563c4b46b994ba70021b36d70 100644 (file)
@@ -997,12 +997,12 @@ static void rna_def_ID(BlenderRNA *brna)
                                 "(initial state is undefined)");
 
        prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_ID_RECALC);
+       RNA_def_property_boolean_sdna(prop, NULL, "recalc", ID_RECALC);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Is Updated", "Data-block is tagged for recalculation");
 
        prop = RNA_def_property(srna, "is_updated_data", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "tag", LIB_TAG_ID_RECALC_DATA);
+       RNA_def_property_boolean_sdna(prop, NULL, "recalc", ID_RECALC_DATA);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Is Updated Data", "Data-block data is tagged for recalculation");
 
index 77fd84a294890d9cd114f904c3b3e957851ab383..1c3a5d3d7be3d1c147a2de909be376bb4ece39f8 100644 (file)
@@ -575,7 +575,7 @@ static void correctivesmooth_modifier_do(
        const bool force_delta_cache_update =
                /* XXX, take care! if mesh data its self changes we need to forcefully recalculate deltas */
                ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO) &&
-                (((ID *)ob->data)->tag & LIB_TAG_ID_RECALC));
+                (((ID *)ob->data)->recalc & ID_RECALC));
 
        bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0;
        MDeformVert *dvert = NULL;