Blender V5.3
attribute_storage.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "CLG_log.h"
10
11#include "BLI_array_utils.hh"
12#include "BLI_assert.hh"
13#include "BLI_color_types.hh"
14#include "BLI_generic_array.hh"
16#include "BLI_memory_counter.hh"
17#include "BLI_resource_scope.hh"
18#include "BLI_string_utils.hh"
19#include "BLI_vector_set.hh"
20
21#include "PRF_profile.hh"
22
23#include "BLT_translation.hh"
24
25#include "BLO_read_write.hh"
26
27#include "DNA_attribute_types.h"
28#include "DNA_meshdata_types.h"
29#include "DNA_userdef_types.h"
30
31#include "BKE_attribute.hh"
35#include "BKE_idtype.hh"
36
37#include <ranges>
38
39namespace blender {
40
41static CLG_LogRef LOG = {"geom.attribute"};
42
43namespace bke {
44
47{
48 auto *sharing_info = new ImplicitSharedValue<GArray<>>(std::move(array));
50 data.data = sharing_info->data.data();
51 data.size = sharing_info->data.size();
52 data.sharing_info = ImplicitSharingPtr<>(sharing_info);
53 return data;
54}
55
57 const int64_t domain_size)
58{
59 const CPPType &type = *value.type();
60 const void *value_ptr = value.get();
61
62 /* Prefer `calloc` to zeroing after allocation since it is faster. */
63 if (memory_is_zero(value_ptr, type.size)) {
64 void *buffer = MEM_new_array_zeroed_aligned(domain_size, type.size, type.alignment, __func__);
65 return array_data_from_garray(GArray<>(type, buffer, domain_size));
66 }
67 GArray<> array(type, domain_size, NoInitialization());
68 type.fill_construct_n(value_ptr, array.data(), domain_size);
69 return array_data_from_garray(std::move(array));
70}
71
73{
74 if (type.is<ColorGeometry4f>()) {
75 static constexpr ColorGeometry4f default_color(1.0f, 1.0f, 1.0f, 1.0f);
76 return GPointer(type, &default_color);
77 }
78 if (type.is<ColorGeometry4b>()) {
79 static constexpr ColorGeometry4b default_color(255, 255, 255, 255);
80 return GPointer(type, &default_color);
81 }
82 return GPointer(type, type.default_value());
83}
84
86 const int64_t domain_size)
87{
88 return from_value(default_value_for_type(type), domain_size);
89}
90
92 const int64_t domain_size)
93{
94 return array_data_from_garray(GArray<>(type, domain_size, NoInitialization()));
95}
96
98 const int64_t domain_size)
99{
101 type.default_construct_n(data.data, domain_size);
102 return data;
103}
104
106{
107 /* Use an array with a single element to store the value. */
110 data.value = sharing_info->data.data();
111 data.sharing_info = ImplicitSharingPtr<>(sharing_info);
112 return data;
113}
114
119
121{
122 if (auto *data = std::get_if<Attribute::ArrayData>(&data_)) {
123 if (!data->sharing_info) {
124 BLI_assert(data->size == 0);
125 return data_;
126 }
127 if (data->sharing_info->is_mutable()) {
128 data->sharing_info->tag_ensured_mutable();
129 return data_;
130 }
131 const CPPType &type = attribute_type_to_cpp_type(type_);
132 ArrayData new_data = ArrayData::from_uninitialized(type, data->size);
133 array_utils::copy(GVArray::from_span({type, data->data, data->size}),
134 GMutableSpan(type, new_data.data, data->size));
135 *data = std::move(new_data);
136 }
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();
140 return data_;
141 }
142 const CPPType &type = attribute_type_to_cpp_type(type_);
143 *data = SingleData::from_value(GPointer(type, data->value));
144 }
145 return data_;
146}
147
149{
150 this->dna_attributes = nullptr;
151 this->dna_attributes_num = 0;
152 memset(this->_pad, 0, sizeof(this->_pad));
153 this->runtime = MEM_new<AttributeStorageRuntime>(__func__);
154}
155
157{
158 this->dna_attributes = nullptr;
159 this->dna_attributes_num = 0;
160 this->runtime = MEM_new<AttributeStorageRuntime>(__func__);
161 this->runtime->attributes.reserve(other.runtime->attributes.size());
162 for (const Attribute &attribute : other) {
163 this->runtime->attributes.add_new(std::make_unique<Attribute>(attribute));
164 }
165}
166
168{
169 if (this == &other) {
170 return *this;
171 }
172 std::destroy_at(this);
173 new (this) AttributeStorage(other);
174 return *this;
175}
176
178{
179 this->dna_attributes = nullptr;
180 this->dna_attributes_num = 0;
181 this->runtime = MEM_new<AttributeStorageRuntime>(__func__, std::move(*other.runtime));
182}
183
185{
186 if (this == &other) {
187 return *this;
188 }
189 std::destroy_at(this);
190 new (this) AttributeStorage(std::move(other));
191 return *this;
192}
193
195{
196 MEM_delete(this->runtime);
197}
198
200{
201 return this->runtime->attributes.size();
202}
203
205{
206 return *this->runtime->attributes[index];
207}
209{
210 return *this->runtime->attributes[index];
211}
212
214{
215 return this->runtime->attributes.index_of_try_as(name);
216}
217
219{
220 const std::unique_ptr<bke::Attribute> *attribute = this->runtime->attributes.lookup_key_ptr_as(
221 name);
222 if (!attribute) {
223 return nullptr;
224 }
225 return attribute->get();
226}
227
229{
230 const std::unique_ptr<bke::Attribute> *attribute = this->runtime->attributes.lookup_key_ptr_as(
231 name);
232 if (!attribute) {
233 return nullptr;
234 }
235 return attribute->get();
236}
237
239 const AttrDomain domain,
240 const AttrType data_type,
242{
243 BLI_assert(!name.empty());
244 BLI_assert(!this->lookup(name));
245 std::unique_ptr<Attribute> ptr = std::make_unique<Attribute>();
246 Attribute &attribute = *ptr;
247 attribute.name_ = std::move(name);
248 attribute.domain_ = domain;
249 attribute.type_ = data_type;
250 attribute.data_ = std::move(data);
251 this->runtime->attributes.add_new(std::move(ptr));
252 return attribute;
253}
254
256{
257 const int index = this->runtime->attributes.index_of_try_as(name);
258 if (index == -1) {
259 return false;
260 }
261 Vector<std::unique_ptr<Attribute>> old_vector = this->runtime->attributes.extract_vector();
262 old_vector.remove(index);
263 this->runtime->attributes.reserve(old_vector.size());
264 for (std::unique_ptr<Attribute> &attribute : old_vector) {
265 this->runtime->attributes.add_new(std::move(attribute));
266 }
267 return true;
268}
269
271{
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;
275}
276
278{
279#ifndef NDEBUG
280 for (const Attribute *attr : attributes) {
281 BLI_assert(this->runtime->attributes.lookup_key_as(attr->name()).get() == attr);
282 }
283#endif
284 if (attributes.is_empty()) {
285 return false;
286 }
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;
290}
291
293{
294 const StringRef name_final = name.is_empty() ? DATA_("Attribute") : name;
295 return BLI_uniquename_cb(
296 [&](const StringRef check_name) { return this->lookup(check_name) != nullptr; },
297 '.',
298 name_final);
299}
300
301void AttributeStorage::rename(Attribute &attr, std::string new_name)
302{
303 BLI_assert(!new_name.empty());
304 /* The VectorSet must be rebuilt from scratch because the data used to create the hash is
305 * changed. */
306 Vector<std::unique_ptr<Attribute>> old_vector = this->runtime->attributes.extract_vector();
307 attr.name_ = std::move(new_name);
308 this->runtime->attributes.reserve(old_vector.size());
309 for (std::unique_ptr<Attribute> &attribute : old_vector) {
310 if (attribute->name() == attr.name_ && attribute.get() != &attr) {
311 continue;
312 }
313 this->runtime->attributes.add_new(std::move(attribute));
314 }
315}
316
317void AttributeStorage::rename(const StringRef old_name, std::string new_name)
318{
319 BLI_assert(this->lookup(old_name) != nullptr);
320 this->rename(*this->lookup(old_name), std::move(new_name));
321}
322
324{
325 /* All the attributes need to be contained in this #AttributeStorage. */
326 BLI_assert(std::all_of(renames.keys().begin(), renames.keys().end(), [&](const Attribute *attr) {
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; });
330 }));
331 if (renames.is_empty()) {
332 return;
333 }
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())) {
339 attr->name_ = *name;
340 }
341 renamed.append_unchecked(std::move(attr));
342 }
343 for (std::unique_ptr<Attribute> &attribute : renamed | std::views::reverse) {
344 this->runtime->attributes.add_new(std::move(attribute));
345 }
346}
347
348void AttributeStorage::resize(const AttrDomain domain, const int64_t new_size)
349{
350 PRF_scope_with_name("AttributeStorage::resize", ProfileCategory::Default);
351 for (Attribute &attr : *this) {
352 if (attr.domain() != domain) {
353 continue;
354 }
355 const CPPType &type = attribute_type_to_cpp_type(attr.data_type());
356 switch (attr.storage_type()) {
358 const auto &data = std::get<bke::Attribute::ArrayData>(attr.data());
359 const int64_t old_size = data.size;
360
361 auto new_data = bke::Attribute::ArrayData::from_uninitialized(type, new_size);
362 type.copy_construct_n(data.data, new_data.data, std::min(old_size, new_size));
363 if (old_size < new_size) {
364 type.default_construct_n(POINTER_OFFSET(new_data.data, type.size * old_size),
365 new_size - old_size);
366 }
367
368 attr.assign_data(std::move(new_data));
369 break;
370 }
372 break;
373 }
374 }
375 }
376}
377
379 const int8_t dna_attr_type,
380 const int64_t size,
381 void **data)
382{
383 switch (dna_attr_type) {
385 static_assert(sizeof(bool) == sizeof(int8_t));
386 return BLO_read_array(&reader, reinterpret_cast<int8_t **>(data), size);
388 return BLO_read_array(&reader, reinterpret_cast<int8_t **>(data), size);
390 return BLO_read_array(&reader, reinterpret_cast<int16_t **>(data), size, 2);
392 return BLO_read_array(&reader, reinterpret_cast<int32_t **>(data), size);
394 return BLO_read_array(&reader, reinterpret_cast<int32_t **>(data), size, 2);
396 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size);
398 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size, 2);
400 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size, 3);
402 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size, 16);
404 return BLO_read_array(&reader, reinterpret_cast<uint8_t **>(data), size, 4);
406 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size, 4);
408 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size, 4);
410 return BLO_read_array(&reader, reinterpret_cast<MStringProperty **>(data), size);
412 return BLO_read_array(&reader, reinterpret_cast<float **>(data), size, 4);
413 default:
414 *data = nullptr;
415 return false;
416 }
417}
418
420 const int8_t dna_attr_type,
421 const int64_t size,
422 void **data,
423 const ImplicitSharingInfo **sharing_info)
424{
425 *sharing_info = BLO_read_shared(&reader, data, [&]() -> const ImplicitSharingInfo * {
426 read_array_data(reader, dna_attr_type, size, data);
427 if (*data == nullptr) {
428 return nullptr;
429 }
430 const CPPType &cpp_type = attribute_type_to_cpp_type(AttrType(dna_attr_type));
431 return new ImplicitSharedValue<GArray<>>(cpp_type, *data, size);
432 });
433}
434
435static std::optional<Attribute::DataVariant> read_attr_data(BlendDataReader &reader,
436 const int8_t dna_storage_type,
437 const int8_t dna_attr_type,
438 blender::Attribute &dna_attr)
439{
440 switch (dna_storage_type) {
442 BLO_read_struct(&reader, AttributeArray, &dna_attr.data);
443 auto *dna_data = static_cast<blender::AttributeArray *>(dna_attr.data);
444 dna_attr.data = nullptr;
445 BLI_SCOPED_DEFER([&]() { MEM_delete(dna_data); });
446 auto &data = *dna_data;
447 read_shared_array(reader, dna_attr_type, data.size, &data.data, &data.sharing_info);
448 if (data.size != 0 && !data.data) {
449 return std::nullopt;
450 }
451 Attribute::ArrayData array_data{
452 data.data, data.size, ImplicitSharingPtr<>(data.sharing_info)};
453 if (data.is_single && data.size) {
454 const CPPType &cpp_type = attribute_type_to_cpp_type(AttrType(dna_attr_type));
455 return Attribute::SingleData::from_value(GPointer(cpp_type, data.data));
456 }
457 return array_data;
458 }
460 BLO_read_struct(&reader, AttributeSingle, &dna_attr.data);
461 auto *dna_data = static_cast<blender::AttributeSingle *>(dna_attr.data);
462 dna_attr.data = nullptr;
463 BLI_SCOPED_DEFER([&]() { MEM_delete(dna_data); });
464 auto &data = *dna_data;
465 read_shared_array(reader, dna_attr_type, 1, &data.data, &data.sharing_info);
466 if (!data.data) {
467 return std::nullopt;
468 }
469 return Attribute::SingleData{data.data, ImplicitSharingPtr<>(data.sharing_info)};
470 }
471 default:
472 return std::nullopt;
473 }
474}
475
477{
478 for (const std::unique_ptr<Attribute> &attr : this->runtime->attributes) {
479 const CPPType &type = attribute_type_to_cpp_type(attr->data_type());
480 if (const auto *data = std::get_if<Attribute::ArrayData>(&attr->data())) {
481 memory.add_shared(data->sharing_info.get(), [&](MemoryCounter &shared_memory) {
482 shared_memory.add(data->size * type.size);
483 });
484 }
485 else if (const auto *data = std::get_if<Attribute::SingleData>(&attr->data())) {
486 memory.add_shared(data->sharing_info.get(),
487 [&](MemoryCounter &shared_memory) { shared_memory.add(type.size); });
488 }
489 }
490}
491
492static std::optional<AttrDomain> read_attr_domain(const int8_t dna_domain)
493{
494 switch (dna_domain) {
502 return AttrDomain(dna_domain);
503 default:
504 return std::nullopt;
505 }
506}
507
509{
510 this->runtime = MEM_new<AttributeStorageRuntime>(__func__);
511
513
514 this->runtime->attributes.reserve(this->dna_attributes_num);
515 for (const int i : IndexRange(this->dna_attributes_num)) {
516 blender::Attribute &dna_attr = this->dna_attributes[i];
517 BLO_read_string(&reader, &dna_attr.name);
518 BLI_SCOPED_DEFER([&]() { MEM_SAFE_DELETE(dna_attr.name); });
519
520 const std::optional<AttrDomain> domain = read_attr_domain(dna_attr.domain);
521 if (!domain) {
522 continue;
523 }
524
525 std::optional<Attribute::DataVariant> data = read_attr_data(
526 reader, dna_attr.storage_type, dna_attr.data_type, dna_attr);
527 if (!data) {
528 continue;
529 }
530
531 std::unique_ptr<Attribute> attribute = std::make_unique<Attribute>();
532 attribute->name_ = dna_attr.name;
533 attribute->domain_ = *domain;
534 attribute->type_ = AttrType(dna_attr.data_type);
535 attribute->data_ = std::move(*data);
536
537 if (!this->runtime->attributes.add(std::move(attribute))) {
538 CLOG_ERROR(&LOG, "Ignoring attribute with duplicate name: \"%s\"", dna_attr.name);
539 }
540 }
541
542 /* These fields are not used at runtime. */
543 MEM_SAFE_DELETE(this->dna_attributes);
544 this->dna_attributes_num = 0;
545}
546
547static void write_array_data(BlendWriter &writer,
548 const AttrType data_type,
549 const void *data,
550 const int64_t size)
551{
552 switch (data_type) {
553 case AttrType::Bool:
554 static_assert(sizeof(bool) == sizeof(int8_t));
555 writer.write_int8_array(size, static_cast<const int8_t *>(data));
556 break;
557 case AttrType::Int8:
558 writer.write_int8_array(size, static_cast<const int8_t *>(data));
559 break;
561 writer.write_int16_array(size * 2, static_cast<const int16_t *>(data));
562 break;
563 case AttrType::Int32:
564 writer.write_int32_array(size, static_cast<const int32_t *>(data));
565 break;
567 writer.write_int32_array(size * 2, static_cast<const int32_t *>(data));
568 break;
569 case AttrType::Float:
570 writer.write_float_array(size, static_cast<const float *>(data));
571 break;
572 case AttrType::Float2:
573 writer.write_float_array(size * 2, static_cast<const float *>(data));
574 break;
575 case AttrType::Float3:
576 writer.write_float3_array(size, static_cast<const float *>(data));
577 break;
579 writer.write_float_array(size * 16, static_cast<const float *>(data));
580 break;
582 writer.write_uint8_array(size * 4, static_cast<const uint8_t *>(data));
583 break;
585 writer.write_float_array(size * 4, static_cast<const float *>(data));
586 break;
588 writer.write_float_array(size * 4, static_cast<const float *>(data));
589 break;
590 case AttrType::String:
592 break;
593 case AttrType::Float4:
594 writer.write_float_array(size * 4, static_cast<const float *>(data));
595 break;
596 }
597}
598
600 const bool use_5_0_compatibility,
603{
604 for (Attribute &attr : data) {
605 blender::Attribute attribute_dna{};
606 attribute_dna.name = attr.name().c_str();
607 attribute_dna.data_type = int16_t(attr.data_type());
608 attribute_dna.domain = int8_t(attr.domain());
609
610 /* The idea is to use a separate DNA struct for each #AttrStorageType. They each need to have a
611 * unique address (while writing a specific ID anyway) in order to be identified when
612 * reading the file, so we add them to the resource scope which outlives this function call.
613 * Using a #ResourceScope is a simple way to get pointer stability when adding every new data
614 * struct without the cost of many small allocations or unnecessary overhead of storing a full
615 * array for every storage type. */
616 const auto create_dna_array = [&](const Attribute::ArrayData &array_data) -> AttributeArray & {
617 auto &array_dna = write_data.scope.construct<AttributeArray>();
618 array_dna.data = array_data.data;
619 array_dna.sharing_info = array_data.sharing_info.get();
620 array_dna.size = array_data.size;
621 return array_dna;
622 };
623
624 if (const auto *data = std::get_if<Attribute::ArrayData>(&attr.data())) {
626 attribute_dna.data = &create_dna_array(*data);
627 }
628 else if (const auto *data = std::get_if<Attribute::SingleData>(&attr.data())) {
629 if (use_5_0_compatibility) {
631 /* Convert single value storage to array storage for forward compatibility.
632 * See #AttributeArray::is_single comment for more details. */
633 const CPPType &cpp_type = attribute_type_to_cpp_type(attr.data_type());
634 const GPointer value(cpp_type, data->value);
635 const int domain_size = get_domain_size(attr.domain());
636 auto &array_data = write_data.scope.construct<Attribute::ArrayData>(
637 Attribute::ArrayData::from_value(value, domain_size));
638
639 auto &array_dna = create_dna_array(array_data);
640 array_dna.is_single = true;
641 attribute_dna.data = &array_dna;
642 }
643 else {
645 auto &single_dna = write_data.scope.construct<blender::AttributeSingle>();
646 single_dna.data = data->value;
647 single_dna.sharing_info = data->sharing_info.get();
648 attribute_dna.data = &single_dna;
649 }
650 }
651
652 write_data.attributes.append(attribute_dna);
653 write_data.writer->generated_pointer_tag(attribute_dna.data);
654 }
655 data.runtime = nullptr;
656}
657
658static void write_shared_array(BlendWriter &writer,
659 const AttrType data_type,
660 const void *data,
661 const int64_t size,
662 const ImplicitSharingInfo *sharing_info)
663{
664 const CPPType &cpp_type = attribute_type_to_cpp_type(data_type);
665 writer.write_shared(data, cpp_type.size * size, sharing_info, [&]() {
666 write_array_data(writer, data_type, data, size);
667 });
668}
669
674
676 const AttributeStorage::BlendWriteData &write_data)
677{
678 /* Use string argument to avoid confusion with the C++ class with the same name. */
679 writer.write_struct_array_by_name("Attribute",
680 write_data.attributes.size(),
681 write_data.attributes.data(),
682 [](BlendStructWriterVoid &struct_writer) {
683 struct_writer.generated_ptr(
684 offsetof(blender::Attribute, data));
685 });
686 for (const blender::Attribute &attr_dna : write_data.attributes) {
687 writer.write_string(attr_dna.name);
688 switch (AttrStorageType(attr_dna.storage_type)) {
690 blender::AttributeSingle *single_dna = static_cast<blender::AttributeSingle *>(
691 attr_dna.data);
693 writer, AttrType(attr_dna.data_type), single_dna->data, 1, single_dna->sharing_info);
694 writer.write_struct(single_dna);
695 break;
696 }
698 blender::AttributeArray *array_dna = static_cast<blender::AttributeArray *>(attr_dna.data);
699 write_shared_array(writer,
700 AttrType(attr_dna.data_type),
701 array_dna->data,
702 array_dna->size,
703 array_dna->sharing_info);
704 writer.write_struct(array_dna);
705 break;
706 }
707 }
708 }
709
710 this->dna_attributes = nullptr;
711 this->dna_attributes_num = 0;
712}
713
715{
716 for (const std::unique_ptr<Attribute> &attribute : this->runtime->attributes) {
717 if (attribute->type_ == bke::AttrType::ColorFloat) {
718 if (auto *data = std::get_if<Attribute::ArrayData>(&attribute->data_)) {
719 fn.implicit_sharing_array(
720 data->sharing_info, reinterpret_cast<ColorGeometry4f *&>(data->data), data->size);
721 }
722 else if (auto *data = std::get_if<Attribute::SingleData>(&attribute->data_)) {
723 fn.implicit_sharing_array(
724 data->sharing_info, reinterpret_cast<ColorGeometry4f *&>(data->value), 1);
725 }
726 }
727 /* Byte colors are always Rec.709 sRGB, no conversion needed. */
728 };
729}
730
731} // namespace bke
732} // namespace blender
#define BLI_SCOPED_DEFER(function_to_defer)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#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
bool is() const
const void * default_value() const
const CPPType * type() const
GPointer()=default
const void * get() const
GSpan()=default
static GVArray from_span(GSpan span)
constexpr IndexRange()=default
SubIterator begin() const
Definition BLI_map.hh:768
SubIterator end() const
Definition BLI_map.hh:778
KeyIterator keys() const &
Definition BLI_map.hh:875
T & construct(Args &&...args)
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool is_empty() const
Definition BLI_set.hh:614
int64_t size() const
void remove(const int64_t index)
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
void blend_read(BlendDataReader &reader)
void rename(StringRef old_name, std::string new_name)
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
void assign_data(DataVariant &&data)
constexpr bool is_empty() const
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
#define attribute(slot)
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)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
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
unsigned char uint8_t
Definition BKE_text.h:79
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)
signed int int32_t
Definition BKE_text.h:78
static CLG_LogRef LOG
Definition logging.cpp:12
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)
Definition readfile.cc:6653
signed char int8_t
Definition BKE_text.h:76
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
signed short int16_t
Definition BKE_text.h:77
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)
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)