From 881ec8b1edb5de70401e66e125abde9b667209ea Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sun, 3 Dec 2023 21:21:03 -0500 Subject: [PATCH] Cleanup: Return multires grid key by value --- source/blender/blenkernel/BKE_pbvh_api.hh | 4 +- source/blender/blenkernel/BKE_subdiv_ccg.hh | 4 +- .../blenkernel/intern/multires_reshape_ccg.cc | 3 +- source/blender/blenkernel/intern/paint.cc | 8 +-- source/blender/blenkernel/intern/pbvh.cc | 7 ++- .../blender/blenkernel/intern/subdiv_ccg.cc | 50 ++++++++----------- .../editors/sculpt_paint/paint_mask.cc | 6 +-- .../editors/sculpt_paint/sculpt_undo.cc | 8 +-- 8 files changed, 36 insertions(+), 54 deletions(-) diff --git a/source/blender/blenkernel/BKE_pbvh_api.hh b/source/blender/blenkernel/BKE_pbvh_api.hh index 1f2c2fe9629..05a1204ebfc 100644 --- a/source/blender/blenkernel/BKE_pbvh_api.hh +++ b/source/blender/blenkernel/BKE_pbvh_api.hh @@ -207,7 +207,7 @@ void BKE_pbvh_update_mesh_pointers(PBVH *pbvh, Mesh *mesh); /** * Do a full rebuild with on Grids data structure. */ -void BKE_pbvh_build_grids(PBVH *pbvh, CCGKey *key, Mesh *me, SubdivCCG *subdiv_ccg); +void BKE_pbvh_build_grids(PBVH *pbvh, const CCGKey *key, Mesh *me, SubdivCCG *subdiv_ccg); /** * Build a PBVH from a BMesh. */ @@ -432,7 +432,7 @@ void BKE_pbvh_redraw_BB(PBVH *pbvh, float bb_min[3], float bb_max[3]); blender::IndexMask BKE_pbvh_get_grid_updates(const PBVH *pbvh, blender::Span nodes, blender::IndexMaskMemory &memory); -void BKE_pbvh_grids_update(PBVH *pbvh, CCGKey *key); +void BKE_pbvh_grids_update(PBVH *pbvh, const CCGKey *key); void BKE_pbvh_subdiv_cgg_set(PBVH *pbvh, SubdivCCG *subdiv_ccg); void BKE_pbvh_vert_coords_apply(PBVH *pbvh, blender::Span vert_positions); diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.hh b/source/blender/blenkernel/BKE_subdiv_ccg.hh index e569b614932..a980c5472e3 100644 --- a/source/blender/blenkernel/BKE_subdiv_ccg.hh +++ b/source/blender/blenkernel/BKE_subdiv_ccg.hh @@ -227,8 +227,8 @@ Mesh *BKE_subdiv_to_ccg_mesh(Subdiv &subdiv, const Mesh &coarse_mesh); /* Create a key for accessing grid elements at a given level. */ -void BKE_subdiv_ccg_key(CCGKey &key, const SubdivCCG &subdiv_ccg, int level); -void BKE_subdiv_ccg_key_top_level(CCGKey &key, const SubdivCCG &subdiv_ccg); +CCGKey BKE_subdiv_ccg_key(const SubdivCCG &subdiv_ccg, int level); +CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg); /* Recalculate all normals based on grid element coordinates. */ void BKE_subdiv_ccg_recalc_normals(SubdivCCG &subdiv_ccg); diff --git a/source/blender/blenkernel/intern/multires_reshape_ccg.cc b/source/blender/blenkernel/intern/multires_reshape_ccg.cc index 6ad5b1e55e1..658b99a242d 100644 --- a/source/blender/blenkernel/intern/multires_reshape_ccg.cc +++ b/source/blender/blenkernel/intern/multires_reshape_ccg.cc @@ -18,8 +18,7 @@ bool multires_reshape_assign_final_coords_from_ccg(const MultiresReshapeContext *reshape_context, SubdivCCG *subdiv_ccg) { - CCGKey reshape_level_key; - BKE_subdiv_ccg_key(reshape_level_key, *subdiv_ccg, reshape_context->reshape.level); + const CCGKey reshape_level_key = BKE_subdiv_ccg_key(*subdiv_ccg, reshape_context->reshape.level); const int reshape_grid_size = reshape_context->reshape.grid_size; const float reshape_grid_size_1_inv = 1.0f / (float(reshape_grid_size) - 1.0f); diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index 8067ccff698..a9aa282e946 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -2157,8 +2157,6 @@ void BKE_sculpt_sync_face_visibility_to_grids(Mesh *mesh, SubdivCCG *subdiv_ccg) const OffsetIndices faces = mesh->faces(); const VArraySpan hide_poly_span(hide_poly); - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, *subdiv_ccg); BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(*subdiv_ccg); threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) { for (const int i : range) { @@ -2201,8 +2199,7 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform) static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg) { - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, *subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(*subdiv_ccg); PBVH *pbvh = BKE_pbvh_new(PBVH_GRIDS); Mesh *base_mesh = BKE_mesh_from_object(ob); @@ -2288,8 +2285,7 @@ bool BKE_object_sculpt_use_dyntopo(const Object *object) void BKE_sculpt_bvh_update_from_ccg(PBVH *pbvh, SubdivCCG *subdiv_ccg) { - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, *subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(*subdiv_ccg); BKE_pbvh_grids_update(pbvh, &key); } diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index c4055c9b95b..181a7a0c324 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -909,7 +909,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh, Mesh *mesh) #endif } -void BKE_pbvh_build_grids(PBVH *pbvh, CCGKey *key, Mesh *me, SubdivCCG *subdiv_ccg) +void BKE_pbvh_build_grids(PBVH *pbvh, const CCGKey *key, Mesh *me, SubdivCCG *subdiv_ccg) { const int gridsize = key->grid_size; const Span grids = subdiv_ccg->grids; @@ -1644,8 +1644,7 @@ void node_update_mask_grids(const CCGKey &key, const Span grids, PBVH static void update_mask_grids(const SubdivCCG &subdiv_ccg, const Span nodes) { - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); if (!key.has_mask) { for (PBVHNode *node : nodes) { node->flag &= ~PBVH_FullyMasked; @@ -3023,7 +3022,7 @@ void BKE_pbvh_draw_debug_cb(PBVH *pbvh, } } -void BKE_pbvh_grids_update(PBVH *pbvh, CCGKey *key) +void BKE_pbvh_grids_update(PBVH *pbvh, const CCGKey *key) { pbvh->gridkey = *key; } diff --git a/source/blender/blenkernel/intern/subdiv_ccg.cc b/source/blender/blenkernel/intern/subdiv_ccg.cc index 88ae5ff6ac9..0a7608b90a1 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg.cc @@ -45,11 +45,11 @@ using blender::VectorSet; * \{ */ static void subdiv_ccg_average_inner_face_grids(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const SubdivCCGFace &face); void subdiv_ccg_average_faces_boundaries_and_corners(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const IndexMask &face_mask); /** \} */ @@ -469,9 +469,6 @@ static void subdiv_ccg_init_faces_vertex_neighborhood(SubdivCCG &subdiv_ccg) } subdiv_ccg_allocate_adjacent_vertices(subdiv_ccg, num_vertices); Vector face_vertices; - /* Key to access elements. */ - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); /* Store adjacency for all faces. */ for (const int face_index : faces.index_range()) { const SubdivCCGFace &face = faces[face_index]; @@ -579,8 +576,9 @@ void BKE_subdiv_ccg_destroy(SubdivCCG *subdiv_ccg) MEM_delete(subdiv_ccg); } -void BKE_subdiv_ccg_key(CCGKey &key, const SubdivCCG &subdiv_ccg, int level) +CCGKey BKE_subdiv_ccg_key(const SubdivCCG &subdiv_ccg, int level) { + CCGKey key; key.level = level; key.elem_size = element_size_bytes_get(subdiv_ccg); key.grid_size = BKE_subdiv_grid_size_from_level(level); @@ -592,11 +590,12 @@ void BKE_subdiv_ccg_key(CCGKey &key, const SubdivCCG &subdiv_ccg, int level) key.has_normals = subdiv_ccg.has_normal; key.has_mask = subdiv_ccg.has_mask; + return key; } -void BKE_subdiv_ccg_key_top_level(CCGKey &key, const SubdivCCG &subdiv_ccg) +CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg) { - BKE_subdiv_ccg_key(key, subdiv_ccg, subdiv_ccg.level); + return BKE_subdiv_ccg_key(subdiv_ccg, subdiv_ccg.level); } /** \} */ @@ -611,7 +610,7 @@ void BKE_subdiv_ccg_key_top_level(CCGKey &key, const SubdivCCG &subdiv_ccg) * * The result is stored in normals storage from TLS. */ static void subdiv_ccg_recalc_inner_face_normals(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, MutableSpan face_normals, const int grid_index) { @@ -641,7 +640,7 @@ static void subdiv_ccg_recalc_inner_face_normals(SubdivCCG &subdiv_ccg, /* Average normals at every grid element, using adjacent faces normals. */ static void subdiv_ccg_average_inner_face_normals(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const Span face_normals, const int grid_index) { @@ -681,8 +680,7 @@ static void subdiv_ccg_average_inner_face_normals(SubdivCCG &subdiv_ccg, static void subdiv_ccg_recalc_inner_grid_normals(SubdivCCG &subdiv_ccg, const IndexMask &face_mask) { using namespace blender; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); const int grid_size_1 = subdiv_ccg.grid_size - 1; threading::EnumerableThreadSpecific> face_normals_tls( @@ -724,9 +722,7 @@ void BKE_subdiv_ccg_update_normals(SubdivCCG &subdiv_ccg, const IndexMask &face_ } subdiv_ccg_recalc_inner_grid_normals(subdiv_ccg, face_mask); - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); - + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); subdiv_ccg_average_faces_boundaries_and_corners(subdiv_ccg, key, face_mask); } @@ -744,7 +740,7 @@ static void average_grid_element_value_v3(float a[3], float b[3]) } static void average_grid_element(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, CCGElem *grid_element_a, CCGElem *grid_element_b) { @@ -778,7 +774,7 @@ static void element_accumulator_init(GridElementAccumulator &accumulator) static void element_accumulator_add(GridElementAccumulator &accumulator, const SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, /*const*/ CCGElem &grid_element) { add_v3_v3(accumulator.co, CCG_elem_co(&key, &grid_element)); @@ -798,7 +794,7 @@ static void element_accumulator_mul_fl(GridElementAccumulator &accumulator, cons } static void element_accumulator_copy(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, CCGElem &destination, const GridElementAccumulator &accumulator) { @@ -812,7 +808,7 @@ static void element_accumulator_copy(SubdivCCG &subdiv_ccg, } static void subdiv_ccg_average_inner_face_grids(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const SubdivCCGFace &face) { const Span grids = subdiv_ccg.grids; @@ -847,7 +843,7 @@ static void subdiv_ccg_average_inner_face_grids(SubdivCCG &subdiv_ccg, } static void subdiv_ccg_average_grids_boundary(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, SubdivCCGAdjacentEdge &adjacent_edge, MutableSpan accumulators) { @@ -889,7 +885,7 @@ struct AverageGridsCornerData { }; static void subdiv_ccg_average_grids_corners(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, SubdivCCGAdjacentVertex &adjacent_vertex) { const int num_adjacent_faces = adjacent_vertex.num_adjacent_faces; @@ -914,7 +910,7 @@ static void subdiv_ccg_average_grids_corners(SubdivCCG &subdiv_ccg, } static void subdiv_ccg_average_boundaries(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const IndexMask &adjacent_edge_mask) { using namespace blender; @@ -931,7 +927,7 @@ static void subdiv_ccg_average_boundaries(SubdivCCG &subdiv_ccg, } static void subdiv_ccg_average_corners(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const IndexMask &adjacent_vert_mask) { using namespace blender; @@ -944,8 +940,7 @@ static void subdiv_ccg_average_corners(SubdivCCG &subdiv_ccg, void BKE_subdiv_ccg_average_grids(SubdivCCG &subdiv_ccg) { using namespace blender; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); /* Average inner boundaries of grids (within one face), across faces * from different face-corners. */ BKE_subdiv_ccg_average_stitch_faces(subdiv_ccg, subdiv_ccg.faces.index_range()); @@ -977,7 +972,7 @@ static void subdiv_ccg_affected_face_adjacency(SubdivCCG &subdiv_ccg, } void subdiv_ccg_average_faces_boundaries_and_corners(SubdivCCG &subdiv_ccg, - CCGKey &key, + const CCGKey &key, const IndexMask &face_mask) { blender::Set adjacent_vert_set; @@ -1001,8 +996,7 @@ void subdiv_ccg_average_faces_boundaries_and_corners(SubdivCCG &subdiv_ccg, void BKE_subdiv_ccg_average_stitch_faces(SubdivCCG &subdiv_ccg, const IndexMask &face_mask) { using namespace blender; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); face_mask.foreach_index(GrainSize(512), [&](const int face_index) { subdiv_ccg_average_inner_face_grids(subdiv_ccg, key, subdiv_ccg.faces[face_index]); }); diff --git a/source/blender/editors/sculpt_paint/paint_mask.cc b/source/blender/editors/sculpt_paint/paint_mask.cc index 49d0634b58b..aa54b99d557 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_mask.cc @@ -237,8 +237,7 @@ static void fill_mask_grids(Main &bmain, { SubdivCCG &subdiv_ccg = *object.sculpt->subdiv_ccg; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); if (value == 0.0f && !key.has_mask) { /* Unlike meshes, don't dynamically remove masks since it is interleaved with other data. */ return; @@ -389,8 +388,7 @@ static void invert_mask_grids(Main &bmain, const BitGroupVector<> &grid_hidden = subdiv_ccg.grid_hidden; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); const Span grids = subdiv_ccg.grids; threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (PBVHNode *node : nodes.slice(range)) { diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.cc b/source/blender/editors/sculpt_paint/sculpt_undo.cc index 394c6ec13e2..8b3c30d6ff7 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_undo.cc @@ -464,8 +464,7 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt } else if (!unode->grids.is_empty() && subdiv_ccg != nullptr) { const int gridsize = subdiv_ccg->grid_size; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, *subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(*subdiv_ccg); const Span grid_indices = unode->grids; blender::MutableSpan co = unode->co; @@ -596,12 +595,9 @@ static bool sculpt_undo_restore_mask(bContext *C, SculptUndoNode *unode, bool *m } else if (!unode->grids.is_empty() && subdiv_ccg != nullptr) { const int gridsize = subdiv_ccg->grid_size; - CCGKey key; - BKE_subdiv_ccg_key_top_level(key, *subdiv_ccg); + const CCGKey key = BKE_subdiv_ccg_key_top_level(*subdiv_ccg); const Span grid_indices = unode->grids; - BKE_subdiv_ccg_key_top_level(key, *subdiv_ccg); - blender::MutableSpan mask = unode->mask; MutableSpan grids = subdiv_ccg->grids;