[Bf-blender-cvs] [367ecff15d7] master: readfile: Move ID refcounting to libquery.

Bastien Montagne noreply at git.blender.org
Wed Feb 19 12:56:07 CET 2020


Commit: 367ecff15d74ed99a305cbfcd46599e59a75db02
Author: Bastien Montagne
Date:   Wed Feb 19 12:50:04 2020 +0100
Branches: master
https://developer.blender.org/rB367ecff15d74ed99a305cbfcd46599e59a75db02

readfile: Move ID refcounting to libquery.

Having that extra ID users handling at readfile level, besides generic
one ensured by libquery, has been something bothering me for a long time
(had to fix my share of bugs due to mismatches between those two areas).

Further more, work on undo speedup will require even more complex ID
refcount management if we want to keep it in readfile.c area.

So idea is instead to generalize what we did for linked data already
when undoing: recompute properly usercount numbers after liblink step,
for all IDs.

Note that extra time required here is neglectable in a whole .blend file
reading (few extra milliseconds when loading a full production scene
e.g.).

Notes:
* Some deprecated data (IPOs) are not refcounted at all anymore, this
should not be an issue in pratice since the are supposed to get deleted
after doversion anyway.
* Refcounting happens after `do_versions_after_linking`, i.e those
functions won't get valid ID usercounts currently. Again, this is not a
problem in current code, if needed we could recompute refcount before,
and then ensure `do_versions_after_linoiing()` actually handles properly
usercount, which it does not currently.

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

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

M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_legacy.c

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

diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index d1188bdb220..efab2039dc3 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -372,7 +372,7 @@ static void setup_app_data(bContext *C,
      * lib_link on local IDs using linked ones.
      * There is no real way to predict amount of changes here, so we have to fully redo
      * refcounting . */
-    BKE_main_id_refcount_recompute(bmain, true);
+    BKE_main_id_refcount_recompute(bmain, false);
   }
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 51e8f080b15..2d87d9f12ff 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1791,31 +1791,6 @@ void *blo_do_versions_newlibadr(FileData *fd, const void *lib, const void *adr)
 }
 
 /* increases user number */
-static void *newlibadr_us(FileData *fd, const void *lib, const void *adr)
-{
-  ID *id = newlibadr(fd, lib, adr);
-
-  id_us_plus_no_lib(id);
-
-  return id;
-}
-
-/* increases user number */
-void *blo_do_versions_newlibadr_us(FileData *fd, const void *lib, const void *adr)
-{
-  return newlibadr_us(fd, lib, adr);
-}
-
-/* ensures real user */
-static void *newlibadr_real_us(FileData *fd, const void *lib, const void *adr)
-{
-  ID *id = newlibadr(fd, lib, adr);
-
-  id_us_ensure_real(id);
-
-  return id;
-}
-
 static void change_link_placeholder_to_real_ID_pointer_fd(FileData *fd, const void *old, void *new)
 {
   for (int i = 0; i < fd->libmap->nentries; i++) {
@@ -2558,7 +2533,7 @@ static void IDP_LibLinkProperty(IDProperty *prop, FileData *fd)
   switch (prop->type) {
     case IDP_ID: /* PointerProperty */
     {
-      void *newaddr = newlibadr_us(fd, NULL, IDP_Id(prop));
+      void *newaddr = newlibadr(fd, NULL, IDP_Id(prop));
       if (IDP_Id(prop) && !newaddr && G.debug) {
         printf("Error while loading \"%s\". Data not found in file!\n", prop->name);
       }
@@ -2650,8 +2625,8 @@ static void lib_link_id(FileData *fd, Main *bmain, ID *id)
   }
 
   if (id->override_library) {
-    id->override_library->reference = newlibadr_us(fd, id->lib, id->override_library->reference);
-    id->override_library->storage = newlibadr_us(fd, id->lib, id->override_library->storage);
+    id->override_library->reference = newlibadr(fd, id->lib, id->override_library->reference);
+    id->override_library->storage = newlibadr(fd, id->lib, id->override_library->storage);
   }
 
   lib_link_id_private_id(fd, bmain, id);
@@ -2785,16 +2760,16 @@ static void direct_link_curveprofile(FileData *fd, CurveProfile *profile)
 static void lib_link_brush(FileData *fd, Main *UNUSED(bmain), Brush *brush)
 {
   /* brush->(mask_)mtex.obj is ignored on purpose? */
-  brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
-  brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex);
+  brush->mtex.tex = newlibadr(fd, brush->id.lib, brush->mtex.tex);
+  brush->mask_mtex.tex = newlibadr(fd, brush->id.lib, brush->mask_mtex.tex);
   brush->clone.image = newlibadr(fd, brush->id.lib, brush->clone.image);
   brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush);
-  brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve);
+  brush->paint_curve = newlibadr(fd, brush->id.lib, brush->paint_curve);
 
   /* link default grease pencil palette */
   if (brush->gpencil_settings != NULL) {
     if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
-      brush->gpencil_settings->material = newlibadr_us(
+      brush->gpencil_settings->material = newlibadr(
           fd, brush->id.lib, brush->gpencil_settings->material);
 
       if (!brush->gpencil_settings->material) {
@@ -2936,7 +2911,7 @@ static void lib_link_nlastrips(FileData *fd, ID *id, ListBase *striplist)
 
   for (strip = striplist->first; strip; strip = strip->next) {
     strip->object = newlibadr(fd, id->lib, strip->object);
-    strip->act = newlibadr_us(fd, id->lib, strip->act);
+    strip->act = newlibadr(fd, id->lib, strip->act);
     strip->ipo = newlibadr(fd, id->lib, strip->ipo);
     for (amod = strip->modifiers.first; amod; amod = amod->next) {
       amod->ob = newlibadr(fd, id->lib, amod->ob);
@@ -2962,7 +2937,7 @@ static void lib_link_constraint_channels(FileData *fd, ID *id, ListBase *chanbas
   bConstraintChannel *chan;
 
   for (chan = chanbase->first; chan; chan = chan->next) {
-    chan->ipo = newlibadr_us(fd, id->lib, chan->ipo);
+    chan->ipo = newlibadr(fd, id->lib, chan->ipo);
   }
 }
 
@@ -3129,7 +3104,7 @@ static void lib_link_action(FileData *fd, Main *UNUSED(bmain), bAction *act)
 {
   // XXX deprecated - old animation system <<<
   for (bActionChannel *chan = act->chanbase.first; chan; chan = chan->next) {
-    chan->ipo = newlibadr_us(fd, act->id.lib, chan->ipo);
+    chan->ipo = newlibadr(fd, act->id.lib, chan->ipo);
     lib_link_constraint_channels(fd, &act->id, &chan->constraintChannels);
   }
   // >>> XXX deprecated - old animation system
@@ -3181,7 +3156,7 @@ static void lib_link_nladata_strips(FileData *fd, ID *id, ListBase *list)
     lib_link_fcurves(fd, id, &strip->fcurves);
 
     /* reassign the counted-reference to action */
-    strip->act = newlibadr_us(fd, id->lib, strip->act);
+    strip->act = newlibadr(fd, id->lib, strip->act);
 
     /* fix action id-root (i.e. if it comes from a pre 2.57 .blend file) */
     if ((strip->act) && (strip->act->idroot == 0)) {
@@ -3278,8 +3253,8 @@ static void lib_link_animdata(FileData *fd, ID *id, AnimData *adt)
   }
 
   /* link action data */
-  adt->action = newlibadr_us(fd, id->lib, adt->action);
-  adt->tmpact = newlibadr_us(fd, id->lib, adt->tmpact);
+  adt->action = newlibadr(fd, id->lib, adt->action);
+  adt->tmpact = newlibadr(fd, id->lib, adt->tmpact);
 
   /* fix action id-roots (i.e. if they come from a pre 2.57 .blend file) */
   if ((adt->action) && (adt->action->idroot == 0)) {
@@ -3365,7 +3340,7 @@ static void lib_link_workspaces(FileData *fd, Main *bmain, WorkSpace *workspace)
   id_us_ensure_real(id);
 
   for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) {
-    layout->screen = newlibadr_us(fd, id->lib, layout->screen);
+    layout->screen = newlibadr(fd, id->lib, layout->screen);
 
     layout_next = layout->next;
     if (layout->screen) {
@@ -3439,14 +3414,14 @@ static void lib_link_ntree(FileData *fd, Library *lib, bNodeTree *ntree)
 {
   ntree->id.lib = lib;
 
-  ntree->gpd = newlibadr_us(fd, lib, ntree->gpd);
+  ntree->gpd = newlibadr(fd, lib, ntree->gpd);
 
   for (bNode *node = ntree->nodes.first; node; node = node->next) {
     /* Link ID Properties -- and copy this comment EXACTLY for easy finding
      * of library blocks that implement this.*/
     IDP_LibLinkProperty(node->prop, fd);
 
-    node->id = newlibadr_us(fd, lib, node->id);
+    node->id = newlibadr(fd, lib, node->id);
 
     for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) {
       IDP_LibLinkProperty(sock->prop, fd);
@@ -3681,7 +3656,7 @@ static void lib_link_constraint_cb(bConstraint *UNUSED(con),
   /* for reference types, we need to increment the usercounts on load... */
   if (is_reference) {
     /* reference type - with usercount */
-    *idpoin = newlibadr_us(cld->fd, cld->id->lib, *idpoin);
+    *idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin);
   }
   else {
     /* target type - no usercount needed */
@@ -3702,7 +3677,7 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
       con->type = CONSTRAINT_TYPE_NULL;
     }
     /* own ipo, all constraints have it */
-    con->ipo = newlibadr_us(fd, id->lib, con->ipo);  // XXX deprecated - old animation system
+    con->ipo = newlibadr(fd, id->lib, con->ipo);  // XXX deprecated - old animation system
 
     /* If linking from a library, clear 'local' library override flag. */
     if (id->lib != NULL) {
@@ -3813,7 +3788,7 @@ static void lib_link_pose(FileData *fd, Main *bmain, Object *ob, bPose *pose)
 
     IDP_LibLinkProperty(pchan->prop, fd);
 
-    pchan->custom = newlibadr_us(fd, arm->id.lib, pchan->custom);
+    pchan->custom = newlibadr(fd, arm->id.lib, pchan->custom);
     if (UNLIKELY(pchan->bone == NULL)) {
       rebuild = true;
     }
@@ -3898,14 +3873,14 @@ static void direct_link_armature(FileData *fd, bArmature *arm)
 
 static void lib_link_camera(FileData *fd, Main *UNUSED(bmain), Camera *ca)
 {
-  ca->ipo = newlibadr_us(fd, ca->id.lib, ca->ipo); /* deprecated, for versioning */
+  ca->ipo = newlibadr(fd, ca->id.lib, ca->ipo); /* deprecated, for versioning */
 
   ca->dof_ob = newlibadr(fd, ca->id.lib, ca->dof_ob); /* deprecated, for versioning */
   ca->dof.focus_object = newlibadr(fd, ca->id.lib, ca->dof.focus_object);
 
   for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
-    bgpic->ima = newlibadr_us(fd, ca->id.lib, bgpic->ima);
-    bgpic->clip = newlibadr_us(fd, ca->id.lib, bgpic->clip);
+    bgpic->ima = newlibadr(fd, ca->id.lib, bgpic->ima);
+    bgpic->clip = newlibadr(fd, ca->id.lib, bgpic->clip);
   }
 }
 
@@ -3930,7 +3905,7 @@ static void direct_link_camera(FileData *fd, Camera *ca)
 
 static void lib_link_light(FileData *fd, Main *UNUSED(bmain), Light *la)
 {
-  la->ipo = newlibadr_us(fd, la->id.lib, la->ipo);  // XXX deprecated - old animation system
+  la->ipo = newlibadr(fd, la->id.lib, la->ipo);  // XXX deprecated - old animation system
 }
 
 static void direct_link_light(FileData *fd, Light *la)
@@ -3966,7 +3941,7 @@ static void lib_link_key(FileData *fd, Main *UNUSED(bmain), Key *key)
 {
   BLI_assert((key->id.tag & LIB_TAG_EXTERN) == 0);
 
-  key->ipo = newlibadr_us(fd, key->id.lib, key->ipo);  // XXX deprecated - old animation system
+  key->ipo = newlibadr(fd, key->id.lib, key->ipo);  // XXX deprecated - old animation system
   key->from = newlibadr(fd, key->id.lib, key->from);
 }
 
@@ -4028,10 +4003,10 @@ static void direct_link_key(FileData *fd, Key *key)
 static void lib_link_mball(FileData *fd, Main *UNUSED(bmain), MetaBall *mb)
 {
   for (int a = 0; a < mb->totcol; a++) {
-    mb->mat[a] = newlibadr_us(fd, mb->id.li

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list