50 data.data = sharing_info->data.data();
51 data.size = sharing_info->data.size();
60 const void *value_ptr = value.
get();
76 return GPointer(type, &default_color);
80 return GPointer(type, &default_color);
122 if (
auto *
data = std::get_if<Attribute::ArrayData>(&data_)) {
123 if (!
data->sharing_info) {
127 if (
data->sharing_info->is_mutable()) {
128 data->sharing_info->tag_ensured_mutable();
135 *
data = std::move(new_data);
137 else if (
auto *
data = std::get_if<Attribute::SingleData>(&data_)) {
138 if (
data->sharing_info->is_mutable()) {
139 data->sharing_info->tag_ensured_mutable();
152 memset(this->
_pad, 0,
sizeof(this->
_pad));
153 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__);
160 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__);
161 this->
runtime->attributes.reserve(other.
runtime->attributes.size());
169 if (
this == &other) {
172 std::destroy_at(
this);
181 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__, std::move(*other.runtime));
186 if (
this == &other) {
189 std::destroy_at(
this);
201 return this->
runtime->attributes.size();
215 return this->
runtime->attributes.index_of_try_as(
name);
220 const std::unique_ptr<bke::Attribute> *
attribute = this->
runtime->attributes.lookup_key_ptr_as(
230 const std::unique_ptr<bke::Attribute> *
attribute = this->
runtime->attributes.lookup_key_ptr_as(
245 std::unique_ptr<Attribute> ptr = std::make_unique<Attribute>();
251 this->
runtime->attributes.add_new(std::move(ptr));
263 this->
runtime->attributes.reserve(old_vector.
size());
264 for (std::unique_ptr<Attribute> &
attribute : old_vector) {
272 const int removed_num = this->
runtime->attributes.remove_if(
273 [&](
const std::unique_ptr<Attribute> &attr) {
return names.
contains(attr->name()); });
274 return removed_num > 0;
280 for (
const Attribute *attr : attributes) {
287 const int removed_num = this->
runtime->attributes.remove_if(
288 [&](
const std::unique_ptr<Attribute> &attr) {
return attributes.
contains(attr.get()); });
289 return removed_num > 0;
296 [&](
const StringRef check_name) {
return this->
lookup(check_name) !=
nullptr; },
307 attr.name_ = std::move(new_name);
308 this->
runtime->attributes.reserve(old_vector.
size());
309 for (std::unique_ptr<Attribute> &
attribute : old_vector) {
320 this->
rename(*this->
lookup(old_name), std::move(new_name));
327 return std::any_of(this->runtime->attributes.begin(),
328 this->runtime->attributes.end(),
329 [&](const std::unique_ptr<Attribute> &a) { return a.get() == attr; });
331 if (renames.is_empty()) {
335 renamed.
reserve(this->runtime->attributes.size());
336 while (!this->runtime->attributes.is_empty()) {
337 std::unique_ptr<Attribute> attr = this->runtime->attributes.pop();
338 if (
const std::optional<StringRef>
name = renames.lookup_try(attr.get())) {
343 for (std::unique_ptr<Attribute> &
attribute : renamed | std::views::reverse) {
344 this->runtime->attributes.add_new(std::move(
attribute));
352 if (attr.
domain() != domain) {
358 const auto &
data = std::get<bke::Attribute::ArrayData>(attr.
data());
363 if (old_size < new_size) {
365 new_size - old_size);
379 const int8_t dna_attr_type,
383 switch (dna_attr_type) {
385 static_assert(
sizeof(bool) ==
sizeof(
int8_t));
420 const int8_t dna_attr_type,
427 if (*
data ==
nullptr) {
436 const int8_t dna_storage_type,
437 const int8_t dna_attr_type,
440 switch (dna_storage_type) {
444 dna_attr.
data =
nullptr;
446 auto &
data = *dna_data;
462 dna_attr.
data =
nullptr;
464 auto &
data = *dna_data;
478 for (
const std::unique_ptr<Attribute> &attr : this->
runtime->attributes) {
480 if (
const auto *
data = std::get_if<Attribute::ArrayData>(&attr->data())) {
482 shared_memory.add(data->size * type.size);
485 else if (
const auto *
data = std::get_if<Attribute::SingleData>(&attr->data())) {
487 [&](
MemoryCounter &shared_memory) { shared_memory.add(type.size); });
494 switch (dna_domain) {
510 this->
runtime = MEM_new<AttributeStorageRuntime>(__func__);
531 std::unique_ptr<Attribute>
attribute = std::make_unique<Attribute>();
538 CLOG_ERROR(&
LOG,
"Ignoring attribute with duplicate name: \"%s\"", dna_attr.
name);
554 static_assert(
sizeof(bool) ==
sizeof(
int8_t));
600 const bool use_5_0_compatibility,
606 attribute_dna.
name = attr.name().c_str();
618 array_dna.
data = array_data.data;
619 array_dna.sharing_info = array_data.sharing_info.get();
620 array_dna.size = array_data.size;
624 if (
const auto *
data = std::get_if<Attribute::ArrayData>(&attr.data())) {
626 attribute_dna.
data = &create_dna_array(*
data);
628 else if (
const auto *
data = std::get_if<Attribute::SingleData>(&attr.data())) {
629 if (use_5_0_compatibility) {
639 auto &array_dna = create_dna_array(array_data);
640 array_dna.is_single =
true;
641 attribute_dna.
data = &array_dna;
647 single_dna.sharing_info =
data->sharing_info.get();
648 attribute_dna.
data = &single_dna;
655 data.runtime =
nullptr;
666 write_array_data(writer, data_type, data, size);
683 struct_writer.generated_ptr(
684 offsetof(blender::Attribute, data));
716 for (
const std::unique_ptr<Attribute> &
attribute : this->
runtime->attributes) {
718 if (
auto *
data = std::get_if<Attribute::ArrayData>(&
attribute->data_)) {
719 fn.implicit_sharing_array(
722 else if (
auto *
data = std::get_if<Attribute::SingleData>(&
attribute->data_)) {
723 fn.implicit_sharing_array(
#define BLI_SCOPED_DEFER(function_to_defer)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define CLOG_ERROR(clg_ref,...)
#define PRF_scope_with_name(ui_name, category)
#define POINTER_OFFSET(v, ofs)
void copy_construct_n(const void *src, void *dst, int64_t n) const
void default_construct_n(void *ptr, int64_t n) const
void fill_construct_n(const void *value, void *dst, int64_t n) const
const void * default_value() const
const CPPType * type() const
static GVArray from_span(GSpan span)
friend class ImplicitSharingPtr
constexpr IndexRange()=default
SubIterator begin() const
KeyIterator keys() const &
T & construct(Args &&...args)
bool contains(const Key &key) const
void remove(const int64_t index)
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
bool remove(StringRef name)
void blend_read(BlendDataReader &reader)
void rename(StringRef old_name, std::string new_name)
Attribute & at_index(int index)
AttributeStorage & operator=(const AttributeStorage &other)
void resize(AttrDomain domain, int64_t new_size)
Attribute * lookup(StringRef name)
void blend_write(BlendWriter &writer, const BlendWriteData &write_data)
std::string unique_name_calc(StringRef name) const
void foreach_working_space_color(const IDTypeForeachColorFunctionCallback &fn)
void count_memory(MemoryCounter &memory) const
Attribute & add(std::string name, bke::AttrDomain domain, bke::AttrType data_type, Attribute::DataVariant data)
int index_of(StringRef name) const
AttrStorageType storage_type() const
const DataVariant & data() const
std::variant< ArrayData, SingleData > DataVariant
DataVariant & data_for_write()
AttrDomain domain() const
StringRefNull name() const
void assign_data(DataVariant &&data)
AttrType data_type() const
constexpr bool is_empty() const
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
static std::optional< AttrDomain > read_attr_domain(const int8_t dna_domain)
static void write_array_data(BlendWriter &writer, const AttrType data_type, const void *data, const int64_t size)
static int get_domain_size(const Mesh &mesh, const AttrDomain domain)
static GPointer default_value_for_type(const CPPType &type)
static Attribute::ArrayData array_data_from_garray(GArray<> array)
void attribute_storage_blend_write_prepare(AttributeStorage &data, bool use_5_0_compatibility, FunctionRef< int(AttrDomain)> get_domain_size, AttributeStorage::BlendWriteData &write_data)
static bool read_array_data(BlendDataReader &reader, const int8_t dna_attr_type, const int64_t size, void **data)
static void read_shared_array(BlendDataReader &reader, const int8_t dna_attr_type, const int64_t size, void **data, const ImplicitSharingInfo **sharing_info)
static void write_shared_array(BlendWriter &writer, const AttrType data_type, const void *data, const int64_t size, const ImplicitSharingInfo *sharing_info)
static std::optional< Attribute::DataVariant > read_attr_data(BlendDataReader &reader, const int8_t dna_storage_type, const int8_t dna_attr_type, blender::Attribute &dna_attr)
const CPPType & attribute_type_to_cpp_type(AttrType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const ImplicitSharingInfo * BLO_read_shared(BlendDataReader *reader, T **data_ptr, FunctionRef< const ImplicitSharingInfo *()> read_fn)
constexpr bool memory_is_zero(const void *data, const size_t size)
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
BMesh const char void * data
bool BLO_read_array(BlendDataReader *reader, T **ptr_p, const SizeT array_size, const int elems=1)
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void *(*) MEM_new_array_zeroed_aligned(size_t len, size_t size, size_t alignment, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
const ImplicitSharingInfoHandle * sharing_info
const ImplicitSharingInfoHandle * sharing_info
struct Attribute * dna_attributes
bke::AttributeStorageRuntime * runtime
void write_struct_array_cast(const int64_t array_size, const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array_by_name(const char *struct_name, int64_t array_size, const void *data, BlendStructWriterFn fn=nullptr)
void write_shared(const void *data, size_t approximate_size_in_bytes, const ImplicitSharingInfo *sharing_info, FunctionRef< void()> write_fn)
void generated_pointer_tag(const void *data)
void write_string(const char *data)
void write_uint8_array(int64_t num, const uint8_t *data)
void write_int8_array(int64_t num, const int8_t *data)
void write_float_array(int64_t num, const float *data)
void write_float3_array(int64_t num, const float *data)
void write_int16_array(int64_t num, const int16_t *data)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_int32_array(int64_t num, const int32_t *data)
Vector< blender::Attribute, 16 > & attributes
BlendWriteData(BlendWriter *writer, ResourceScope &scope)
static ArrayData from_uninitialized(const CPPType &type, int64_t domain_size)
static ArrayData from_default_value(const CPPType &type, int64_t domain_size)
static ArrayData from_value(const GPointer &value, int64_t domain_size)
static ArrayData from_constructed(const CPPType &type, int64_t domain_size)
static SingleData from_value(const GPointer &value)
static SingleData from_default_value(const CPPType &type)
ImplicitSharingPtr sharing_info