From 4e10b196ac15339cfded8d5615f04ac40c93e19b Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 29 Apr 2021 12:59:44 +0200 Subject: Functions: make copying virtual arrays to span more efficient Sometimes functions expect a span instead of a virtual array. If the virtual array is a span internally already, great. But if it is not (e.g. the position attribute on a mesh), the elements have to be copied over to a span. This patch makes the copying process more efficient by giving the compiler more opportunity for optimization. --- source/blender/functions/FN_generic_virtual_array.hh | 8 ++++++++ source/blender/functions/intern/generic_virtual_array.cc | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'source/blender/functions') diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh index c1af00fd4cd..848deb6bc04 100644 --- a/source/blender/functions/FN_generic_virtual_array.hh +++ b/source/blender/functions/FN_generic_virtual_array.hh @@ -128,6 +128,7 @@ class GVArray { this->get_internal_single(r_value); } + void materialize_to_uninitialized(void *dst) const; void materialize_to_uninitialized(const IndexMask mask, void *dst) const; template const VArray *try_get_internal_varray() const @@ -152,6 +153,8 @@ class GVArray { virtual bool is_single_impl() const; virtual void get_internal_single_impl(void *UNUSED(r_value)) const; + virtual void materialize_to_uninitialized_impl(const IndexMask mask, void *dst) const; + virtual const void *try_get_internal_varray_impl() const; }; @@ -361,6 +364,11 @@ template class GVArray_For_VArray : public GVArray { *(T *)r_value = varray_->get_internal_single(); } + void materialize_to_uninitialized_impl(const IndexMask mask, void *dst) const override + { + varray_->materialize_to_uninitialized(mask, MutableSpan((T *)dst, mask.min_array_size())); + } + const void *try_get_internal_varray_impl() const override { return varray_; diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc index e11501828f8..754a2156a65 100644 --- a/source/blender/functions/intern/generic_virtual_array.cc +++ b/source/blender/functions/intern/generic_virtual_array.cc @@ -22,7 +22,18 @@ namespace blender::fn { * GVArray. */ +void GVArray::materialize_to_uninitialized(void *dst) const +{ + this->materialize_to_uninitialized(IndexMask(size_), dst); +} + void GVArray::materialize_to_uninitialized(const IndexMask mask, void *dst) const +{ + BLI_assert(mask.min_array_size() <= size_); + this->materialize_to_uninitialized_impl(mask, dst); +} + +void GVArray::materialize_to_uninitialized_impl(const IndexMask mask, void *dst) const { for (const int64_t i : mask) { void *elem_dst = POINTER_OFFSET(dst, type_->size() * i); -- cgit v1.2.3