BLI: Add missing overrides to some generic virtual array implementations

The lack of these functions in the "single trivial value" and "sliced
GVArray" implementations caused some code to call fack to the base
class functions. Those are much slower since they involve a virtual
function call per element. For example, this changed the runtime of
creating a new boolean attribute set to "true" on one million faces
from 3.4 ms to 0.35 ms.

Pull Request: https://projects.blender.org/blender/blender/pulls/118161
This commit is contained in:
Hans Goudey
2024-02-13 19:59:58 +01:00
committed by Hans Goudey
parent 83c3da2e55
commit 9cf304160b
@@ -265,21 +265,33 @@ template<int BufferSize> class GVArrayImpl_For_SmallTrivialSingleValue : public
}
private:
void get(const int64_t /*index*/, void *r_value) const override
void get(const int64_t index, void *r_value) const final
{
this->copy_value_to(r_value);
this->get_to_uninitialized(index, r_value);
}
void get_to_uninitialized(const int64_t /*index*/, void *r_value) const override
void get_to_uninitialized(const int64_t /*index*/, void *r_value) const final
{
this->copy_value_to(r_value);
memcpy(r_value, &buffer_, type_->size());
}
void copy_value_to(void *dst) const
void materialize(const IndexMask &mask, void *dst) const final
{
memcpy(dst, &buffer_, type_->size());
this->materialize_to_uninitialized(mask, dst);
}
void materialize_to_uninitialized(const IndexMask &mask, void *dst) const final
{
type_->fill_construct_indices(buffer_, dst, mask);
}
void materialize_compressed(const IndexMask &mask, void *dst) const final
{
this->materialize_compressed_to_uninitialized(mask, dst);
}
void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const final
{
type_->fill_construct_n(buffer_, dst, mask.size());
}
CommonVArrayInfo common_info() const override
CommonVArrayInfo common_info() const final
{
return CommonVArrayInfo{CommonVArrayInfo::Type::Single, true, &buffer_};
}
@@ -499,15 +511,29 @@ class GVArrayImpl_For_SlicedGVArray : public GVArrayImpl {
return {};
}
void materialize(const IndexMask &mask, void *dst) const final
{
IndexMaskMemory memory;
const IndexMask shifted_mask = mask.shift(offset_, memory);
varray_.materialize(shifted_mask, dst);
}
void materialize_to_uninitialized(const IndexMask &mask, void *dst) const final
{
IndexMaskMemory memory;
const IndexMask shifted_mask = mask.shift(offset_, memory);
varray_.materialize_to_uninitialized(shifted_mask, dst);
}
void materialize_compressed(const IndexMask &mask, void *dst) const final
{
IndexMaskMemory memory;
const IndexMask shifted_mask = mask.shift(offset_, memory);
varray_.materialize_compressed(shifted_mask, dst);
}
void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const override
{
IndexMaskFromSegment mask_from_segment;
mask.foreach_segment([&](const IndexMaskSegment segment, const int64_t start) {
const IndexMask &segment_mask = mask_from_segment.update(
{segment.offset() + offset_, segment.base_span()});
varray_.materialize_compressed_to_uninitialized(segment_mask,
POINTER_OFFSET(dst, type_->size() * start));
});
IndexMaskMemory memory;
const IndexMask shifted_mask = mask.shift(offset_, memory);
varray_.materialize_compressed_to_uninitialized(shifted_mask, dst);
}
};