Skip to content

Commit 8a43c77

Browse files
committed
Merge pull request #2190 from nvmkuruc/usdgeomhash
Replace boost hash usage with TfHash in pxr/usd/usdGeom (Internal change: 2269112)
2 parents 363c02d + c6901f6 commit 8a43c77

6 files changed

Lines changed: 34 additions & 16 deletions

File tree

pxr/usd/usdGeom/bboxCache.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "pxr/base/work/withScopedParallelism.h"
4141

42+
#include "pxr/base/tf/hash.h"
4243
#include "pxr/base/tf/pyLock.h"
4344
#include "pxr/base/tf/stringUtils.h"
4445
#include "pxr/base/tf/token.h"
@@ -1520,13 +1521,5 @@ UsdGeomBBoxCache::_PrimContext::ToString() const {
15201521
}
15211522
}
15221523

1523-
size_t hash_value(const UsdGeomBBoxCache::_PrimContext &key)
1524-
{
1525-
size_t hash = hash_value(key.prim);
1526-
boost::hash_combine(hash, key.instanceInheritablePurpose.Hash());
1527-
return hash;
1528-
}
1529-
1530-
15311524
PXR_NAMESPACE_CLOSE_SCOPE
15321525

pxr/usd/usdGeom/bboxCache.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "pxr/usd/usdGeom/pointInstancer.h"
3131
#include "pxr/usd/usd/attributeQuery.h"
3232
#include "pxr/base/gf/bbox3d.h"
33+
#include "pxr/base/tf/hash.h"
3334
#include "pxr/base/tf/hashmap.h"
3435
#include "pxr/base/work/dispatcher.h"
3536

@@ -541,10 +542,18 @@ class UsdGeomBBoxCache
541542
// Helper to determine if we should use extents hints for \p prim.
542543
inline bool _UseExtentsHintForPrim(UsdPrim const &prim) const;
543544

545+
// Specialize TfHashAppend for TfHash
546+
template <typename HashState>
547+
friend void TfHashAppend(HashState& h, const _PrimContext &key)
548+
{
549+
h.Append(key.prim);
550+
h.Append(key.instanceInheritablePurpose);
551+
}
552+
544553
// Need hash_value for boost to key cache entries by prim context.
545-
friend size_t hash_value(const _PrimContext &key);
554+
friend size_t hash_value(const _PrimContext &key) { return TfHash{}(key); }
546555

547-
typedef boost::hash<_PrimContext> _PrimContextHash;
556+
typedef TfHash _PrimContextHash;
548557
typedef TfHashMap<_PrimContext, _Entry, _PrimContextHash> _PrimBBoxHashMap;
549558

550559
// Finds the cache entry for the prim context if it exists.

pxr/usd/usdGeom/primvar.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,15 @@ class UsdGeomPrimvar
694694
return lhs.GetAttr().GetPath() < rhs.GetAttr().GetPath();
695695
}
696696

697+
// Specialize TfHashAppend for TfHash
698+
template <typename HashState>
699+
friend void TfHashAppend(HashState& h, const UsdGeomPrimvar& obj) {
700+
h.Append(obj.GetAttr());
701+
}
702+
697703
// hash_value overload for std/boost hash.
698-
USDGEOM_API
699704
friend size_t hash_value(const UsdGeomPrimvar &obj) {
700-
return hash_value(obj.GetAttr());
705+
return TfHash{}(obj);
701706
}
702707

703708

pxr/usd/usdGeom/testenv/testUsdGeomPrimvar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,5 +692,17 @@ def test_InvalidPrimvar(self):
692692
with self.assertRaises(RuntimeError):
693693
u1.GetElementSize()
694694

695+
def test_Hash(self):
696+
"""Validate different primvar objects referring to the same underlying
697+
property hash to the same value."""
698+
stage = Usd.Stage.CreateInMemory()
699+
mesh = UsdGeom.Mesh.Define(stage, '/mesh')
700+
meshPrimvarsAPI = UsdGeom.PrimvarsAPI(mesh)
701+
primvar = meshPrimvarsAPI.CreatePrimvar("pv", Sdf.ValueTypeNames.Int)
702+
self.assertTrue(primvar)
703+
self.assertIsNot(primvar, meshPrimvarsAPI.GetPrimvar("pv"))
704+
self.assertEqual(primvar, meshPrimvarsAPI.GetPrimvar("pv"))
705+
self.assertEqual(hash(primvar), hash(meshPrimvarsAPI.GetPrimvar("pv")))
706+
695707
if __name__ == "__main__":
696708
unittest.main()

pxr/usd/usdGeom/wrapPrimvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ _GetTimeSamplesInInterval(const UsdGeomPrimvar &self,
100100
return result;
101101
}
102102

103-
static size_t __hash__(const UsdGeomPrimvar &self) { return hash_value(self); }
103+
static size_t __hash__(const UsdGeomPrimvar &self) { return TfHash{}(self); }
104104

105105
// We override __getattribute__ for UsdGeomPrimvar to check object validity
106106
// and raise an exception instead of crashing from Python.

pxr/usd/usdGeom/xformCache.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
#include "pxr/usd/usdGeom/xformable.h"
3333

3434
#include "pxr/base/gf/matrix4d.h"
35+
#include "pxr/base/tf/hash.h"
3536
#include "pxr/base/tf/hashmap.h"
3637
#include "pxr/base/tf/token.h"
3738

38-
#include <boost/functional/hash.hpp>
39-
4039
PXR_NAMESPACE_OPEN_SCOPE
4140

4241

@@ -170,7 +169,7 @@ class UsdGeomXformCache
170169
// Helper function to get or create a new entry for a prim in the ctm cache.
171170
_Entry * _GetCacheEntryForPrim(const UsdPrim &prim);
172171

173-
typedef TfHashMap<UsdPrim, _Entry, boost::hash<UsdPrim> > _PrimHashMap;
172+
typedef TfHashMap<UsdPrim, _Entry, TfHash> _PrimHashMap;
174173
_PrimHashMap _ctmCache;
175174

176175
// The time at which this stack is querying and caching attribute values.

0 commit comments

Comments
 (0)