[Bf-blender-cvs] [6eb98d4e3c5] temp-T78835: Depsgraph: Use explicit flag that ID is to copied for copy-on-write

Sergey Sharybin noreply at git.blender.org
Thu Jul 30 15:44:36 CEST 2020


Commit: 6eb98d4e3c54c45aa952e47f356151d6ffd44624
Author: Sergey Sharybin
Date:   Thu Jul 30 11:53:13 2020 +0200
Branches: temp-T78835
https://developer.blender.org/rB6eb98d4e3c54c45aa952e47f356151d6ffd44624

Depsgraph: Use explicit flag that ID is to copied for copy-on-write

Before this this situation was deducted using NO_MAIN flag, which is
no really reliable.

This new flags makes things explicit. Currently unused, but will be
used by the new code, and will replace legacy checks eventually.

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

M	source/blender/blenkernel/BKE_lib_id.h
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc

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

diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index d46a03e90af..3ea60ce0264 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -126,6 +126,14 @@ enum {
   /** Generate a local copy, outside of bmain, to work on (used by COW e.g.). */
   LIB_ID_COPY_LOCALIZE = LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT |
                          LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_CACHES,
+
+  /* Copying of the ID is requested by the dependency graph's Copy-on_Write mechanism.
+   * In this case some data will be shared between original and copied datablocks. For example:
+   * - Session UUIDs are not re-generated, which makes the dependency graph possible to match
+   *   original and copied data, preserving runtime caches.
+   * - Physics caches are shared between original and copied datablocks, avoiding duplicate of
+   *   the entire cache to appear multiple times in memory. */
+  LIB_ID_COPY_ON_WRITE = (1 << 27),
 };
 
 void BKE_libblock_copy_ex(struct Main *bmain,
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index 79d6c8d6a77..e2837b97c1e 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -289,7 +289,10 @@ bool id_copy_inplace_no_main(const ID *id, ID *newid)
 #endif
 
   bool result = BKE_id_copy_ex(
-      nullptr, (ID *)id_for_copy, &newid, (LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE));
+      nullptr,
+      (ID *)id_for_copy,
+      &newid,
+      (LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE | LIB_ID_COPY_ON_WRITE));
 
 #ifdef NESTED_ID_NASTY_WORKAROUND
   if (result) {
@@ -311,8 +314,11 @@ bool scene_copy_inplace_no_main(const Scene *scene, Scene *new_scene)
   id_for_copy = nested_id_hack_get_discarded_pointers(&id_hack_storage, &scene->id);
 #endif
 
-  bool result = BKE_id_copy_ex(
-      nullptr, id_for_copy, (ID **)&new_scene, LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE);
+  bool result = BKE_id_copy_ex(nullptr,
+                               id_for_copy,
+                               (ID **)&new_scene,
+                               LIB_ID_COPY_LOCALIZE | LIB_ID_CREATE_NO_ALLOCATE |
+                                   LIB_ID_COPY_ON_WRITE);
 
 #ifdef NESTED_ID_NASTY_WORKAROUND
   if (result) {



More information about the Bf-blender-cvs mailing list