Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-08-30 22:54:53 +0300
committerHans Goudey <h.goudey@me.com>2022-08-30 22:56:05 +0300
commit25237d2625078c6d14d744f288776299efd3c7c8 (patch)
tree17d11451a5b816b15905e34402aa1b046d666c7a /source/blender/blenkernel/intern/geometry_component_curve.cc
parentd81e947c591ec6f3de2bc407b9f837b2efa36890 (diff)
Attributes: Improve custom data initialization options
When allocating new `CustomData` layers, often we do redundant initialization of arrays. For example, it's common that values are allocated, set to their default value, and then set to some other value. This is wasteful, and it negates the benefits of optimizations to the allocator like D15082. There are two reasons for this. The first is array-of-structs storage that makes it annoying to initialize values manually, and the second is confusing options in the Custom Data API. This patch addresses the latter. The `CustomData` "alloc type" options are rearranged. Now, besides the options that use existing layers, there are two remaining: * `CD_SET_DEFAULT` sets the default value. * Usually zeroes, but for colors this is white (how it was before). * Should be used when you add the layer but don't set all values. * `CD_CONSTRUCT` refers to the "default construct" C++ term. * Only necessary or defined for non-trivial types like vertex groups. * Doesn't do anything for trivial types like `int` or `float3`. * Should be used every other time, when all values will be set. The attribute API's `AttributeInit` types are updated as well. To update code, replace `CD_CALLOC` with `CD_SET_DEFAULT` and `CD_DEFAULT` with `CD_CONSTRUCT`. This doesn't cause any functional changes yet. Follow-up commits will change to avoid initializing new layers where the correctness is clear. Differential Revision: https://developer.blender.org/D15617
Diffstat (limited to 'source/blender/blenkernel/intern/geometry_component_curve.cc')
-rw-r--r--source/blender/blenkernel/intern/geometry_component_curve.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 22f105af0f1..56a7e38b2fc 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -547,7 +547,8 @@ static GVArray varray_from_initializer(const AttributeInit &initializer,
const Span<SplinePtr> splines)
{
switch (initializer.type) {
- case AttributeInit::Type::Default:
+ case AttributeInit::Type::Construct:
+ case AttributeInit::Type::DefaultValue:
/* This function shouldn't be called in this case, since there
* is no need to copy anything to the new custom data array. */
BLI_assert_unreachable();
@@ -560,7 +561,7 @@ static GVArray varray_from_initializer(const AttributeInit &initializer,
total_num += spline->size();
}
return GVArray::ForSpan(GSpan(*bke::custom_data_type_to_cpp_type(data_type),
- static_cast<const AttributeInitMove &>(initializer).data,
+ static_cast<const AttributeInitMoveArray &>(initializer).data,
total_num));
}
BLI_assert_unreachable();
@@ -580,7 +581,7 @@ static bool create_point_attribute(CurveEval *curve,
/* First check the one case that allows us to avoid copying the input data. */
if (splines.size() == 1 && initializer.type == AttributeInit::Type::MoveArray) {
- void *source_data = static_cast<const AttributeInitMove &>(initializer).data;
+ void *source_data = static_cast<const AttributeInitMoveArray &>(initializer).data;
if (!splines.first()->attributes.create_by_move(attribute_id, data_type, source_data)) {
MEM_freeN(source_data);
return false;
@@ -600,7 +601,7 @@ static bool create_point_attribute(CurveEval *curve,
}
/* With a default initializer type, we can keep the values at their initial values. */
- if (initializer.type == AttributeInit::Type::Default) {
+ if (ELEM(initializer.type, AttributeInit::Type::DefaultValue, AttributeInit::Type::Construct)) {
return true;
}
@@ -616,7 +617,7 @@ static bool create_point_attribute(CurveEval *curve,
write_attribute.finish();
if (initializer.type == AttributeInit::Type::MoveArray) {
- MEM_freeN(static_cast<const AttributeInitMove &>(initializer).data);
+ MEM_freeN(static_cast<const AttributeInitMoveArray &>(initializer).data);
}
return true;