Curve: reduce overhead in debug builds
This commit is contained in:
@@ -117,6 +117,14 @@ class CurvesGeometryRuntime {
|
||||
|
||||
/** Stores weak references to material data blocks. */
|
||||
std::unique_ptr<bake::BakeMaterialsList> bake_materials;
|
||||
|
||||
/**
|
||||
* Type counts have to be set eagerly after each operation. It's checked with asserts that the
|
||||
* type counts are correct when accessed. However, this check is expensive and shouldn't be done
|
||||
* all the time because it makes debug builds unusable in some situations that would be fine
|
||||
* otherwise.
|
||||
*/
|
||||
bool check_type_counts = true;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -894,13 +902,22 @@ inline bool CurvesGeometry::has_curve_with_type(const Span<CurveType> types) con
|
||||
|
||||
inline const std::array<int, CURVE_TYPES_NUM> &CurvesGeometry::curve_type_counts() const
|
||||
{
|
||||
BLI_assert(this->runtime->type_counts == calculate_type_counts(this->curve_types()));
|
||||
#ifndef NDEBUG
|
||||
|
||||
if (this->runtime->check_type_counts) {
|
||||
const std::array<int, CURVE_TYPES_NUM> actual_type_counts = calculate_type_counts(
|
||||
this->curve_types());
|
||||
BLI_assert(this->runtime->type_counts == actual_type_counts);
|
||||
this->runtime->check_type_counts = false;
|
||||
}
|
||||
#endif
|
||||
return this->runtime->type_counts;
|
||||
}
|
||||
|
||||
inline OffsetIndices<int> CurvesGeometry::points_by_curve() const
|
||||
{
|
||||
return OffsetIndices<int>({this->curve_offsets, this->curve_num + 1});
|
||||
return OffsetIndices<int>({this->curve_offsets, this->curve_num + 1},
|
||||
offset_indices::NoSortCheck{});
|
||||
}
|
||||
|
||||
inline int CurvesGeometry::evaluated_points_num() const
|
||||
|
||||
@@ -116,7 +116,8 @@ CurvesGeometry::CurvesGeometry(const CurvesGeometry &other)
|
||||
other.runtime->evaluated_length_cache,
|
||||
other.runtime->evaluated_tangent_cache,
|
||||
other.runtime->evaluated_normal_cache,
|
||||
{}});
|
||||
{},
|
||||
true});
|
||||
|
||||
if (other.runtime->bake_materials) {
|
||||
this->runtime->bake_materials = std::make_unique<bake::BakeMaterialsList>(
|
||||
@@ -1065,6 +1066,7 @@ void CurvesGeometry::tag_topology_changed()
|
||||
this->tag_positions_changed();
|
||||
this->runtime->evaluated_offsets_cache.tag_dirty();
|
||||
this->runtime->nurbs_basis_cache.tag_dirty();
|
||||
this->runtime->check_type_counts = true;
|
||||
}
|
||||
void CurvesGeometry::tag_normals_changed()
|
||||
{
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
|
||||
namespace blender::offset_indices {
|
||||
|
||||
/** Utility struct that can be passed into a function to skip a check for sorted indices. */
|
||||
struct NoSortCheck {};
|
||||
|
||||
/**
|
||||
* References an array of ascending indices. A pair of consecutive indices encode an index range.
|
||||
* Another common way to store the same kind of data is to store the start and size of every range
|
||||
@@ -35,6 +38,13 @@ template<typename T> class OffsetIndices {
|
||||
BLI_assert(offsets_.size() < 2 || std::is_sorted(offsets_.begin(), offsets_.end()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as above, but skips the debug check that indices are sorted, because that can have a
|
||||
* high performance impact making debug builds unusable for files that would be fine otherwise.
|
||||
* This can be used when it is known that the indices are sorted already.
|
||||
*/
|
||||
OffsetIndices(const Span<T> offsets, NoSortCheck) : offsets_(offsets) {}
|
||||
|
||||
/** Return the total number of elements in the referenced arrays. */
|
||||
T total_size() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user