[Bf-blender-cvs] [f9c9e000ca4] master: Undo: optimize edit-mode undo

Campbell Barton noreply at git.blender.org
Tue Jul 13 09:10:49 CEST 2021


Commit: f9c9e000ca42c8cc169dec22c702904944ee2513
Author: Campbell Barton
Date:   Tue Jul 13 16:51:06 2021 +1000
Branches: master
https://developer.blender.org/rBf9c9e000ca42c8cc169dec22c702904944ee2513

Undo: optimize edit-mode undo

- Tag the object data instead of the object when decoding
  (this avoids duplicating mesh object-data on each undo-step).
- Calculate face normals as part of multi-threaded tessellation.

This gives ~11% speedup with 1.5x million polygons.

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

M	source/blender/editors/armature/editarmature_undo.c
M	source/blender/editors/curve/editcurve_undo.c
M	source/blender/editors/curve/editfont_undo.c
M	source/blender/editors/lattice/editlattice_undo.c
M	source/blender/editors/mesh/editmesh_undo.c
M	source/blender/editors/metaball/editmball_undo.c

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

diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index 725945f8edc..832e75b2a8b 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -206,7 +206,7 @@ static void armature_undosys_step_decode(struct bContext *C,
     }
     undoarm_to_editarm(&elem->data, arm);
     arm->needs_flush_to_id = 1;
-    DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+    DEG_id_tag_update(&arm->id, ID_RECALC_GEOMETRY);
   }
 
   /* The first element is always active */
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 88f6398567d..210411c6eb5 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -267,7 +267,7 @@ static void curve_undosys_step_decode(struct bContext *C,
     }
     undocurve_to_editcurve(bmain, &elem->data, obedit->data, &obedit->shapenr);
     cu->editnurb->needs_flush_to_id = 1;
-    DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+    DEG_id_tag_update(&cu->id, ID_RECALC_GEOMETRY);
   }
 
   /* The first element is always active */
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index b61506d9346..6eaf8971eb0 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -379,7 +379,7 @@ static void font_undosys_step_decode(struct bContext *C,
 
   Curve *cu = obedit->data;
   undofont_to_editfont(&us->data, cu);
-  DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+  DEG_id_tag_update(&cu->id, ID_RECALC_GEOMETRY);
 
   ED_undo_object_set_active_or_warn(
       CTX_data_scene(C), CTX_data_view_layer(C), obedit, us_p->name, &LOG);
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index d92a81179cc..23eaf991fd3 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -240,7 +240,7 @@ static void lattice_undosys_step_decode(struct bContext *C,
     }
     undolatt_to_editlatt(&elem->data, lt->editlatt);
     lt->editlatt->needs_flush_to_id = 1;
-    DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+    DEG_id_tag_update(&lt->id, ID_RECALC_GEOMETRY);
   }
 
   /* The first element is always active */
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index 613c58e87c8..7a89dbd831d 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -681,14 +681,20 @@ static void undomesh_to_editmesh(UndoMesh *um, Object *ob, BMEditMesh *em, Key *
   BM_mesh_bm_from_me(bm,
                      &um->me,
                      (&(struct BMeshFromMeshParams){
-                         .calc_face_normal = true,
+                         /* Handled with tessellation. */
+                         .calc_face_normal = false,
                          .active_shapekey = um->shapenr,
                      }));
 
   em_tmp = BKE_editmesh_create(bm);
   *em = *em_tmp;
 
-  BKE_editmesh_looptri_calc(em);
+  /* Calculate face normals and tessellation at once since it's multi-threaded.
+   * The vertex normals are stored in the undo-mesh, so this doesn't need to be updated. */
+  BKE_editmesh_looptri_calc_ex(em,
+                               &(const struct BMeshCalcTessellation_Params){
+                                   .face_normals = true,
+                               });
 
   em->selectmode = um->selectmode;
   bm->selectmode = um->selectmode;
@@ -867,7 +873,7 @@ static void mesh_undosys_step_decode(struct bContext *C,
     BMEditMesh *em = me->edit_mesh;
     undomesh_to_editmesh(&elem->data, obedit, em, me->key);
     em->needs_flush_to_id = 1;
-    DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+    DEG_id_tag_update(&me->id, ID_RECALC_GEOMETRY);
   }
 
   /* The first element is always active */
diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c
index a8b471a7c92..f7b53b5513f 100644
--- a/source/blender/editors/metaball/editmball_undo.c
+++ b/source/blender/editors/metaball/editmball_undo.c
@@ -215,7 +215,7 @@ static void mball_undosys_step_decode(struct bContext *C,
     }
     undomball_to_editmball(&elem->data, mb);
     mb->needs_flush_to_id = 1;
-    DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+    DEG_id_tag_update(&mb->id, ID_RECALC_GEOMETRY);
   }
 
   /* The first element is always active */



More information about the Bf-blender-cvs mailing list