[Bf-blender-cvs] [5a98e382755] master: Curves: Avoid duplicating evaluated positions with all poly curves

Hans Goudey noreply at git.blender.org
Thu Apr 14 00:13:40 CEST 2022


Commit: 5a98e3827559c9363c2e942daf05c09a8f0f7863
Author: Hans Goudey
Date:   Wed Apr 13 17:13:30 2022 -0500
Branches: master
https://developer.blender.org/rB5a98e3827559c9363c2e942daf05c09a8f0f7863

Curves: Avoid duplicating evaluated positions with all poly curves

If all of the curves are poly curves, the evaluated positions are the
same as the original positions. In this case just reuse the original
positions span as the evaluated positions.

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

M	source/blender/blenkernel/BKE_curves.hh
M	source/blender/blenkernel/intern/curves_geometry.cc

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

diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index 9dafe2095e7..06971a2243a 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -76,6 +76,11 @@ class CurvesGeometryRuntime {
   mutable Vector<float3> evaluated_position_cache;
   mutable std::mutex position_cache_mutex;
   mutable bool position_cache_dirty = true;
+  /**
+   * The evaluated positions result, using a separate span in case all curves are poly curves,
+   * in which case a separate array of evaluated positions is unnecessary.
+   */
+  mutable Span<float3> evaluated_positions_span;
 
   /**
    * Cache of lengths along each evaluated curve for for each evaluated point. If a curve is
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 5c89dfd4df5..bdd8b3fc3d0 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -577,18 +577,25 @@ void CurvesGeometry::ensure_nurbs_basis_cache() const
 Span<float3> CurvesGeometry::evaluated_positions() const
 {
   if (!this->runtime->position_cache_dirty) {
-    return this->runtime->evaluated_position_cache;
+    return this->runtime->evaluated_positions_span;
   }
 
   /* A double checked lock. */
   std::scoped_lock lock{this->runtime->position_cache_mutex};
   if (!this->runtime->position_cache_dirty) {
-    return this->runtime->evaluated_position_cache;
+    return this->runtime->evaluated_positions_span;
   }
 
   threading::isolate_task([&]() {
+    if (this->is_single_type(CURVE_TYPE_POLY)) {
+      this->runtime->evaluated_positions_span = this->positions();
+      this->runtime->evaluated_position_cache.clear_and_make_inline();
+      return;
+    }
+
     this->runtime->evaluated_position_cache.resize(this->evaluated_points_num());
     MutableSpan<float3> evaluated_positions = this->runtime->evaluated_position_cache;
+    this->runtime->evaluated_positions_span = evaluated_positions;
 
     VArray<int8_t> types = this->curve_types();
     VArray<bool> cyclic = this->cyclic();
@@ -645,7 +652,7 @@ Span<float3> CurvesGeometry::evaluated_positions() const
   });
 
   this->runtime->position_cache_dirty = false;
-  return this->runtime->evaluated_position_cache;
+  return this->runtime->evaluated_positions_span;
 }
 
 Span<float3> CurvesGeometry::evaluated_tangents() const



More information about the Bf-blender-cvs mailing list