[Bf-blender-cvs] [893c36a7c95] temp-trimesh-sculpt: prepare for merge

Joseph Eagar noreply at git.blender.org
Wed Oct 14 04:05:46 CEST 2020


Commit: 893c36a7c95d926b15c1db603d3b3291cc00158e
Author: Joseph Eagar
Date:   Sun Oct 4 17:09:55 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rB893c36a7c95d926b15c1db603d3b3291cc00158e

prepare for merge

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

M	source/blender/blenkernel/intern/pbvh_trimesh.c
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/editors/interface/interface_template_search_menu.c
M	source/blender/editors/mesh/editmesh_select_similar.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/trimesh/intern/trimesh_log.c
M	source/blender/trimesh/trimesh.h

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

diff --git a/source/blender/blenkernel/intern/pbvh_trimesh.c b/source/blender/blenkernel/intern/pbvh_trimesh.c
index 47023dfccf8..f398714d1ef 100644
--- a/source/blender/blenkernel/intern/pbvh_trimesh.c
+++ b/source/blender/blenkernel/intern/pbvh_trimesh.c
@@ -1944,6 +1944,9 @@ bool BKE_pbvh_trimesh_update_topology(PBVH *bvh,
   pbvh_trimesh_verify(bvh);
 #endif
 
+  TM_mesh_elem_table_ensure(bvh->tm, TM_VERTEX|TM_TRI);
+  TM_mesh_elem_index_ensure(bvh->tm, TM_VERTEX|TM_TRI);
+
   return modified;
 }
 
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 5f3826d257a..a514f06dac4 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -27,6 +27,7 @@ set(INC
   ../../../intern/guardedalloc
   ../../../intern/numaapi/include
   ../../../extern/wcwidth
+  ../../../extern/parallel-hashmap
 )
 
 set(INC_SYS
diff --git a/source/blender/editors/interface/interface_template_search_menu.c b/source/blender/editors/interface/interface_template_search_menu.c
index 5bde51846a8..0dac2b5cd41 100644
--- a/source/blender/editors/interface/interface_template_search_menu.c
+++ b/source/blender/editors/interface/interface_template_search_menu.c
@@ -33,6 +33,7 @@
 #include "DNA_shader_fx_types.h"
 #include "DNA_texture_types.h"
 
+#include "BLI_ghash.h"
 #include "BLI_alloca.h"
 #include "BLI_dynstr.h"
 #include "BLI_ghash.h"
diff --git a/source/blender/editors/mesh/editmesh_select_similar.c b/source/blender/editors/mesh/editmesh_select_similar.c
index b3fb9747070..5a1895d784c 100644
--- a/source/blender/editors/mesh/editmesh_select_similar.c
+++ b/source/blender/editors/mesh/editmesh_select_similar.c
@@ -27,6 +27,7 @@
 #include "BLI_kdtree.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_ghash.h"
 
 #include "BKE_context.h"
 #include "BKE_editmesh.h"
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 7b41b1df0ab..671078e8118 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -620,6 +620,7 @@ void ED_region_do_draw(bContext *C, ARegion *region)
       SpaceLink *sl = area->spacedata.first;
 
       PointerRNA ptr;
+
       RNA_pointer_create(&screen->id, &RNA_Space, sl, &ptr);
 
       wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 58815d85281..51758997aa2 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1348,7 +1348,9 @@ void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *
 void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter *iter)
 {
   if (orig_data->unode->type == SCULPT_UNDO_COORDS) {
-    if (orig_data->bm_log) {
+    if (orig_data->tm_log) {
+      TM_log_original_vert_data(orig_data->tm_log, iter->tm_vert,  &orig_data->co, &orig_data->no);
+    } else if (orig_data->bm_log) {
       BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co, &orig_data->no);
     }
     else {
@@ -1574,7 +1576,7 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
   };
 
   TaskParallelSettings settings;
-  BKE_pbvh_parallel_range_settings(&settings, true && !ss->bm, totnode);
+  BKE_pbvh_parallel_range_settings(&settings, true && !ss->tm, totnode);
   BLI_task_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings);
 
   BKE_pbvh_node_color_buffer_free(ss->pbvh);
@@ -1707,6 +1709,9 @@ bool SCULPT_brush_test_sphere(SculptBrushTest *test, const float co[3])
 
 bool SCULPT_brush_test_sphere_sq(SculptBrushTest *test, const float co[3])
 {
+  if (!co) {
+    return false;
+  }
   float distsq = len_squared_v3v3(co, test->location);
 
   if (distsq <= test->radius_squared) {
@@ -5676,7 +5681,7 @@ static void sculpt_topology_update(Sculpt *sd,
   Brush *brush,
   UnifiedPaintSettings *UNUSED(ups))
 {
-  return;
+  //return;
   SculptSession *ss = ob->sculpt;
 
   int n, totnode;
diff --git a/source/blender/trimesh/intern/trimesh_log.c b/source/blender/trimesh/intern/trimesh_log.c
index 4b49f9e7bb8..25a3536fd5e 100644
--- a/source/blender/trimesh/intern/trimesh_log.c
+++ b/source/blender/trimesh/intern/trimesh_log.c
@@ -33,6 +33,7 @@
 #include "trimesh.h"
 #include "BLI_threadsafe_mempool.h"
 #include "BLI_array.h"
+#include "BLI_threads.h"
 
 #include "DNA_customdata_types.h"
 #include "DNA_mesh_types.h"
@@ -87,6 +88,8 @@ typedef struct TriMeshLog {
 
   int cd_vert_mask_index;
 
+  SpinLock lock;
+
   int curgroup;
 } TriMeshLog;
 
@@ -108,6 +111,8 @@ static void trimesh_add_group(TriMeshLog *log, bool set_curgroup) {
 TriMeshLog *TM_log_new(TM_TriMesh *tm, int cd_vert_mask_index) {
   TriMeshLog *log = MEM_callocN(sizeof(*log), "TriMeshLog");
 
+  BLI_spin_init(&log->lock);
+
   log->elemhash_ptr = BLI_ghash_ptr_new("TriMeshLog ghash ptr");
   log->elemhash_id = BLI_ghash_int_new("TriMeshLog ghash int");
   log->elemhash_entry = BLI_ghash_int_new("TriMeshLog ghash entry");
@@ -122,6 +127,8 @@ TriMeshLog *TM_log_new(TM_TriMesh *tm, int cd_vert_mask_index) {
 }
 
 void TM_log_free(TriMeshLog *log) {
+  BLI_spin_end(&log->lock);
+
   BLI_ghash_free(log->elemhash_ptr, NULL, NULL);
   BLI_ghash_free(log->elemhash_id, NULL, NULL);
   BLI_ghash_free(log->elemhash_entry, NULL, NULL);
@@ -193,13 +200,17 @@ static void tlog_ptr(TriMeshLog *log, void *f) {
 static int tlog_start(TriMeshLog *log, int code) {
   int i = log->totentries;
 
+  BLI_spin_lock(&log->lock);
   tlog_i(log, code);
+  BLI_spin_unlock(&log->lock);
 
   return i;
 }
 
 static void tlog_end(TriMeshLog *log, int entry_i) {
+  BLI_spin_lock(&log->lock);
   tlog_i(log, entry_i);
+  BLI_spin_unlock(&log->lock);
 }
 
 enum {
@@ -236,9 +247,11 @@ static float vert_mask_get(TMVert *v, const int cd_vert_mask_offset)
 }
 
 static void elemhash_add(TriMeshLog *log, void *elem, int id, int entryidx) {
+  BLI_spin_lock(&log->lock);
   BLI_ghash_insert(log->elemhash_id, (void*)id, elem);
   BLI_ghash_insert(log->elemhash_ptr, elem, (void*)id);
   BLI_ghash_insert(log->elemhash_entry, (void*)id, (void*)entryidx);
+  BLI_spin_unlock(&log->lock);
 }
 
 static void *elemhash_lookup_id(TriMeshLog *log, int id) {
@@ -248,9 +261,12 @@ static void *elemhash_lookup_id(TriMeshLog *log, int id) {
 static int elemhash_get_id(TriMeshLog *log, void *elem) {
   void **ret = NULL;
 
+  //XXX lock contention issue?
+  BLI_spin_lock(&log->lock);
   ret = BLI_ghash_lookup_p(log->elemhash_ptr, elem);
+  BLI_spin_unlock(&log->lock);
 
-  if (!ret || !*ret) {
+  if (!ret) {
     return -1;
   }
 
@@ -260,37 +276,40 @@ static int elemhash_get_id(TriMeshLog *log, void *elem) {
 static int elemhash_ensure_id(TriMeshLog *log, void *elem) {
   void **ret = NULL;
 
+  BLI_spin_lock(&log->lock);
   ret = BLI_ghash_lookup_p(log->elemhash_ptr, elem);
 
-  if (!ret || !*ret) {
+  if (!ret) {
     int id = log->idgen++;
+    BLI_spin_unlock(&log->lock);
+
     elemhash_add(log, elem, id, -1);
 
     return id;
+  } else {
+    int ret2 = (int)(*ret);
+    BLI_spin_unlock(&log->lock);
+    return ret2;
   }
-
-  return (int)(*ret);
 }
 
 static int elemhash_get_entry(TriMeshLog *log, int id) {
   void **ret = NULL;
 
+  BLI_spin_lock(&log->lock);
   ret = BLI_ghash_lookup_p(log->elemhash_ptr, (void*)id);
+  int ret2 = ret ? (int)(*ret) : -1;
+  BLI_spin_unlock(&log->lock);
 
-  if (!ret) {
-    return -1;
-  }
-
-  return (int)(*ret);
+  return ret2;
 }
 
 int TM_log_vert_add(TriMeshLog *log, TMVert *v, const int cd_mask_offset, bool skipcd) {
-  int id = log->idgen++;
+  int start = tlog_start(log, LOG_VERT_ADD);
 
+  int id = log->idgen++;
   elemhash_add(log, v, id, log->totentries);
 
-  int start = tlog_start(log, LOG_VERT_ADD);
-
   tlog_i(log, id);
   tlog_v3(log, v->co);
   tlog_v3(log, v->no);
@@ -309,7 +328,7 @@ int elemhash_has_id(TriMeshLog *log, void *elem) {
 int elemhash_get_vert_id(TriMeshLog *log, TMVert *v, int cd_vert_mask_offset) {
   int ret = elemhash_get_id(log, v);
 
-  if (!v) {
+  if (ret < 0) {
     return TM_log_vert_add(log, v, cd_vert_mask_offset, false);
   }
 
@@ -317,14 +336,13 @@ int elemhash_get_vert_id(TriMeshLog *log, TMVert *v, int cd_vert_mask_offset) {
 }
 
 int BLI_trimesh_log_edge_add(TriMeshLog *log, TMEdge *e, const int cd_mask_offset, int skipcd) {
-  int id = log->idgen++;
-
-  elemhash_add(log, e, id, log->totentries);
-
   int v1id = elemhash_get_vert_id(log, e->v1, cd_mask_offset);
   int v2id = elemhash_get_vert_id(log, e->v2, cd_mask_offset);
 
   int start = tlog_start(log, LOG_EDGE_ADD);
+  int id = log->idgen++;
+  elemhash_add(log, e, id, log->totentries);
+
   tlog_i(log, id);
   tlog_i(log, v1id);
   tlog_i(log, v2id);
@@ -444,12 +462,9 @@ static int trimesh_read_loop(TriMeshLog *tlog, TMLoopData *l, int entry_i) {
 }
 
 int BLI_trimesh_log_tri(TriMeshLog *log, TMFace *tri, bool skipcd) {
-  int id = log->idgen++;
 
   int cd_vert_mask_offset = log->cd_vert_mask_index;
 
-  elemhash_add(log, tri, id, log->totentries);
-
   int e1 = elemhash_get_edge_id(log, tri->e1, cd_vert_mask_offset);
   int e2 = elemhash_get_edge_id(log, tri->e2, cd_vert_mask_offset);
   int e3 = elemhash_get_edge_id(log, tri->e3, cd_vert_mask_offset);
@@ -457,7 +472,10 @@ int BLI_trimesh_log_tri(TriMeshLog *log, TMFace *tri, bool skipcd) {
   int v1 = elemhash_get_vert_id(log, tri->v1, cd_vert_mask_offset);
   int v2 = elemhash_get_vert_id(log, tri->v1, cd_vert_mask_offset);
   int v3 = elemhash_get_vert_id(log, tri->v1, cd_vert_mask_offset);
+
   int start = tlog_start(log, LOG_TRI_ADD);
+  int id = log->idgen++;
+  elemhash_add(log, tri, id, log->totentries);
 
   tlog_i(log, id);
   tlog_i(log, skipcd);
@@ -476,6 +494,8 @@ int BLI_trimesh_log_tri(TriMeshLog *log, TMFace *tri, bool skipcd) {
     trimesh_log_loop(log, tri, tri->l3);
   }
 
+  tlog_end(log, start);
+
   return id;
 }
 
@@ -612,6 +632,7 @@ int BLI_trimesh_log_vert_state(TriMeshLog *log, TMVert *v) {
   tlog_v3(log, v->no);
   tlog_i3(log, ivec);
   tlog_f(log, TM_ELEM_CD_GET_FLOAT(v, log->cd_vert_mask_index));
+  tlog_end(log, start);
 }
 
 void BLI_log_add_setpoint(TriMeshLog *log, int setgroup) {
@@ 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list