109 T *dst = r_span.
data();
114 mask.foreach_index([&](
const int64_t i) { dst[i] = this->
get(i); });
118 const T *
src =
static_cast<const T *
>(info.
data);
123 const T single = *
static_cast<const T *
>(info.
data);
124 mask.foreach_index([&](
const int64_t i) { dst[i] = single; });
135 T *dst = r_span.
data();
140 mask.foreach_index([&](
const int64_t i) {
new (dst + i)
T(this->
get(i)); });
144 const T *
src =
static_cast<const T *
>(info.
data);
149 const T single = *
static_cast<const T *
>(info.
data);
150 mask.foreach_index([&](
const int64_t i) {
new (dst + i)
T(single); });
164 mask.to_best_mask_type([&](
auto best_mask) {
166 r_span[i] = this->get(best_mask[i]);
177 T *dst = r_span.
data();
178 mask.to_best_mask_type([&](
auto best_mask) {
180 new (dst + i) T(this->get(best_mask[i]));
224 src.data(), this->size_,
const_cast<T *
>(
static_cast<const T *
>(info.
data)));
269 data_[index] = value;
279 if (other.size() != this->size_) {
286 return data_ ==
static_cast<const T *
>(other_info.
data);
291 mask.to_best_mask_type([&](
auto best_mask) {
293 r_span[i] = data_[best_mask[i]];
301 T *dst = r_span.
data();
302 mask.to_best_mask_type([&](
auto best_mask) {
304 new (dst + i) T(data_[best_mask[i]]);
326 inline constexpr
bool is_trivial_extended_v<VArrayImpl_For_Span_final<T>> =
true;
334 template<
typename Container,
typename T =
typename Container::value_type>
337 Container container_;
343 this->
data_ =
const_cast<T *
>(container_.data());
389 inline constexpr
bool is_trivial_extended_v<VArrayImpl_For_Single<T>> = is_trivial_extended_v<T>;
406 T get(
const int64_t index)
const override
408 return get_func_(index);
411 void materialize(IndexMask
mask, MutableSpan<T> r_span)
const override
413 T *dst = r_span.data();
414 mask.foreach_index([&](
const int64_t i) { dst[i] = get_func_(i); });
417 void materialize_to_uninitialized(IndexMask
mask, MutableSpan<T> r_span)
const override
419 T *dst = r_span.data();
420 mask.foreach_index([&](
const int64_t i) {
new (dst + i)
T(get_func_(i)); });
423 void materialize_compressed(IndexMask
mask, MutableSpan<T> r_span)
const override
426 T *dst = r_span.data();
427 mask.to_best_mask_type([&](
auto best_mask) {
428 for (
const int64_t i : IndexRange(best_mask.size())) {
429 dst[i] = get_func_(best_mask[i]);
434 void materialize_compressed_to_uninitialized(IndexMask
mask,
435 MutableSpan<T> r_span)
const override
438 T *dst = r_span.data();
439 mask.to_best_mask_type([&](
auto best_mask) {
440 for (
const int64_t i : IndexRange(best_mask.size())) {
441 new (dst + i) T(get_func_(best_mask[i]));
450 template<
typename StructT,
452 ElemT (*GetFunc)(
const StructT &),
453 void (*SetFunc)(StructT &, ElemT) =
nullptr>
464 template<
typename OtherStructT,
466 OtherElemT (*OtherGetFunc)(
const OtherStructT &),
467 void (*OtherSetFunc)(OtherStructT &, OtherElemT)>
471 ElemT get(
const int64_t index)
const override
473 return GetFunc(
data_[index]);
476 void set(
const int64_t index, ElemT value)
override
478 SetFunc(
data_[index], std::move(value));
481 void materialize(IndexMask
mask, MutableSpan<ElemT> r_span)
const override
483 ElemT *dst = r_span.data();
487 void materialize_to_uninitialized(IndexMask
mask, MutableSpan<ElemT> r_span)
const override
489 ElemT *dst = r_span.data();
490 mask.foreach_index([&](
const int64_t i) {
new (dst + i) ElemT(GetFunc(
data_[i])); });
493 void materialize_compressed(IndexMask
mask, MutableSpan<ElemT> r_span)
const override
496 ElemT *dst = r_span.data();
497 mask.to_best_mask_type([&](
auto best_mask) {
498 for (
const int64_t i : IndexRange(best_mask.size())) {
499 dst[i] = GetFunc(data_[best_mask[i]]);
504 void materialize_compressed_to_uninitialized(IndexMask
mask,
505 MutableSpan<ElemT> r_span)
const override
508 ElemT *dst = r_span.data();
509 mask.to_best_mask_type([&](
auto best_mask) {
510 for (
const int64_t i : IndexRange(best_mask.size())) {
511 new (dst + i) ElemT(GetFunc(data_[best_mask[i]]));
516 bool is_same(
const VArrayImpl<ElemT> &other)
const override
518 if (other.size() != this->size_) {
521 if (
const VArrayImpl_For_DerivedSpan<StructT, ElemT, GetFunc> *other_typed =
522 dynamic_cast<const VArrayImpl_For_DerivedSpan<StructT, ElemT, GetFunc> *
>(&other)) {
523 return other_typed->data_ ==
data_;
525 if (
const VArrayImpl_For_DerivedSpan<StructT, ElemT, GetFunc, SetFunc> *other_typed =
526 dynamic_cast<const VArrayImpl_For_DerivedSpan<StructT, ElemT, GetFunc, SetFunc> *
>(
528 return other_typed->data_ ==
data_;
534 template<
typename StructT,
536 ElemT (*GetFunc)(
const StructT &),
537 void (*SetFunc)(StructT &, ElemT)>
538 inline constexpr
bool
563 return {[](
const void *
buffer) {
567 else if constexpr (std::is_same_v<StorageT,
const VArrayImpl<T> *>) {
568 return {[](
const void *
buffer) {
return *(
const StorageT *)
buffer; }};
570 else if constexpr (std::is_same_v<StorageT, std::shared_ptr<
const VArrayImpl<T>>>) {
571 return {[](
const void *
buffer) {
return ((
const StorageT *)
buffer)->get(); }};
619 impl_ = this->impl_from_storage();
625 impl_ = this->impl_from_storage();
626 other.storage_.reset();
627 other.impl_ =
nullptr;
645 storage_ = std::move(
impl);
652 template<
typename ImplT,
typename... Args>
void emplace(Args &&...args)
656 if constexpr (std::is_copy_constructible_v<ImplT> && Storage::template is_inline_v<ImplT>) {
659 impl_ = &storage_.template emplace<ImplT>(std::forward<Args>(args)...);
664 std::shared_ptr<const VArrayImpl<T>>
ptr = std::make_shared<ImplT>(
665 std::forward<Args>(args)...);
667 storage_ = std::move(
ptr);
674 if (
this == &other) {
678 impl_ = this->impl_from_storage();
684 if (
this == &other) {
687 storage_ = std::move(other.storage_);
688 impl_ = this->impl_from_storage();
689 other.storage_.reset();
690 other.impl_ =
nullptr;
707 return impl_ !=
nullptr;
720 return impl_->
get(index);
729 return (*
this)[index];
738 if (impl_ ==
nullptr) {
741 return impl_->
size();
747 return this->
size() == 0;
777 return Span<T>(
static_cast<const T *
>(info.
data), this->size());
796 return *
static_cast<const T *
>(info.
data);
804 if (!*
this || !other) {
812 if (other.
impl_->is_same(*impl_)) {
833 this->materialize_to_uninitialized(
IndexMask(this->
size()), r_span);
860 template<
typename T>
class VMutableArray;
869 namespace varray_tag {
904 this->
template emplace<VArrayImpl_For_Span_final<T>>(mutable_span);
909 this->
template emplace<VArrayImpl_For_Single<T>>(std::move(value),
size);
915 template<
typename ImplT,
typename... Args>
static VArray For(Args &&...args)
919 varray.template emplace<ImplT>(std::forward<Args>(args)...);
953 template<
typename StructT, T (*GetFunc)(const StructT &)>
959 return VArray::For<VArrayImpl_For_DerivedSpan<StructT, T, GetFunc>>(span);
969 return VArray::For<VArrayImpl_For_ArrayContainer<ContainerT>>(std::move(container));
1010 varray.template emplace<ImplT>(std::forward<Args>(args)...);
1019 return VMutableArray::For<VArrayImpl_For_Span_final<T>>(values);
1026 template<
typename StructT, T (*GetFunc)(const StructT &),
void (*SetFunc)(StructT &, T)>
1029 return VMutableArray::For<VArrayImpl_For_DerivedSpan<StructT, T, GetFunc, SetFunc>>(values);
1078 this->get_impl()->set(index, std::move(value));
1087 this->get_impl()->set_all(
src);
1093 return this->get_impl()->try_assign_GVMutableArray(varray);
1107 template<
typename T>
static constexpr
bool is_VArray_v<VArray<T>> =
true;
1110 template<
typename T>
static constexpr
bool is_VMutableArray_v<VMutableArray<T>> =
true;
1136 this->size_ = varray_.
size();
1139 this->data_ =
static_cast<const T *
>(info.
data);
1145 this->data_ = owned_data_.
data();
1150 : varray_(
std::move(other.varray_)), owned_data_(
std::move(other.owned_data_))
1155 this->size_ = varray_.
size();
1158 this->data_ =
static_cast<const T *
>(info.
data);
1161 this->data_ = owned_data_.
data();
1163 other.data_ =
nullptr;
1169 if (
this == &other) {
1172 std::destroy_at(
this);
1189 bool save_has_been_called_ =
false;
1190 bool show_not_saved_warning_ =
true;
1204 this->size_ = varray_.
size();
1207 this->data_ =
const_cast<T *
>(
static_cast<const T *
>(info.
data));
1210 if (copy_values_to_span) {
1218 this->data_ = owned_data_.
data();
1223 : varray_(
std::move(other.varray_)),
1224 owned_data_(
std::move(other.owned_data_)),
1225 show_not_saved_warning_(other.show_not_saved_warning_)
1231 this->size_ = varray_.
size();
1234 this->data_ =
static_cast<T *
>(
const_cast<void *
>(info.
data));
1237 this->data_ = owned_data_.
data();
1239 other.data_ =
nullptr;
1246 if (show_not_saved_warning_) {
1247 if (!save_has_been_called_) {
1248 std::cout <<
"Warning: Call `save()` to make sure that changes persist in all cases.\n";
1256 if (
this == &other) {
1259 std::destroy_at(
this);
1272 save_has_been_called_ =
true;
1273 if (this->data_ != owned_data_.
data()) {
1281 show_not_saved_warning_ =
false;
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
const RealExtraInfo & extra_info() const
void reinitialize(const int64_t new_size)
constexpr int64_t size() const
constexpr void fill(const T &value)
constexpr T * data() const
MutableVArraySpan()=default
void disable_not_applied_warning()
MutableVArraySpan & operator=(MutableVArraySpan &&other)
MutableVArraySpan(MutableVArraySpan &&other)
MutableVArraySpan(VMutableArray< T > varray, const bool copy_values_to_span=true)
const VMutableArray< T > & varray() const
SingleAsSpan(const VArray< T > &varray)
const T & operator[](const int64_t index) const
SingleAsSpan(T value, int64_t size)
constexpr const T * data() const
constexpr int64_t size() const
IndexRange index_range() const
void materialize(MutableSpan< T > r_span) const
T operator[](const int64_t index) const
void materialize(IndexMask mask, MutableSpan< T > r_span) const
VArrayCommon(const VArrayImpl< T > *impl)
void copy_from(const VArrayCommon &other)
void materialize_compressed(IndexMask mask, MutableSpan< T > r_span) const
VArrayCommon(const VArrayCommon &other)
T get_internal_single() const
const VArrayImpl< T > * impl_
VArrayCommon(VArrayCommon &&other) noexcept
void move_from(VArrayCommon &&other) noexcept
T get(const int64_t index) const
void materialize_compressed_to_uninitialized(IndexMask mask, MutableSpan< T > r_span) const
bool is_same(const VArrayCommon< T > &other) const
bool try_assign_GVArray(GVArray &varray) const
VArrayCommon(std::shared_ptr< const VArrayImpl< T >> impl)
void materialize_to_uninitialized(MutableSpan< T > r_span) const
CommonVArrayInfo common_info() const
void materialize_to_uninitialized(IndexMask mask, MutableSpan< T > r_span) const
Span< T > get_internal_span() const
void emplace(Args &&...args)
const VArrayImpl< T > * impl_from_storage() const
VArrayImpl_For_ArrayContainer(Container container)
VArrayImpl_For_DerivedSpan(const MutableSpan< StructT > data)
VArrayImpl_For_Func(const int64_t size, GetFunc get_func)
VArrayImpl_For_Single(T value, const int64_t size)
CommonVArrayInfo common_info() const override
void materialize_compressed_to_uninitialized(IndexMask mask, MutableSpan< T > r_span) const override
void materialize_compressed(IndexMask mask, MutableSpan< T > r_span) const override
T get(const int64_t UNUSED(index)) const override
CommonVArrayInfo common_info() const override
void materialize_compressed(IndexMask mask, MutableSpan< T > r_span) const override
void materialize_compressed_to_uninitialized(IndexMask mask, MutableSpan< T > r_span) const override
void set(const int64_t index, T value) final
bool is_same(const VArrayImpl< T > &other) const final
VArrayImpl_For_Span(const int64_t size)
T get(const int64_t index) const final
VArrayImpl_For_Span(const MutableSpan< T > data)
virtual bool is_same(const VArrayImpl< T > &UNUSED(other)) const
virtual void materialize_to_uninitialized(IndexMask mask, MutableSpan< T > r_span) const
virtual bool try_assign_GVArray(GVArray &UNUSED(varray)) const
virtual void materialize_compressed_to_uninitialized(IndexMask mask, MutableSpan< T > r_span) const
virtual CommonVArrayInfo common_info() const
virtual void materialize_compressed(IndexMask mask, MutableSpan< T > r_span) const
virtual void materialize(IndexMask mask, MutableSpan< T > r_span) const
virtual T get(int64_t index) const =0
VArrayImpl(const int64_t size)
virtual ~VArrayImpl()=default
VArraySpan(VArraySpan &&other)
VArraySpan(VArray< T > varray)
VArraySpan & operator=(VArraySpan &&other)
VArray(const VArrayImpl< T > *impl)
VArray & operator=(VArray &&other) noexcept
VArray(const VArray &other)=default
VArray(varray_tag::single, T value, const int64_t size)
static VArray ForDerivedSpan(Span< StructT > values)
VArray(std::shared_ptr< const VArrayImpl< T >> impl)
VArray(VArray &&other) noexcept=default
VArray & operator=(const VArray &other)
static VArray ForContainer(ContainerT container)
VArray(varray_tag::span, Span< T > span)
static VArray ForSingle(T value, const int64_t size)
static VArray For(Args &&...args)
static VArray ForSpan(Span< T > values)
static VArray ForFunc(const int64_t size, GetFunc get_func)
virtual void set(int64_t index, T value)=0
virtual void set_all(Span< T > src)
virtual bool try_assign_GVMutableArray(GVMutableArray &UNUSED(varray)) const
void set(const int64_t index, T value)
VMutableArray & operator=(VMutableArray &&other) noexcept
VMutableArray(std::shared_ptr< const VMutableArrayImpl< T >> impl)
static VMutableArray ForDerivedSpan(MutableSpan< StructT > values)
VMutableArray & operator=(const VMutableArray &other)
static VMutableArray ForSpan(MutableSpan< T > values)
static VMutableArray For(Args &&...args)
bool try_assign_GVMutableArray(GVMutableArray &varray) const
MutableSpan< T > get_internal_span() const
VMutableArray(VMutableArray &&other) noexcept=default
VMutableArray(const VMutableArray &other)=default
VMutableArray(const VMutableArrayImpl< T > *impl)
void set_all(Span< T > src)
SyclQueue void void * src
ccl_global float * buffer
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
constexpr bool is_same_any_v
static constexpr bool is_VArray_v
static constexpr bool is_VMutableArray_v
void uninitialized_fill_n(T *dst, int64_t n, const T &value)
void initialized_copy_n(const T *src, int64_t n, T *dst)
constexpr bool is_trivial_extended_v
CommonVArrayInfo(const Type _type, const bool _may_have_ownership, const void *_data)
CommonVArrayInfo()=default