[Bf-blender-cvs] [8fdc78678a4] temp-varray-get-set-multiple: progress
Jacques Lucke
noreply at git.blender.org
Sun Sep 26 15:09:33 CEST 2021
Commit: 8fdc78678a445433b0c40eaad0ea11a0984503c6
Author: Jacques Lucke
Date: Sat Sep 25 15:10:42 2021 +0200
Branches: temp-varray-get-set-multiple
https://developer.blender.org/rB8fdc78678a445433b0c40eaad0ea11a0984503c6
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 7d0537178ef..eac7818ab33 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -647,15 +647,6 @@ template<typename T> class VMutableArray_For_SplinePoints final : public VMutabl
data_[indices.spline_index][indices.point_index] = value;
}
- void set_all_impl(Span<T> src) final
- {
- for (const int spline_index : data_.index_range()) {
- const int offset = offsets_[spline_index];
- const int next_offsets = offsets_[spline_index + 1];
- data_[spline_index].copy_from(src.slice(offset, next_offsets - offset));
- }
- }
-
void materialize_impl(const IndexMask mask, MutableSpan<T> r_span) const final
{
point_attribute_materialize({(Span<T> *)data_.data(), data_.size()}, offsets_, mask, r_span);
@@ -722,29 +713,6 @@ class VMutableArray_For_SplinePosition final : public VMutableArray<float3> {
}
}
- void set_all_impl(Span<float3> src) final
- {
- for (const int spline_index : splines_.index_range()) {
- Spline &spline = *splines_[spline_index];
- const int offset = offsets_[spline_index];
- const int next_offset = offsets_[spline_index + 1];
- if (BezierSpline *bezier_spline = dynamic_cast<BezierSpline *>(&spline)) {
- MutableSpan<float3> positions = bezier_spline->positions();
- MutableSpan<float3> handle_positions_left = bezier_spline->handle_positions_left();
- MutableSpan<float3> handle_positions_right = bezier_spline->handle_positions_right();
- for (const int i : IndexRange(next_offset - offset)) {
- const float3 delta = src[offset + i] - positions[i];
- handle_positions_left[i] += delta;
- handle_positions_right[i] += delta;
- positions[i] = src[offset + i];
- }
- }
- else {
- spline.positions().copy_from(src.slice(offset, next_offset - offset));
- }
- }
- }
-
/** Utility so we can pass positions to the materialize functions above. */
Array<Span<float3>> get_position_spans() const
{
@@ -1115,10 +1083,9 @@ class DynamicPointAttributeProvider final : public DynamicAttributesProvider {
const int total_size = curve->control_point_offsets().last();
GVArrayPtr source_varray = varray_from_initializer(initializer, data_type, total_size);
- /* TODO: When we can call a variant of #set_all with a virtual array argument,
+ /* TODO: When we can call a variant of #set_multiple_by_copy with a virtual array argument,
* this theoretically unnecessary materialize step could be removed. */
- GVArray_GSpan source_varray_span{*source_varray};
- write_attribute.varray->set_all(source_varray_span.data());
+ write_attribute.varray->set_multiple_by_copy(*source_varray);
if (initializer.type == AttributeInit::Type::MoveArray) {
MEM_freeN(static_cast<const AttributeInitMove &>(initializer).data);
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index 3beb75ff1c1..3b4b7df42d4 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -44,6 +44,7 @@
namespace blender {
template<typename T> class VMutableArray;
+template<typename T> class VArray_For_Span;
/* An immutable virtual array. */
template<typename T> class VArray {
@@ -268,6 +269,11 @@ template<typename T> class VMutableArray : public VArray<T> {
this->set_multiple(src_varray, IndexMask(this->size_));
}
+ void set_multiple(const Span<T> src)
+ {
+ this->set_multiple(VArray_For_Span<T>{src});
+ }
+
void set_multiple(const VArray<T> &src_varray, const IndexMask mask)
{
BLI_assert(mask.min_array_size() <= this->size_);
@@ -290,13 +296,6 @@ template<typename T> class VMutableArray : public VArray<T> {
return this->can_get_multiple_efficiently_impl(src_varray);
}
- /* Copy the values from the source span to all elements in the virtual array. */
- void set_all(Span<T> src)
- {
- BLI_assert(src.size() == this->size_);
- this->set_all_impl(src);
- }
-
MutableSpan<T> get_internal_span()
{
BLI_assert(this->is_span());
@@ -317,20 +316,6 @@ template<typename T> class VMutableArray : public VArray<T> {
UNUSED_VARS(src_varray);
return false;
}
-
- virtual void set_all_impl(Span<T> src)
- {
- if (this->is_span()) {
- const MutableSpan<T> span = this->get_internal_span();
- initialized_copy_n(src.data(), this->size_, span.data());
- }
- else {
- const int64_t size = this->size_;
- for (int64_t i = 0; i < size; i++) {
- this->set(i, src[i]);
- }
- }
- }
};
template<typename T> using VArrayPtr = std::unique_ptr<VArray<T>>;
@@ -551,7 +536,7 @@ template<typename T> class VMutableArray_Span final : public MutableSpan<T> {
if (this->data_ != owned_data_.data()) {
return;
}
- varray_.set_all(owned_data_);
+ varray_.set_multiple(owned_data_);
}
void disable_not_applied_warning()
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index ba6439ebed0..e8a31f8f44a 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -208,6 +208,7 @@ class GVMutableArray : public GVArray {
}
void set_multiple_by_copy(const GVArray &src_varray);
+ void set_multiple_by_copy(const GSpan &src);
void set_multiple_by_copy(const GVArray &src_varray, const IndexMask mask);
void _set_multiple_by_copy(const GVArray &src_varray, const IndexMask mask);
bool _can_set_multiple_efficiently(const GVArray &src_varray) const;
@@ -233,12 +234,6 @@ class GVMutableArray : public GVArray {
void fill(const void *value);
- /* Copy the values from the source buffer to all elements in the virtual array. */
- void set_all(const void *src)
- {
- this->set_all_impl(src);
- }
-
protected:
virtual void set_by_copy_impl(const int64_t index, const void *value);
virtual void set_by_relocate_impl(const int64_t index, void *value);
@@ -247,8 +242,6 @@ class GVMutableArray : public GVArray {
virtual void set_multiple_by_copy_impl(const GVArray &src_varray, IndexMask mask);
virtual bool can_set_multiple_efficiently_impl(const GVArray &src_varray) const;
- virtual void set_all_impl(const void *src);
-
virtual void *try_get_internal_mutable_varray_impl();
};
@@ -578,11 +571,6 @@ template<typename T> class GVMutableArray_For_VMutableArray : public GVMutableAr
varray_->set(index, std::move(value_));
}
- void set_all_impl(const void *src) override
- {
- varray_->set_all(Span((T *)src, size_));
- }
-
void materialize_impl(const IndexMask mask, void *dst) const override
{
varray_->materialize(mask, MutableSpan((T *)dst, mask.min_array_size()));
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index 3b269a64d7c..ba7886dd001 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -207,6 +207,11 @@ void GVMutableArray::set_multiple_by_copy(const GVArray &src_varray)
this->set_multiple_by_copy(src_varray, IndexMask(size_));
}
+void GVMutableArray::set_multiple_by_copy(const GSpan &src)
+{
+ this->set_multiple_by_copy(GVArray_For_GSpan{src});
+}
+
void GVMutableArray::set_multiple_by_copy(const GVArray &src_varray, const IndexMask mask)
{
if (src_varray._can_get_multiple_efficiently(*this)) {
@@ -244,19 +249,6 @@ bool GVMutableArray::can_set_multiple_efficiently_impl(const GVArray &UNUSED(src
return false;
}
-void GVMutableArray::set_all_impl(const void *src)
-{
- if (this->is_span()) {
- const GMutableSpan span = this->get_internal_span();
- type_->copy_assign_n(src, span.data(), size_);
- }
- else {
- for (int64_t i : IndexRange(size_)) {
- this->set_by_copy(i, POINTER_OFFSET(src, type_->size() * i));
- }
- }
-}
-
void *GVMutableArray::try_get_internal_mutable_varray_impl()
{
return nullptr;
More information about the Bf-blender-cvs
mailing list