From 384a02a214cad88f3180deee36b22529c213ddaf Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 7 Apr 2022 10:02:34 +0200 Subject: BLI: add missing materialize methods for virtual arrays This does two things: * Introduce new `materialize_compressed` methods. Those are used when the dst array should not have any gaps. * Add materialize methods in various classes where they were missing (and therefore caused overhead, because slower fallbacks had to be used). --- .../blenlib/intern/generic_virtual_array.cc | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/generic_virtual_array.cc b/source/blender/blenlib/intern/generic_virtual_array.cc index 8a6ef8e792f..6cdbbde671a 100644 --- a/source/blender/blenlib/intern/generic_virtual_array.cc +++ b/source/blender/blenlib/intern/generic_virtual_array.cc @@ -24,6 +24,22 @@ void GVArrayImpl::materialize_to_uninitialized(const IndexMask mask, void *dst) } } +void GVArrayImpl::materialize_compressed(IndexMask mask, void *dst) const +{ + for (const int64_t i : mask.index_range()) { + void *elem_dst = POINTER_OFFSET(dst, type_->size() * i); + this->get(mask[i], elem_dst); + } +} + +void GVArrayImpl::materialize_compressed_to_uninitialized(IndexMask mask, void *dst) const +{ + for (const int64_t i : mask.index_range()) { + void *elem_dst = POINTER_OFFSET(dst, type_->size() * i); + this->get_to_uninitialized(mask[i], elem_dst); + } +} + void GVArrayImpl::get(const int64_t index, void *r_value) const { type_->destruct(r_value); @@ -172,6 +188,27 @@ GSpan GVArrayImpl_For_GSpan::get_internal_span() const return GSpan(*type_, data_, size_); } +void GVArrayImpl_For_GSpan::materialize(const IndexMask mask, void *dst) const +{ + type_->copy_assign_indices(data_, dst, mask); +} + +void GVArrayImpl_For_GSpan::materialize_to_uninitialized(const IndexMask mask, void *dst) const +{ + type_->copy_construct_indices(data_, dst, mask); +} + +void GVArrayImpl_For_GSpan::materialize_compressed(const IndexMask mask, void *dst) const +{ + type_->copy_assign_compressed(data_, dst, mask); +} + +void GVArrayImpl_For_GSpan::materialize_compressed_to_uninitialized(const IndexMask mask, + void *dst) const +{ + type_->copy_construct_compressed(data_, dst, mask); +} + class GVArrayImpl_For_GSpan_final final : public GVArrayImpl_For_GSpan { public: using GVArrayImpl_For_GSpan::GVArrayImpl_For_GSpan; @@ -231,6 +268,26 @@ class GVArrayImpl_For_SingleValueRef : public GVArrayImpl { { type_->copy_assign(value_, r_value); } + + void materialize(const IndexMask mask, void *dst) const override + { + type_->fill_assign_indices(value_, dst, mask); + } + + void materialize_to_uninitialized(const IndexMask mask, void *dst) const override + { + type_->fill_construct_indices(value_, dst, mask); + } + + void materialize_compressed(const IndexMask mask, void *dst) const + { + type_->fill_assign_n(value_, dst, mask.size()); + } + + void materialize_compressed_to_uninitialized(const IndexMask mask, void *dst) const + { + type_->fill_construct_n(value_, dst, mask.size()); + } }; class GVArrayImpl_For_SingleValueRef_final final : public GVArrayImpl_For_SingleValueRef { @@ -448,6 +505,22 @@ class GVArrayImpl_For_SlicedGVArray : public GVArrayImpl { { varray_.get_internal_single(r_value); } + + void materialize_compressed_to_uninitialized(const IndexMask mask, void *dst) const override + { + if (mask.is_range()) { + const IndexRange mask_range = mask.as_range(); + const IndexRange offset_mask_range{mask_range.start() + offset_, mask_range.size()}; + varray_.materialize_compressed_to_uninitialized(offset_mask_range, dst); + } + else { + Vector offset_mask_indices(mask.size()); + for (const int64_t i : mask.index_range()) { + offset_mask_indices[i] = mask[i] + offset_; + } + varray_.materialize_compressed_to_uninitialized(offset_mask_indices.as_span(), dst); + } + } }; /** \} */ @@ -505,6 +578,16 @@ void GVArrayCommon::materialize_to_uninitialized(const IndexMask mask, void *dst impl_->materialize_to_uninitialized(mask, dst); } +void GVArrayCommon::materialize_compressed(IndexMask mask, void *dst) const +{ + impl_->materialize_compressed(mask, dst); +} + +void GVArrayCommon::materialize_compressed_to_uninitialized(IndexMask mask, void *dst) const +{ + impl_->materialize_compressed_to_uninitialized(mask, dst); +} + bool GVArrayCommon::may_have_ownership() const { return impl_->may_have_ownership(); -- cgit v1.2.3