[Bf-blender-cvs] [ab9b89ac5d8] temp_bmesh_multires: Fixed two remaining performance bugs with dyntopo:

Joseph Eagar noreply at git.blender.org
Wed Mar 24 22:10:02 CET 2021


Commit: ab9b89ac5d80c7c44e096d226a5e31578527ada3
Author: Joseph Eagar
Date:   Wed Mar 24 14:09:02 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBab9b89ac5d80c7c44e096d226a5e31578527ada3

Fixed two remaining performance bugs with dyntopo:

* Normals are now updated in threads.
* The sculpt neighbor code was using the slower BM_LOOPS_OF_VERT
  instead of BM_EDGES_OF_VERT, fixed.

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

M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index b7ba937d457..97f66b8947e 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -2680,7 +2680,54 @@ bool pbvh_bmesh_node_nearest_to_ray(PBVHNode *node,
   return hit;
 }
 
+typedef struct UpdateNormalsTaskData {
+  PBVHNode **nodes;
+  int totnode;
+} UpdateNormalsTaskData;
+
+static void pbvh_update_normals_task_cb(void *__restrict userdata,
+                                        const int n,
+                                        const TaskParallelTLS *__restrict UNUSED(tls))
+{
+  BMVert *v;
+  BMFace *f;
+  UpdateNormalsTaskData *data = (UpdateNormalsTaskData*) userdata;
+  PBVHNode *node = data->nodes[n];
+
+  TGSET_ITER (f, node->bm_faces) {
+    BM_face_normal_update(f);
+  }
+  TGSET_ITER_END
+
+  TGSET_ITER (v, node->bm_unique_verts) {
+    BM_vert_normal_update(v);
+  }
+  TGSET_ITER_END
+
+  node->flag &= ~PBVH_UpdateNormals;
+}
+
 void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
+{
+  TaskParallelSettings settings;
+  UpdateNormalsTaskData data = {nodes, totnode};
+
+  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
+  BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_task_cb, &settings);
+
+#if 0 //in theory we shouldn't need to update normals in bm_other_verts.
+  for (int i=0; i<totnode; i++) {
+    PBVHNode *node = nodes[i];
+
+    TGSET_ITER (v, node->bm_other_verts) {
+      BM_vert_normal_update(v);
+    }
+    TGSET_ITER_END
+  }
+#endif
+}
+
+void pbvh_bmesh_normals_update_old(PBVHNode **nodes, int totnode)
 {
   for (int n = 0; n < totnode; n++) {
     PBVHNode *node = nodes[n];
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 42ee4f742c1..778bcf86b1f 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -1078,7 +1078,7 @@ static bool pixel_bounds_uv(const float uv_quad[4][2],
 }
 #endif
 
-__attribute__((optnone)) static bool pixel_bounds_array(
+static bool pixel_bounds_array(
     float (*in_uv)[2], rcti *bounds_px, const int ibuf_x, const int ibuf_y, int tot)
 {
   /* UV bounds */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index cb6ff71f0f4..adab8f42174 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1039,6 +1039,16 @@ static void sculpt_vertex_neighbors_get_bmesh(SculptSession *ss,
   iter->neighbors = iter->neighbors_fixed;
   iter->neighbor_indices = iter->neighbor_indices_fixed;
 
+#if 1 //note that BM_EDGES_OF_VERT should be faster then BM_LOOPS_OF_VERT
+  BMEdge *e;
+  BM_ITER_ELEM (e, &liter, v, BM_EDGES_OF_VERT) {
+    BMVert *v_other = BM_edge_other_vert(e, v);
+
+    sculpt_vertex_neighbor_add(
+        iter, BKE_pbvh_make_vref((intptr_t)v_other), BM_elem_index_get(v_other));
+  }
+#else
+
   BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
     const BMVert *adj_v[2] = {l->prev->v, l->next->v};
     for (int i = 0; i < ARRAY_SIZE(adj_v); i++) {
@@ -1050,6 +1060,7 @@ static void sculpt_vertex_neighbors_get_bmesh(SculptSession *ss,
       }
     }
   }
+#endif
 }
 
 static void sculpt_vertex_neighbors_get_faces(SculptSession *ss,
@@ -1165,7 +1176,7 @@ bool SCULPT_vertex_is_boundary(const SculptSession *ss, const SculptVertRef vert
 {
   switch (BKE_pbvh_type(ss->pbvh)) {
     case PBVH_BMESH: {
-      MDynTopoVert *mv = BKE_PBVH_DYNVERT(ss->cd_dyn_vert, ((BMVert*)(vertex.i)));
+      MDynTopoVert *mv = BKE_PBVH_DYNVERT(ss->cd_dyn_vert, ((BMVert *)(vertex.i)));
       return mv->flag & DYNVERT_BOUNDARY;
     }
     case PBVH_FACES: {
@@ -4414,8 +4425,9 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
   BLI_task_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings);
 }
 
-__attribute__((optnone)) static void do_elastic_deform_brush_task_cb_ex(
-    void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
+static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata,
+                                               const int n,
+                                               const TaskParallelTLS *__restrict UNUSED(tls))
 {
   SculptThreadedTaskData *data = userdata;
   SculptSession *ss = data->ob->sculpt;
@@ -6223,18 +6235,19 @@ static void sculpt_topology_update(Sculpt *sd,
   bool modified;
 
   /* do nodes under the brush cursor */
-  modified = BKE_pbvh_bmesh_update_topology_nodes(ss->pbvh,
-                                       SCULPT_search_sphere_cb,
-                                       topology_undopush_cb,
-                                       &sdata,
-                                       mode,
-                                       ss->cache->location,
-                                       ss->cache->view_normal,
-                                       ss->cache->radius,
-                                       (brush->flag & BRUSH_FRONTFACE) != 0,
-                                       (brush->falloff_shape != PAINT_FALLOFF_SHAPE_SPHERE),
-                                       symidx,
-                                       brush->sculpt_tool != SCULPT_TOOL_DRAW_SHARP);
+  modified = BKE_pbvh_bmesh_update_topology_nodes(
+      ss->pbvh,
+      SCULPT_search_sphere_cb,
+      topology_undopush_cb,
+      &sdata,
+      mode,
+      ss->cache->location,
+      ss->cache->view_normal,
+      ss->cache->radius,
+      (brush->flag & BRUSH_FRONTFACE) != 0,
+      (brush->falloff_shape != PAINT_FALLOFF_SHAPE_SPHERE),
+      symidx,
+      brush->sculpt_tool != SCULPT_TOOL_DRAW_SHARP);
 
   /* Update average stroke position. */
   copy_v3_v3(location, ss->cache->true_location);
@@ -9548,7 +9561,7 @@ void SCULPT_boundary_info_ensure(Object *object)
 
     MEM_SAFE_FREE(ss->vertex_info.boundary);
 
-    //return; //XXX
+    // return; //XXX
     BM_mesh_elem_index_ensure(ss->bm, BM_VERT);
 
     BM_ITER_MESH (v, &iter, ss->bm, BM_VERTS_OF_MESH) {
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 3cf7079560d..0567bcadc7c 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -777,7 +777,7 @@ GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(int totgrid, BLI_bitmap **grid_hid
  * \{ */
 
 /* Output a BMVert into a VertexBufferFormat array at v_index. */
-__attribute__((optnone)) static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
+static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
                                           GPUVertBuf *vert_buf,
                                           int v_index,
                                           const float fno[3],



More information about the Bf-blender-cvs mailing list