From 03b57d39731a3902ac99d2e8e23aa309ac21c131 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 28 Jan 2022 17:47:14 -0600 Subject: Fix T94476: Threading/performance issue with curve to points node For every spline, *all* of the normals and tangents in the output were normalized. The node is multithreaded, so sometimes a thread overwrote the normalized result from another thread. Fixing this problem also made the node orders of magnitude faster when there are many splines. --- .../nodes/geometry/nodes/node_geo_curve_to_points.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index 19efd4b7508..c0c1244f031 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -282,18 +282,20 @@ static void copy_uniform_sample_point_attributes(const Span splines, } if (!data.tangents.is_empty()) { - spline.sample_with_index_factors( - spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); - for (float3 &tangent : data.tangents) { - tangent = math::normalize(tangent); + Span src_tangents = spline.evaluated_tangents(); + MutableSpan sampled_tangents = data.tangents.slice(offset, size); + spline.sample_with_index_factors(src_tangents, uniform_samples, sampled_tangents); + for (float3 &vector : sampled_tangents) { + vector = math::normalize(vector); } } if (!data.normals.is_empty()) { - spline.sample_with_index_factors( - spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); - for (float3 &normals : data.normals) { - normals = math::normalize(normals); + Span src_normals = spline.evaluated_normals(); + MutableSpan sampled_normals = data.normals.slice(offset, size); + spline.sample_with_index_factors(src_normals, uniform_samples, sampled_normals); + for (float3 &vector : sampled_normals) { + vector = math::normalize(vector); } } } -- cgit v1.2.3