Attributes: Integrate implicit sharing with the attribute API #107059

Merged
Jacques Lucke merged 8 commits from HooglyBoogly/blender:implicit-sharing-attribute-api into main 2023-04-19 11:21:21 +02:00
6 changed files with 25 additions and 10 deletions
Showing only changes of commit 21ef74bbb3 - Show all commits

View File

@ -660,10 +660,16 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
MutableAttributeAccessor attributes = mesh_final->attributes_for_write();
const AttributeReader positions = attributes.lookup<float3>("position");
if (positions) {
attributes.add<float3>(
"rest_position",
ATTR_DOMAIN_POINT,
AttributeInitShared(positions.varray.common_info().data, *positions.sharing_info));
if (positions.sharing_info && positions.varray.is_span()) {
attributes.add<float3>("rest_position",
ATTR_DOMAIN_POINT,
AttributeInitShared(positions.varray.get_internal_span().data(),

I think you make too many implicit assumptions here:

  • The attribute is definitely shared.
  • The attribute is definitely stored as continuous array.

Both assumptions generally have to be checked for.

I think you make too many implicit assumptions here: * The attribute is definitely shared. * The attribute is definitely stored as continuous array. Both assumptions generally have to be checked for.

I thought it was reasonable to assume that sharing_info != nullptr implies varray.is_span(), but I can also check the latter explicitly too. I guess this will get nicer when attributes don't always have to be stored as contiguous arrays.

I should definitely check for sharing_info here though. I did it elsewhere and forgot here.

I thought it was reasonable to assume that `sharing_info != nullptr` implies `varray.is_span()`, but I can also check the latter explicitly too. I guess this will get nicer when attributes don't always have to be stored as contiguous arrays. I should definitely check for `sharing_info` here though. I did it elsewhere and forgot here.
*positions.sharing_info));
}
else {
attributes.add<float3>(
"rest_position", ATTR_DOMAIN_POINT, AttributeInitVArray(positions.varray));
}
}
}

View File

@ -168,7 +168,8 @@ static void add_instances_from_component(
}
const eCustomDataType type = bke::cpp_type_to_custom_data_type(src.varray.type());
if (src.varray.size() == dst_component.instances_num() && src.sharing_info) {
if (src.varray.size() == dst_component.instances_num() && src.sharing_info &&
src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
dst_attributes.add(id, ATTR_DOMAIN_INSTANCE, type, init);

View File

@ -72,7 +72,8 @@ static void convert_instances_to_points(GeometrySet &geometry_set,
const eCustomDataType type = item.value.data_type;
const GAttributeReader src = src_attributes.lookup(id);
if (selection.size() == instances.instances_num() && src.sharing_info) {
if (selection.size() == instances.instances_num() && src.sharing_info &&
src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
dst_attributes.add(id, ATTR_DOMAIN_POINT, type, init);

View File

@ -579,8 +579,15 @@ static void interpolate_curve_attributes(bke::CurvesGeometry &child_curves,
}
const GAttributeReader src = point_attributes.lookup(id);
const bke::AttributeInitShared init(src.varray.get_internal_span().data(), *src.sharing_info);
children_attributes.add(id, ATTR_DOMAIN_CURVE, meta_data.data_type, init);
if (src.sharing_info && src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
children_attributes.add(id, ATTR_DOMAIN_CURVE, meta_data.data_type, init);
}
else {
children_attributes.add(
id, ATTR_DOMAIN_CURVE, meta_data.data_type, bke::AttributeInitVArray(src.varray));
}
return true;
});
}

View File

@ -120,7 +120,7 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
continue;
}
if (share_arrays && src.domain == domain && src.sharing_info) {
if (share_arrays && src.domain == domain && src.sharing_info && src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
dst_attributes.add(attribute_id, ATTR_DOMAIN_POINT, data_type, init);

View File

@ -67,7 +67,7 @@ static void geometry_set_points_to_vertices(
const AttributeIDRef id = entry.key;
const eCustomDataType data_type = entry.value.data_type;
const GAttributeReader src = src_attributes.lookup(id);
if (selection.size() == points->totpoint && src.sharing_info) {
if (selection.size() == points->totpoint && src.sharing_info && src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
dst_attributes.add(id, ATTR_DOMAIN_POINT, data_type, init);