[Bf-blender-cvs] [a1c3e451002] master: Geometry Nodes: Multithread curve resample node

Hans Goudey noreply at git.blender.org
Mon Jun 21 04:57:55 CEST 2021


Commit: a1c3e451002b79b5822da78e9562f12a6f1b0cc6
Author: Hans Goudey
Date:   Sun Jun 20 21:57:47 2021 -0500
Branches: master
https://developer.blender.org/rBa1c3e451002b79b5822da78e9562f12a6f1b0cc6

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.

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc

===================================================================

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;



More information about the Bf-blender-cvs mailing list