diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 06789e34ad4..8753d0ee6af 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -15,6 +15,9 @@ #include "BLI_math_rotation.hh" #include "BLI_task.hh" + +#include "BLI_packing_task.hh" + #include "DNA_curves_types.h" #include "BKE_attribute_math.hh" @@ -1466,7 +1469,25 @@ static void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves, MutableSpan r_values) { attribute_math::DefaultMixer mixer(r_values); - + + Array curves_points_num(curves.curves_num()); + + for (const int index : curves.curves_range()){ + curves_points_num[index] = curves.points_num_for_curve(index); + } + + packing_task::pack(curves_points_num, 1000, [&](const Span indices){ + Span mixer_mask; + for (const int i_curve : indices){ + for (const int i_point : curves.points_for_curve(i_curve)) { + mixer.mix_in(i_curve, old_values[i_point]); + } + const int64_t fff = i_curve; + mixer_mask = Span(&fff, 1); + mixer.finalize(mixer_mask); + } + }); +/* threading::parallel_for(curves.curves_range(), 128, [&](const IndexRange range) { for (const int i_curve : range) { for (const int i_point : curves.points_for_curve(i_curve)) { @@ -1474,7 +1495,7 @@ static void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves, } } mixer.finalize(range); - }); + });*/ } /** diff --git a/source/blender/blenlib/BLI_packing_task.hh b/source/blender/blenlib/BLI_packing_task.hh new file mode 100644 index 00000000000..51a7ae53e7f --- /dev/null +++ b/source/blender/blenlib/BLI_packing_task.hh @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +/** \file + */ + +#include "BLI_array.hh" +#include "BLI_vector.hh" +#include "BLI_span.hh" +#include "BLI_sort.hh" +#include "BLI_index_range.hh" +#include "BLI_task.hh" + +namespace blender::packing_task{ + +template +static void pack(const Span weight, const int weight_grain, Function func){ + + Array indices = weight.index_range().as_span(); + parallel_sort(indices.begin(), indices.end(), [&](const int a, const int b){ + return weight[a] < weight[b]; + }); + + int accumulate = 0; + int start = 0; + int end = 0; + + Vector> calls; + calls.reserve(weight.size()); + + auto call = [&](){ + IndexRange range = IndexRange(start, end - start); + Span index_range = indices.as_span().slice(range); + calls.append(index_range); + accumulate = 0; + }; + for (const int index : indices.index_range()){ + const int range_index = index+1; + accumulate += weight[index]; + if (accumulate >= weight_grain){ + start = end; + end = range_index; + call(); + } + } + if (accumulate != 0) { + start = end; + end = weight.size(); + call(); + } + + threading::parallel_for_each(calls, func); +} + +} // namespace blender::packing_task diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 470ffebcad4..b6dbfdcfbf9 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -282,6 +282,7 @@ set(SRC BLI_multi_value_map.hh BLI_noise.h BLI_noise.hh + BLI_packing_task.hh BLI_parameter_pack_utils.hh BLI_path_util.h BLI_polyfill_2d.h