From 0da90f05fe130fee0ea9e7744c9d8e95d8d45d2a Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 23 Jul 2024 22:33:10 -0400 Subject: [PATCH] Cleanup: Sculpt: Simplify scratch array usage for BVH build --- source/blender/blenkernel/intern/pbvh.cc | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index 7d368a8ed0d..d40ef9510dc 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -109,7 +109,7 @@ static bool face_materials_match(const Span material_indices, /* Adapted from BLI_kdopbvh.c */ /* Returns the index of the first element on the right of the partition */ static int partition_prim_indices(MutableSpan prim_indices, - int *prim_scratch, + MutableSpan prim_scratch, int lo, int hi, int axis, @@ -417,7 +417,7 @@ static void build_sub(Tree &pbvh, const Span> prim_bounds, int offset, int count, - int *prim_scratch, + MutableSpan prim_scratch, int depth) { const Span prim_to_face_map = pbvh.type() == Type::Mesh ? @@ -425,11 +425,6 @@ static void build_sub(Tree &pbvh, pbvh.subdiv_ccg_->grid_to_face_map; int end; - if (!prim_scratch) { - prim_scratch = static_cast( - MEM_malloc_arrayN(pbvh.prim_indices_.size(), sizeof(int), __func__)); - } - /* Decide whether this is a leaf or not */ const bool below_leaf_limit = count <= leaf_limit || depth >= STACK_FIXED_DEPTH - 1; if (below_leaf_limit) { @@ -447,10 +442,6 @@ static void build_sub(Tree &pbvh, offset, count); - if (node_index == 0) { - MEM_SAFE_FREE(prim_scratch); - } - return; } } @@ -529,10 +520,6 @@ static void build_sub(Tree &pbvh, offset + count - end, prim_scratch, depth + 1); - - if (node_index == 0) { - MEM_SAFE_FREE(prim_scratch); - } } static void pbvh_build(Tree &pbvh, @@ -569,7 +556,7 @@ static void pbvh_build(Tree &pbvh, prim_bounds, 0, totprim, - nullptr, + Array(pbvh.prim_indices_.size()), 0); }