[Bf-blender-cvs] [340bfdef2e4] blender2.8: Depsgraph: store mode and time in depsgraph, add view layer / scene accessors.

Brecht Van Lommel noreply at git.blender.org
Fri Apr 13 14:23:03 CEST 2018


Commit: 340bfdef2e424c59e85785c1660db805b3255882
Author: Brecht Van Lommel
Date:   Fri Apr 6 09:17:53 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB340bfdef2e424c59e85785c1660db805b3255882

Depsgraph: store mode and time in depsgraph, add view layer / scene accessors.

Scene, view layer and mode are now set in the constructor and never changed.
Time is updated on frame changes to indicate which frame is being or has been
evaluated last.

This is a step towards making EvaluationContext obsolete.

Differential Revision: https://developer.blender.org/D3144

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

M	source/blender/blenkernel/intern/scene.c
M	source/blender/depsgraph/DEG_depsgraph.h
M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_debug.cc
M	source/blender/depsgraph/intern/depsgraph_eval.cc
M	source/blender/depsgraph/intern/depsgraph_query.cc
M	source/blender/depsgraph/intern/depsgraph_tag.cc
M	source/blender/editors/object/object_bake_api.c
M	source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/render/intern/source/convertblender.c
M	source/blender/render/intern/source/external_engine.c

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

diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index b27f7370ff4..596599deb75 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -2193,7 +2193,7 @@ Depsgraph *BKE_scene_get_depsgraph(Scene *scene,
 		{
 			*key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__);
 			**key_ptr = key;
-			*depsgraph_ptr = DEG_graph_new();
+			*depsgraph_ptr = DEG_graph_new(scene, view_layer, DAG_EVAL_VIEWPORT);
 		}
 		depsgraph = *depsgraph_ptr;
 	}
diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h
index 43fb83e205b..9c00ed2ddcc 100644
--- a/source/blender/depsgraph/DEG_depsgraph.h
+++ b/source/blender/depsgraph/DEG_depsgraph.h
@@ -118,7 +118,9 @@ void DEG_depsgraph_enable_copy_on_write(void);
 
 /* Create new Depsgraph instance */
 // TODO: what args are needed here? What's the building-graph entry point?
-Depsgraph *DEG_graph_new(void);
+Depsgraph *DEG_graph_new(struct Scene *scene,
+                         struct ViewLayer *view_layer,
+                         eEvaluationMode mode);
 
 /* Free Depsgraph itself and all its data */
 void DEG_graph_free(Depsgraph *graph);
diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index 8600022b7c3..ceba87338a0 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -49,6 +49,22 @@ struct ViewLayer;
 extern "C" {
 #endif
 
+/* *********************** DEG input data ********************* */
+
+/* Get scene that depsgraph was built for. */
+struct Scene *DEG_get_input_scene(const Depsgraph *graph);
+
+/* Get view layer that depsgraph was built for. */
+struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph);
+
+/* Get evaluation mode that depsgraph was built for. */
+eEvaluationMode DEG_get_mode(const Depsgraph *graph);
+
+/* Get time that depsgraph is being evaluated or was last evaluated at. */
+float DEG_get_ctime(const Depsgraph *graph);
+
+/* ********************* DEG evaluated data ******************* */
+
 /* Check if given ID type was tagged for update. */
 bool DEG_id_type_tagged(struct Main *bmain, short id_type);
 
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
index 339046dfac0..85f465efb82 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
@@ -127,8 +127,8 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la
 		build_view_layer(scene->set, set_view_layer);
 	}
 
-	graph_->scene = scene;
-	graph_->view_layer = view_layer;
+	BLI_assert(graph_->scene == scene);
+	BLI_assert(graph_->view_layer == view_layer);
 }
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index 3500f38467d..a87358187f2 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -49,6 +49,8 @@ extern "C" {
 #include "DNA_sequence_types.h"
 
 #include "RNA_access.h"
+
+#include "BKE_scene.h"
 }
 
 #include <algorithm>
@@ -92,11 +94,15 @@ static void remove_from_vector(vector<T> *vector, const T& value)
 	              vector->end());
 }
 
-Depsgraph::Depsgraph()
+Depsgraph::Depsgraph(Scene *scene,
+                     ViewLayer *view_layer,
+                     eEvaluationMode mode)
   : time_source(NULL),
     need_update(true),
-    scene(NULL),
-    view_layer(NULL)
+    scene(scene),
+    view_layer(view_layer),
+    mode(mode),
+    ctime(BKE_scene_frame_get(scene))
 {
 	BLI_spin_init(&lock);
 	id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
@@ -559,9 +565,14 @@ string deg_color_end(void)
 /* Public Graph API */
 
 /* Initialize a new Depsgraph */
-Depsgraph *DEG_graph_new()
-{
-	DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph);
+Depsgraph *DEG_graph_new(Scene *scene,
+                         ViewLayer *view_layer,
+                         eEvaluationMode mode)
+{
+	DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph,
+	                                                   scene,
+	                                                   view_layer,
+	                                                   mode);
 	return reinterpret_cast<Depsgraph *>(deg_depsgraph);
 }
 
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 985991e91e3..9fa6b38166d 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -38,6 +38,8 @@
 
 #include "BLI_threads.h"  /* for SpinLock */
 
+#include "DEG_depsgraph.h"
+
 #include "intern/depsgraph_types.h"
 
 struct ID;
@@ -100,7 +102,9 @@ struct Depsgraph {
 	typedef vector<OperationDepsNode *> OperationNodes;
 	typedef vector<IDDepsNode *> IDDepsNodes;
 
-	Depsgraph();
+	Depsgraph(Scene *scene,
+	          ViewLayer *view_layer,
+	          eEvaluationMode mode);
 	~Depsgraph();
 
 	/**
@@ -187,9 +191,13 @@ struct Depsgraph {
 	 */
 	SpinLock lock;
 
-	/* Scene and layer this dependency graph is built for. */
+	/* Scene, layer, mode this dependency graph is built for. */
 	Scene *scene;
 	ViewLayer *view_layer;
+	eEvaluationMode mode;
+
+	/* Time at which dependency graph is being or was last evaluated. */
+	float ctime;
 };
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc
index e8d166532ad..78b1c6f88c5 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -37,9 +37,12 @@ extern "C" {
 #include "DNA_scene_types.h"
 }  /* extern "C" */
 
+#include "DNA_object_types.h"
+
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_debug.h"
 #include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
 #include "intern/depsgraph_intern.h"
 #include "intern/nodes/deg_node_id.h"
@@ -72,7 +75,7 @@ bool DEG_debug_graph_relations_validate(Depsgraph *graph,
                                         Scene *scene,
                                         ViewLayer *view_layer)
 {
-	Depsgraph *temp_depsgraph = DEG_graph_new();
+	Depsgraph *temp_depsgraph = DEG_graph_new(scene, view_layer, DEG_get_mode(graph));
 	bool valid = true;
 	DEG_graph_build_from_view_layer(temp_depsgraph, bmain, scene, view_layer);
 	if (!DEG_debug_compare(temp_depsgraph, graph)) {
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index 0b3e4fd8db9..d50e55e4cfb 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -134,9 +134,10 @@ void DEG_evaluate_on_refresh(EvaluationContext *eval_ctx,
                              Depsgraph *graph)
 {
 	DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+	deg_graph->ctime = BKE_scene_frame_get(deg_graph->scene);
 	/* Update time on primary timesource. */
 	DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
-	tsrc->cfra = BKE_scene_frame_get(deg_graph->scene);
+	tsrc->cfra = deg_graph->ctime;
 	DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph);
 }
 
@@ -147,6 +148,7 @@ void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx,
                                  float ctime)
 {
 	DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+	deg_graph->ctime = ctime;
 	/* Update time on primary timesource. */
 	DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
 	tsrc->cfra = ctime;
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index 4e70e56ae71..6f0ba26c8f7 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -49,6 +49,31 @@ extern "C" {
 #include "intern/depsgraph_intern.h"
 #include "intern/nodes/deg_node_id.h"
 
+struct Scene *DEG_get_input_scene(const Depsgraph *graph)
+{
+	const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+	return deg_graph->scene;
+}
+
+struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph)
+{
+	const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+	return deg_graph->view_layer;
+}
+
+eEvaluationMode DEG_get_mode(const Depsgraph *graph)
+{
+	const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+	return deg_graph->mode;
+}
+
+float DEG_get_ctime(const Depsgraph *graph)
+{
+	const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+	return deg_graph->ctime;
+}
+
+
 bool DEG_id_type_tagged(Main *bmain, short id_type)
 {
 	return bmain->id_tag_update[BKE_idcode_to_index(id_type)] != 0;
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index d1de12f4591..6a6ebd1be44 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -425,20 +425,6 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
 	id_tag_update_ntree_special(bmain, graph, id, flag);
 }
 
-/* TODO(sergey): Consider storing scene and view layer at depsgraph allocation
- * time.
- */
-void deg_ensure_scene_view_layer(Depsgraph *graph,
-                                 Scene *scene,
-                                 ViewLayer *view_layer)
-{
-	if (!graph->need_update) {
-		return;
-	}
-	graph->scene = scene;
-	graph->view_layer = view_layer;
-}
-
 void deg_id_tag_update(Main *bmain, ID *id, int flag)
 {
 	deg_graph_id_tag_update(bmain, NULL, id, flag);
@@ -449,11 +435,6 @@ void deg_id_tag_update(Main *bmain, ID *id, int flag)
 			                                             view_layer,
 			                                             false);
 			if (depsgraph != NULL) {
-				/* Make sure depsgraph is pointing to a correct scene and
-				 * view layer. This is mainly required in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list