[Bf-blender-cvs] [7784957] depsgraph_refactor: Depsgraph: use command-line switch to legacy depsgraph

Sergey Sharybin noreply at git.blender.org
Wed Jan 7 16:24:03 CET 2015


Commit: 7784957df947ada04e2fb31659eb1e3090134754
Author: Sergey Sharybin
Date:   Wed Jan 7 20:21:44 2015 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rB7784957df947ada04e2fb31659eb1e3090134754

Depsgraph: use command-line switch to legacy depsgraph

This is because of couple of reasons:

- It should be able to switch to legacy depsgraph to back up the production.
- It's not really reliable to switch dependency graphs on runtime. It might
  always be some missing update or so. Plus keeping two dependency graphs
  up to date is slower.

To use legacy depsgraph run blender with --debug-depsgraph command line arg.

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

M	source/blender/blenkernel/intern/depsgraph.c
M	source/blender/blenkernel/intern/object_update.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/depsgraph/DEG_depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_eval.cpp
M	source/creator/creator.c

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

diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 1d81a03..4a4987e 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -1335,11 +1335,14 @@ static void (*EditorsUpdateSceneCb)(Main *bmain, Scene *scene, int updated) = NU
 
 void DAG_editors_update_cb(void (*id_func)(Main *bmain, ID *id), void (*scene_func)(Main *bmain, Scene *scene, int updated))
 {
-	EditorsUpdateIDCb = id_func;
-	EditorsUpdateSceneCb = scene_func;
-
-	/* New dependency graph. */
-	DEG_editors_set_update_cb(id_func, scene_func);
+	if (DEG_depsgraph_use_legacy()) {
+		EditorsUpdateIDCb = id_func;
+		EditorsUpdateSceneCb = scene_func;
+	}
+	else {
+		/* New dependency graph. */
+		DEG_editors_set_update_cb(id_func, scene_func);
+	}
 }
 
 static void dag_editors_id_update(Main *bmain, ID *id)
@@ -1630,51 +1633,65 @@ static void dag_scene_build(Main *bmain, Scene *sce)
 /* clear all dependency graphs */
 void DAG_relations_tag_update(Main *bmain)
 {
-	Scene *sce;
-	for (sce = bmain->scene.first; sce; sce = sce->id.next) {
-		dag_scene_free(sce);
+	if (DEG_depsgraph_use_legacy()) {
+		Scene *sce;
+		for (sce = bmain->scene.first; sce; sce = sce->id.next) {
+			dag_scene_free(sce);
+		}
+	}
+	else {
+		/* New dependency graph. */
+		DEG_relations_tag_update(bmain);
 	}
-	/* New dependency graph. */
-	DEG_relations_tag_update(bmain);
 }
 
 /* rebuild dependency graph only for a given scene */
 void DAG_scene_relations_rebuild(Main *bmain, Scene *sce)
 {
-	dag_scene_free(sce);
-	DEG_scene_relations_update(bmain, sce);
-	/* New dependency graph. */
-	DEG_scene_relations_rebuild(bmain, sce);
+	if (DEG_depsgraph_use_legacy()) {
+		dag_scene_free(sce);
+	}
+	else {
+		/* New dependency graph. */
+		DEG_scene_relations_rebuild(bmain, sce);
+	}
 }
 
 /* create dependency graph if it was cleared or didn't exist yet */
 void DAG_scene_relations_update(Main *bmain, Scene *sce)
 {
-	if (!sce->theDag)
-		dag_scene_build(bmain, sce);
-	/* New dependency graph. */
-	DEG_scene_relations_update(bmain, sce);
+	if (DEG_depsgraph_use_legacy()) {
+		if (!sce->theDag)
+			dag_scene_build(bmain, sce);
+	}
+	else {
+		/* New dependency graph. */
+		DEG_scene_relations_update(bmain, sce);
+	}
 }
 
 void DAG_scene_relations_validate(Main *bmain, Scene *sce)
 {
-	DEG_debug_scene_relations_validate(bmain, sce);
+	if (!DEG_depsgraph_use_legacy()) {
+		DEG_debug_scene_relations_validate(bmain, sce);
+	}
 }
 
 void DAG_scene_free(Scene *sce)
 {
-	if (sce->theDag) {
-		free_forest(sce->theDag);
-		MEM_freeN(sce->theDag);
-		sce->theDag = NULL;
+	if (DEG_depsgraph_use_legacy()) {
+		if (sce->theDag) {
+			free_forest(sce->theDag);
+			MEM_freeN(sce->theDag);
+			sce->theDag = NULL;
+		}
 	}
-
-	/********* new depsgraph *********/
-	if (sce->depsgraph) {
-		DEG_graph_free(sce->depsgraph);
-		sce->depsgraph = NULL;
+	else {
+		if (sce->depsgraph) {
+			DEG_graph_free(sce->depsgraph);
+			sce->depsgraph = NULL;
+		}
 	}
-	/******************/
 }
 
 static void lib_id_recalc_tag(Main *bmain, ID *id)
@@ -2357,7 +2374,13 @@ void DAG_on_visible_update(Main *bmain, const bool do_time)
 {
 	ListBase listbase;
 	DagSceneLayer *dsl;
-	
+
+	if (!DEG_depsgraph_use_legacy()) {
+		/* Inform new dependnecy graphs about visibility changes. */
+		DEG_on_visible_update(bmain, do_time);
+		return;
+	}
+
 	/* get list of visible scenes and layers */
 	dag_current_scene_layers(bmain, &listbase);
 	
@@ -2427,9 +2450,6 @@ void DAG_on_visible_update(Main *bmain, const bool do_time)
 			DAG_id_tag_update(&mask->id, 0);
 		}
 	}
-
-	/* Inform new dependnecy graphs about visibility changes. */
-	DEG_on_visible_update(bmain, do_time);
 }
 
 static void dag_id_flush_update__isDependentTexture(void *userData, Object *UNUSED(ob), ID **idpoin)
@@ -2800,6 +2820,11 @@ void DAG_ids_clear_recalc(Main *bmain)
 
 void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
 {
+	if (!DEG_depsgraph_use_legacy()) {
+		DEG_id_tag_update_ex(bmain, id, flag);
+		return;
+	}
+
 	if (id == NULL) return;
 
 	if (G.debug & G_DEBUG_DEPSGRAPH) {
@@ -2858,8 +2883,6 @@ void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
 			/* BLI_assert(!"invalid flag for this 'idtype'"); */
 		}
 	}
-	
-	DEG_id_tag_update_ex(bmain, id, flag);
 }
 
 void DAG_id_tag_update(ID *id, short flag)
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 50cd1dc..7f6fc91 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -60,7 +60,7 @@
 #include "DEG_depsgraph.h"
 
 #ifdef WITH_LEGACY_DEPSGRAPH
-#  define DEBUG_PRINT if (DEG_get_eval_mode() == DEG_EVAL_MODE_NEW && G.debug & G_DEBUG_DEPSGRAPH) printf
+#  define DEBUG_PRINT if (!DEG_depsgraph_use_legacy() && G.debug & G_DEBUG_DEPSGRAPH) printf
 #else
 #  define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf
 #endif
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 4648c80..06a7d91 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1667,7 +1667,7 @@ void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *sc
 {
 	Scene *sce_iter;
 #ifdef WITH_LEGACY_DEPSGRAPH
-	bool use_new_eval = DEG_get_eval_mode() == DEG_EVAL_MODE_NEW;
+	bool use_new_eval = !DEG_depsgraph_use_legacy();
 #endif
 
 	/* keep this first */
@@ -1791,7 +1791,7 @@ void BKE_scene_update_for_newframe_ex(EvaluationContext *eval_ctx, Main *bmain,
 	double start_time = PIL_check_seconds_timer();
 #endif
 #ifdef WITH_LEGACY_DEPSGRAPH
-	bool use_new_eval = DEG_get_eval_mode() == DEG_EVAL_MODE_NEW;
+	bool use_new_eval = !DEG_depsgraph_use_legacy();
 #else
 	/* TODO(sergey): Pass to evaluation routines instead of storing layer in the graph? */
 	(void) do_invisible_flush;
diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h
index d9b1a80..3316aab 100644
--- a/source/blender/depsgraph/DEG_depsgraph.h
+++ b/source/blender/depsgraph/DEG_depsgraph.h
@@ -65,14 +65,8 @@ struct PropertyRNA;
 extern "C" {
 #endif
 
-/* XXX arbitrary debug values to test the depsgraph, remove eventually */
-typedef enum eDEG_EvalMode {
-	DEG_EVAL_MODE_OLD = 0, /* also works with any other debug_value, if not used below */
-	DEG_EVAL_MODE_NEW = 14228,
-} eDEG_EvalMode;
-
-eDEG_EvalMode DEG_get_eval_mode(void);
-void DEG_set_eval_mode(eDEG_EvalMode mode);
+bool DEG_depsgraph_use_legacy(void);
+void DEG_depsgraph_switch_to_legacy(void);
 
 /* ************************************************ */
 /* Depsgraph API */
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cpp b/source/blender/depsgraph/intern/depsgraph_eval.cpp
index e7b2988..c8ba33b 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cpp
@@ -53,26 +53,24 @@ extern "C" {
 #include "depsgraph_intern.h"
 #include "depsgraph_debug.h"
 
-eDEG_EvalMode DEG_get_eval_mode(void)
+#ifdef WITH_LEGACY_DEPSGRAPH
+static bool use_legacy_depsgraph = false;
+#endif
+
+bool DEG_depsgraph_use_legacy(void)
 {
 #ifdef WITH_LEGACY_DEPSGRAPH
-	switch (G.debug_value) {
-		case DEG_EVAL_MODE_NEW: return DEG_EVAL_MODE_NEW;
-		default: return DEG_EVAL_MODE_OLD;
-	}
+	return use_legacy_depsgraph;
 #else
 	BLI_assert(!"Should not be used with new depsgraph");
-	return DEG_EVAL_MODE_NEW;
+	return false;
 #endif
 }
 
-void DEG_set_eval_mode(eDEG_EvalMode mode)
+void DEG_depsgraph_switch_to_legacy(void)
 {
 #ifdef WITH_LEGACY_DEPSGRAPH
-	switch (mode) {
-		case DEG_EVAL_MODE_NEW: G.debug_value = DEG_EVAL_MODE_NEW;
-		default: G.debug_value = DEG_EVAL_MODE_OLD;
-	}
+	use_legacy_depsgraph = true;
 #else
 	BLI_assert(!"Should not be used with new depsgraph");
 #endif
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 8ee4322..f8b80ba 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -326,6 +326,9 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
 	BLI_argsPrintArgDoc(ba, "--debug-all");
 
 	printf("\n");
+	BLI_argsPrintArgDoc(ba, "--legacy-depsgraph");
+
+	printf("\n");
 	BLI_argsPrintArgDoc(ba, "--debug-fpe");
 	BLI_argsPrintArgDoc(ba, "--disable-crash-handler");
 
@@ -836,6 +839,12 @@ static int set_threads(int argc, const char **argv, void *UNUSED(data))
 	}
 }
 
+static int depsgraph_use_legacy(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+	DEG_depsgraph_switch_to_legacy();
+	return 0;
+}
+
 static int set_verbosity(int argc, const char **argv, void *UNUSED(data))
 {
 	if (argc > 1) {
@@ -1386,6 +1395,8 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
 	BLI_argsAdd(ba, 1, NULL, "--debug-jobs",  "\n\tEnable time profiling for background jobs.", debug_mode_generic, (void *)G_DEBUG_JOBS);
 	BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph", "\n\tEnable debug messages from dependency graph", debug_mode_generic, (void *)G_DEBUG_DEPSGRAPH);
 
+	BLI_argsAdd(ba, 1, NULL, "--legacy-depsgraph", "\n\tUse legacy dependency graph", depsgraph_use_legacy, NULL);
+
 	BLI_argsAdd(ba, 1, NULL, "--verbose", "<verbose>\n\tSet logging verbosity level.", set_verbosity, NULL);
 
 	BLI_argsAdd(ba, 1, NULL, "--factory-startup", "\n\tSkip reading the "STRINGIFY (BLENDER_STARTUP_FILE)" in the users home directory", set_factory_startup, NULL);




More information about the Bf-blender-cvs mailing list