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-04-25 21:39:51 +0300
committerHans Goudey <h.goudey@me.com>2022-04-25 21:40:07 +0300
commitf431be224fa58374386a32dba2542ee20d2a2d61 (patch)
tree7470402341cd9e9b8f5dbb50dc101249bf15c4bb /source/blender/blenkernel/intern/curves_geometry.cc
parent845e2ed3a282913cd9d37207a313627275acc158 (diff)
Curves: Cache the number of curves of each type
Remembering the number of curves of every type makes it fast to know whether processing specific to a single curve type has to be done. This information was accessed in quite a few places, so this should be an overall reduction in overhead for the new curves type. The cache is computed eagerly, in other words every time after changing the curve types. In order to reduce verbosity I added helper functions for some common ways to set the types. Differential Revision: https://developer.blender.org/D14732
Diffstat (limited to 'source/blender/blenkernel/intern/curves_geometry.cc')
-rw-r--r--source/blender/blenkernel/intern/curves_geometry.cc48
1 files changed, 28 insertions, 20 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 8e97884516c..7a09b87490b 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -85,6 +85,9 @@ static void copy_curves_geometry(CurvesGeometry &dst, const CurvesGeometry &src)
dst.tag_topology_changed();
+ /* Though type counts are a cache, they must be copied because they are calculated eagerly. */
+ dst.runtime->type_counts = src.runtime->type_counts;
+
dst.update_customdata_pointers();
}
@@ -237,38 +240,38 @@ MutableSpan<int8_t> CurvesGeometry::curve_types_for_write()
return get_mutable_attribute<int8_t>(*this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE);
}
-bool CurvesGeometry::has_curve_with_type(const CurveType type) const
+void CurvesGeometry::fill_curve_types(const CurveType type)
{
- const VArray<int8_t> curve_types = this->curve_types();
- if (curve_types.is_single()) {
- return curve_types.get_internal_single() == type;
- }
- if (curve_types.is_span()) {
- return curve_types.get_internal_span().contains(type);
- }
- /* The curves types array should be a single value or a span. */
- BLI_assert_unreachable();
- return false;
+ this->curve_types_for_write().fill(type);
+ this->runtime->type_counts.fill(0);
+ this->runtime->type_counts[type] = this->curves_num();
+ this->tag_topology_changed();
}
-std::array<int, CURVE_TYPES_NUM> CurvesGeometry::count_curve_types() const
+void CurvesGeometry::fill_curve_types(const IndexMask selection, const CurveType type)
{
- using CountsType = std::array<int, CURVE_TYPES_NUM>;
+ /* A potential performance optimization is only counting the changed indices. */
+ this->curve_types_for_write().fill_indices(selection, type);
+ this->update_curve_types();
+ this->tag_topology_changed();
+}
- CountsType identity;
- identity.fill(0);
+std::array<int, CURVE_TYPES_NUM> calculate_type_counts(const VArray<int8_t> &types)
+{
+ using CountsType = std::array<int, CURVE_TYPES_NUM>;
+ CountsType counts;
+ counts.fill(0);
- const VArray<int8_t> types = this->curve_types();
if (types.is_single()) {
- identity[types.get_internal_single()] = this->curves_num();
- return identity;
+ counts[types.get_internal_single()] = types.size();
+ return counts;
}
Span<int8_t> types_span = types.get_internal_span();
return threading::parallel_reduce(
- this->curves_range(),
+ types.index_range(),
2048,
- identity,
+ counts,
[&](const IndexRange curves_range, const CountsType &init) {
CountsType result = init;
for (const int curve_index : curves_range) {
@@ -285,6 +288,11 @@ std::array<int, CURVE_TYPES_NUM> CurvesGeometry::count_curve_types() const
});
}
+void CurvesGeometry::update_curve_types()
+{
+ this->runtime->type_counts = calculate_type_counts(this->curve_types());
+}
+
Span<float3> CurvesGeometry::positions() const
{
return {(const float3 *)this->position, this->point_size};