From c59a039fa8b8b78848c64889e85ed91b9070a336 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 25 Apr 2020 23:38:19 +0200 Subject: [PATCH] pgraph: fix RenderState/TransformState count in PStats exploding This was a regression in 1.10.6 that caused PStats to misreport the amount of RenderState/TransformStates in the application. --- panda/src/pgraph/renderState.I | 30 +++++++++++++++++++++++++++++- panda/src/pgraph/renderState.h | 5 +++++ panda/src/pgraph/transformState.I | 30 +++++++++++++++++++++++++++++- panda/src/pgraph/transformState.h | 5 +++++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/panda/src/pgraph/renderState.I b/panda/src/pgraph/renderState.I index d232ecb00a..b722a4cc07 100644 --- a/panda/src/pgraph/renderState.I +++ b/panda/src/pgraph/renderState.I @@ -481,6 +481,34 @@ flush_level() { _cache_counter.flush_level(); } +/** + * Overrides this method to update PStats appropriately. + */ +INLINE void RenderState:: +cache_ref_only() const { +#ifdef DO_PSTATS + int old_referenced_bits = get_referenced_bits(); + NodeCachedReferenceCount::cache_ref_only(); + consider_update_pstats(old_referenced_bits); +#else // DO_PSTATS + NodeCachedReferenceCount::cache_ref_only(); +#endif // DO_PSTATS +} + +/** + * Overrides this method to update PStats appropriately. + */ +INLINE void RenderState:: +cache_unref_only() const { +#ifdef DO_PSTATS + int old_referenced_bits = get_referenced_bits(); + NodeCachedReferenceCount::cache_unref_only(); + consider_update_pstats(old_referenced_bits); +#else // DO_PSTATS + NodeCachedReferenceCount::cache_unref_only(); +#endif // DO_PSTATS +} + #ifndef CPPPARSER /** * Handy templated version of get_attrib that casts to the right type. @@ -533,7 +561,7 @@ check_hash() const { */ INLINE bool RenderState:: do_cache_unref() const { - cache_unref_only(); + NodeCachedReferenceCount::cache_unref_only(); return unref(); } diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index c9e3719082..03f4b01ca4 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -169,6 +169,11 @@ public: INLINE void get_attrib_def(CPT(AttribType) &attrib) const; #endif // CPPPARSER + INLINE void cache_ref_only() const; + +protected: + INLINE void cache_unref_only() const; + private: INLINE void check_hash() const; bool validate_filled_slots() const; diff --git a/panda/src/pgraph/transformState.I b/panda/src/pgraph/transformState.I index 474b78891f..fe83edc991 100644 --- a/panda/src/pgraph/transformState.I +++ b/panda/src/pgraph/transformState.I @@ -753,6 +753,34 @@ flush_level() { _cache_counter.flush_level(); } +/** + * Overrides this method to update PStats appropriately. + */ +INLINE void TransformState:: +cache_ref_only() const { +#ifdef DO_PSTATS + int old_referenced_bits = get_referenced_bits(); + NodeCachedReferenceCount::cache_ref_only(); + consider_update_pstats(old_referenced_bits); +#else // DO_PSTATS + NodeCachedReferenceCount::cache_ref_only(); +#endif // DO_PSTATS +} + +/** + * Overrides this method to update PStats appropriately. + */ +INLINE void TransformState:: +cache_unref_only() const { +#ifdef DO_PSTATS + int old_referenced_bits = get_referenced_bits(); + NodeCachedReferenceCount::cache_unref_only(); + consider_update_pstats(old_referenced_bits); +#else // DO_PSTATS + NodeCachedReferenceCount::cache_unref_only(); +#endif // DO_PSTATS +} + /** * Reimplements NodeReferenceCount::node_unref(). We do this because we have * a non-virtual unref() method. @@ -769,7 +797,7 @@ do_node_unref() const { */ INLINE bool TransformState:: do_cache_unref() const { - cache_unref_only(); + NodeCachedReferenceCount::cache_unref_only(); return unref(); } diff --git a/panda/src/pgraph/transformState.h b/panda/src/pgraph/transformState.h index 75b4fedb0e..59a47daec7 100644 --- a/panda/src/pgraph/transformState.h +++ b/panda/src/pgraph/transformState.h @@ -213,6 +213,11 @@ public: INLINE static void flush_level(); + INLINE void cache_ref_only() const; + +protected: + INLINE void cache_unref_only() const; + private: INLINE bool do_cache_unref() const; INLINE bool do_node_unref() const;