[Bf-blender-cvs] [b683e965ab9] master: Depsgraph: Only invoke callbacks when there are changes

Sergey Sharybin noreply at git.blender.org
Tue May 28 17:11:05 CEST 2019


Commit: b683e965ab9720e82e734069990ff6c469980318
Author: Sergey Sharybin
Date:   Tue May 28 15:52:26 2019 +0200
Branches: master
https://developer.blender.org/rBb683e965ab9720e82e734069990ff6c469980318

Depsgraph: Only invoke callbacks when there are changes

Only affects when an evaluated dependency graph is requested via
context.

Makes it cheap to call when there are no changes made to the graph

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

M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/blenkernel/intern/scene.c

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

diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 581df648add..0dcb109240c 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -148,6 +148,7 @@ int BKE_scene_orientation_slot_get_index(const struct TransformOrientationSlot *
 /* **  Scene evaluation ** */
 
 void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph, struct Main *bmain);
+void BKE_scene_graph_evaluated_ensure(struct Depsgraph *depsgraph, struct Main *bmain);
 
 void BKE_scene_graph_update_for_newframe(struct Depsgraph *depsgraph, struct Main *bmain);
 
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 28b0ae23ffe..4ae87713aa5 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1365,7 +1365,7 @@ Depsgraph *CTX_data_evaluated_depsgraph(const bContext *C)
 {
   Depsgraph *depsgraph = CTX_data_depsgraph(C);
   Main *bmain = CTX_data_main(C);
-  BKE_scene_graph_update_tagged(depsgraph, bmain);
+  BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
   return depsgraph;
 }
 
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 971e878ccbc..d1136b05e91 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1509,9 +1509,16 @@ static void prepare_mesh_for_viewport_render(Main *bmain, const ViewLayer *view_
 
 /* TODO(sergey): This actually should become view_layer_graph or so.
  * Same applies to update_for_newframe.
+ *
+ * If only_if_tagged is truth then the function will do nothing if the dependency graph is up
+ * to date already.
  */
-void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
+static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool only_if_tagged)
 {
+  if (only_if_tagged && DEG_is_fully_evaluated(depsgraph)) {
+    return;
+  }
+
   Scene *scene = DEG_get_input_scene(depsgraph);
   ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
 
@@ -1548,6 +1555,16 @@ void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
   DEG_ids_clear_recalc(bmain, depsgraph);
 }
 
+void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
+{
+  scene_graph_update_tagged(depsgraph, bmain, false);
+}
+
+void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
+{
+  scene_graph_update_tagged(depsgraph, bmain, true);
+}
+
 /* applies changes right away, does all sets too */
 void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain)
 {



More information about the Bf-blender-cvs mailing list