From 4c1f766d0d8c82c18d0ccf3281d44deedf8270b1 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 14 Dec 2023 15:39:33 -0500 Subject: [PATCH] Cleanup: Remove unnecessary PBVH threading settings function There were just two more places using the C threading API in sculpt code. Switch them to the C++ API and remove the settings function. --- source/blender/blenkernel/BKE_pbvh_api.hh | 9 ---- source/blender/blenkernel/intern/pbvh.cc | 8 ---- .../blender/blenkernel/intern/pbvh_pixels.cc | 13 +++--- .../sculpt_paint/sculpt_brush_types.cc | 2 - .../editors/sculpt_paint/sculpt_face_set.cc | 2 - .../sculpt_paint/sculpt_paint_image.cc | 42 ++++++++----------- .../editors/sculpt_paint/sculpt_smooth.cc | 2 - .../editors/sculpt_paint/sculpt_transform.cc | 3 -- 8 files changed, 23 insertions(+), 58 deletions(-) diff --git a/source/blender/blenkernel/BKE_pbvh_api.hh b/source/blender/blenkernel/BKE_pbvh_api.hh index 14d84ad754e..8e7b4f00177 100644 --- a/source/blender/blenkernel/BKE_pbvh_api.hh +++ b/source/blender/blenkernel/BKE_pbvh_api.hh @@ -602,19 +602,10 @@ void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node, */ bool BKE_pbvh_node_has_vert_with_normal_update_tag(PBVH *pbvh, PBVHNode *node); -// void BKE_pbvh_node_BB_reset(PBVHNode *node); -// void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]); - bool pbvh_has_mask(const PBVH *pbvh); bool pbvh_has_face_sets(PBVH *pbvh); -/* Parallelization. */ - -void BKE_pbvh_parallel_range_settings(TaskParallelSettings *settings, - bool use_threading, - int totnode); - blender::Span BKE_pbvh_get_vert_positions(const PBVH *pbvh); blender::MutableSpan BKE_pbvh_get_vert_positions(PBVH *pbvh); blender::Span BKE_pbvh_get_vert_normals(const PBVH *pbvh); diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index edfffab763e..b425a577013 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -3044,14 +3044,6 @@ void BKE_pbvh_get_frustum_planes(const PBVH *pbvh, PBVHFrustumPlanes *planes) } } -void BKE_pbvh_parallel_range_settings(TaskParallelSettings *settings, - bool use_threading, - int totnode) -{ - memset(settings, 0, sizeof(*settings)); - settings->use_threading = use_threading && totnode > 1; -} - Mesh *BKE_pbvh_get_mesh(PBVH *pbvh) { return pbvh->mesh; diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc index e2dabe7765e..39f785766ad 100644 --- a/source/blender/blenkernel/intern/pbvh_pixels.cc +++ b/source/blender/blenkernel/intern/pbvh_pixels.cc @@ -466,11 +466,8 @@ struct EncodePixelsUserData { const UVPrimitiveLookup *uv_primitive_lookup; }; -static void do_encode_pixels(void *__restrict userdata, - const int n, - const TaskParallelTLS *__restrict /*tls*/) +static void do_encode_pixels(EncodePixelsUserData *data, const int n) { - EncodePixelsUserData *data = static_cast(userdata); const uv_islands::MeshData &mesh_data = *data->mesh_data; Image *image = data->image; ImageUser image_user = *data->image_user; @@ -710,9 +707,11 @@ static bool update_pixels(PBVH *pbvh, Mesh *mesh, Image *image, ImageUser *image user_data.uv_primitive_lookup = &uv_primitive_lookup; user_data.uv_masks = &uv_masks; - TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, true, nodes_to_update.size()); - BLI_task_parallel_range(0, nodes_to_update.size(), &user_data, do_encode_pixels, &settings); + threading::parallel_for(nodes_to_update.index_range(), 1, [&](const IndexRange range) { + for (const int i : range) { + do_encode_pixels(&user_data, i); + } + }); if (USE_WATERTIGHT_CHECK) { apply_watertight_check(pbvh, image, image_user); } diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.cc b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc index 58c95900a8b..44a679b6488 100644 --- a/source/blender/editors/sculpt_paint/sculpt_brush_types.cc +++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc @@ -2318,8 +2318,6 @@ void SCULPT_do_slide_relax_brush(Sculpt *sd, Object *ob, Span nodes) BKE_curvemapping_init(brush->curve); - TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, true, nodes.size()); if (ss->cache->alt_smooth) { SCULPT_boundary_info_ensure(ob); for (int i = 0; i < 4; i++) { diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index a075817092b..35a5a4e6312 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -454,8 +454,6 @@ void do_draw_face_sets_brush(Sculpt *sd, Object *ob, Span nodes) BKE_curvemapping_init(brush->curve); - TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, true, nodes.size()); if (ss->cache->alt_smooth) { SCULPT_boundary_info_ensure(ob); for (int i = 0; i < 4; i++) { diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc index c40db45d127..68378a5a39d 100644 --- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc +++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc @@ -327,11 +327,8 @@ static std::vector init_uv_primitives_brush_test(SculptSession *ss, return brush_test; } -static void do_paint_pixels(void *__restrict userdata, - const int n, - const TaskParallelTLS *__restrict tls) +static void do_paint_pixels(TexturePaintingUserData *data, const int n) { - TexturePaintingUserData *data = static_cast(userdata); Object *ob = data->ob; SculptSession *ss = ob->sculpt; const Brush *brush = data->brush; @@ -339,7 +336,7 @@ static void do_paint_pixels(void *__restrict userdata, PBVHNode *node = data->nodes[n]; PBVHData &pbvh_data = BKE_pbvh_pixels_data_get(*pbvh); NodeData &node_data = BKE_pbvh_pixels_node_data_get(*node); - const int thread_id = BLI_task_parallel_thread_id(tls); + const int thread_id = BLI_task_parallel_thread_id(nullptr); const Span positions = SCULPT_mesh_deformed_positions_get(ss); std::vector brush_test = init_uv_primitives_brush_test( @@ -472,11 +469,8 @@ static void push_undo(const NodeData &node_data, } } -static void do_push_undo_tile(void *__restrict userdata, - const int n, - const TaskParallelTLS *__restrict /*tls*/) +static void do_push_undo_tile(TexturePaintingUserData *data, const int n) { - TexturePaintingUserData *data = static_cast(userdata); PBVHNode *node = data->nodes[n]; NodeData &node_data = BKE_pbvh_pixels_node_data_get(*node); @@ -501,14 +495,6 @@ static void do_push_undo_tile(void *__restrict userdata, } } -static void do_mark_dirty_regions(void *__restrict userdata, - const int n, - const TaskParallelTLS *__restrict /*tls*/) -{ - TexturePaintingUserData *data = static_cast(userdata); - PBVHNode *node = data->nodes[n]; - BKE_pbvh_pixels_mark_image_dirty(*node, *data->image_data.image, *data->image_data.image_user); -} /* -------------------------------------------------------------------- */ /** \name Fix non-manifold edge bleeding. @@ -580,6 +566,7 @@ void SCULPT_do_paint_brush_image(PaintModeSettings *paint_mode_settings, Object *ob, blender::Span texnodes) { + using namespace blender; Brush *brush = BKE_paint_brush(&sd->paint); TexturePaintingUserData data = {nullptr}; @@ -591,14 +578,19 @@ void SCULPT_do_paint_brush_image(PaintModeSettings *paint_mode_settings, return; } - TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, true, texnodes.size()); - BLI_task_parallel_range(0, texnodes.size(), &data, do_push_undo_tile, &settings); - BLI_task_parallel_range(0, texnodes.size(), &data, do_paint_pixels, &settings); + threading::parallel_for(texnodes.index_range(), 1, [&](const IndexRange range) { + for (const int i : range) { + do_push_undo_tile(&data, i); + } + }); + threading::parallel_for(texnodes.index_range(), 1, [&](const IndexRange range) { + for (const int i : range) { + do_paint_pixels(&data, i); + } + }); fix_non_manifold_seam_bleeding(*ob, data); - TaskParallelSettings settings_flush; - - BKE_pbvh_parallel_range_settings(&settings_flush, false, texnodes.size()); - BLI_task_parallel_range(0, texnodes.size(), &data, do_mark_dirty_regions, &settings_flush); + for (PBVHNode *node : texnodes) { + BKE_pbvh_pixels_mark_image_dirty(*node, *data.image_data.image, *data.image_data.image_user); + } } diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.cc b/source/blender/editors/sculpt_paint/sculpt_smooth.cc index 2224ded6a9f..7d7401ea0e2 100644 --- a/source/blender/editors/sculpt_paint/sculpt_smooth.cc +++ b/source/blender/editors/sculpt_paint/sculpt_smooth.cc @@ -506,8 +506,6 @@ void do_surface_smooth_brush(Sculpt *sd, Object *ob, Span nodes) { Brush *brush = BKE_paint_brush(&sd->paint); - TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, true, nodes.size()); for (int i = 0; i < brush->surface_smooth_iterations; i++) { threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) { for (const int i : range) { diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.cc b/source/blender/editors/sculpt_paint/sculpt_transform.cc index 80b474db56c..d56c5fa1b12 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.cc +++ b/source/blender/editors/sculpt_paint/sculpt_transform.cc @@ -269,9 +269,6 @@ static void sculpt_transform_radius_elastic(Sculpt *sd, Object *ob, const float sculpt_transform_matrices_init( ss, symm, ss->filter_cache->transform_displacement_mode, transform_mats); - TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->nodes.size()); - /* Elastic transform needs to apply all transform matrices to all vertices and then combine the * displacement proxies as all vertices are modified by all symmetry passes. */ for (ePaintSymmetryFlags symmpass = PAINT_SYMM_NONE; symmpass <= symm; symmpass++) {