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.
This commit is contained in:
2021-06-20 21:57:47 -05:00
parent b45cee1aaf
commit a1c3e45100

View File

@@ -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, static std::unique_ptr<CurveEval> resample_curve(const CurveEval &input_curve,
const SampleModeParam &mode_param) 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()) { std::unique_ptr<CurveEval> output_curve = std::make_unique<CurveEval>();
if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_COUNT) { output_curve->resize(input_splines.size());
BLI_assert(mode_param.count); MutableSpan<SplinePtr> output_splines = output_curve->splines();
output_curve->add_spline(resample_spline(*spline, *mode_param.count));
} if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_COUNT) {
else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_LENGTH) { threading::parallel_for(input_splines.index_range(), 128, [&](IndexRange range) {
BLI_assert(mode_param.length); for (const int i : range) {
const float length = spline->length(); BLI_assert(mode_param.count);
const int count = std::max(int(length / *mode_param.length), 1); output_splines[i] = resample_spline(*input_splines[i], *mode_param.count);
output_curve->add_spline(resample_spline(*spline, 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; output_curve->attributes = input_curve.attributes;