Cleanup: Sculpt: Use C++ threading API

Also remove unnecessarily parallelized loop that was just setting a
flag for every PBVH node.
This commit is contained in:
Hans Goudey
2023-09-21 13:41:49 -04:00
parent 805c58d9ec
commit 72a33623e6
2 changed files with 24 additions and 48 deletions

View File

@@ -23,7 +23,6 @@
#include "BLI_polyfill_2d.h"
#include "BLI_rect.h"
#include "BLI_span.hh"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
@@ -701,14 +700,10 @@ static void sculpt_gesture_face_set_begin(bContext *C, SculptGestureContext *sgc
BKE_sculpt_update_object_for_edit(depsgraph, sgcontext->vc.obact, true, false, false);
}
static void face_set_gesture_apply_task_cb(void *__restrict userdata,
const int i,
const TaskParallelTLS *__restrict /*tls*/)
static void face_set_gesture_apply_task(SculptGestureContext *sgcontext, PBVHNode *node)
{
SculptGestureContext *sgcontext = static_cast<SculptGestureContext *>(userdata);
SculptGestureFaceSetOperation *face_set_operation = (SculptGestureFaceSetOperation *)
sgcontext->operation;
PBVHNode *node = sgcontext->nodes[i];
bool any_updated = false;
SCULPT_undo_push_node(sgcontext->vc.obact, node, SCULPT_UNDO_FACE_SETS);
@@ -733,10 +728,12 @@ static void face_set_gesture_apply_task_cb(void *__restrict userdata,
static void sculpt_gesture_face_set_apply_for_symmetry_pass(bContext * /*C*/,
SculptGestureContext *sgcontext)
{
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, sgcontext->nodes.size());
BLI_task_parallel_range(
0, sgcontext->nodes.size(), sgcontext, face_set_gesture_apply_task_cb, &settings);
using namespace blender;
threading::parallel_for(sgcontext->nodes.index_range(), 1, [&](const IndexRange range) {
for (const int i : range) {
face_set_gesture_apply_task(sgcontext, sgcontext->nodes[i]);
}
});
}
static void sculpt_gesture_face_set_end(bContext * /*C*/, SculptGestureContext *sgcontext)
@@ -779,14 +776,10 @@ static void sculpt_gesture_mask_begin(bContext *C, SculptGestureContext *sgconte
BKE_sculpt_update_object_for_edit(depsgraph, sgcontext->vc.obact, false, true, false);
}
static void mask_gesture_apply_task_cb(void *__restrict userdata,
const int i,
const TaskParallelTLS *__restrict /*tls*/)
static void mask_gesture_apply_task(SculptGestureContext *sgcontext, PBVHNode *node)
{
SculptGestureContext *sgcontext = static_cast<SculptGestureContext *>(userdata);
SculptGestureMaskOperation *mask_operation = (SculptGestureMaskOperation *)sgcontext->operation;
Object *ob = sgcontext->vc.obact;
PBVHNode *node = sgcontext->nodes[i];
const bool is_multires = BKE_pbvh_type(sgcontext->ss->pbvh) == PBVH_GRIDS;
@@ -822,10 +815,12 @@ static void mask_gesture_apply_task_cb(void *__restrict userdata,
static void sculpt_gesture_mask_apply_for_symmetry_pass(bContext * /*C*/,
SculptGestureContext *sgcontext)
{
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, sgcontext->nodes.size());
BLI_task_parallel_range(
0, sgcontext->nodes.size(), sgcontext, mask_gesture_apply_task_cb, &settings);
using namespace blender;
threading::parallel_for(sgcontext->nodes.index_range(), 1, [&](const IndexRange range) {
for (const int i : range) {
mask_gesture_apply_task(sgcontext, sgcontext->nodes[i]);
}
});
}
static void sculpt_gesture_mask_end(bContext *C, SculptGestureContext *sgcontext)
@@ -1483,13 +1478,8 @@ static void sculpt_gesture_project_begin(bContext *C, SculptGestureContext *sgco
BKE_sculpt_update_object_for_edit(depsgraph, sgcontext->vc.obact, false, false, false);
}
static void project_line_gesture_apply_task_cb(void *__restrict userdata,
const int i,
const TaskParallelTLS *__restrict /*tls*/)
static void project_line_gesture_apply_task(SculptGestureContext *sgcontext, PBVHNode *node)
{
SculptGestureContext *sgcontext = static_cast<SculptGestureContext *>(userdata);
PBVHNode *node = sgcontext->nodes[i];
PBVHVertexIter vd;
bool any_updated = false;
@@ -1526,13 +1516,14 @@ static void project_line_gesture_apply_task_cb(void *__restrict userdata,
static void sculpt_gesture_project_apply_for_symmetry_pass(bContext * /*C*/,
SculptGestureContext *sgcontext)
{
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, sgcontext->nodes.size());
switch (sgcontext->shape_type) {
case SCULPT_GESTURE_SHAPE_LINE:
BLI_task_parallel_range(
0, sgcontext->nodes.size(), sgcontext, project_line_gesture_apply_task_cb, &settings);
using namespace blender;
threading::parallel_for(sgcontext->nodes.index_range(), 1, [&](const IndexRange range) {
for (const int i : range) {
project_line_gesture_apply_task(sgcontext, sgcontext->nodes[i]);
}
});
break;
case SCULPT_GESTURE_SHAPE_LASSO:
case SCULPT_GESTURE_SHAPE_BOX:

View File

@@ -37,7 +37,6 @@
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_task.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
@@ -637,15 +636,6 @@ static bool sculpt_undo_restore_face_sets(bContext *C,
return modified;
}
static void sculpt_undo_bmesh_restore_generic_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHNode **nodes = static_cast<PBVHNode **>(userdata);
BKE_pbvh_node_mark_redraw(nodes[n]);
}
static void sculpt_undo_bmesh_restore_generic(SculptUndoNode *unode, Object *ob, SculptSession *ss)
{
if (unode->applied) {
@@ -659,14 +649,9 @@ static void sculpt_undo_bmesh_restore_generic(SculptUndoNode *unode, Object *ob,
if (unode->type == SCULPT_UNDO_MASK) {
Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(ss->pbvh, {});
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, nodes.size());
BLI_task_parallel_range(0,
nodes.size(),
static_cast<void *>(nodes.data()),
sculpt_undo_bmesh_restore_generic_task_cb,
&settings);
for (PBVHNode *node : nodes) {
BKE_pbvh_node_mark_redraw(node);
}
}
else {
SCULPT_pbvh_clear(ob);