diff options
author | Hans Goudey <h.goudey@me.com> | 2021-06-21 05:57:47 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-06-21 05:57:47 +0300 |
commit | a1c3e451002b79b5822da78e9562f12a6f1b0cc6 (patch) | |
tree | 8422b90665cc2dca32844b29e2b0341475802a60 /source | |
parent | b45cee1aafdd04221e7991a0be155f0101345897 (diff) |
Geometry Nodes: Multithread curve resample node
Optimize the node for the case of many splines. In a test file with
14000 splines, the node is 3x faster (72ms to 24ms) on an 8 core CPU.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc index e879ec624c0..bf122bab613 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc @@ -138,19 +138,28 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count) static std::unique_ptr<CurveEval> resample_curve(const CurveEval &input_curve, const SampleModeParam &mode_param) { - std::unique_ptr<CurveEval> output_curve = std::make_unique<CurveEval>(); + Span<SplinePtr> input_splines = input_curve.splines(); - for (const SplinePtr &spline : input_curve.splines()) { - if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_COUNT) { - BLI_assert(mode_param.count); - output_curve->add_spline(resample_spline(*spline, *mode_param.count)); - } - else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_LENGTH) { - BLI_assert(mode_param.length); - const float length = spline->length(); - const int count = std::max(int(length / *mode_param.length), 1); - output_curve->add_spline(resample_spline(*spline, count)); - } + std::unique_ptr<CurveEval> output_curve = std::make_unique<CurveEval>(); + output_curve->resize(input_splines.size()); + MutableSpan<SplinePtr> output_splines = output_curve->splines(); + + if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_COUNT) { + threading::parallel_for(input_splines.index_range(), 128, [&](IndexRange range) { + for (const int i : range) { + BLI_assert(mode_param.count); + output_splines[i] = resample_spline(*input_splines[i], *mode_param.count); + } + }); + } + else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_LENGTH) { + threading::parallel_for(input_splines.index_range(), 128, [&](IndexRange range) { + for (const int i : range) { + const float length = input_splines[i]->length(); + const int count = std::max(int(length / *mode_param.length), 1); + output_splines[i] = resample_spline(*input_splines[i], count); + } + }); } output_curve->attributes = input_curve.attributes; |