[Bf-blender-cvs] [a72721a2aea] sculpt-dev: Sculpt-dev: Performance improvements

Joseph Eagar noreply at git.blender.org
Sat Nov 13 10:16:01 CET 2021


Commit: a72721a2aeaddbc950a955e0f01bbd9583b773d2
Author: Joseph Eagar
Date:   Sat Nov 13 01:13:47 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rBa72721a2aeaddbc950a955e0f01bbd9583b773d2

Sculpt-dev: Performance improvements

* PBVH_BMESH construction is now partially
  threaded.
* Fixed n**2 behavior in freelist-based
  bmesh id implementation.  I'd really
  rather get range-tree faster, but
  this works as a stopgap.
* Removed a bunch of debug ATTR_NO_OPTs.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/attribute.c
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/blenlib/intern/BLI_mempool.c
M	source/blender/blenlib/intern/BLI_table_gset.c
M	source/blender/bmesh/bmesh_class.h
M	source/blender/bmesh/intern/bmesh_construct.c
M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/bmesh/intern/bmesh_mesh_convert.c
M	source/blender/bmesh/intern/bmesh_structure.h
M	source/blender/editors/geometry/geometry_attributes.c
M	source/blender/editors/sculpt_paint/paint_mask.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesrna/intern/rna_attribute.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 6a4f144cc15..e855016ae28 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -309,7 +309,8 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
                           const int cd_face_node_offset,
                           const int cd_sculpt_vert,
                           const int cd_face_areas,
-                          bool fast_draw);
+                          bool fast_draw,
+                          bool update_sculptverts);
 void BKE_pbvh_update_offsets(PBVH *pbvh,
                              const int cd_vert_node_offset,
                              const int cd_face_node_offset,
@@ -319,6 +320,18 @@ void BKE_pbvh_free(PBVH *pbvh);
 
 void BKE_pbvh_set_bm_log(PBVH *pbvh, struct BMLog *log);
 
+/* update MSculptVerts, doesn't take pbvh argument to allow usage if pbvh doesn't currently exist
+ */
+void BKE_pbvh_update_sculpt_verts(struct BMesh *bm,
+                                  const int cd_sculpt_vert,
+                                  const int cd_faceset_offset,
+                                  const int cd_vert_node_offset,
+                                  const int cd_face_node_offset,
+                                  const int boundary_symmetry,
+                                  const int vcol_type,
+                                  const AttributeDomain vcol_domain,
+                                  const int cd_vcol_offset);
+
 /** update original data, only data whose r_** parameters are passed in will be updated*/
 void BKE_pbvh_bmesh_update_origvert(
     PBVH *pbvh, struct BMVert *v, float **r_co, float **r_no, float **r_color, bool log_undo);
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 88b4c9a43e5..53d97ff0f13 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -194,7 +194,7 @@ bool BKE_id_attribute_find_unique_name(ID *id,
   return BLI_uniquename_cb(unique_name_cb, &data, NULL, '.', outname, MAX_CUSTOMDATA_LAYER_NAME);
 }
 
-ATTR_NO_OPT CustomDataLayer *BKE_id_attribute_new(
+CustomDataLayer *BKE_id_attribute_new(
     ID *id, const char *name, const int type, const AttributeDomain domain, ReportList *reports)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
@@ -300,7 +300,7 @@ CustomDataLayer *BKE_id_attribute_find(const ID *id,
   return NULL;
 }
 
-ATTR_NO_OPT CustomDataLayer *BKE_id_attribute_from_index(const ID *id, int lookup_index)
+CustomDataLayer *BKE_id_attribute_from_index(const ID *id, int lookup_index)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
@@ -501,7 +501,7 @@ CustomDataLayer *BKE_id_attributes_active_color_get(ID *id)
   return NULL;
 }
 
-ATTR_NO_OPT void BKE_id_attributes_active_color_set(ID *id, CustomDataLayer *active_layer)
+void BKE_id_attributes_active_color_set(ID *id, CustomDataLayer *active_layer)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
@@ -585,7 +585,7 @@ CustomDataLayer *BKE_id_attributes_render_color_get(ID *id)
   return NULL;
 }
 
-ATTR_NO_OPT void BKE_id_attributes_render_color_set(ID *id, CustomDataLayer *active_layer)
+void BKE_id_attributes_render_color_set(ID *id, CustomDataLayer *active_layer)
 {
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 19c05a3612c..f5f48e2b49b 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -5077,10 +5077,10 @@ void CustomData_set_layer_unique_name(CustomData *data, int index)
       customdata_unique_check, &data_arg, NULL, '.', nlayer->name, sizeof(nlayer->name));
 }
 
-ATTR_NO_OPT void CustomData_validate_layer_name(const CustomData *data,
-                                                int type,
-                                                const char *name,
-                                                char *outname)
+void CustomData_validate_layer_name(const CustomData *data,
+                                    int type,
+                                    const char *name,
+                                    char *outname)
 {
   int index = -1;
 
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 243f61c470c..0541f620373 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -2382,7 +2382,7 @@ void BKE_sculpt_ensure_orig_mesh_data(Scene *scene, Object *object)
   DEG_id_tag_update(&object->id, ID_RECALC_GEOMETRY);
 }
 
-static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
+static PBVH *build_pbvh_for_dynamic_topology(Object *ob, bool update_sculptverts)
 {
   PBVH *pbvh = BKE_pbvh_new();
 
@@ -2397,7 +2397,8 @@ static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
                        ob->sculpt->cd_face_node_offset,
                        ob->sculpt->cd_sculpt_vert,
                        ob->sculpt->cd_face_areas,
-                       ob->sculpt->fast_draw);
+                       ob->sculpt->fast_draw,
+                       update_sculptverts);
   pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
   pbvh_show_face_sets_set(pbvh, false);
 
@@ -2609,7 +2610,7 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
 
   if (ob->sculpt->bm != NULL) {
     /* Sculpting on a BMesh (dynamic-topology) gets a special PBVH. */
-    pbvh = build_pbvh_for_dynamic_topology(ob);
+    pbvh = build_pbvh_for_dynamic_topology(ob, false);
 
     ob->sculpt->pbvh = pbvh;
   }
@@ -2638,7 +2639,7 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
       SCULPT_dyntopo_node_layers_add(ob->sculpt, ob);
       SCULPT_undo_ensure_bmlog(ob);
 
-      pbvh = build_pbvh_for_dynamic_topology(ob);
+      pbvh = build_pbvh_for_dynamic_topology(ob, true);
 
       SCULPT_update_customdata_refs(ob->sculpt, ob);
     }
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 991398accb7..7c7526e8227 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1372,10 +1372,10 @@ static int pbvh_get_buffers_update_flags(PBVH *UNUSED(pbvh))
 }
 
 /* updates pbvh->vcol_domain, vcol_type too */
-ATTR_NO_OPT bool BKE_pbvh_get_color_layer(PBVH *pbvh,
-                                          const Mesh *me,
-                                          CustomDataLayer **r_cl,
-                                          AttributeDomain *r_attr)
+bool BKE_pbvh_get_color_layer(PBVH *pbvh,
+                              const Mesh *me,
+                              CustomDataLayer **r_cl,
+                              AttributeDomain *r_attr)
 {
   CustomDataLayer *cl = BKE_id_attributes_active_color_get((ID *)me);
   AttributeDomain domain;
@@ -1669,6 +1669,14 @@ static void pbvh_update_draw_buffers(
     ldata = pbvh->ldata;
   }
 
+  if (!vdata && me) {
+    vdata = &me->vdata;
+  }
+
+  if (!ldata && me) {
+    ldata = &me->ldata;
+  }
+
   CustomDataLayer *vcol_layer = NULL;
   AttributeDomain domain;
   BKE_pbvh_get_color_layer(pbvh, me, &vcol_layer, &domain);
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index bc9e85e553f..ceeda40c931 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -300,12 +300,47 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
 
   BKE_pbvh_node_fully_hidden_set(n, !has_visible);
   n->flag |= PBVH_UpdateNormals | PBVH_UpdateCurvatureDir | PBVH_UpdateTris;
+  n->flag |= PBVH_UpdateBB | PBVH_UpdateOriginalBB;
 
   if (add_orco) {
     BKE_pbvh_bmesh_check_tris(pbvh, n);
   }
 }
 
+static void pbvh_print_mem_size(PBVH *pbvh)
+{
+  BMesh *bm = pbvh->bm;
+  CustomData *cdatas[4] = {&bm->vdata, &bm->edata, &bm->ldata, &bm->pdata};
+
+  int tots[4] = {bm->totvert, bm->totedge, bm->totloop, bm->totface};
+  int sizes[4] = {
+      (int)sizeof(BMVert), (int)sizeof(BMEdge), (int)sizeof(BMLoop), (int)sizeof(BMFace)};
+
+  float memsize1[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+  float memsize2[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+  for (int i = 0; i < 4; i++) {
+    CustomData *cdata = cdatas[i];
+
+    memsize1[i] = (float)(sizes[i] * tots[i]) / 1024.0f / 1024.0f;
+    memsize2[i] = (float)(cdata->totsize * tots[i]) / 1024.0f / 1024.0f;
+  }
+
+  printf("base sizes:\n");
+  printf("  v: %.2fmb e: %.2fmb l: %.2fmb f: %.2fmb\n",
+         memsize1[0],
+         memsize1[1],
+         memsize1[2],
+         memsize1[3]);
+
+  printf("custom attribute sizes:\n");
+  printf("  v: %.2fmb e: %.2fmb l: %.2fmb f: %.2fmb\n",
+         memsize2[0],
+         memsize2[1],
+         memsize2[2],
+         memsize2[3]);
+}
+
 /* Recursively split the node if it exceeds the leaf_limit */
 static void pbvh_bmesh_node_split(
     PBVH *pbvh, const BBC *bbc_array, int node_index, bool add_orco, int depth)
@@ -318,7 +353,7 @@ static void pbvh_bmesh_node_split(
   BKE_pbvh_free_proxyarray(pbvh, n);
 #endif
 
-  if (depth > 6 || BLI_table_gset_len(n->bm_faces) <= pbvh->leaf_limit) {
+  if (n->depth >= pbvh->depth_limit || BLI_table_gset_len(n->bm_faces) <= pbvh->leaf_limit) {
     /* Node limit not exceeded */
     pbvh_bmesh_node_finalize(pbvh, node_index, cd_vert_node_offset, cd_face_node_offset, add_orco);
     return;
@@ -355,6 +390,8 @@ static void pbvh_bmesh_node_split(
   /* Initialize children */
   PBVHNode *c1 = &pbvh->nodes[children], *c2 = &pbvh->nodes[children + 1];
 
+  c1->depth = c2->depth = n->depth + 1;
+
   c1->flag |= PBVH_Leaf;
   c2->flag |= PBVH_Leaf;
   c1->bm_faces = BLI_table_gset_new_ex("bm_faces", BLI_table_gset_len(n->bm_faces) / 2);
@@ -476,7 +513,7 @@ bool pbvh_bmesh_node_limit_ensure(PBVH *pbvh, int node_index)
 
   // pbvh_bmesh_check_nodes(pbvh);
 
-  if (bm_faces_size <= pbvh->leaf_limit) {
+  if (bm_faces_size <= pbvh->leaf_limit || pbvh->nodes[node_index].depth >= pbvh->depth_limit) {
     /* Node limit not exceeded */
     return false;
   }
@@ -809,7 +846,7 @@ void BKE_pbvh_bmesh_regen_nod

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list