[Bf-blender-cvs] [d04b16b] depsgraph_refactor: Depsgraph: Experiment with time source dependnecy update

Sergey Sharybin noreply at git.blender.org
Fri Nov 7 12:54:54 CET 2014


Commit: d04b16b3b25133635bee3085a97931939036f34a
Author: Sergey Sharybin
Date:   Fri Nov 7 12:47:03 2014 +0100
Branches: depsgraph_refactor
https://developer.blender.org/rBd04b16b3b25133635bee3085a97931939036f34a

Depsgraph: Experiment with time source dependnecy update

Goal is to be able to play animation back for investigating how flush
happens, how object dependencies are being evaluated and all the rest
of the stuff which isn't so visible with the static scene.

Main idea here is to have a relations in the depsgraph between the time
source node and all the nodes which depends on time. We go with the
relations approach in order to make it fast to figure out which nodes
are to be tagged for updated when the time changes. It is faster to
iterate over the time dependencies rather than iterating over the whole
depsgraph,

Now, currently dependency graph's relations links only possible between
operation nodes. For this reason we don't use actual dependency structure
to define relations between time and nodes, but we've got a list of nodes
which depends on time stored in the time source node. This is the most
simple way to deal for now.

Currently we use relation between time and ID nodes, which corresponds
to how current depsgraph works, in the future we'll likely need to make
it relation betteen time source and individual components.

Or maybe even revisit the time flushes..

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

M	source/blender/depsgraph/intern/depsgraph.cpp
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build_relations.cpp
M	source/blender/depsgraph/intern/depsgraph_eval.cpp
M	source/blender/depsgraph/intern/depsnode.cpp
M	source/blender/depsgraph/intern/depsnode.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph.cpp b/source/blender/depsgraph/intern/depsgraph.cpp
index 3e6b1a8..a66c21c 100644
--- a/source/blender/depsgraph/intern/depsgraph.cpp
+++ b/source/blender/depsgraph/intern/depsgraph.cpp
@@ -253,6 +253,13 @@ DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from, OperationDeps
 	return rel;
 }
 
+/* Add new dependency between outer ID node and time. */
+void Depsgraph::add_new_time_relation(IDDepsNode *from)
+{
+	TimeSourceDepsNode *time_src = find_time_source();
+	time_src->add_time_dependency(from);
+}
+
 /* Sort nodes to determine evaluation order for operation nodes
  * where dependency relationships won't get violated.
  */
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index cfe7faf..715086e 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -141,7 +141,10 @@ struct Depsgraph {
 	DepsRelation *add_new_relation(OperationDepsNode *from, OperationDepsNode *to,
 	                               eDepsRelation_Type type, 
 	                               const string &description);
-	
+
+	/* Add new dependency between outer ID node and time. */
+	void add_new_time_relation(IDDepsNode *from);
+
 	/* Sort nodes to determine evaluation order for operation nodes
 	 * where dependency relationships won't get violated.
 	 */
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index 6622618..0f38b4d 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -101,6 +101,58 @@ extern "C" {
 
 #include "stubs.h" // XXX: REMOVE THIS INCLUDE ONCE DEPSGRAPH REFACTOR PROJECT IS DONE!!!
 
+/* TODO(sergey): This is a stupid copy of function from depsgraph.c/ */
+static bool object_modifiers_use_time(Object *ob)
+{
+	ModifierData *md;
+
+	/* check if a modifier in modifier stack needs time input */
+	for (md = (ModifierData *)ob-> modifiers.first;
+	     md != NULL;
+	     md = (ModifierData *)md->next)
+	{
+		if (modifier_dependsOnTime(md)) {
+			return true;
+		}
+	}
+
+	/* check whether any modifiers are animated */
+	if (ob->adt) {
+		AnimData *adt = ob->adt;
+		FCurve *fcu;
+
+		/* action - check for F-Curves with paths containing 'modifiers[' */
+		if (adt->action) {
+			for (fcu = (FCurve *)adt->action->curves.first;
+			     fcu != NULL;
+			     fcu = (FCurve *)fcu->next)
+			{
+				if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
+					return true;
+			}
+		}
+
+		/* This here allows modifier properties to get driven and still update properly
+		 *
+		 * Workaround to get [#26764] (e.g. subsurf levels not updating when animated/driven)
+		 * working, without the updating problems ([#28525] [#28690] [#28774] [#28777]) caused
+		 * by the RNA updates cache introduced in r.38649
+		 */
+		for (fcu = (FCurve *)adt->drivers.first;
+		     fcu != NULL;
+		     fcu = (FCurve *)fcu->next)
+		{
+			if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
+				return true;
+		}
+
+		/* XXX: also, should check NLA strips, though for now assume that nobody uses
+		 * that and we can omit that for performance reasons... */
+	}
+
+	return false;
+}
+
 /* ************************************************* */
 /* Relations Builder */
 
@@ -152,6 +204,14 @@ void DepsgraphRelationBuilder::build_scene(Scene *scene)
 
 void DepsgraphRelationBuilder::build_object(Scene *scene, Object *ob)
 {
+	/* TODO(sergey): This is mainly for the testing purposes, in the final
+	 * design we'll need to add relation between individual component to the
+	 * time source.
+	 */
+	if (object_modifiers_use_time(ob)) {
+		m_graph->add_new_time_relation(m_graph->find_id_node(&ob->id));
+	}
+
 	if (ob->parent)
 		build_object_parent(ob);
 	
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cpp b/source/blender/depsgraph/intern/depsgraph_eval.cpp
index d9541ae..88dd744 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cpp
@@ -248,11 +248,9 @@ void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx,
 	/* update time on primary timesource */
 	TimeSourceDepsNode *tsrc = graph->find_time_source();
 	tsrc->cfra = ctime;
-	
-#if 0 /* XXX TODO */
-	graph->tag_update(tsrc);
-#endif
-	
+
+	tsrc->tag_update(graph);
+
 	/* perform recalculation updates */
 	DEG_evaluate_on_refresh(eval_ctx, graph);
 }
diff --git a/source/blender/depsgraph/intern/depsnode.cpp b/source/blender/depsgraph/intern/depsnode.cpp
index 35df955..0a35661 100644
--- a/source/blender/depsgraph/intern/depsnode.cpp
+++ b/source/blender/depsgraph/intern/depsnode.cpp
@@ -67,6 +67,24 @@ DepsNode::~DepsNode()
 /* ******************************************************** */
 /* Generic Nodes */
 
+/* Time Source Node ============================================== */
+
+void TimeSourceDepsNode::tag_update(Depsgraph *graph)
+{
+	for (vector<IDDepsNode*>::const_iterator it_id = id_nodes.begin();
+	     it_id != id_nodes.end();
+	     ++it_id)
+	{
+		IDDepsNode *id_node = *it_id;
+		id_node->tag_update(graph);
+	}
+}
+
+void TimeSourceDepsNode::add_time_dependency(IDDepsNode *from)
+{
+	id_nodes.push_back(from);
+}
+
 /* Root Node ============================================== */
 
 TimeSourceDepsNode *RootDepsNode::add_time_source(const string &name)
diff --git a/source/blender/depsgraph/intern/depsnode.h b/source/blender/depsgraph/intern/depsnode.h
index 0f7a69d..c9014bc 100644
--- a/source/blender/depsgraph/intern/depsnode.h
+++ b/source/blender/depsgraph/intern/depsnode.h
@@ -27,6 +27,8 @@
 #ifndef __DEPSNODE_H__
 #define __DEPSNODE_H__
 
+#include <vector>
+
 #include "MEM_guardedalloc.h"
 
 #include "depsgraph_types.h"
@@ -83,18 +85,25 @@ public:
 #define DEG_DEPSNODE_DEFINE(NodeType, type_, tname_) \
 	const DepsNode::TypeInfo NodeType::typeinfo = DepsNode::TypeInfo(type_, tname_)
 
+using std::vector;
 
 /* Generic Nodes ======================= */
 
 struct ComponentDepsNode;
+struct IDDepsNode;
 
 /* Time Source Node */
 struct TimeSourceDepsNode : public DepsNode {
 	// XXX: how do we keep track of the chain of time sources for propagation of delays?
-	
+
 	double cfra;                    /* new "current time" */
 	double offset;                  /* time-offset relative to the "official" time source that this one has */
-	
+
+	void tag_update(Depsgraph *graph);
+	void add_time_dependency(IDDepsNode *from);
+
+	vector<IDDepsNode*> id_nodes;
+
 	DEG_DEPSNODE_DECLARE;
 };




More information about the Bf-blender-cvs mailing list