diff options
author | Hans Goudey <h.goudey@me.com> | 2022-02-10 19:58:35 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-02-10 19:59:20 +0300 |
commit | 7682d7de046185382985999f8f6b6e7dcf860582 (patch) | |
tree | 6fae3aeb24d1d1a5d40e40bc489d8498566583fb /source/blender/blenkernel | |
parent | 2cd1472f86dd0c3f8792f8d28b1238f9dffb3739 (diff) |
Refactor: Move PBVH update tag out of MVert
This is part of the project of converting `MVert` into `float3`.
(more details in T93602), The pbvh update flag is removed and
replaced with a bitmap stored in the PBVH structure. This
patch is similar to D13878. This is mainly setup for an eventual
performance improvement by removing the extra data from
mesh vertices, but if it's consistent with testing in the other patch
doing the same thing for another "temp tag", then it may actually
increase the speed of sculpt code slightly, since less memory needs
to be loaded when checking/changing the flags.
Differential Revision: https://developer.blender.org/D14000
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_pbvh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 29 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_intern.h | 4 |
3 files changed, 22 insertions, 13 deletions
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 1ef1c98ce83..42dfd7f14ff 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -299,6 +299,8 @@ bool BKE_pbvh_node_fully_masked_get(PBVHNode *node); void BKE_pbvh_node_fully_unmasked_set(PBVHNode *node, int fully_masked); bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node); +void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index); + void BKE_pbvh_node_get_grids(PBVH *pbvh, PBVHNode *node, int **grid_indices, diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index bfedd4d3f49..c925942d810 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -610,7 +610,9 @@ void BKE_pbvh_build_mesh(PBVH *pbvh, } MEM_freeN(prim_bbc); - MEM_freeN(pbvh->vert_bitmap); + + /* Clear the bitmap so it can be used as an update tag later on. */ + BLI_bitmap_set_all(pbvh->vert_bitmap, false, totvert); } void BKE_pbvh_build_grids(PBVH *pbvh, @@ -714,6 +716,8 @@ void BKE_pbvh_free(PBVH *pbvh) MEM_freeN(pbvh->prim_indices); } + MEM_SAFE_FREE(pbvh->vert_bitmap); + MEM_freeN(pbvh); } @@ -1021,8 +1025,7 @@ static void pbvh_update_normals_clear_task_cb(void *__restrict userdata, const int totvert = node->uniq_verts; for (int i = 0; i < totvert; i++) { const int v = verts[i]; - const MVert *mvert = &pbvh->verts[v]; - if (mvert->flag & ME_VERT_PBVH_UPDATE) { + if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { zero_v3(vnors[v]); } } @@ -1065,7 +1068,7 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, for (int j = sides; j--;) { const int v = vtri[j]; - if (pbvh->verts[v].flag & ME_VERT_PBVH_UPDATE) { + if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { /* NOTE: This avoids `lock, add_v3_v3, unlock` * and is five to ten times quicker than a spin-lock. * Not exact equivalent though, since atomicity is only ensured for one component @@ -1094,13 +1097,12 @@ static void pbvh_update_normals_store_task_cb(void *__restrict userdata, for (int i = 0; i < totvert; i++) { const int v = verts[i]; - MVert *mvert = &pbvh->verts[v]; /* No atomics necessary because we are iterating over uniq_verts only, * so we know only this thread will handle this vertex. */ - if (mvert->flag & ME_VERT_PBVH_UPDATE) { + if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { normalize_v3(vnors[v]); - mvert->flag &= ~ME_VERT_PBVH_UPDATE; + BLI_BITMAP_DISABLE(pbvh->vert_bitmap, v); } } @@ -1117,7 +1119,7 @@ static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode) * bounding box of its adjacent faces will be as well. * - However this is only true for the vertices that have actually been * edited, not for all vertices in the nodes marked for update, so we - * can only update vertices marked with ME_VERT_PBVH_UPDATE. + * can only update vertices marked in the `vert_bitmap`. */ PBVHUpdateData data = { @@ -1826,6 +1828,12 @@ bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node) return (node->flag & PBVH_Leaf) && (node->flag & PBVH_FullyUnmasked); } +void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index) +{ + BLI_assert(pbvh->type == PBVH_FACES); + BLI_BITMAP_ENABLE(pbvh->vert_bitmap, index); +} + void BKE_pbvh_node_get_verts(PBVH *pbvh, PBVHNode *node, const int **r_vert_indices, @@ -1971,9 +1979,8 @@ bool BKE_pbvh_node_vert_update_check_any(PBVH *pbvh, PBVHNode *node) for (int i = 0; i < totvert; i++) { const int v = verts[i]; - const MVert *mvert = &pbvh->verts[v]; - if (mvert->flag & ME_VERT_PBVH_UPDATE) { + if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { return true; } } @@ -2827,7 +2834,7 @@ void BKE_pbvh_vert_coords_apply(PBVH *pbvh, const float (*vertCos)[3], const int /* no need for float comparison here (memory is exactly equal or not) */ if (memcmp(mvert->co, vertCos[a], sizeof(float[3])) != 0) { copy_v3_v3(mvert->co, vertCos[a]); - mvert->flag |= ME_VERT_PBVH_UPDATE; + BKE_pbvh_vert_mark_update(pbvh, a); } } diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h index 9562cda5f28..53379d8a032 100644 --- a/source/blender/blenkernel/intern/pbvh_intern.h +++ b/source/blender/blenkernel/intern/pbvh_intern.h @@ -153,8 +153,8 @@ struct PBVH { int totgrid; BLI_bitmap **grid_hidden; - /* Only used during BVH build and update, - * don't need to remain valid after */ + /* Used during BVH build and later to mark that a vertex needs to update + * (its normal must be recalculated). */ BLI_bitmap *vert_bitmap; #ifdef PERFCNTRS |