From 0154fbd86d46a06ef01ba5d1c3659edd0aaa9f2f Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Mon, 23 Jan 2023 12:31:16 -0800 Subject: [PATCH] Replace boost hash usage with TfHash in pxr/usd/usd --- pxr/usd/usd/clipCache.cpp | 14 +++--- pxr/usd/usd/clipSetDefinition.h | 36 +++++++------- pxr/usd/usd/collectionAPI.cpp | 2 - pxr/usd/usd/collectionMembershipQuery.cpp | 8 +--- pxr/usd/usd/crateFile.h | 48 ++++++++++--------- pxr/usd/usd/instanceCache.h | 4 +- pxr/usd/usd/instanceKey.cpp | 16 +++---- pxr/usd/usd/object.cpp | 12 +++-- pxr/usd/usd/prim.cpp | 5 +- pxr/usd/usd/primDataHandle.h | 5 +- pxr/usd/usd/primFlags.h | 10 ++-- pxr/usd/usd/shared.h | 5 +- pxr/usd/usd/stageCache.cpp | 2 +- pxr/usd/usd/stageLoadRules.cpp | 6 +-- pxr/usd/usd/stagePopulationMask.cpp | 6 +-- pxr/usd/usd/testenv/testUsdCollectionAPI.py | 9 ++++ pxr/usd/usd/testenv/testUsdStageLoadUnload.py | 8 +++- pxr/usd/usd/timeCode.h | 5 +- pxr/usd/usd/wrapPrimFlags.cpp | 8 ++-- 19 files changed, 106 insertions(+), 103 deletions(-) diff --git a/pxr/usd/usd/clipCache.cpp b/pxr/usd/usd/clipCache.cpp index 8b0c45fe6d..c582e1d8be 100644 --- a/pxr/usd/usd/clipCache.cpp +++ b/pxr/usd/usd/clipCache.cpp @@ -38,6 +38,7 @@ #include "pxr/base/gf/vec2d.h" #include "pxr/base/trace/trace.h" #include "pxr/base/tf/diagnostic.h" +#include "pxr/base/tf/hash.h" #include "pxr/base/tf/mallocTag.h" #include "pxr/base/tf/ostreamMethods.h" @@ -84,13 +85,12 @@ class Usd_ClipCache::Lifeboat::Data { inline size_t operator()(const ManifestKey& key) const { - size_t hash = key.primPath.GetHash(); - boost::hash_combine(hash, TfHash()(key.clipSetName)); - boost::hash_combine(hash, key.clipPrimPath.GetHash()); - for (const auto& p : key.clipAssetPaths) { - boost::hash_combine(hash, p.GetHash()); - } - return hash; + return TfHash::Combine( + key.primPath, + key.clipSetName, + key.clipPrimPath, + key.clipAssetPaths + ); } }; }; diff --git a/pxr/usd/usd/clipSetDefinition.h b/pxr/usd/usd/clipSetDefinition.h index 1b41bbfeb5..e445f8d39a 100644 --- a/pxr/usd/usd/clipSetDefinition.h +++ b/pxr/usd/usd/clipSetDefinition.h @@ -31,6 +31,7 @@ #include "pxr/base/vt/array.h" #include "pxr/base/gf/vec2d.h" #include "pxr/base/tf/declarePtrs.h" +#include "pxr/base/tf/hash.h" #include @@ -76,40 +77,39 @@ class Usd_ClipSetDefinition size_t GetHash() const { - size_t hash = indexOfLayerWhereAssetPathsFound; - boost::hash_combine(hash, sourceLayerStack); - boost::hash_combine(hash, sourcePrimPath); + size_t hash = TfHash::Combine( + indexOfLayerWhereAssetPathsFound, + sourceLayerStack, + sourcePrimPath + ); if (clipAssetPaths) { - for (const auto& assetPath : *clipAssetPaths) { - boost::hash_combine(hash, assetPath.GetHash()); - } + hash = TfHash::Combine(hash, *clipAssetPaths); } if (clipManifestAssetPath) { - boost::hash_combine(hash, clipManifestAssetPath->GetHash()); + hash = TfHash::Combine(hash, *clipManifestAssetPath); } if (clipPrimPath) { - boost::hash_combine(hash, *clipPrimPath); + hash = TfHash::Combine(hash, *clipPrimPath); } if (clipActive) { - for (const auto& active : *clipActive) { - boost::hash_combine(hash, active[0]); - boost::hash_combine(hash, active[1]); - } + hash = TfHash::Combine(hash, *clipActive); } if (clipTimes) { - for (const auto& time : *clipTimes) { - boost::hash_combine(hash, time[0]); - boost::hash_combine(hash, time[1]); - } + hash = TfHash::Combine(hash, *clipTimes); } if (interpolateMissingClipValues) { - boost::hash_combine(hash, *interpolateMissingClipValues); + hash = TfHash::Combine(hash, *interpolateMissingClipValues); } - return hash; } + template + friend void TfHashAppend(HashState& h, + const Usd_ClipSetDefinition& definition) { + h.Append(definition.GetHash()); + } + boost::optional > clipAssetPaths; boost::optional clipManifestAssetPath; boost::optional clipPrimPath; diff --git a/pxr/usd/usd/collectionAPI.cpp b/pxr/usd/usd/collectionAPI.cpp index d21ed74526..b4f75514a0 100644 --- a/pxr/usd/usd/collectionAPI.cpp +++ b/pxr/usd/usd/collectionAPI.cpp @@ -339,8 +339,6 @@ PXR_NAMESPACE_CLOSE_SCOPE #include "pxr/usd/usd/primRange.h" -#include - #include PXR_NAMESPACE_OPEN_SCOPE diff --git a/pxr/usd/usd/collectionMembershipQuery.cpp b/pxr/usd/usd/collectionMembershipQuery.cpp index c3c55ec481..8db2c225b3 100644 --- a/pxr/usd/usd/collectionMembershipQuery.cpp +++ b/pxr/usd/usd/collectionMembershipQuery.cpp @@ -360,14 +360,10 @@ UsdCollectionMembershipQuery::Hash::operator()( std::vector<_Entry> entries(q._pathExpansionRuleMap.begin(), q._pathExpansionRuleMap.end()); std::sort(entries.begin(), entries.end()); - size_t h = 0; - for (_Entry const& entry: entries) { - boost::hash_combine(h, entry.first); - boost::hash_combine(h, entry.second); - } + // Don't hash _hasExcludes because it is derived from // the contents of _pathExpansionRuleMap. - return h; + return TfHash()(entries); } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usd/crateFile.h b/pxr/usd/usd/crateFile.h index 6f397fd155..399367e6e0 100644 --- a/pxr/usd/usd/crateFile.h +++ b/pxr/usd/usd/crateFile.h @@ -31,6 +31,7 @@ #include "crateValueInliners.h" #include "pxr/base/arch/fileSystem.h" +#include "pxr/base/tf/hash.h" #include "pxr/base/tf/token.h" #include "pxr/base/vt/array.h" #include "pxr/base/vt/value.h" @@ -43,7 +44,6 @@ #include "pxr/usd/sdf/types.h" #include -#include #include #include @@ -198,12 +198,12 @@ struct TimeSamples { } friend size_t hash_value(TimeSamples const &ts) { - size_t h = 0; - boost::hash_combine(h, ts.valueRep); - boost::hash_combine(h, ts.times); - boost::hash_combine(h, ts.values); - boost::hash_combine(h, ts.valuesFileOffset); - return h; + return TfHash::Combine( + ts.valueRep, + ts.times, + ts.values, + ts.valuesFileOffset + ); } friend std::ostream & @@ -271,7 +271,7 @@ struct _SectionName { struct _Hasher { template inline size_t operator()(const T &val) const { - return boost::hash()(val); + return TfHash()(val); } }; @@ -350,9 +350,10 @@ class CrateFile return !(*this == other); } friend size_t tbb_hasher(ZeroCopySource const &z) { - size_t seed = reinterpret_cast(z._addr); - boost::hash_combine(seed, z._numBytes); - return seed; + return TfHash::Combine( + reinterpret_cast(z._addr), + z._numBytes + ); } // Return true if the refcount is nonzero. @@ -590,9 +591,10 @@ class CrateFile } friend size_t hash_value(const Field &f) { _Hasher h; - size_t result = h(f.tokenIndex); - boost::hash_combine(result, f.valueRep); - return result; + return TfHash::Combine( + h(f.tokenIndex), + f.valueRep + ); } TokenIndex tokenIndex; ValueRep valueRep; @@ -615,10 +617,11 @@ class CrateFile } friend size_t hash_value(Spec const &s) { _Hasher h; - size_t result = h(s.pathIndex); - boost::hash_combine(result, s.fieldSetIndex); - boost::hash_combine(result, s.specType); - return result; + return TfHash::Combine( + h(s.pathIndex), + s.fieldSetIndex, + s.specType + ); } PathIndex pathIndex; FieldSetIndex fieldSetIndex; @@ -652,10 +655,11 @@ class CrateFile } friend size_t hash_value(Spec_0_0_1 const &s) { _Hasher h; - size_t result = h(s.pathIndex); - boost::hash_combine(result, s.fieldSetIndex); - boost::hash_combine(result, s.specType); - return result; + return TfHash::Combine( + h(s.pathIndex), + s.fieldSetIndex, + s.specType + ); } PathIndex pathIndex; FieldSetIndex fieldSetIndex; diff --git a/pxr/usd/usd/instanceCache.h b/pxr/usd/usd/instanceCache.h index 36c97b2b2b..0a25a7e30c 100644 --- a/pxr/usd/usd/instanceCache.h +++ b/pxr/usd/usd/instanceCache.h @@ -261,7 +261,7 @@ class Usd_InstanceCache // Mapping from instance key <-> prototype prim path. // This stores the path of the prototype prim that should be used // for all instanceable prim indexes with the given instance key. - typedef TfHashMap > + typedef TfHashMap _InstanceKeyToPrototypeMap; typedef TfHashMap _PrototypeToInstanceKeyMap; @@ -288,7 +288,7 @@ class Usd_InstanceCache // These maps contain lists of pending changes and are the only containers // that should be modified during registration and unregistration. typedef TfHashMap< - Usd_InstanceKey, _PrimIndexPaths, boost::hash > + Usd_InstanceKey, _PrimIndexPaths, TfHash> _InstanceKeyToPrimIndexesMap; _InstanceKeyToPrimIndexesMap _pendingAddedPrimIndexes; _InstanceKeyToPrimIndexesMap _pendingRemovedPrimIndexes; diff --git a/pxr/usd/usd/instanceKey.cpp b/pxr/usd/usd/instanceKey.cpp index 1f3ebde12b..51a045a8b8 100644 --- a/pxr/usd/usd/instanceKey.cpp +++ b/pxr/usd/usd/instanceKey.cpp @@ -25,8 +25,7 @@ #include "pxr/usd/usd/instanceKey.h" #include "pxr/usd/usd/resolver.h" #include "pxr/usd/pcp/primIndex.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -140,13 +139,12 @@ Usd_InstanceKey::operator==(const Usd_InstanceKey& rhs) const size_t Usd_InstanceKey::_ComputeHash() const { - size_t hash = hash_value(_pcpInstanceKey); - for (const Usd_ClipSetDefinition& clipDefs: _clipDefs) { - boost::hash_combine(hash, clipDefs.GetHash()); - } - boost::hash_combine(hash, _mask); - boost::hash_combine(hash, _loadRules); - return hash; + return TfHash::Combine( + _pcpInstanceKey, + _clipDefs, + _mask, + _loadRules + ); } std::ostream & diff --git a/pxr/usd/usd/object.cpp b/pxr/usd/usd/object.cpp index a4543d47e9..f1b37c36d2 100644 --- a/pxr/usd/usd/object.cpp +++ b/pxr/usd/usd/object.cpp @@ -412,11 +412,13 @@ size_t hash_value(const UsdObject &obj) { size_t seed = 510-922-3000; - boost::hash_combine(seed, long(obj._type)); - boost::hash_combine(seed, obj._prim); - boost::hash_combine(seed, obj._proxyPrimPath); - boost::hash_combine(seed, obj._propName.Hash()); - return seed; + return TfHash::Combine( + seed, + long(obj._type), + obj._prim, + obj._proxyPrimPath, + obj._propName.Hash() + ); } std::string diff --git a/pxr/usd/usd/prim.cpp b/pxr/usd/usd/prim.cpp index dacbb72b86..e410d52ccc 100644 --- a/pxr/usd/usd/prim.cpp +++ b/pxr/usd/usd/prim.cpp @@ -54,8 +54,7 @@ #include "pxr/base/tf/ostreamMethods.h" #include "pxr/base/tf/pxrTslRobinMap/robin_set.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -1670,7 +1669,7 @@ struct UsdPrim_TargetFinder WorkSingularTask _consumerTask; Predicate const &_predicate; tbb::concurrent_queue _workQueue; - tbb::concurrent_unordered_set > _seenPrims; + tbb::concurrent_unordered_set _seenPrims; SdfPathVector _result; bool _recurse; }; diff --git a/pxr/usd/usd/primDataHandle.h b/pxr/usd/usd/primDataHandle.h index 46e8df0dc0..66929a796f 100644 --- a/pxr/usd/usd/primDataHandle.h +++ b/pxr/usd/usd/primDataHandle.h @@ -26,7 +26,8 @@ #include "pxr/pxr.h" #include "pxr/usd/usd/api.h" -#include +#include "pxr/base/tf/hash.h" + #include PXR_NAMESPACE_OPEN_SCOPE @@ -126,7 +127,7 @@ class Usd_PrimDataHandle // Provide hash_value. friend size_t hash_value(const Usd_PrimDataHandle &h) { - return boost::hash_value(h._p.get()); + return TfHash()(h._p.get()); } friend element_type *get_pointer(const Usd_PrimDataHandle &h) { diff --git a/pxr/usd/usd/primFlags.h b/pxr/usd/usd/primFlags.h index 6c260510d0..a38cc398ce 100644 --- a/pxr/usd/usd/primFlags.h +++ b/pxr/usd/usd/primFlags.h @@ -76,8 +76,7 @@ #include "pxr/usd/usd/api.h" #include "pxr/base/arch/hints.h" #include "pxr/base/tf/bitUtils.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -275,10 +274,9 @@ class Usd_PrimFlagsPredicate // hash overload. friend size_t hash_value(const Usd_PrimFlagsPredicate &p) { - size_t hash = p._mask.to_ulong(); - boost::hash_combine(hash, p._values.to_ulong()); - boost::hash_combine(hash, p._negate); - return hash; + return TfHash::Combine( + p._mask.to_ulong(), p._values.to_ulong(), p._negate + ); } // Whether or not to negate the predicate's result. diff --git a/pxr/usd/usd/shared.h b/pxr/usd/usd/shared.h index dc0518b288..d8ccd9b495 100644 --- a/pxr/usd/usd/shared.h +++ b/pxr/usd/usd/shared.h @@ -26,8 +26,8 @@ #include "pxr/pxr.h" #include "pxr/usd/usd/api.h" +#include "pxr/base/tf/hash.h" -#include #include #include @@ -105,8 +105,7 @@ struct Usd_Shared // hash_value. friend inline size_t hash_value(Usd_Shared const &sh) { - using boost::hash_value; - return hash_value(sh._held->data); + return TfHash()(sh._held->data); } private: boost::intrusive_ptr> _held; diff --git a/pxr/usd/usd/stageCache.cpp b/pxr/usd/usd/stageCache.cpp index e13db36496..a7f0b96b32 100644 --- a/pxr/usd/usd/stageCache.cpp +++ b/pxr/usd/usd/stageCache.cpp @@ -25,12 +25,12 @@ #include "pxr/usd/usd/stageCache.h" #include "pxr/usd/sdf/layer.h" +#include "pxr/base/tf/hash.h" #include "pxr/usd/usd/debugCodes.h" #include "pxr/usd/usd/stage.h" #include "pxr/usd/ar/resolverContext.h" -#include #include #include #include diff --git a/pxr/usd/usd/stageLoadRules.cpp b/pxr/usd/usd/stageLoadRules.cpp index ee0540d73c..7ee24a709e 100644 --- a/pxr/usd/usd/stageLoadRules.cpp +++ b/pxr/usd/usd/stageLoadRules.cpp @@ -24,12 +24,11 @@ #include "pxr/pxr.h" #include "pxr/usd/usd/stageLoadRules.h" #include "pxr/base/tf/diagnostic.h" +#include "pxr/base/tf/hash.h" #include "pxr/base/tf/ostreamMethods.h" #include "pxr/base/tf/registryManager.h" #include "pxr/base/tf/stl.h" -#include - #include PXR_NAMESPACE_OPEN_SCOPE @@ -341,8 +340,7 @@ operator<<(std::ostream &os, UsdStageLoadRules const &rules) size_t hash_value(UsdStageLoadRules const &rules) { - boost::hash > > h; - return h(rules._rules); + return TfHash()(rules._rules); } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usd/stagePopulationMask.cpp b/pxr/usd/usd/stagePopulationMask.cpp index acac0c4897..0d67c0b5ba 100644 --- a/pxr/usd/usd/stagePopulationMask.cpp +++ b/pxr/usd/usd/stagePopulationMask.cpp @@ -24,10 +24,9 @@ #include "pxr/pxr.h" #include "pxr/usd/usd/stagePopulationMask.h" #include "pxr/base/tf/diagnostic.h" +#include "pxr/base/tf/hash.h" #include "pxr/base/tf/ostreamMethods.h" -#include - #include PXR_NAMESPACE_OPEN_SCOPE @@ -272,8 +271,7 @@ operator<<(std::ostream &os, UsdStagePopulationMask const &mask) size_t hash_value(UsdStagePopulationMask const &mask) { - boost::hash > h; - return h(mask._paths); + return TfHash()(mask._paths); } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usd/testenv/testUsdCollectionAPI.py b/pxr/usd/usd/testenv/testUsdCollectionAPI.py index 002f1a4359..06699cea3e 100644 --- a/pxr/usd/usd/testenv/testUsdCollectionAPI.py +++ b/pxr/usd/usd/testenv/testUsdCollectionAPI.py @@ -662,6 +662,15 @@ def test_ExplicitOnlyAndIncludeRoot(self): self.assertEqual( Usd.ComputeIncludedPathsFromCollection(query, stage), []) + def test_HashMembershipQuery(self): + self.assertEqual( + hash(Usd.UsdCollectionMembershipQuery()), + hash(Usd.UsdCollectionMembershipQuery()) + ) + self.assertEqual( + hash(Usd.CollectionAPI.Get(testPrim, 'allGeom').ComputeMembershipQuery()), + hash(Usd.CollectionAPI.Get(testPrim, 'allGeom').ComputeMembershipQuery()) + ) if __name__ == "__main__": unittest.main() diff --git a/pxr/usd/usd/testenv/testUsdStageLoadUnload.py b/pxr/usd/usd/testenv/testUsdStageLoadUnload.py index 064ce4f133..49707dbbcc 100644 --- a/pxr/usd/usd/testenv/testUsdStageLoadUnload.py +++ b/pxr/usd/usd/testenv/testUsdStageLoadUnload.py @@ -426,7 +426,13 @@ def addPayload(prim): '/other/child/none/child/all/two/prim']) self.assertEqual(testStage.GetLoadRules(), r) - + + def test_HashLoadRules(self): + self.assertEqual(Usd.StageLoadRules(), Usd.StageLoadRules()) + self.assertEqual(Usd.StageLoadRules.LoadAll(), + Usd.StageLoadRules.LoadAll()) + self.assertEqual(Usd.StageLoadRules.LoadNone(), + Usd.StageLoadRules.LoadNone()) def test_LoadAndUnload(self): """Test Stage::LoadUnload thoroughly, as all other requests funnel into it. diff --git a/pxr/usd/usd/timeCode.h b/pxr/usd/usd/timeCode.h index cf0f7a1711..c96c161aa3 100644 --- a/pxr/usd/usd/timeCode.h +++ b/pxr/usd/usd/timeCode.h @@ -29,8 +29,7 @@ #include "pxr/usd/sdf/timeCode.h" #include "pxr/base/arch/hints.h" #include "pxr/base/tf/staticTokens.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -195,7 +194,7 @@ class UsdTimeCode { /// Hash function. friend size_t hash_value(const UsdTimeCode &time) { - return boost::hash_value(time._value); + return TfHash()(time._value); } private: diff --git a/pxr/usd/usd/wrapPrimFlags.cpp b/pxr/usd/usd/wrapPrimFlags.cpp index c5b795eeb7..7c0b3e9380 100644 --- a/pxr/usd/usd/wrapPrimFlags.cpp +++ b/pxr/usd/usd/wrapPrimFlags.cpp @@ -22,6 +22,7 @@ // language governing permissions and limitations under the Apache License. // #include "pxr/pxr.h" +#include "pxr/base/tf/hash.h" #include "pxr/usd/usd/prim.h" #include "pxr/usd/usd/primFlags.h" @@ -30,7 +31,6 @@ #include #include #include -#include #include @@ -80,13 +80,11 @@ namespace { // Hash implementations. size_t __hash__Term(const Usd_Term &t) { - size_t h = static_cast(t.flag); - boost::hash_combine(h, t.negated); - return h; + return TfHash::Combine(t.flag, t.negated); } size_t __hash__Predicate(const Usd_PrimFlagsPredicate &p) { - return hash_value(p); + return TfHash{}(p); } // Call implementations.