[Bf-blender-cvs] [5b10d08db39] temp_bmesh_multires: Sculpt dyntopo:
Joseph Eagar
noreply at git.blender.org
Sat Jul 17 13:12:57 CEST 2021
Commit: 5b10d08db397c77cd5369e676abfca3a1f2a1268
Author: Joseph Eagar
Date: Sat Jul 17 04:10:28 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB5b10d08db397c77cd5369e676abfca3a1f2a1268
Sculpt dyntopo:
* Prototyped a threaded bmesh->Mesh converter function. It's about
20-30% faster. Currently disabled.
* Tried to fix more of the bugs when stepping between sculpt and
other undo step types in the global undo stack.
===================================================================
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/bmesh/intern/bmesh_log.h
M source/blender/bmesh/intern/bmesh_mesh_convert.c
M source/blender/bmesh/intern/bmesh_mesh_convert_threaded.c
M source/blender/editors/sculpt_paint/sculpt_automasking.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/windowmanager/intern/wm_files.c
===================================================================
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index abdcfeb8d6c..11f1eb86492 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -445,6 +445,11 @@ static void bm_log_verts_unmake_pre(
uint id = POINTER_AS_UINT(key);
BMVert *v = bm_log_vert_from_id(log, id);
+ if (!v) {
+ printf("bm_log error; vertex id: %p\n", key);
+ continue;
+ }
+
/* Ensure the log has the final values of the vertex before
* deleting it */
bm_log_vert_bmvert_copy(log, entry, lv, v, cd_vert_mask_offset, true);
@@ -464,11 +469,16 @@ static void bm_log_verts_unmake(
uint id = POINTER_AS_UINT(key);
BMVert *v = bm_log_vert_from_id(log, id);
+ if (!v) {
+ printf("bmlog error. vertex id: %p\n", key);
+ continue;
+ }
+
BM_vert_kill(bm, v);
}
}
-ATTR_NO_OPT static void bm_log_faces_unmake(
+static void bm_log_faces_unmake(
BMesh *bm, BMLog *log, GHash *faces, BMLogEntry *entry, BMLogCallbacks *callbacks)
{
GHashIterator gh_iter;
@@ -554,7 +564,7 @@ static void bm_log_verts_restore(
}
}
-ATTR_NO_OPT static void bm_log_faces_restore(
+static void bm_log_faces_restore(
BMesh *bm, BMLog *log, GHash *faces, BMLogEntry *entry, BMLogCallbacks *callbacks)
{
GHashIterator gh_iter;
@@ -1004,9 +1014,46 @@ int BM_log_length(const BMLog *log)
return BLI_listbase_count(&log->entries);
}
+void BM_log_print_entry(BMLog *log, BMLogEntry *entry)
+{
+ BMLogEntry *first = entry;
+
+ if (!log) {
+ log = entry->log;
+ }
+
+ while (first->combined_prev) {
+ first = first->combined_prev;
+ }
+
+ printf("==bmlog step==\n");
+
+ while (first) {
+ if (first->fully_copy) {
+ printf(" ==full mesh copy==\n");
+ }
+ else {
+ printf(" ==entry==\n");
+ printf(" modified:\n");
+ printf(" verts: %d\n", BLI_ghash_len(entry->modified_verts));
+ printf(" faces: %d\n", BLI_ghash_len(entry->modified_faces));
+ printf(" new:\n");
+ printf(" verts: %d\n", BLI_ghash_len(entry->added_verts));
+ printf(" faces: %d\n", BLI_ghash_len(entry->added_faces));
+ printf(" deleted:\n");
+ printf(" verts: %d\n", BLI_ghash_len(entry->deleted_verts));
+ printf(" faces: %d\n", BLI_ghash_len(entry->deleted_faces));
+ printf("\n");
+ }
+ printf("\n");
+ first = first->combined_next;
+ }
+}
+
/* Apply a consistent ordering to BMesh vertices */
void BM_log_mesh_elems_reorder(BMesh *bm, BMLog *log)
{
+#if 0 // TODO: make sure no edge cases relying on this function still exist
uint *varr;
uint *farr;
@@ -1054,6 +1101,7 @@ void BM_log_mesh_elems_reorder(BMesh *bm, BMLog *log)
MEM_freeN(varr);
MEM_freeN(farr);
+#endif
}
BMLogEntry *BM_log_entry_check_customdata(BMesh *bm, BMLog *log)
diff --git a/source/blender/bmesh/intern/bmesh_log.h b/source/blender/bmesh/intern/bmesh_log.h
index 850bdf099c5..df41cb26d50 100644
--- a/source/blender/bmesh/intern/bmesh_log.h
+++ b/source/blender/bmesh/intern/bmesh_log.h
@@ -128,3 +128,5 @@ uint BM_log_vert_id_get(BMLog *log, BMVert *v);
BMVert *BM_log_id_vert_get(BMLog *log, uint id);
uint BM_log_face_id_get(BMLog *log, BMFace *f);
BMFace *BM_log_id_face_get(BMLog *log, uint id);
+
+void BM_log_print_entry(BMLog *log, BMLogEntry *entry);
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.c b/source/blender/bmesh/intern/bmesh_mesh_convert.c
index 9f6bdbf2e65..e8072cc4e69 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.c
@@ -79,6 +79,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"
+#include "BLI_array.h"
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
@@ -659,7 +660,7 @@ void BM_mesh_bm_from_me(Object *ob,
/**
* \brief BMesh -> Mesh
*/
-static BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
+BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
{
const int cd_shape_keyindex_offset = CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX);
BMVert **vertMap = NULL;
@@ -701,7 +702,7 @@ static BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
* Returns custom-data shapekey index from a keyblock or -1
* \note could split this out into a more generic function.
*/
-static int bm_to_mesh_shape_layer_index_from_kb(BMesh *bm, KeyBlock *currkey)
+int bm_to_mesh_shape_layer_index_from_kb(BMesh *bm, KeyBlock *currkey)
{
int i;
int j = 0;
@@ -738,6 +739,7 @@ BLI_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e)
*
* \param bmain: May be NULL in case \a calc_object_remap parameter option is not set.
*/
+
void BM_mesh_bm_to_me(
Main *bmain, Object *ob, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
{
@@ -796,18 +798,21 @@ void BM_mesh_bm_to_me(
me->totface = 0;
me->act_face = -1;
+ CustomData *srcdatas[] = {&bm->vdata, &bm->edata, &bm->ldata, &bm->pdata};
+ int id_flags[4] = {-1, -1, -1, -1};
+
{
CustomData_MeshMasks mask = CD_MASK_MESH;
CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra);
CustomDataMask extra2 = params->copy_mesh_id_layers ? CD_MASK_MESH_ID : 0;
- // clear mesh id layer flags
+ // copy id layers? temporarily clear cd_temporary and cd_flag_elem_nocopy flags
if (params->copy_mesh_id_layers) {
- CustomData *srcdatas[] = {&bm->vdata, &bm->edata, &bm->ldata, &bm->pdata};
-
for (int i = 0; i < 4; i++) {
int idx = CustomData_get_layer_index(srcdatas[i], CD_MESH_ID);
+
if (idx >= 0) {
+ id_flags[i] = srcdatas[i]->layers[idx].flag;
srcdatas[i]->layers[idx].flag &= ~(CD_FLAG_TEMPORARY | CD_FLAG_ELEM_NOCOPY);
}
}
@@ -1180,15 +1185,12 @@ void BM_mesh_bm_to_me(
/* To be removed as soon as COW is enabled by default. */
BKE_mesh_runtime_clear_geometry(me);
+ // restore original cd layer flags to bmesh id layers
if (params->copy_mesh_id_layers) {
- // restore mesh id layer flags in bm
- CustomData *srcdatas[] = {&bm->vdata, &bm->edata, &bm->ldata, &bm->pdata};
-
for (int i = 0; i < 4; i++) {
int idx = CustomData_get_layer_index(srcdatas[i], CD_MESH_ID);
-
if (idx >= 0) {
- srcdatas[i]->layers[idx].flag |= CD_FLAG_TEMPORARY | CD_FLAG_ELEM_NOCOPY;
+ srcdatas[i]->layers[idx].flag = id_flags[i];
}
}
}
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert_threaded.c b/source/blender/bmesh/intern/bmesh_mesh_convert_threaded.c
index 44957591b9f..97c148d27bd 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert_threaded.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert_threaded.c
@@ -12,6 +12,7 @@
# include "BLI_listbase.h"
# include "BLI_math_vector.h"
# include "BLI_task.h"
+# include "BLI_threads.h"
# include "BKE_customdata.h"
# include "BKE_mesh.h"
@@ -68,7 +69,9 @@ typedef struct BMThreadData {
# define ELEM_NEXT(type, ptr, size) ((type *)(((char *)ptr) + size))
-void bm_vert_task(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
+static void bm_vert_task(void *__restrict userdata,
+ const int n,
+ const TaskParallelTLS *__restrict tls)
{
BMThreadData *data = userdata;
BMesh *bm = data->bm;
@@ -111,7 +114,9 @@ void bm_vert_task(void *__restrict userdata, const int n, const TaskParallelTLS
}
}
-void bm_edge_task(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
+static void bm_edge_task(void *__restrict userdata,
+ const int n,
+ const TaskParallelTLS *__restrict tls)
{
BMThreadData *data = userdata;
BMesh *bm = data->bm;
@@ -156,7 +161,9 @@ void bm_edge_task(void *__restrict userdata, const int n, const TaskParallelTLS
}
}
-void bm_loop_task(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
+static void bm_loop_task(void *__restrict userdata,
+ const int n,
+ const TaskParallelTLS *__restrict tls)
{
BMThreadData *data = userdata;
BMesh *bm = data->bm;
@@ -199,7 +206,9 @@ void bm_loop_task(void *__restrict userdata, const int n, const TaskParallelTLS
}
}
-void bm_face_task(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
+static void bm_face_task(void *__restrict userdata,
+ const int n,
+ const TaskParallelTLS *__restrict tls)
{
BMThreadData *data = userdata;
BMesh *bm = data->bm;
@@ -389,16 +398,11 @@ BMesh *BM_mesh_bm_from_me_threaded(BMesh *bm,
// bm->vpool = BLI_mem
- MVert *mvert;
- MEdge *medge;
- MLoop *mloop;
- MPoly *mp;
KeyBlock *actkey, *block;
- BMVert *v;
BMEdge *e;
BMFace *f;
float(*keyco)[3] = NULL;
- int totloops, i;
+ int i;
CustomData_MeshMasks mask = CD_MASK_BMESH;
CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra);
@@ -554,7 +558,6 @@ BMesh *BM_mesh_bm_from_me_threaded(BMesh *bm,
BLI_task_parallel_range(0, data.totcf, &data, bm_face_task, &settings);
BMIter iter;
- BMLoop *l;
// link edges
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
@@ -583,4 +586,609 @@ BMesh *BM_mesh_bm_from_me_threaded(BMesh *bm,
return bm;
}
+
+static void bm_unmark_temp_cdlayers(BMesh *bm)
+{
+ CustomData_unmark_temporary_nocopy(&bm->vdata);
+ CustomData_unmark_temporary_nocopy(&bm->edata);
+ CustomData_unmark_temporary_nocopy(&bm->ldata);
+ CustomData_unmark_temporary_nocopy(&bm->pdata);
+}
+
+static void bm_mark_temp_cdlayers(BMesh *bm)
+{
+ CustomData_mark_temporary_nocopy(&bm->vdata);
+ CustomData_mark_temporary_nocopy(&bm->edata);
+ CustomData_mark_temporary_nocopy(&bm->ldata);
+ CustomData_mark_temporary_nocopy(&bm->pdata);
+}
+
+typedef struct BMToMeTask {
+ Mesh *me;
+ BMesh *bm;
+ Object *ob;
+ Main *bmain;
+ const struct BMeshToMeshParams *params;
+ struct CustomData_MeshMasks mask;
+ uint64_t extra2;
+} BMToMeTask;
+
+static void me_vert_task(void *__restrict userdata)
+{
+ BMToMeTask *data = (BMToMeTask *)userdata;
+ Mesh *me = data->me;
+ BMesh *bm = dat
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list