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.
This commit is contained in:
Hans Goudey 2023-12-14 15:39:33 -05:00
parent ce4ec6d42b
commit 4c1f766d0d
8 changed files with 23 additions and 58 deletions

@ -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<blender::float3> BKE_pbvh_get_vert_positions(const PBVH *pbvh);
blender::MutableSpan<blender::float3> BKE_pbvh_get_vert_positions(PBVH *pbvh);
blender::Span<blender::float3> BKE_pbvh_get_vert_normals(const PBVH *pbvh);

@ -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;

@ -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<EncodePixelsUserData *>(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);
}

@ -2318,8 +2318,6 @@ void SCULPT_do_slide_relax_brush(Sculpt *sd, Object *ob, Span<PBVHNode *> 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++) {

@ -454,8 +454,6 @@ void do_draw_face_sets_brush(Sculpt *sd, Object *ob, Span<PBVHNode *> 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++) {

@ -327,11 +327,8 @@ static std::vector<bool> 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<TexturePaintingUserData *>(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<float3> positions = SCULPT_mesh_deformed_positions_get(ss);
std::vector<bool> 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<TexturePaintingUserData *>(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<TexturePaintingUserData *>(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<PBVHNode *> 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);
}
}

@ -506,8 +506,6 @@ void do_surface_smooth_brush(Sculpt *sd, Object *ob, Span<PBVHNode *> 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) {

@ -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++) {