Depsgraph: Use more meaningful name for flags storage
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Sep 2018 12:35:42 +0000 (14:35 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Sep 2018 13:20:06 +0000 (15:20 +0200)
source/blender/depsgraph/intern/builder/deg_builder.cc
source/blender/depsgraph/intern/builder/deg_builder_cycle.cc
source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
source/blender/depsgraph/intern/depsgraph_debug.cc
source/blender/depsgraph/intern/depsgraph_query_filter.cc
source/blender/depsgraph/intern/depsgraph_query_foreach.cc
source/blender/depsgraph/intern/eval/deg_eval.cc
source/blender/depsgraph/intern/eval/deg_eval_flush.cc
source/blender/depsgraph/intern/nodes/deg_node.h

index 73edf0ef9935d6e4baa0d9d848ec83aff5b6d98c..aacd106ceed507305674c9c3d2b07cb0fa76c519 100644 (file)
@@ -58,10 +58,14 @@ namespace {
 
 void deg_graph_build_flush_visibility(Depsgraph *graph)
 {
+       enum {
+               DEG_NODE_VISITED = (1 << 0),
+       };
+
        BLI_Stack *stack = BLI_stack_new(sizeof(OperationDepsNode *),
                                         "DEG flush layers stack");
        foreach (OperationDepsNode *op_node, graph->operations) {
-               op_node->done = 0;
+               op_node->custom_flags = 0;
                op_node->num_links_pending = 0;
                foreach (DepsRelation *rel, op_node->outlinks) {
                        if ((rel->from->type == DEG_NODE_TYPE_OPERATION) &&
@@ -72,7 +76,7 @@ void deg_graph_build_flush_visibility(Depsgraph *graph)
                }
                if (op_node->num_links_pending == 0) {
                        BLI_stack_push(stack, &op_node);
-                       op_node->done = 1;
+                       op_node->custom_flags |= DEG_NODE_VISITED;
                }
        }
        while (!BLI_stack_is_empty(stack)) {
@@ -94,9 +98,11 @@ void deg_graph_build_flush_visibility(Depsgraph *graph)
                                        BLI_assert(op_from->num_links_pending > 0);
                                        --op_from->num_links_pending;
                                }
-                               if (op_from->num_links_pending == 0 && op_from->done == 0) {
+                               if ((op_from->num_links_pending == 0) &&
+                                   (op_from->custom_flags & DEG_NODE_VISITED) == 0)
+                               {
                                        BLI_stack_push(stack, &op_from);
-                                       op_from->done = 1;
+                                       op_from->custom_flags |= DEG_NODE_VISITED;
                                }
                        }
                }
index feaba1a4aa8fa4ee25fe16a1cfeb77fc03129ac7..0d28344ef95fa7af061d44312b678a6983496b01 100644 (file)
@@ -86,22 +86,22 @@ struct CyclesSolverState {
 BLI_INLINE void set_node_visited_state(DepsNode *node,
                                        eCyclicCheckVisitedState state)
 {
-       node->done = (node->done & ~0x3) | (int)state;
+       node->custom_flags = (node->custom_flags & ~0x3) | (int)state;
 }
 
 BLI_INLINE eCyclicCheckVisitedState get_node_visited_state(DepsNode *node)
 {
-       return (eCyclicCheckVisitedState)(node->done & 0x3);
+       return (eCyclicCheckVisitedState)(node->custom_flags & 0x3);
 }
 
 BLI_INLINE void set_node_num_visited_children(DepsNode *node, int num_children)
 {
-       node->done = (node->done & 0x3) | (num_children << 2);
+       node->custom_flags = (node->custom_flags & 0x3) | (num_children << 2);
 }
 
 BLI_INLINE int get_node_num_visited_children(DepsNode *node)
 {
-       return node->done >> 2;
+       return node->custom_flags >> 2;
 }
 
 void schedule_node_to_stack(CyclesSolverState *state, OperationDepsNode *node)
@@ -124,7 +124,7 @@ void schedule_leaf_nodes(CyclesSolverState *state)
                                has_inlinks = true;
                        }
                }
-               node->done = 0;
+               node->custom_flags = 0;
                if (has_inlinks == false) {
                        schedule_node_to_stack(state, node);
                }
index 17e64c5f685ffe42e6887b2f3a342cf123818306..a39b18f2f0a9453cead6400de736df9ebf959dc4 100644 (file)
@@ -65,16 +65,16 @@ enum {
 
 static void deg_graph_tag_paths_recursive(DepsNode *node)
 {
-       if (node->done & OP_VISITED) {
+       if (node->custom_flags & OP_VISITED) {
                return;
        }
-       node->done |= OP_VISITED;
+       node->custom_flags |= OP_VISITED;
        foreach (DepsRelation *rel, node->inlinks) {
                deg_graph_tag_paths_recursive(rel->from);
                /* Do this only in inlinks loop, so the target node does not get
                 * flagged.
                 */
-               rel->from->done |= OP_REACHABLE;
+               rel->from->custom_flags |= OP_REACHABLE;
        }
 }
 
@@ -84,13 +84,13 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
        foreach (OperationDepsNode *target, graph->operations) {
                /* Clear tags. */
                foreach (OperationDepsNode *node, graph->operations) {
-                       node->done = 0;
+                       node->custom_flags = 0;
                }
                /* Mark nodes from which we can reach the target
                 * start with children, so the target node and direct children are not
                 * flagged.
                 */
-               target->done |= OP_VISITED;
+               target->custom_flags |= OP_VISITED;
                foreach (DepsRelation *rel, target->inlinks) {
                        deg_graph_tag_paths_recursive(rel->from);
                }
@@ -101,13 +101,14 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
                {
                        DepsRelation *rel = *it_rel;
                        if (rel->from->type == DEG_NODE_TYPE_TIMESOURCE) {
-                               /* HACK: time source nodes don't get "done" flag set/cleared. */
+                               /* HACK: time source nodes don't get "custom_flags" flag
+                                * set/cleared. */
                                /* TODO: there will be other types in future, so iterators above
                                 * need modifying.
                                 */
                                ++it_rel;
                        }
-                       else if (rel->from->done & OP_REACHABLE) {
+                       else if (rel->from->custom_flags & OP_REACHABLE) {
                                rel->unlink();
                                OBJECT_GUARDED_DELETE(rel, DepsRelation);
                                ++num_removed_relations;
index f7adaafe5b3b025f2640e36e856392c2a3305100..91db054b006f0eb3a3549d3888065c0ae95a5c3c 100644 (file)
@@ -171,11 +171,11 @@ bool DEG_debug_consistency_check(Depsgraph *graph)
        /* Validate node valency calculated in both directions. */
        foreach (DEG::OperationDepsNode *node, deg_graph->operations) {
                node->num_links_pending = 0;
-               node->done = 0;
+               node->custom_flags = 0;
        }
 
        foreach (DEG::OperationDepsNode *node, deg_graph->operations) {
-               if (node->done) {
+               if (node->custom_flags) {
                        printf("Node %s is twice in the operations!\n",
                               node->identifier().c_str());
                        return false;
@@ -187,7 +187,7 @@ bool DEG_debug_consistency_check(Depsgraph *graph)
                                ++to->num_links_pending;
                        }
                }
-               node->done = 1;
+               node->custom_flags = 1;
        }
 
        foreach (DEG::OperationDepsNode *node, deg_graph->operations) {
index 46abd9d99411be1fb5d06acc9cf2e49648ef4358..11858bd1b1c5c095d6d5f74d88a9c4c0de289baf 100644 (file)
@@ -120,12 +120,12 @@ static void deg_unlink_opnode(Depsgraph *graph, OperationDepsNode *op_node)
 static void deg_filter_remove_unwanted_ids(Depsgraph *graph, GSet *retained_ids)
 {
        /* 1) First pass over ID nodes + their operations
-        * - Identify and tag ID's (via "done = 1") to be removed
+        * - Identify and tag ID's (via "custom_flags = 1") to be removed
         * - Remove all links to/from operations that will be removed
         */
        foreach (IDDepsNode *id_node, graph->id_nodes) {
-               id_node->done = !BLI_gset_haskey(retained_ids, (void *)id_node->id_orig);
-               if (id_node->done) {
+               id_node->custom_flags = !BLI_gset_haskey(retained_ids, (void *)id_node->id_orig);
+               if (id_node->custom_flags) {
                        GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
                        {
                                foreach (OperationDepsNode *op_node, comp_node->operations) {
@@ -143,7 +143,7 @@ static void deg_filter_remove_unwanted_ids(Depsgraph *graph, GSet *retained_ids)
        {
                OperationDepsNode *op_node = *it_opnode;
                IDDepsNode *id_node = op_node->owner->owner;
-               if (id_node->done) {
+               if (id_node->custom_flags) {
                        it_opnode = graph->operations.erase(it_opnode);
                }
                else {
@@ -164,7 +164,7 @@ static void deg_filter_remove_unwanted_ids(Depsgraph *graph, GSet *retained_ids)
                IDDepsNode *id_node = *it_id;
                ID *id = id_node->id_orig;
 
-               if (id_node->done) {
+               if (id_node->custom_flags) {
                        /* Destroy node data, then remove from collections, and free */
                        id_node->destroy();
 
index c8aaf353874501e69bf2ba7e703829415a5b26ec..b6138e4e81cee48b8cb68e55ea8d141c9ddb05b6 100644 (file)
@@ -60,6 +60,9 @@ extern "C" {
 namespace DEG {
 
 typedef std::deque<OperationDepsNode *> TraversalQueue;
+enum {
+       DEG_NODE_VISITED = (1 << 0),
+};
 
 static void deg_foreach_clear_flags(const Depsgraph *graph)
 {
@@ -67,7 +70,7 @@ static void deg_foreach_clear_flags(const Depsgraph *graph)
                op_node->scheduled = false;
        }
        foreach (IDDepsNode *id_node, graph->id_nodes) {
-               id_node->done = false;
+               id_node->custom_flags = 0;
        }
 }
 
@@ -96,7 +99,7 @@ static void deg_foreach_dependent_ID(const Depsgraph *graph,
                }
        }
        GHASH_FOREACH_END();
-       target_id_node->done = true;
+       target_id_node->custom_flags |= DEG_NODE_VISITED;
        /* Process the queue. */
        while (!queue.empty()) {
                /* get next operation node to process. */
@@ -106,10 +109,10 @@ static void deg_foreach_dependent_ID(const Depsgraph *graph,
                        /* Check whether we need to inform callee about corresponding ID node. */
                        ComponentDepsNode *comp_node = op_node->owner;
                        IDDepsNode *id_node = comp_node->owner;
-                       if (!id_node->done) {
+                       if ((id_node->custom_flags & DEG_NODE_VISITED) == 0) {
                                /* TODO(sergey): Is it orig or CoW? */
                                callback(id_node->id_orig, user_data);
-                               id_node->done = true;
+                               id_node->custom_flags |= DEG_NODE_VISITED;
                        }
                        /* Schedule outgoing operation nodes. */
                        if (op_node->outlinks.size() == 1) {
@@ -161,7 +164,7 @@ static void deg_foreach_ancestor_ID(const Depsgraph *graph,
                }
        }
        GHASH_FOREACH_END();
-       target_id_node->done = true;
+       target_id_node->custom_flags |= DEG_NODE_VISITED;
        /* Process the queue. */
        while (!queue.empty()) {
                /* get next operation node to process. */
@@ -171,10 +174,10 @@ static void deg_foreach_ancestor_ID(const Depsgraph *graph,
                        /* Check whether we need to inform callee about corresponding ID node. */
                        ComponentDepsNode *comp_node = op_node->owner;
                        IDDepsNode *id_node = comp_node->owner;
-                       if (!id_node->done) {
+                       if ((id_node->custom_flags & DEG_NODE_VISITED) == 0) {
                                /* TODO(sergey): Is it orig or CoW? */
                                callback(id_node->id_orig, user_data);
-                               id_node->done = true;
+                               id_node->custom_flags |= DEG_NODE_VISITED;
                        }
                        /* Schedule incoming operation nodes. */
                        if (op_node->inlinks.size() == 1) {
index fb8b8e73ef6d0ca989a6426c1ca7b4ff5018248c..0d1adfb0144abf60e49953b042bc128fc0360170 100644 (file)
@@ -178,7 +178,6 @@ static void initialize_execution(DepsgraphEvalState *state, Depsgraph *graph)
        calculate_pending_parents(graph);
        /* Clear tags and other things which needs to be clear. */
        foreach (OperationDepsNode *node, graph->operations) {
-               node->done = 0;
                if (do_stats) {
                        node->stats.reset_current();
                }
index 16cb1b394f6bba59a936330925539af6351b9350..e59aed0f8d8475c0545859f59b594a4771ea9785 100644 (file)
@@ -106,9 +106,9 @@ void flush_init_id_node_func(
 {
        Depsgraph *graph = (Depsgraph *)data_v;
        IDDepsNode *id_node = graph->id_nodes[i];
-       id_node->done = ID_STATE_NONE;
+       id_node->custom_flags = ID_STATE_NONE;
        GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
-               comp_node->done = COMPONENT_STATE_NONE;
+               comp_node->custom_flags = COMPONENT_STATE_NONE;
        GHASH_FOREACH_END();
 }
 
@@ -151,7 +151,7 @@ BLI_INLINE void flush_schedule_entrypoints(Depsgraph *graph, FlushQueue *queue)
 
 BLI_INLINE void flush_handle_id_node(IDDepsNode *id_node)
 {
-       id_node->done = ID_STATE_MODIFIED;
+       id_node->custom_flags = ID_STATE_MODIFIED;
 }
 
 /* TODO(sergey): We can reduce number of arguments here. */
@@ -160,10 +160,10 @@ BLI_INLINE void flush_handle_component_node(IDDepsNode *id_node,
                                             FlushQueue *queue)
 {
        /* We only handle component once. */
-       if (comp_node->done == COMPONENT_STATE_DONE) {
+       if (comp_node->custom_flags == COMPONENT_STATE_DONE) {
                return;
        }
-       comp_node->done = COMPONENT_STATE_DONE;
+       comp_node->custom_flags = COMPONENT_STATE_DONE;
        /* Tag all required operations in component for update.  */
        foreach (OperationDepsNode *op, comp_node->operations) {
                /* We don't want to flush tags in "upstream" direction for
@@ -183,9 +183,9 @@ BLI_INLINE void flush_handle_component_node(IDDepsNode *id_node,
                ComponentDepsNode *pose_comp =
                        id_node->find_component(DEG_NODE_TYPE_EVAL_POSE);
                BLI_assert(pose_comp != NULL);
-               if (pose_comp->done == COMPONENT_STATE_NONE) {
+               if (pose_comp->custom_flags == COMPONENT_STATE_NONE) {
                        queue->push_front(pose_comp->get_entry_operation());
-                       pose_comp->done = COMPONENT_STATE_SCHEDULED;
+                       pose_comp->custom_flags = COMPONENT_STATE_SCHEDULED;
                }
        }
 }
@@ -236,7 +236,7 @@ void flush_editors_id_update(Main *bmain,
                              const DEGEditorUpdateContext *update_ctx)
 {
        foreach (IDDepsNode *id_node, graph->id_nodes) {
-               if (id_node->done != ID_STATE_MODIFIED) {
+               if (id_node->custom_flags != ID_STATE_MODIFIED) {
                        continue;
                }
                DEG_id_type_tag(bmain, GS(id_node->id_orig->name));
@@ -251,7 +251,7 @@ void flush_editors_id_update(Main *bmain,
                /* Gather recalc flags from all changed components. */
                GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
                {
-                       if (comp_node->done != COMPONENT_STATE_DONE) {
+                       if (comp_node->custom_flags != COMPONENT_STATE_DONE) {
                                continue;
                        }
                        DepsNodeFactory *factory = deg_type_get_factory(comp_node->type);
@@ -311,7 +311,7 @@ void invalidate_tagged_evaluated_data(Depsgraph *graph)
 {
 #ifdef INVALIDATE_ON_FLUSH
        foreach (IDDepsNode *id_node, graph->id_nodes) {
-               if (id_node->done != ID_STATE_MODIFIED) {
+               if (id_node->custom_flags != ID_STATE_MODIFIED) {
                        continue;
                }
                ID *id_cow = id_node->id_cow;
@@ -320,7 +320,7 @@ void invalidate_tagged_evaluated_data(Depsgraph *graph)
                }
                GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
                {
-                       if (comp_node->done != COMPONENT_STATE_DONE) {
+                       if (comp_node->custom_flags != COMPONENT_STATE_DONE) {
                                continue;
                        }
                        switch (comp_node->type) {
index 603a6be7cebfbdf190e2d368498b94033f4b0e10..ef2a73258fdb5879eab29534b9fe2f69bf4172dd 100644 (file)
@@ -80,9 +80,15 @@ struct DepsNode {
        eDepsNode_Type type;  /* Structural type of node. */
        Relations inlinks;    /* Nodes which this one depends on. */
        Relations outlinks;   /* Nodes which depend on this one. */
-       int done;     /* Generic tags for traversal algorithms. */
        Stats stats;  /* Evaluation statistics. */
 
+       /* Generic tags for traversal algorithms and such.
+        *
+        * Actual meaning of values depends on a specific area. Every area is to
+        * clean this before use.
+        */
+       int custom_flags;
+
        /* Methods. */
        DepsNode();
        virtual ~DepsNode();