[Bf-blender-cvs] [f55023c82a1] temp-varray-get-set-multiple: progress

Jacques Lucke noreply at git.blender.org
Sun Sep 26 15:09:35 CEST 2021


Commit: f55023c82a12420ea172c94f1b77ed181cbb544e
Author: Jacques Lucke
Date:   Sun Sep 26 13:23:09 2021 +0200
Branches: temp-varray-get-set-multiple
https://developer.blender.org/rBf55023c82a12420ea172c94f1b77ed181cbb544e

progress

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

M	source/blender/blenkernel/intern/geometry_component_curve.cc
M	source/blender/blenlib/BLI_virtual_array.hh
M	source/blender/functions/FN_generic_virtual_array.hh
M	source/blender/functions/intern/generic_virtual_array.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 0cd9448626b..a7159ebe090 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -293,6 +293,49 @@ template<typename T> class VArray_For_SplineToPoint final : public VArray<T> {
     const PointIndices indices = lookup_point_indices(offsets_, index);
     return original_data_[indices.spline_index];
   }
+
+  void get_multiple_impl(VMutableArray<T> &dst_varray, const IndexMask mask) const final
+  {
+    const int total_size = offsets_.last();
+    if (mask.is_range() && mask.as_range() == IndexRange(total_size)) {
+      for (const int spline_index : original_data_.index_range()) {
+        const int offset = offsets_[spline_index];
+        const int next_offset = offsets_[spline_index + 1];
+        dst_varray.set_multiple(original_data_[spline_index],
+                                IndexRange{offset, next_offset - offset});
+      }
+    }
+    else {
+      int spline_index = 0;
+      for (const int dst_index : mask) {
+        while (offsets_[spline_index] < dst_index) {
+          spline_index++;
+        }
+        dst_varray.set(dst_index, original_data_[spline_index]);
+      }
+    }
+  }
+
+  void get_multiple_to_uninitialized_impl(T *dst, const IndexMask mask) const final
+  {
+    const int total_size = offsets_.last();
+    if (mask.is_range() && mask.as_range() == IndexRange(total_size)) {
+      for (const int spline_index : original_data_.index_range()) {
+        const int offset = offsets_[spline_index];
+        const int next_offset = offsets_[spline_index + 1];
+        uninitialized_fill_n(dst + offset, next_offset - offset, original_data_[spline_index]);
+      }
+    }
+    else {
+      int spline_index = 0;
+      for (const int dst_index : mask) {
+        while (offsets_[spline_index] < dst_index) {
+          spline_index++;
+        }
+        new (dst + dst_index) T(original_data_[spline_index]);
+      }
+    }
+  }
 };
 
 static GVArrayPtr adapt_curve_domain_spline_to_point(const CurveEval &curve, GVArrayPtr varray)
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index dc487970908..09741c0a42d 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -46,6 +46,7 @@ namespace blender {
 template<typename T> class VMutableArray;
 template<typename T> class VArray_For_Span;
 template<typename T> class VMutableArray_For_MutableSpan;
+template<typename T> class VArray_For_Single;
 
 /* An immutable virtual array. */
 template<typename T> class VArray {
@@ -251,6 +252,11 @@ template<typename T> class VMutableArray : public VArray<T> {
     this->set_multiple(VArray_For_Span<T>{src});
   }
 
+  void set_multiple(const T &value, const IndexMask mask)
+  {
+    this->set_multiple(VArray_For_Single<T>{value, this->size_}, mask);
+  }
+
   void set_multiple(const VArray<T> &src_varray, const IndexMask mask)
   {
     BLI_assert(mask.min_array_size() <= this->size_);
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index 337c9321ef0..d08abab3225 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -262,6 +262,10 @@ class GVArray_For_GSpan : public GVArray {
   void get_impl(const int64_t index, void *r_value) const override;
   void get_to_uninitialized_impl(const int64_t index, void *r_value) const override;
 
+  void get_multiple_impl(GVMutableArray &dst_varray, IndexMask mask) const override;
+  void get_multiple_to_uninitialized_impl(void *dst, IndexMask mask) const override;
+  bool can_get_multiple_efficiently_impl(const GVMutableArray &dst_varray) const override;
+
   bool is_span_impl() const override;
   GSpan get_internal_span_impl() const override;
 };
@@ -301,10 +305,17 @@ class GVMutableArray_For_GMutableSpan : public GVMutableArray {
   void get_impl(const int64_t index, void *r_value) const override;
   void get_to_uninitialized_impl(const int64_t index, void *r_value) const override;
 
+  void get_multiple_impl(GVMutableArray &dst_varray, IndexMask mask) const override;
+  void get_multiple_to_uninitialized_impl(void *dst, IndexMask mask) const override;
+  bool can_get_multiple_efficiently_impl(const GVMutableArray &dst_varray) const override;
+
   void set_by_copy_impl(const int64_t index, const void *value) override;
   void set_by_move_impl(const int64_t index, void *value) override;
   void set_by_relocate_impl(const int64_t index, void *value) override;
 
+  void set_multiple_by_copy_impl(const GVArray &src_varray, IndexMask mask) override;
+  bool can_set_multiple_efficiently_impl(const GVArray &src_varray) const override;
+
   bool is_span_impl() const override;
   GSpan get_internal_span_impl() const override;
 };
@@ -328,6 +339,10 @@ class GVArray_For_SingleValueRef : public GVArray {
   void get_impl(const int64_t index, void *r_value) const override;
   void get_to_uninitialized_impl(const int64_t index, void *r_value) const override;
 
+  void get_multiple_impl(GVMutableArray &dst_varray, IndexMask mask) const override;
+  void get_multiple_to_uninitialized_impl(void *dst, IndexMask mask) const override;
+  bool can_get_multiple_efficiently_impl(const GVMutableArray &dst_varray) const override;
+
   bool is_span_impl() const override;
   GSpan get_internal_span_impl() const override;
 
@@ -368,6 +383,25 @@ template<typename T> class GVArray_For_VArray : public GVArray {
     new (r_value) T(varray_->get(index));
   }
 
+  void get_multiple_impl(GVMutableArray &dst_varray, IndexMask mask) const override
+  {
+    /* `const_cast` is ok because the data is not actually modified. */
+    GVMutableArray_Typed<T> dst_typed{const_cast<GVMutableArray &>(dst_varray)};
+    varray_->get_multiple(*dst_typed, mask);
+  }
+
+  void get_multiple_to_uninitialized_impl(void *dst, IndexMask mask) const override
+  {
+    varray_->get_multiple_to_uninitialized((T *)dst, mask);
+  }
+
+  bool can_get_multiple_efficiently_impl(const GVMutableArray &dst_varray) const override
+  {
+    /* `const_cast` is ok because the data is not actually modified. */
+    GVMutableArray_Typed<T> dst_typed{const_cast<GVMutableArray &>(dst_varray)};
+    return varray_->_can_get_multiple_efficiently(*dst_typed);
+  }
+
   bool is_span_impl() const override
   {
     return varray_->is_span();
@@ -394,6 +428,8 @@ template<typename T> class GVArray_For_VArray : public GVArray {
   }
 };
 
+template<typename T> class GVMutableArray_For_VMutableArray;
+
 /* Used to convert any generic virtual array into a typed one. */
 template<typename T> class VArray_For_GVArray : public VArray<T> {
  protected:
@@ -417,6 +453,23 @@ template<typename T> class VArray_For_GVArray : public VArray<T> {
     return value;
   }
 
+  void get_multiple_impl(VMutableArray<T> &dst_varray, IndexMask mask) const override
+  {
+    GVMutableArray_For_VMutableArray<T> generic_dst{dst_varray};
+    varray_->get_multiple(generic_dst, mask);
+  }
+
+  void get_multiple_to_uninitialized_impl(T *dst, IndexMask mask) const override
+  {
+    varray_->get_multiple_to_uninitialized(dst, mask);
+  }
+
+  bool can_get_multiple_efficiently_impl(const VMutableArray<T> &dst_varray) const override
+  {
+    GVMutableArray_For_VMutableArray<T> generic_dst{const_cast<VMutableArray<T> &>(dst_varray)};
+    return varray_->_can_get_multiple_efficiently(generic_dst);
+  }
+
   bool is_span_impl() const override
   {
     return varray_->is_span();
@@ -464,11 +517,40 @@ template<typename T> class VMutableArray_For_GVMutableArray : public VMutableArr
     return value;
   }
 
+  void get_multiple_impl(VMutableArray<T> &dst_varray, IndexMask mask) const override
+  {
+    GVMutableArray_For_VMutableArray<T> generic_dst{dst_varray};
+    varray_->get_multiple(generic_dst, mask);
+  }
+
+  void get_multiple_to_uninitialized_impl(T *dst, IndexMask mask) const override
+  {
+    varray_->get_multiple_to_uninitialized(dst, mask);
+  }
+
+  bool can_get_multiple_efficiently_impl(const VMutableArray<T> &dst_varray) const override
+  {
+    GVMutableArray_For_VMutableArray<T> generic_dst{const_cast<VMutableArray<T> &>(dst_varray)};
+    return varray_->_can_get_multiple_efficiently(generic_dst);
+  }
+
   void set_impl(const int64_t index, T value) override
   {
     varray_->set_by_relocate(index, &value);
   }
 
+  void set_multiple_impl(const VArray<T> &src_varray, IndexMask mask) override
+  {
+    GVArray_For_VArray<T> generic_src{src_varray};
+    varray_->set_multiple_by_copy(generic_src, mask);
+  }
+
+  bool can_set_multiple_efficiently_impl(const VArray<T> &src_varray) const override
+  {
+    GVArray_For_VArray<T> generic_src{src_varray};
+    return varray_->_can_set_multiple_efficiently(generic_src);
+  }
+
   bool is_span_impl() const override
   {
     return varray_->is_span();
@@ -518,6 +600,25 @@ template<typename T> class GVMutableArray_For_VMutableArray : public GVMutableAr
     new (r_value) T(varray_->get(index));
   }
 
+  void get_multiple_impl(GVMutableArray &dst_varray, IndexMask mask) const override
+  {
+    /* `const_cast` is ok because the data is not actually modified. */
+    GVMutableArray_Typed<T> dst_typed{const_cast<GVMutableArray &>(dst_varray)};
+    varray_->get_multiple(*dst_typed, mask);
+  }
+
+  void get_multiple_to_uninitialized_impl(void *dst, IndexMask mask) const override
+  {
+    varray_->get_multiple_to_uninitialized((T *)dst, mask);
+  }
+
+  bool can_get_multiple_efficiently_impl(const GVMutableArray &dst_varray) const override
+  {
+    /* `const_cast` is ok because the data is not actually modified. */
+    GVMutableArray_Typed<T> dst_typed{const_cast<GVMutableArray &>(dst_varray)};
+    return varray_->_can_get_multiple_efficiently(*dst_typed);
+  }
+
   bool is_span_impl() const override
   {
     return varray_->is_span();
@@ -558,6 +659,18 @@ template<typename T> class GVMutableArray_For_VMutableArray : public GVMutableAr
     varray_->set(index, std::move

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list