Page MenuHome
Paste P1128

Sculpt: experiment using TBB instead of BLI_task
ActivePublic

Authored by Brecht Van Lommel (brecht) on Oct 6 2019, 1:41 PM.
commit eabc6f0678ffd088944e98d2b695aeed94a832f7
Author: Brecht Van Lommel <brechtvanlommel@gmail.com>
Date: Sun Oct 6 12:10:39 2019 +0200
Sculpt: experiment using TBB instead of BLI_task
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index dedf76ee839..44868236938 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -28,6 +28,10 @@
/* For embedding CCGKey in iterator. */
#include "BKE_ccg.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct BMLog;
struct BMesh;
struct CCGElem;
@@ -44,6 +48,7 @@ struct PBVH;
struct PBVHNode;
struct SubdivCCG;
struct TaskParallelSettings;
+struct TaskParallelTLS;
typedef struct PBVH PBVH;
typedef struct PBVHNode PBVHNode;
@@ -430,14 +435,37 @@ void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node,
bool BKE_pbvh_node_vert_update_check_any(PBVH *bvh, PBVHNode *node);
-void BKE_pbvh_parallel_range_settings(struct TaskParallelSettings *settings,
- bool use_threading,
- int totnode);
-
// void BKE_pbvh_node_BB_reset(PBVHNode *node);
// void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]);
bool pbvh_has_mask(PBVH *bvh);
void pbvh_show_mask_set(PBVH *bvh, bool show_mask);
+/* Parallelization */
+typedef void (*PBVHParallelReduceFunc)(void *__restrict userdata, void *__restrict userdata_chunk);
+
+typedef void (*PBVHParallelRangeFunc)(void *__restrict userdata,
+ const int iter,
+ const struct TaskParallelTLS *__restrict tls);
+
+typedef struct PBVHParallelSettings {
+ void *userdata_chunk;
+ size_t userdata_chunk_size;
+ PBVHParallelReduceFunc func_reduce;
+} PBVHParallelSettings;
+
+void BKE_pbvh_parallel_range_settings(struct PBVHParallelSettings *settings,
+ bool use_threading,
+ int totnode);
+
+void BKE_pbvh_parallel_range(const int start,
+ const int stop,
+ void *userdata,
+ PBVHParallelRangeFunc func,
+ const struct PBVHParallelSettings *settings);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __BKE_PBVH_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 47b44c3828a..1525a3e7661 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -58,6 +58,7 @@ set(INC
set(INC_SYS
${GLEW_INCLUDE_PATH}
${ZLIB_INCLUDE_DIRS}
+ ${TBB_INCLUDE_DIRS}
)
set(SRC
@@ -183,6 +184,7 @@ set(SRC
intern/particle_system.c
intern/pbvh.c
intern/pbvh_bmesh.c
+ intern/pbvh_parallel.cpp
intern/pointcache.c
intern/report.c
intern/rigidbody.c
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 7ed986204d5..e9bf7893cda 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1093,12 +1093,11 @@ static void pbvh_faces_update_normals(PBVH *bvh, PBVHNode **nodes, int totnode)
.vnors = vnors,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
- BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_accum_task_cb, &settings);
-
- BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_store_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_normals_accum_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_normals_store_task_cb, &settings);
MEM_freeN(vnors);
}
@@ -1148,9 +1147,9 @@ static void pbvh_update_mask_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, in
.flag = flag,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
- BLI_task_parallel_range(0, totnode, &data, pbvh_update_mask_redraw_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_mask_redraw_task_cb, &settings);
}
static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata,
@@ -1186,9 +1185,9 @@ void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag)
.flag = flag,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
- BLI_task_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings);
}
static int pbvh_get_buffers_update_flags(PBVH *bvh, bool show_vcol)
@@ -1295,9 +1294,9 @@ static void pbvh_update_draw_buffers(
.show_vcol = show_vcol,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
- BLI_task_parallel_range(0, totnode, &data, pbvh_update_draw_buffer_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_draw_buffer_cb, &settings);
}
static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag)
@@ -2712,13 +2711,10 @@ void pbvh_show_mask_set(PBVH *bvh, bool show_mask)
bvh->show_mask = show_mask;
}
-void BKE_pbvh_parallel_range_settings(TaskParallelSettings *settings,
- bool use_threading,
- int totnode)
+void BKE_pbvh_parallel_range_settings(PBVHParallelSettings *settings,
+ /* TODO: remove or use */
+ bool UNUSED(use_threading),
+ int UNUSED(totnode))
{
- const int threaded_limit = 1;
- BLI_parallel_range_settings_defaults(settings);
- settings->use_threading = use_threading && (totnode > threaded_limit);
- settings->min_iter_per_thread = 1;
- settings->scheduling_mode = TASK_SCHEDULING_DYNAMIC;
+ memset(settings, 0, sizeof(*settings));
}
diff --git a/source/blender/blenkernel/intern/pbvh_parallel.cpp b/source/blender/blenkernel/intern/pbvh_parallel.cpp
new file mode 100644
index 00000000000..7500b791ef2
--- /dev/null
+++ b/source/blender/blenkernel/intern/pbvh_parallel.cpp
@@ -0,0 +1,112 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_task.h"
+
+#include "BKE_pbvh.h"
+
+#include <tbb/tbb.h>
+
+struct PBVHReduceTask {
+ PBVHParallelRangeFunc func;
+ void *userdata;
+
+ PBVHParallelReduceFunc func_reduce;
+ void *userdata_chunk;
+ size_t userdata_chunk_size;
+ bool userdata_chunk_free;
+
+ PBVHReduceTask()
+ {
+ }
+
+ PBVHReduceTask(PBVHReduceTask &other, tbb::split)
+ : func(other.func),
+ userdata(other.userdata),
+ func_reduce(other.func_reduce),
+ userdata_chunk_size(other.userdata_chunk_size),
+ userdata_chunk_free(true)
+ {
+ /* TODO: is there significant malloc overhead? */
+ userdata_chunk = MEM_mallocN(userdata_chunk_size, "PBVHReduceTask");
+ memcpy(userdata_chunk, other.userdata_chunk, userdata_chunk_size);
+ }
+
+ ~PBVHReduceTask()
+ {
+ if (userdata_chunk_free) {
+ MEM_freeN(userdata_chunk);
+ }
+ }
+
+ void operator()(const tbb::blocked_range<int> &r) const
+ {
+ TaskParallelTLS tls;
+ tls.thread_id = 0; /* TODO */
+ tls.userdata_chunk = userdata_chunk;
+ for (int i = r.begin(); i != r.end(); ++i) {
+ func(userdata, i, &tls);
+ }
+ }
+
+ void join(const PBVHReduceTask &other)
+ {
+ func_reduce(userdata_chunk, other.userdata_chunk);
+ }
+};
+
+struct PBVHTask {
+ PBVHParallelRangeFunc func;
+ void *userdata;
+
+ void operator()(const tbb::blocked_range<int> &r) const
+ {
+ TaskParallelTLS tls;
+ tls.thread_id = 0; /* TODO */
+ tls.userdata_chunk = NULL;
+ for (int i = r.begin(); i != r.end(); ++i) {
+ func(userdata, i, &tls);
+ }
+ }
+};
+
+void BKE_pbvh_parallel_range(const int start,
+ const int stop,
+ void *userdata,
+ PBVHParallelRangeFunc func,
+ const struct PBVHParallelSettings *settings)
+{
+ if (settings->func_reduce) {
+ PBVHReduceTask task;
+ task.func = func;
+ task.userdata = userdata;
+
+ task.func_reduce = settings->func_reduce;
+ task.userdata_chunk = settings->userdata_chunk;
+ task.userdata_chunk_size = settings->userdata_chunk_size;
+ task.userdata_chunk_free = false;
+
+ parallel_for(tbb::blocked_range<int>(start, stop), task);
+ }
+ else {
+ PBVHTask task;
+ task.func = func;
+ task.userdata = userdata;
+ parallel_for(tbb::blocked_range<int>(start, stop), task);
+ }
+}
diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index a93e55685d2..d160fba4013 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -166,9 +166,9 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
.value = value,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, mask_flood_fill_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, mask_flood_fill_task_cb, &settings);
if (multires) {
multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
@@ -343,9 +343,9 @@ bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *
.clip_planes_final = clip_planes_final,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, mask_box_select_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, mask_box_select_task_cb, &settings);
if (nodes) {
MEM_freeN(nodes);
@@ -532,9 +532,9 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
data.task_data.mode = mode;
data.task_data.value = value;
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, mask_gesture_lasso_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, mask_gesture_lasso_task_cb, &settings);
if (nodes) {
MEM_freeN(nodes);
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 81e3f04a0d1..77c95c6acb3 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -2072,9 +2072,9 @@ static void calculate_average_weight(SculptThreadedTaskData *data,
struct WPaintAverageAccum *accum = MEM_mallocN(sizeof(*accum) * totnode, __func__);
data->custom_data = accum;
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (data->sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, data, do_wpaint_brush_calc_average_weight_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, data, do_wpaint_brush_calc_average_weight_cb_ex, &settings);
uint accum_len = 0;
double accum_weight = 0.0;
@@ -2120,22 +2120,22 @@ static void wpaint_paint_leaves(bContext *C,
data.strength = BKE_brush_weight_get(scene, brush);
/* NOTE: current mirroring code cannot be run in parallel */
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, !(me->editflag & ME_EDIT_MIRROR_X), totnode);
switch ((eBrushWeightPaintTool)brush->weightpaint_tool) {
case WPAINT_TOOL_AVERAGE:
calculate_average_weight(&data, nodes, totnode);
- BLI_task_parallel_range(0, totnode, &data, do_wpaint_brush_draw_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_wpaint_brush_draw_task_cb_ex, &settings);
break;
case WPAINT_TOOL_SMEAR:
- BLI_task_parallel_range(0, totnode, &data, do_wpaint_brush_smear_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_wpaint_brush_smear_task_cb_ex, &settings);
break;
case WPAINT_TOOL_BLUR:
- BLI_task_parallel_range(0, totnode, &data, do_wpaint_brush_blur_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_wpaint_brush_blur_task_cb_ex, &settings);
break;
case WPAINT_TOOL_DRAW:
- BLI_task_parallel_range(0, totnode, &data, do_wpaint_brush_draw_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_wpaint_brush_draw_task_cb_ex, &settings);
break;
}
}
@@ -3126,9 +3126,9 @@ static void calculate_average_color(SculptThreadedTaskData *data,
struct VPaintAverageAccum *accum = MEM_mallocN(sizeof(*accum) * totnode, __func__);
data->custom_data = accum;
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
- BLI_task_parallel_range(0, totnode, data, do_vpaint_brush_calc_average_color_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, data, do_vpaint_brush_calc_average_color_cb_ex, &settings);
uint accum_len = 0;
uint accum_value[3] = {0};
@@ -3172,21 +3172,21 @@ static void vpaint_paint_leaves(bContext *C,
.lcol = (uint *)me->mloopcol,
.me = me,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
switch ((eBrushVertexPaintTool)brush->vertexpaint_tool) {
case VPAINT_TOOL_AVERAGE:
calculate_average_color(&data, nodes, totnode);
- BLI_task_parallel_range(0, totnode, &data, do_vpaint_brush_draw_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_vpaint_brush_draw_task_cb_ex, &settings);
break;
case VPAINT_TOOL_BLUR:
- BLI_task_parallel_range(0, totnode, &data, do_vpaint_brush_blur_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_vpaint_brush_blur_task_cb_ex, &settings);
break;
case VPAINT_TOOL_SMEAR:
- BLI_task_parallel_range(0, totnode, &data, do_vpaint_brush_smear_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_vpaint_brush_smear_task_cb_ex, &settings);
break;
case VPAINT_TOOL_DRAW:
- BLI_task_parallel_range(0, totnode, &data, do_vpaint_brush_draw_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_vpaint_brush_draw_task_cb_ex, &settings);
break;
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 853324c7e17..320853bffeb 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -402,17 +402,17 @@ static void do_nearest_vertex_get_task_cb(void *__restrict userdata,
BKE_pbvh_vertex_iter_end;
}
-static void nearest_vertex_get_finalize(void *__restrict userdata, void *__restrict tls)
+static void nearest_vertex_get_reduce(void *__restrict tls_join, void *__restrict tls)
{
- SculptThreadedTaskData *data = userdata;
+ NearestVertexTLSData *join = tls_join;
NearestVertexTLSData *nvtd = tls;
- if (data->nearest_vertex_index == -1) {
- data->nearest_vertex_index = nvtd->nearest_vertex_index;
- data->nearest_vertex_distance_squared = nvtd->nearest_vertex_distance_squared;
+ if (join->nearest_vertex_index == -1) {
+ join->nearest_vertex_index = nvtd->nearest_vertex_index;
+ join->nearest_vertex_distance_squared = nvtd->nearest_vertex_distance_squared;
}
- else if (nvtd->nearest_vertex_distance_squared < data->nearest_vertex_distance_squared) {
- data->nearest_vertex_index = nvtd->nearest_vertex_index;
- data->nearest_vertex_distance_squared = nvtd->nearest_vertex_distance_squared;
+ else if (nvtd->nearest_vertex_distance_squared < join->nearest_vertex_distance_squared) {
+ join->nearest_vertex_index = nvtd->nearest_vertex_index;
+ join->nearest_vertex_distance_squared = nvtd->nearest_vertex_distance_squared;
}
}
@@ -439,25 +439,23 @@ static int sculpt_nearest_vertex_get(
.ob = ob,
.nodes = nodes,
.max_distance_squared = max_distance * max_distance,
- .nearest_vertex_index = -1,
};
copy_v3_v3(task_data.nearest_vertex_search_co, co);
- task_data.nearest_vertex_distance_squared = FLT_MAX;
NearestVertexTLSData nvtd;
nvtd.nearest_vertex_index = -1;
nvtd.nearest_vertex_distance_squared = FLT_MAX;
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- settings.func_finalize = nearest_vertex_get_finalize;
+ settings.func_reduce = nearest_vertex_get_reduce;
settings.userdata_chunk = &nvtd;
settings.userdata_chunk_size = sizeof(NearestVertexTLSData);
- BLI_task_parallel_range(0, totnode, &task_data, do_nearest_vertex_get_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &task_data, do_nearest_vertex_get_task_cb, &settings);
MEM_SAFE_FREE(nodes);
- return task_data.nearest_vertex_index;
+ return nvtd.nearest_vertex_index;
}
static bool is_symmetry_iteration_valid(char i, char symm)
@@ -934,9 +932,9 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
.nodes = nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP) && !ss->bm, totnode);
- BLI_task_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings);
MEM_SAFE_FREE(nodes);
}
@@ -1417,9 +1415,10 @@ static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
* \{ */
typedef struct AreaNormalCenterTLSData {
- float private_co[2][3];
- float private_no[2][3];
- int private_count[2];
+ /* 0=towards view, 1=flipped */
+ float area_cos[2][3];
+ float area_nos[2][3];
+ int area_count[2];
} AreaNormalCenterTLSData;
static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
@@ -1429,8 +1428,8 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;
AreaNormalCenterTLSData *anctd = tls->userdata_chunk;
- float(*area_nos)[3] = data->area_nos;
- float(*area_cos)[3] = data->area_cos;
+ const bool use_area_nos = data->use_area_nos;
+ const bool use_area_cos = data->use_area_cos;
PBVHVertexIter vd;
SculptUndoNode *unode = NULL;
@@ -1483,13 +1482,13 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
normal_tri_v3(no, UNPACK3(co_tri));
flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f);
- if (area_cos) {
- add_v3_v3(anctd->private_co[flip_index], co);
+ if (use_area_cos) {
+ add_v3_v3(anctd->area_cos[flip_index], co);
}
- if (area_nos) {
- add_v3_v3(anctd->private_no[flip_index], no);
+ if (use_area_nos) {
+ add_v3_v3(anctd->area_nos[flip_index], no);
}
- anctd->private_count[flip_index] += 1;
+ anctd->area_count[flip_index] += 1;
}
}
}
@@ -1535,40 +1534,35 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
flip_index = (dot_v3v3(ss->cache ? ss->cache->view_normal : ss->cursor_view_normal, no) <=
0.0f);
- if (area_cos) {
- add_v3_v3(anctd->private_co[flip_index], co);
+ if (use_area_cos) {
+ add_v3_v3(anctd->area_cos[flip_index], co);
}
- if (area_nos) {
- add_v3_v3(anctd->private_no[flip_index], no);
+ if (use_area_nos) {
+ add_v3_v3(anctd->area_nos[flip_index], no);
}
- anctd->private_count[flip_index] += 1;
+ anctd->area_count[flip_index] += 1;
}
}
BKE_pbvh_vertex_iter_end;
}
}
-static void calc_area_normal_and_center_finalize(void *__restrict userdata, void *__restrict tls)
+static void calc_area_normal_and_center_reduce(void *__restrict tls_join, void *__restrict tls)
{
- SculptThreadedTaskData *data = userdata;
+ AreaNormalCenterTLSData *join = tls_join;
AreaNormalCenterTLSData *anctd = tls;
- float(*area_nos)[3] = data->area_nos;
- float(*area_cos)[3] = data->area_cos;
+
/* for flatten center */
- if (area_cos) {
- add_v3_v3(area_cos[0], anctd->private_co[0]);
- add_v3_v3(area_cos[1], anctd->private_co[1]);
- }
+ add_v3_v3(join->area_cos[0], anctd->area_cos[0]);
+ add_v3_v3(join->area_cos[1], anctd->area_cos[1]);
/* for area normal */
- if (area_nos) {
- add_v3_v3(area_nos[0], anctd->private_no[0]);
- add_v3_v3(area_nos[1], anctd->private_no[1]);
- }
+ add_v3_v3(join->area_nos[0], anctd->area_nos[0]);
+ add_v3_v3(join->area_nos[1], anctd->area_nos[1]);
/* weights */
- data->count[0] += anctd->private_count[0];
- data->count[1] += anctd->private_count[1];
+ join->area_count[0] += anctd->area_count[0];
+ join->area_count[1] += anctd->area_count[1];
}
static void calc_area_center(
@@ -1579,11 +1573,6 @@ static void calc_area_center(
const bool has_bm_orco = ss->bm && sculpt_stroke_is_dynamic_topology(ss, brush);
int n;
- /* 0=towards view, 1=flipped */
- float area_cos[2][3] = {{0.0f}};
-
- int count[2] = {0};
-
/* Intentionally set 'sd' to NULL since we share logic with vertex paint. */
SculptThreadedTaskData data = {
.sd = NULL,
@@ -1592,24 +1581,22 @@ static void calc_area_center(
.nodes = nodes,
.totnode = totnode,
.has_bm_orco = has_bm_orco,
- .area_cos = area_cos,
- .area_nos = NULL,
- .count = count,
+ .use_area_cos = true,
};
AreaNormalCenterTLSData anctd = {{{0}}};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- settings.func_finalize = calc_area_normal_and_center_finalize;
+ settings.func_reduce = calc_area_normal_and_center_reduce;
settings.userdata_chunk = &anctd;
settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
- BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings);
/* for flatten center */
- for (n = 0; n < ARRAY_SIZE(area_cos); n++) {
- if (count[n] != 0) {
- mul_v3_v3fl(r_area_co, area_cos[n], 1.0f / count[n]);
+ for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) {
+ if (anctd.area_count[n] != 0) {
+ mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.area_count[n]);
break;
}
}
@@ -1637,11 +1624,6 @@ bool sculpt_pbvh_calc_area_normal(const Brush *brush,
SculptSession *ss = ob->sculpt;
const bool has_bm_orco = ss->bm && sculpt_stroke_is_dynamic_topology(ss, brush);
- /* 0=towards view, 1=flipped */
- float area_nos[2][3] = {{0.0f}};
-
- int count[2] = {0};
-
/* Intentionally set 'sd' to NULL since this is used for vertex paint too. */
SculptThreadedTaskData data = {
.sd = NULL,
@@ -1650,24 +1632,22 @@ bool sculpt_pbvh_calc_area_normal(const Brush *brush,
.nodes = nodes,
.totnode = totnode,
.has_bm_orco = has_bm_orco,
- .area_cos = NULL,
- .area_nos = area_nos,
- .count = count,
+ .use_area_nos = true,
.any_vertex_sampled = false,
};
AreaNormalCenterTLSData anctd = {{{0}}};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, use_threading, totnode);
- settings.func_finalize = calc_area_normal_and_center_finalize;
+ settings.func_reduce = calc_area_normal_and_center_reduce;
settings.userdata_chunk = &anctd;
settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
- BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings);
/* for area normal */
- for (int i = 0; i < ARRAY_SIZE(area_nos); i++) {
- if (normalize_v3_v3(r_area_no, area_nos[i]) != 0.0f) {
+ for (int i = 0; i < ARRAY_SIZE(anctd.area_nos); i++) {
+ if (normalize_v3_v3(r_area_no, anctd.area_nos[i]) != 0.0f) {
break;
}
}
@@ -1685,12 +1665,6 @@ static void calc_area_normal_and_center(
const bool has_bm_orco = ss->bm && sculpt_stroke_is_dynamic_topology(ss, brush);
int n;
- /* 0=towards view, 1=flipped */
- float area_cos[2][3] = {{0.0f}};
- float area_nos[2][3] = {{0.0f}};
-
- int count[2] = {0};
-
/* Intentionally set 'sd' to NULL since this is used for vertex paint too. */
SculptThreadedTaskData data = {
.sd = NULL,
@@ -1699,24 +1673,23 @@ static void calc_area_normal_and_center(
.nodes = nodes,
.totnode = totnode,
.has_bm_orco = has_bm_orco,
- .area_cos = area_cos,
- .area_nos = area_nos,
- .count = count,
+ .use_area_cos = true,
+ .use_area_nos = true,
};
AreaNormalCenterTLSData anctd = {{{0}}};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- settings.func_finalize = calc_area_normal_and_center_finalize;
+ settings.func_reduce = calc_area_normal_and_center_reduce;
settings.userdata_chunk = &anctd;
settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
- BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings);
/* for flatten center */
- for (n = 0; n < ARRAY_SIZE(area_cos); n++) {
- if (count[n] != 0) {
- mul_v3_v3fl(r_area_co, area_cos[n], 1.0f / count[n]);
+ for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) {
+ if (anctd.area_count[n] != 0) {
+ mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.area_count[n]);
break;
}
}
@@ -1725,8 +1698,8 @@ static void calc_area_normal_and_center(
}
/* for area normal */
- for (n = 0; n < ARRAY_SIZE(area_nos); n++) {
- if (normalize_v3_v3(r_area_no, area_nos[n]) != 0.0f) {
+ for (n = 0; n < ARRAY_SIZE(anctd.area_nos); n++) {
+ if (normalize_v3_v3(r_area_no, anctd.area_nos[n]) != 0.0f) {
break;
}
}
@@ -2825,7 +2798,7 @@ static void smooth(Sculpt *sd,
.strength = strength,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
switch (type) {
@@ -2843,16 +2816,16 @@ static void smooth(Sculpt *sd,
settings.userdata_chunk = data_chunk;
settings.userdata_chunk_size = size;
- BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_multires_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_smooth_brush_multires_task_cb_ex, &settings);
MEM_freeN(data_chunk);
break;
}
case PBVH_FACES:
- BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_mesh_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_smooth_brush_mesh_task_cb_ex, &settings);
break;
case PBVH_BMESH:
- BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_bmesh_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_smooth_brush_bmesh_task_cb_ex, &settings);
break;
}
@@ -2884,10 +2857,10 @@ static void bmesh_topology_rake(
.nodes = nodes,
.strength = factor,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_topology_rake_bmesh_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_topology_rake_bmesh_task_cb_ex, &settings);
}
}
@@ -2941,9 +2914,9 @@ static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int tot
.nodes = nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_mask_brush_draw_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_mask_brush_draw_task_cb_ex, &settings);
}
static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
@@ -3028,9 +3001,9 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
.offset = offset,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings);
}
static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata,
@@ -3104,9 +3077,9 @@ static void do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
.offset = offset,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_draw_sharp_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_draw_sharp_brush_task_cb_ex, &settings);
}
/**
@@ -3220,9 +3193,9 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
.flippedbstrength = flippedbstrength,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings);
}
static void do_pinch_brush_task_cb_ex(void *__restrict userdata,
@@ -3282,9 +3255,9 @@ static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
.nodes = nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings);
}
static void do_grab_brush_task_cb_ex(void *__restrict userdata,
@@ -3354,9 +3327,9 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
.grab_delta = grab_delta,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings);
}
/* Regularized Kelvinlets: Sculpting Brushes based on Fundamental Solutions of Elasticity
@@ -3603,9 +3576,9 @@ static void do_elastic_deform_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, in
.grab_delta = grab_delta,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_elastic_deform_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_elastic_deform_brush_task_cb_ex, &settings);
}
static void do_pose_brush_task_cb_ex(void *__restrict userdata,
@@ -3696,14 +3669,14 @@ static void do_pose_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
.transform_trans_inv = transform_trans_inv,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_pose_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_pose_brush_task_cb_ex, &settings);
}
typedef struct PoseGrowFactorTLSData {
float pos_avg[3];
- int tot_pos_avg;
+ int pos_count;
} PoseGrowFactorTLSData;
static void pose_brush_grow_factor_task_cb_ex(void *__restrict userdata,
@@ -3732,7 +3705,7 @@ static void pose_brush_grow_factor_task_cb_ex(void *__restrict userdata,
data->pose_factor[vd.index] = max;
if (check_vertex_pivot_symmetry(vd.co, active_co, symm)) {
add_v3_v3(gftd->pos_avg, vd.co);
- gftd->tot_pos_avg++;
+ gftd->pos_count++;
}
}
}
@@ -3740,12 +3713,12 @@ static void pose_brush_grow_factor_task_cb_ex(void *__restrict userdata,
BKE_pbvh_vertex_iter_end;
}
-static void pose_brush_grow_factor_finalize(void *__restrict userdata, void *__restrict tls)
+static void pose_brush_grow_factor_reduce(void *__restrict tls_join, void *__restrict tls)
{
- SculptThreadedTaskData *data = userdata;
+ PoseGrowFactorTLSData *join = tls_join;
PoseGrowFactorTLSData *gftd = tls;
- add_v3_v3(data->tot_pos_avg, gftd->pos_avg);
- data->tot_pos_count += gftd->tot_pos_avg;
+ add_v3_v3(join->pos_avg, gftd->pos_avg);
+ join->pos_count += gftd->pos_count;
}
/* Grow the factor until its boundary is near to the offset pose origin */
@@ -3764,12 +3737,12 @@ static void sculpt_pose_grow_pose_factor(
.totnode = totnode,
.pose_factor = pose_factor,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
PoseGrowFactorTLSData gftd;
- gftd.tot_pos_avg = 0;
+ gftd.pos_count = 0;
zero_v3(gftd.pos_avg);
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- settings.func_finalize = pose_brush_grow_factor_finalize;
+ settings.func_reduce = pose_brush_grow_factor_reduce;
settings.userdata_chunk = &gftd;
settings.userdata_chunk_size = sizeof(PoseGrowFactorTLSData);
@@ -3777,15 +3750,13 @@ static void sculpt_pose_grow_pose_factor(
float prev_len = FLT_MAX;
data.prev_mask = MEM_mallocN(sculpt_vertex_count_get(ss) * sizeof(float), "prev mask");
while (grow_next_iteration) {
- zero_v3(data.tot_pos_avg);
- data.tot_pos_count = 0;
zero_v3(gftd.pos_avg);
- gftd.tot_pos_avg = 0;
+ gftd.pos_count = 0;
memcpy(data.prev_mask, pose_factor, sculpt_vertex_count_get(ss) * sizeof(float));
- BLI_task_parallel_range(0, totnode, &data, pose_brush_grow_factor_task_cb_ex, &settings);
- if (data.tot_pos_count != 0) {
- mul_v3_fl(data.tot_pos_avg, 1.0f / (float)data.tot_pos_count);
- float len = len_v3v3(data.tot_pos_avg, pose_origin);
+ BKE_pbvh_parallel_range(0, totnode, &data, pose_brush_grow_factor_task_cb_ex, &settings);
+ if (gftd.pos_count != 0) {
+ mul_v3_fl(gftd.pos_avg, 1.0f / (float)gftd.pos_count);
+ float len = len_v3v3(gftd.pos_avg, pose_origin);
if (len < prev_len) {
prev_len = len;
grow_next_iteration = true;
@@ -3954,9 +3925,9 @@ static void sculpt_pose_brush_init(
/* Smooth the pose brush factor for cleaner deformation */
for (int i = 0; i < 4; i++) {
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, pose_brush_init_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, pose_brush_init_task_cb_ex, &settings);
}
MEM_SAFE_FREE(nodes);
@@ -4024,9 +3995,9 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
.cono = cono,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings);
}
static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata,
@@ -4145,9 +4116,9 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
.grab_delta = grab_delta,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_snake_hook_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_snake_hook_brush_task_cb_ex, &settings);
}
static void do_thumb_brush_task_cb_ex(void *__restrict userdata,
@@ -4217,9 +4188,9 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
.cono = cono,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings);
}
static void do_rotate_brush_task_cb_ex(void *__restrict userdata,
@@ -4290,9 +4261,9 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
.angle = angle,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings);
}
static void do_layer_brush_task_cb_ex(void *__restrict userdata,
@@ -4387,9 +4358,9 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
};
BLI_mutex_init(&data.mutex);
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings);
BLI_mutex_end(&data.mutex);
}
@@ -4455,9 +4426,9 @@ static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
.nodes = nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings);
}
static void calc_sculpt_plane(
@@ -4664,9 +4635,9 @@ static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
.area_co = area_co,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings);
}
static void do_clay_brush_task_cb_ex(void *__restrict userdata,
@@ -4762,9 +4733,9 @@ static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
.area_co = area_co,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings);
}
static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata,
@@ -4892,9 +4863,9 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
.mat = mat,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_clay_strips_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_clay_strips_brush_task_cb_ex, &settings);
}
static void do_fill_brush_task_cb_ex(void *__restrict userdata,
@@ -4985,9 +4956,9 @@ static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
.area_co = area_co,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings);
}
static void do_scrape_brush_task_cb_ex(void *__restrict userdata,
@@ -5077,9 +5048,9 @@ static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
.area_co = area_co,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings);
}
static void do_gravity_task_cb_ex(void *__restrict userdata,
@@ -5146,9 +5117,9 @@ static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, fl
.offset = offset,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings);
}
void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3])
@@ -5315,9 +5286,9 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
.nodes = nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
if (sculpt_brush_needs_normal(ss, brush)) {
update_sculpt_normal(sd, ob, nodes, totnode);
@@ -5537,9 +5508,9 @@ static void sculpt_combine_proxies(Sculpt *sd, Object *ob)
.nodes = nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings);
}
MEM_SAFE_FREE(nodes);
@@ -5627,9 +5598,9 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_use
.vertCos = vertCos,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, sculpt_flush_stroke_deform_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, sculpt_flush_stroke_deform_task_cb, &settings);
if (vertCos) {
sculpt_vertcos_to_key(ob, ss->kb, vertCos);
@@ -8219,10 +8190,10 @@ static void sculpt_filter_cache_init(Object *ob, Sculpt *sd)
.nodes = ss->filter_cache->nodes,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
- BLI_task_parallel_range(
+ BKE_pbvh_parallel_range(
0, ss->filter_cache->totnode, &data, filter_cache_init_task_cb, &settings);
}
@@ -8418,10 +8389,10 @@ static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *
.filter_strength = filter_strength,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
- BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, mesh_filter_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, ss->filter_cache->totnode, &data, mesh_filter_task_cb, &settings);
if (ss->modifiers_active || ss->kb) {
sculpt_flush_stroke_deform(sd, ob, true);
@@ -8695,9 +8666,9 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
.prev_mask = prev_mask,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(0, totnode, &data, mask_filter_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, mask_filter_task_cb, &settings);
if (ELEM(filter_type, MASK_FILTER_GROW, MASK_FILTER_SHRINK)) {
MEM_freeN(prev_mask);
@@ -8806,13 +8777,12 @@ static void dirty_mask_compute_range_task_cb(void *__restrict userdata,
BKE_pbvh_vertex_iter_end;
}
-static void dirty_mask_compute_range_finalize(void *__restrict userdata, void *__restrict tls)
+static void dirty_mask_compute_range_reduce(void *__restrict tls_join, void *__restrict tls)
{
- SculptThreadedTaskData *data = userdata;
+ DirtyMaskRangeData *join = tls_join;
DirtyMaskRangeData *range = tls;
-
- data->dirty_mask_min = min_ff(range->min, data->dirty_mask_min);
- data->dirty_mask_max = max_ff(range->max, data->dirty_mask_max);
+ join->min = min_ff(range->min, join->min);
+ join->max = max_ff(range->max, join->max);
}
static void dirty_mask_apply_task_cb(void *__restrict userdata,
@@ -8883,8 +8853,6 @@ static int sculpt_dirty_mask_exec(bContext *C, wmOperator *op)
.sd = sd,
.ob = ob,
.nodes = nodes,
- .dirty_mask_min = FLT_MAX,
- .dirty_mask_max = -FLT_MAX,
.dirty_mask_dirty_only = RNA_boolean_get(op->ptr, "dirty_only"),
};
DirtyMaskRangeData range = {
@@ -8892,15 +8860,17 @@ static int sculpt_dirty_mask_exec(bContext *C, wmOperator *op)
.max = -FLT_MAX,
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- settings.func_finalize = dirty_mask_compute_range_finalize;
+ settings.func_reduce = dirty_mask_compute_range_reduce;
settings.userdata_chunk = &range;
settings.userdata_chunk_size = sizeof(DirtyMaskRangeData);
- BLI_task_parallel_range(0, totnode, &data, dirty_mask_compute_range_task_cb, &settings);
- BLI_task_parallel_range(0, totnode, &data, dirty_mask_apply_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, totnode, &data, dirty_mask_compute_range_task_cb, &settings);
+ data.dirty_mask_min = range.min;
+ data.dirty_mask_max = range.max;
+ BKE_pbvh_parallel_range(0, totnode, &data, dirty_mask_apply_task_cb, &settings);
MEM_SAFE_FREE(nodes);
@@ -9059,10 +9029,10 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent *
int smooth_iterations = RNA_int_get(op->ptr, "smooth_iterations");
BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false);
for (int i = 0; i < smooth_iterations; i++) {
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
- BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, mask_filter_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, ss->filter_cache->totnode, &data, mask_filter_task_cb, &settings);
}
/* Pivot position */
@@ -9128,10 +9098,10 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent *
.mask_expand_invert_mask = RNA_boolean_get(op->ptr, "invert"),
.mask_expand_keep_prev_mask = RNA_boolean_get(op->ptr, "keep_previous_mask"),
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
- BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings);
ss->filter_cache->mask_update_current_it = mask_expand_update_it;
}
@@ -9266,10 +9236,10 @@ static int sculpt_mask_expand_invoke(bContext *C, wmOperator *op, const wmEvent
.mask_expand_invert_mask = RNA_boolean_get(op->ptr, "invert"),
.mask_expand_keep_prev_mask = RNA_boolean_get(op->ptr, "keep_previous_mask"),
};
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
- BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings);
+ BKE_pbvh_parallel_range(0, ss->filter_cache->totnode, &data, sculpt_expand_task_cb, &settings);
const char *status_str = TIP_(
"Move the mouse to expand the mask from the active vertex. LBM: confirm mask, ESC/RMB: "
@@ -9583,10 +9553,10 @@ void ED_sculpt_update_modal_transform(struct bContext *C)
mul_m4_m4m4(data.transform_mats[i], pivot_mat, data.transform_mats[i]);
}
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(
&settings, (sd->flags & SCULPT_USE_OPENMP), ss->filter_cache->totnode);
- BLI_task_parallel_range(
+ BKE_pbvh_parallel_range(
0, ss->filter_cache->totnode, &data, sculpt_transform_task_cb, &settings);
if (ss->modifiers_active || ss->kb) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index cbc13e5f0d2..be79ebbd6e5 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -195,10 +195,8 @@ typedef struct SculptThreadedTaskData {
int filter_type;
float filter_strength;
- /* 0=towards view, 1=flipped */
- float (*area_cos)[3];
- float (*area_nos)[3];
- int *count;
+ bool use_area_cos;
+ bool use_area_nos;
bool any_vertex_sampled;
float *prev_mask;
@@ -208,13 +206,8 @@ typedef struct SculptThreadedTaskData {
float *pose_factor;
float (*transform_rot)[4], (*transform_trans)[4], (*transform_trans_inv)[4];
- float tot_pos_avg[3];
- int tot_pos_count;
-
float max_distance_squared;
float nearest_vertex_search_co[3];
- int nearest_vertex_index;
- float nearest_vertex_distance_squared;
int mask_expand_update_it;
bool mask_expand_invert_mask;
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 74e5444bc3e..3e45e82ee66 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -343,9 +343,9 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C,
BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
- TaskParallelSettings settings;
+ PBVHParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
- BLI_task_parallel_range(
+ BKE_pbvh_parallel_range(
0, totnode, nodes, sculpt_undo_bmesh_restore_generic_task_cb, &settings);
if (nodes) {

Event Timeline

Brecht Van Lommel (brecht) changed the title of this paste from untitled to Sculpt: experiment using TBB instead of BLI_task.