diff --git a/source/blender/blenkernel/intern/multires_reshape_smooth.cc b/source/blender/blenkernel/intern/multires_reshape_smooth.cc index 3547a76b780..cfc2ec9c22e 100644 --- a/source/blender/blenkernel/intern/multires_reshape_smooth.cc +++ b/source/blender/blenkernel/intern/multires_reshape_smooth.cc @@ -14,7 +14,7 @@ #include "BLI_math_matrix.h" #include "BLI_math_vector.h" -#include "BLI_task.h" +#include "BLI_task.hh" #include "BLI_utildefines.h" #include "BKE_customdata.hh" @@ -315,16 +315,6 @@ using ForeachTopLevelGridCoordCallback = const GridCoord *grid_coord, void *userdata_v); -struct ForeachHighLevelCoordTaskData { - const MultiresReshapeSmoothContext *reshape_smooth_context; - - int inner_grid_size; - float inner_grid_size_1_inv; - - ForeachTopLevelGridCoordCallback callback; - void *callback_userdata_v; -}; - /* Find grid index which given face was created for. */ static int get_face_grid_index(const MultiresReshapeSmoothContext *reshape_smooth_context, const Face *face) @@ -405,59 +395,42 @@ static void interpolate_grid_coord(GridCoord *result, result->v = lerp(u, v03, v12); } -static void foreach_toplevel_grid_coord_task(void *__restrict userdata_v, - const int face_index, - const TaskParallelTLS *__restrict /*tls*/) -{ - ForeachHighLevelCoordTaskData *data = static_cast(userdata_v); - - const MultiresReshapeSmoothContext *reshape_smooth_context = data->reshape_smooth_context; - const int inner_grid_size = data->inner_grid_size; - const float inner_grid_size_1_inv = data->inner_grid_size_1_inv; - - const Face *face = &reshape_smooth_context->geometry.faces[face_index]; - const GridCoord *face_grid_coords[4]; - grid_coords_from_face_verts(reshape_smooth_context, face, face_grid_coords); - - for (int y = 0; y < inner_grid_size; ++y) { - const float ptex_v = float(y) * inner_grid_size_1_inv; - for (int x = 0; x < inner_grid_size; ++x) { - const float ptex_u = float(x) * inner_grid_size_1_inv; - - PTexCoord ptex_coord; - ptex_coord.ptex_face_index = face_index; - ptex_coord.u = ptex_u; - ptex_coord.v = ptex_v; - - GridCoord grid_coord; - interpolate_grid_coord(&grid_coord, face_grid_coords, ptex_u, ptex_v); - - data->callback(reshape_smooth_context, &ptex_coord, &grid_coord, data->callback_userdata_v); - } - } -} - static void foreach_toplevel_grid_coord(const MultiresReshapeSmoothContext *reshape_smooth_context, ForeachTopLevelGridCoordCallback callback, void *callback_userdata_v) { + using namespace blender; const MultiresReshapeContext *reshape_context = reshape_smooth_context->reshape_context; const int level_difference = (reshape_context->top.level - reshape_context->reshape.level); - ForeachHighLevelCoordTaskData data; - data.reshape_smooth_context = reshape_smooth_context; - data.inner_grid_size = (1 << level_difference) + 1; - data.inner_grid_size_1_inv = 1.0f / float(data.inner_grid_size - 1); - data.callback = callback; - data.callback_userdata_v = callback_userdata_v; - - TaskParallelSettings parallel_range_settings; - BLI_parallel_range_settings_defaults(¶llel_range_settings); - parallel_range_settings.min_iter_per_thread = 1; + const int inner_grid_size = (1 << level_difference) + 1; + const float inner_grid_size_1_inv = 1.0f / float(inner_grid_size - 1); const int num_faces = reshape_smooth_context->geometry.num_faces; - BLI_task_parallel_range( - 0, num_faces, &data, foreach_toplevel_grid_coord_task, ¶llel_range_settings); + threading::parallel_for(IndexRange(num_faces), 1, [&](const IndexRange range) { + for (const int face_index : range) { + const Face *face = &reshape_smooth_context->geometry.faces[face_index]; + const GridCoord *face_grid_coords[4]; + grid_coords_from_face_verts(reshape_smooth_context, face, face_grid_coords); + + for (int y = 0; y < inner_grid_size; ++y) { + const float ptex_v = float(y) * inner_grid_size_1_inv; + for (int x = 0; x < inner_grid_size; ++x) { + const float ptex_u = float(x) * inner_grid_size_1_inv; + + PTexCoord ptex_coord; + ptex_coord.ptex_face_index = face_index; + ptex_coord.u = ptex_u; + ptex_coord.v = ptex_v; + + GridCoord grid_coord; + interpolate_grid_coord(&grid_coord, face_grid_coords, ptex_u, ptex_v); + + callback(reshape_smooth_context, &ptex_coord, &grid_coord, callback_userdata_v); + } + } + } + }); } /** \} */