[Bf-blender-cvs] [d87f289] depsgraph_refactor: Depsgraph: Changes in the way how tagging objects and relations for update are working together

Sergey Sharybin noreply at git.blender.org
Mon Feb 23 17:03:55 CET 2015


Commit: d87f289ba7d633f6837289f91cf33c6daa1da16f
Author: Sergey Sharybin
Date:   Mon Feb 23 19:15:31 2015 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rBd87f289ba7d633f6837289f91cf33c6daa1da16f

Depsgraph: Changes in the way how tagging objects and relations for update are working together

The idea is to get rid of rather obscure set which stored missing IDs for delayed update
after the relations are up-to-date. New idea is to re-use the ID recalc flags and do needed
re-scheduling during depsgraph build. This is combined together with layers visibility check
so would not add extra slowdown or so.

This change also makes it so ob->recalc flags are properly set and reset, which was discovered
needed for the animation paths update and likely for other baking-like areas which does manual
scene update.

===================================================================

M	source/blender/blenkernel/intern/object_update.c
M	source/blender/depsgraph/intern/depsgraph.cpp
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build.cpp
M	source/blender/depsgraph/intern/depsgraph_tag.cpp

===================================================================

diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index c62e8a1..4985f5d 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -299,8 +299,7 @@ void BKE_object_eval_uber_transform(EvaluationContext *UNUSED(eval_ctx),
 {
 	/* TODO(sergey): Currently it's a duplicate of logic in BKE_object_handle_update_ex(). */
 	// XXX: it's almost redundant now...
-	
-	
+
 	/* Handle proxy copy for target, */
 	if (ob->id.lib && ob->proxy_from) {
 		if (ob->proxy_from->proxy_group) {
@@ -316,6 +315,11 @@ void BKE_object_eval_uber_transform(EvaluationContext *UNUSED(eval_ctx),
 		else
 			copy_m4_m4(ob->obmat, ob->proxy_from->obmat);
 	}
+
+	ob->recalc &= ~(OB_RECALC_OB|OB_RECALC_TIME);
+	if (ob->data == NULL) {
+		ob->recalc &= ~OB_RECALC_DATA;
+	}
 }
 
 void BKE_object_eval_uber_data(EvaluationContext *eval_ctx,
@@ -325,4 +329,6 @@ void BKE_object_eval_uber_data(EvaluationContext *eval_ctx,
 	DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
 	BLI_assert(ob->type != OB_ARMATURE);
 	BKE_object_handle_data_update(eval_ctx, scene, ob);
+
+	ob->recalc &= ~(OB_RECALC_DATA|OB_RECALC_TIME);
 }
diff --git a/source/blender/depsgraph/intern/depsgraph.cpp b/source/blender/depsgraph/intern/depsgraph.cpp
index cfb8b13..d7e9cd2 100644
--- a/source/blender/depsgraph/intern/depsgraph.cpp
+++ b/source/blender/depsgraph/intern/depsgraph.cpp
@@ -420,13 +420,6 @@ void Depsgraph::add_entry_tag(OperationDepsNode *node)
 	this->entry_tags.insert(node);
 }
 
-/* Tag a specific ID as needing updates. */
-void Depsgraph::add_id_tag(ID *id)
-{
-	/* Tagging of actual operations happens in DEG_scene_relations_update(). */
-	this->id_tags.insert(id);
-}
-
 void Depsgraph::clear_all_nodes()
 {
 	clear_id_nodes();
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 11dbf10..2170904 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -93,7 +93,6 @@ struct Depsgraph {
 	typedef unordered_map<const ID *, IDDepsNode *> IDNodeMap;
 	typedef unordered_set<SubgraphDepsNode *> Subgraphs;
 	typedef unordered_set<OperationDepsNode *> EntryTags;
-	typedef unordered_set<ID *> IDTags;
 	typedef vector<OperationDepsNode *> OperationNodes;
 
 	Depsgraph();
@@ -150,9 +149,6 @@ struct Depsgraph {
 	/* Tag a specific node as needing updates. */
 	void add_entry_tag(OperationDepsNode *node);
 
-	/* Tag a specific ID as needing updates. */
-	void add_id_tag(ID *id);
-
 	/* Clear storage used by all nodes. */
 	void clear_all_nodes();
 
@@ -176,11 +172,6 @@ struct Depsgraph {
 	/* Nodes which have been tagged as "directly modified". */
 	EntryTags entry_tags;
 
-	/* Nodes which have been tagged for update but were missing
-	 * in the current dependency graph.
-	 */
-	IDTags id_tags;
-
 	/* Convenience Data ................... */
 
 	/* XXX: should be collected after building (if actually needed?) */
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index a8a39b3..b96f263 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -468,7 +468,7 @@ static void deg_graph_transitive_reduction(Depsgraph *graph)
 	}
 }
 
-static void deg_graph_flush_node_layers(Depsgraph *graph)
+static void deg_graph_build_finalize(Depsgraph *graph)
 {
 	std::stack<OperationDepsNode*> stack;
 
@@ -492,6 +492,8 @@ static void deg_graph_flush_node_layers(Depsgraph *graph)
 		if (node->num_links_pending == 0) {
 			stack.push(node);
 		}
+		IDDepsNode *id_node = node->owner->owner;
+		id_node->id->flag |= LIB_DOIT;
 	}
 
 	while (!stack.empty()) {
@@ -529,6 +531,27 @@ static void deg_graph_flush_node_layers(Depsgraph *graph)
 					id_node->layers |= id_to->layers;
 				}
 			}
+
+			/* Re-tag ID for update if it was tagged befoee the relations
+			 * update tag.
+			 */
+			ID *id = id_node->id;
+			if (id->flag & LIB_ID_RECALC_ALL &&
+			    id->flag & LIB_DOIT)
+			{
+				id_node->tag_update(graph);
+				if (GS(id->name) == ID_OB) {
+					Object *object = (Object *)id;
+					if (object->recalc & OB_RECALC_TIME) {
+						ComponentDepsNode *anim_comp =
+						        id_node->find_component(DEPSNODE_TYPE_ANIMATION);
+						if (anim_comp != NULL) {
+							anim_comp->tag_update(graph);
+						}
+					}
+				}
+				id->flag &= ~LIB_DOIT;
+			}
 		}
 	}
 }
@@ -721,7 +744,9 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
 		deg_graph_transitive_reduction(graph);
 	}
 
-	deg_graph_flush_node_layers(graph);
+	/* 5) Flush visibility layer and re-schedule nodes for update. */
+	deg_graph_build_finalize(graph);
+
 #if 0
 	if (!DEG_debug_consistency_check(graph)) {
 		printf("Consistency validation failed, ABORTING!\n");
@@ -767,18 +792,6 @@ void DEG_scene_relations_update(Main *bmain, Scene *scene)
 		return;
 	}
 
-	/* Store all oeprations which needs to be re-tagged in new graph. */
-	for (Depsgraph::EntryTags::const_iterator it = graph->entry_tags.begin();
-	     it != graph->entry_tags.end();
-	     ++it)
-	{
-		OperationDepsNode *node = *it;
-		/* TODO(sergey): Ideally we'll need to only re-tag operations,
-		 * not the whole ID nodes.
-		 */
-		graph->add_id_tag(node->owner->owner->id);
-	}
-
 	/* Clear all previous nodes and operations. */
 	graph->clear_all_nodes();
 	graph->operations.clear();
@@ -788,15 +801,6 @@ void DEG_scene_relations_update(Main *bmain, Scene *scene)
 	/* Build new nodes and relations. */
 	DEG_graph_build_from_scene(graph, bmain, scene);
 
-	for (Depsgraph::IDTags::const_iterator it = graph->id_tags.begin();
-	     it != graph->id_tags.end();
-	     ++it)
-	{
-		ID *id = *it;
-		DEG_graph_id_tag_update(bmain, graph, id);
-	}
-	graph->id_tags.clear();
-
 	graph->need_update = false;
 }
 
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cpp b/source/blender/depsgraph/intern/depsgraph_tag.cpp
index b01398b..8865467 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cpp
@@ -74,6 +74,25 @@ static void lib_id_recalc_data_tag(Main *bmain, ID *id)
 static void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag)
 {
 	if (flag) {
+		/* This bit of code ensures legacy object->recalc flags
+		 * are still filled in the same way as it was expected
+		 * with the old dependency graph.
+		 *
+		 * This is because some areas like motion paths and likely
+		 * some other physics baking process are doing manual scene
+		 * update on all the frames, trying to minimize number of
+		 * updates.
+		 *
+		 * But this flag will also let us to re-construct entry
+		 * nodes for update after relations update and after layer
+		 * visibility changes.
+		 */
+		short idtype = GS(id->name);
+		if (idtype == ID_OB) {
+			Object *object = (Object *)id;
+			object->recalc |= (flag & OB_RECALC_ALL);
+		}
+
 		if (flag & OB_RECALC_OB)
 			lib_id_recalc_tag(bmain, id);
 		if (flag & (OB_RECALC_DATA | PSYS_RECALC))
@@ -102,13 +121,9 @@ void DEG_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id)
 {
 	IDDepsNode *node = graph->find_id_node(id);
 	lib_id_recalc_tag(bmain, id);
-	if (node) {
+	if (node != NULL) {
 		node->tag_update(graph);
 	}
-	else {
-		/* Store the ID for tagging later. */
-		graph->add_id_tag(id);
-	}
 }
 
 /* Tag nodes related to a specific piece of data */




More information about the Bf-blender-cvs mailing list