From d001e143a90bd99976972dc7648d175a995cbbba Mon Sep 17 00:00:00 2001 From: Nicola Date: Thu, 3 Apr 2025 00:14:41 +0200 Subject: [PATCH] Sculpt: Avoid use of BKE_pbvh_redraw_BB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When sculpting high-res meshes, the total number of nodes in the BVH tree can get quite high and — especially when the brush radius is low — comparable to the number of vertices influenced by the brush. Under these conditions, algorithms that run on each node of the BVH, especially if single-threaded, can become a bottleneck. This issue is particularly prominent in multires, where the leaf limit is 2500. The main culprit is `BKE_pbvh_redraw_BB`, which is used when flushing an update to calculate the redraw bounds. Because partial drawing is currently broken, and because a future reimplementation of partial drawing is unlikely to adopt the existing approach, this PR removes the partial drawing logic from `flush_update_step`. This patch provides a speedup ranging from 1.25x to 1.45x, depending on the brush size, when sculpting a small portion of a multires mesh with roughly 8.1 million faces and 12.6 million vertices using the draw brush. Pull Request: https://projects.blender.org/blender/blender/pulls/136471 --- source/blender/editors/sculpt_paint/sculpt.cc | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 6780030b075..48a531990ab 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -5220,21 +5220,9 @@ void flush_update_step(const bContext *C, const UpdateType update_type) /* Slow update with full dependency graph update and all that comes with it. * Needed when there are modifiers or full shading in the 3D viewport. */ DEG_id_tag_update(&ob.id, ID_RECALC_GEOMETRY); - ED_region_tag_redraw(®ion); } - else { - /* Fast path where we just update the BVH nodes that changed, and redraw - * only the part of the 3D viewport where changes happened. */ - rcti r; - if (rv3d && SCULPT_get_redraw_rect(region, *rv3d, ob, r)) { - r.xmin += region.winrct.xmin - 2; - r.xmax += region.winrct.xmin + 2; - r.ymin += region.winrct.ymin - 2; - r.ymax += region.winrct.ymin + 2; - ED_region_tag_redraw_partial(®ion, &r, true); - } - } + ED_region_tag_redraw(®ion); const bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(ob); if (update_type == UpdateType::Position && !ss.shapekey_active) {