Skip to content

Commit 6d76738

Browse files
committed
Merge pull request #2458 from brechtvl/onetbb-atomic-usdgeom
oneTBB: tbb::atomic to std::atomic in usdGeom (Internal change: 2326830)
2 parents b3b2f1e + 9bfec01 commit 6d76738

File tree

2 files changed

+53
-55
lines changed

2 files changed

+53
-55
lines changed

pxr/usd/usdGeom/bboxCache.cpp

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class UsdGeomBBoxCache::_BBoxTask {
8787
_ThreadXformCache* _xfCaches;
8888
public:
8989
_BBoxTask() : _owner(nullptr), _xfCaches(nullptr) {}
90-
_BBoxTask(const _PrimContext& primContext,
90+
_BBoxTask(const _PrimContext& primContext,
9191
const GfMatrix4d &inverseComponentCtm,
9292
UsdGeomBBoxCache* owner, _ThreadXformCache* xfCaches)
9393
: _primContext(primContext)
@@ -186,7 +186,7 @@ class UsdGeomBBoxCache::_PrototypeBBoxResolver
186186
// In order to resolve the bounding box for prototypePrim, we need
187187
// to compute the bounding boxes for all prototypes for nested
188188
// instances.
189-
_PrototypeTask& prototypeTaskData =
189+
_PrototypeTask& prototypeTaskData =
190190
prototypeTaskStatus.first->second;
191191
prototypeTaskData.numDependencies = requiredPrototypes.size();
192192
}
@@ -207,15 +207,15 @@ class UsdGeomBBoxCache::_PrototypeBBoxResolver
207207
{
208208
UsdGeomBBoxCache::_BBoxTask(
209209
prototype, GfMatrix4d(1.0), _owner, xfCaches)();
210-
210+
211211
// Update all of the prototype prims that depended on the completed
212212
// prototype and dispatch new tasks for those whose dependencies have
213213
// been resolved. We're guaranteed that all the entries were populated
214214
// by _PopulateTasksForPrototype, so we don't check the result of
215215
// 'find()'.
216216
const _PrototypeTask& prototypeData =
217217
prototypeTasks->find(prototype)->second;
218-
for (const auto& dependentPrototype :
218+
for (const auto& dependentPrototype :
219219
prototypeData.dependentPrototypes) {
220220
_PrototypeTask& dependentPrototypeData =
221221
prototypeTasks->find(dependentPrototype)->second;
@@ -589,7 +589,7 @@ UsdGeomBBoxCache::_ComputePointInstanceBoundsHelper(
589589
VtMatrix4dArray const &cinstanceTransforms = instanceTransforms;
590590

591591
const UsdStagePtr stage = instancer.GetPrim().GetStage();
592-
592+
593593
for (int64_t const *iid = instanceIdBegin, * const iend = iid + numIds;
594594
iid != iend; ++iid) {
595595

@@ -603,7 +603,7 @@ UsdGeomBBoxCache::_ComputePointInstanceBoundsHelper(
603603
thisBounds = ComputeUntransformedBound(protoPrim);
604604
thisBounds.Transform(cinstanceTransforms[*iid] * xform);
605605
}
606-
606+
607607
return true;
608608
}
609609

@@ -745,14 +745,14 @@ bool
745745
UsdGeomBBoxCache::_ShouldIncludePrim(const UsdPrim& prim)
746746
{
747747
TRACE_FUNCTION();
748-
749-
// If the prim is typeless or has an unknown type, it may have descendants
748+
749+
// If the prim is typeless or has an unknown type, it may have descendants
750750
// that are imageable. Hence, we include it in bbox computations.
751751
if (!prim.IsA<UsdTyped>()) {
752752
return true;
753753
}
754754

755-
// If the prim is typed it can participate in child bound accumulation only
755+
// If the prim is typed it can participate in child bound accumulation only
756756
// if it is imageable.
757757
if (!prim.IsA<UsdGeomImageable>()) {
758758
TF_DEBUG(USDGEOM_BBOX).Msg("[BBox Cache] excluded, not IMAGEABLE type. "
@@ -896,13 +896,13 @@ UsdGeomBBoxCache::_ComputePurposeInfo(
896896
// inheritable.
897897
if (prim.IsPrototype()) {
898898
if (primContext.instanceInheritablePurpose.IsEmpty()) {
899-
// If the instancing prim's purpose is not inheritable, this
899+
// If the instancing prim's purpose is not inheritable, this
900900
// prototype prim context won't provide an inheritable purpose to
901901
// its children either.
902902
entry->purposeInfo = UsdGeomImageable::PurposeInfo(
903903
UsdGeomTokens->default_, false);
904904
} else {
905-
// Otherwise this prototype can provide the instancing prim's
905+
// Otherwise this prototype can provide the instancing prim's
906906
// inheritable pupose to its children.
907907
entry->purposeInfo = UsdGeomImageable::PurposeInfo(
908908
primContext.instanceInheritablePurpose, true);
@@ -913,27 +913,27 @@ UsdGeomBBoxCache::_ComputePurposeInfo(
913913
if (parentPrim && parentPrim.GetPath() != SdfPath::AbsoluteRootPath()) {
914914
// Try and get the parent prim's purpose first. If we find it in the
915915
// cache, we can compute this prim's purpose efficiently by avoiding
916-
// the n^2 recursion which results from using the
916+
// the n^2 recursion which results from using the
917917
// UsdGeomImageable::ComputePurpose() API directly.
918-
919-
// If this prim is in a prototype then its parent prim will be too.
918+
919+
// If this prim is in a prototype then its parent prim will be too.
920920
// The parent prim's context will have the same inheritable purpose
921921
// from the instance as this prim context does.
922922
_PrimContext parentPrimContext(
923923
parentPrim, primContext.instanceInheritablePurpose);
924924
_Entry *parentEntry = _FindEntry(parentPrimContext);
925925
if (parentEntry) {
926926
if (IsRecursive) {
927-
// If this is recursive make sure the parent's purpose is
927+
// If this is recursive make sure the parent's purpose is
928928
// computed and cached first.
929929
_ComputePurposeInfo<IsRecursive>(
930930
parentEntry, parentPrimContext);
931931
entry->purposeInfo = img.ComputePurposeInfo(
932932
parentEntry->purposeInfo);
933933
return;
934934
} else {
935-
// Not recursive. just check that the parent purpose has
936-
// been computed.
935+
// Not recursive. just check that the parent purpose has
936+
// been computed.
937937
if (parentEntry->purposeInfo) {
938938
entry->purposeInfo = img.ComputePurposeInfo(
939939
parentEntry->purposeInfo);
@@ -946,7 +946,7 @@ UsdGeomBBoxCache::_ComputePurposeInfo(
946946
parentPrimContext.ToString().c_str());
947947
}
948948
}
949-
}
949+
}
950950
TF_DEBUG(USDGEOM_BBOX).Msg("[BBox Cache] Computing purpose without "
951951
"cached parent for <%s>\n",
952952
primContext.ToString().c_str());
@@ -976,7 +976,7 @@ UsdGeomBBoxCache::_ShouldPruneChildren(const UsdPrim &prim,
976976
if (prim.IsA<UsdGeomBoundable>()) {
977977
return true;
978978
}
979-
979+
980980
if (!_UseExtentsHintForPrim(prim)) {
981981
return false;
982982
}
@@ -993,9 +993,9 @@ UsdGeomBBoxCache::_FindOrCreateEntriesForPrim(
993993
const _PrimContext& primContext,
994994
std::vector<_PrimContext> *prototypePrimContexts)
995995
{
996-
// Add an entry for the prim to the cache and if the bound is already in
996+
// Add an entry for the prim to the cache and if the bound is already in
997997
// the cache, return it.
998-
//
998+
//
999999
// Note that this means we always have an entry for the given prim,
10001000
// even if that prim does not pass the predicate given to the tree
10011001
// iterator below (e.g., the prim is a class).
@@ -1012,7 +1012,7 @@ UsdGeomBBoxCache::_FindOrCreateEntriesForPrim(
10121012

10131013
// isIncluded only gets cached in the multi-threaded path for child prims,
10141014
// make sure the prim we're querying has the correct flag cached also. We
1015-
// can't do this in _ResolvePrim because we need to compute the flag for
1015+
// can't do this in _ResolvePrim because we need to compute the flag for
10161016
// children before recursing upon them.
10171017
entry->isIncluded = _ShouldIncludePrim(primContext.prim);
10181018

@@ -1023,13 +1023,13 @@ UsdGeomBBoxCache::_FindOrCreateEntriesForPrim(
10231023

10241024
TfHashSet<_PrimContext, _PrimContextHash> seenPrototypePrimContexts;
10251025

1026-
UsdPrimRange range(primContext.prim,
1026+
UsdPrimRange range(primContext.prim,
10271027
(UsdPrimIsActive && UsdPrimIsDefined && !UsdPrimIsAbstract));
10281028
for (auto it = range.begin(); it != range.end(); ++it) {
10291029
_PrimContext cachePrimContext(
10301030
*it, primContext.instanceInheritablePurpose);
10311031
_Entry *cacheEntry = _InsertEntry(cachePrimContext);
1032-
1032+
10331033
if (_ShouldPruneChildren(*it, cacheEntry)) {
10341034
// The entry already exists and is complete, we don't need
10351035
// the child entries for this query.
@@ -1040,14 +1040,14 @@ UsdGeomBBoxCache::_FindOrCreateEntriesForPrim(
10401040
// to compute bounding boxes for the prototype prims.
10411041
const UsdPrim prototype = it->GetPrototype();
10421042
// We typically compute the purpose for prims later in _ResolvePrim,
1043-
// but for an instance prim, we need to compute the purpose for this
1044-
// prim context now so that we can associate this instance's
1045-
// inheritable purpose with the prototype.
1046-
//
1047-
// Note that we recursively cache the computed purposes of all
1043+
// but for an instance prim, we need to compute the purpose for this
1044+
// prim context now so that we can associate this instance's
1045+
// inheritable purpose with the prototype.
1046+
//
1047+
// Note that we recursively cache the computed purposes of all
10481048
// cached ancestors of the prim here as we won't have necessarily
10491049
// computed them before reaching this prim. It should be safe to
1050-
// cache ancestors recursively as this code is not used in a
1050+
// cache ancestors recursively as this code is not used in a
10511051
// multithreaded context.
10521052
_ComputePurposeInfo<true>(cacheEntry, cachePrimContext);
10531053
_PrimContext prototypePrimContext(
@@ -1078,31 +1078,31 @@ UsdGeomBBoxCache::_Resolve(
10781078
// If the bound is in the cache, return it.
10791079
std::vector<_PrimContext> prototypePrimContexts;
10801080
_PrimContext primContext(prim);
1081-
_Entry *entry = _FindOrCreateEntriesForPrim(primContext,
1081+
_Entry *entry = _FindOrCreateEntriesForPrim(primContext,
10821082
&prototypePrimContexts);
10831083
if (entry && entry->isComplete) {
10841084
*bboxes = entry->bboxes;
10851085
return (!bboxes->empty());
10861086
}
10871087

10881088
WorkWithScopedParallelism([&]() {
1089-
1089+
10901090
// Resolve all prototype prims first to avoid having to synchronize
10911091
// tasks that depend on the same prototype.
10921092
if (!prototypePrimContexts.empty()) {
10931093
_PrototypeBBoxResolver bboxesForPrototypes(this);
10941094
bboxesForPrototypes.Resolve(prototypePrimContexts);
10951095
}
1096-
1096+
10971097
// XXX: This swapping out is dubious... see XXX below.
10981098
_ThreadXformCache xfCaches;
10991099
xfCaches.local().Swap(_ctmCache);
1100-
1100+
11011101
// Find the nearest ancestor prim that's a model or a subcomponent.
11021102
UsdPrim modelPrim = _GetNearestComponent(prim);
11031103
GfMatrix4d inverseComponentCtm = _ctmCache.GetLocalToWorldTransform(
11041104
modelPrim).GetInverse();
1105-
1105+
11061106
_dispatcher.Run(
11071107
_BBoxTask(primContext, inverseComponentCtm, this, &xfCaches));
11081108
_dispatcher.Wait();
@@ -1114,10 +1114,10 @@ UsdGeomBBoxCache::_Resolve(
11141114
// worker it won't populate the local xfCaches we're swapping with.
11151115
xfCaches.local().Swap(_ctmCache);
11161116
});
1117-
1117+
11181118
// Note: the map may contain unresolved entries, but future queries will
11191119
// populate them.
1120-
1120+
11211121
// If the bound is in the cache, return it.
11221122
entry = _FindEntry(primContext);
11231123
if (entry == nullptr) {
@@ -1198,10 +1198,10 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
11981198
// Setting the time redundantly will be a no-op;
11991199
xfCache.SetTime(_time);
12001200

1201-
// Compute the purpose for the entry. Note that we do not do this
1201+
// Compute the purpose for the entry. Note that we do not do this
12021202
// recursively because _ResolvePrim can be called multithreaded across
1203-
// siblings and any parent's purposes should already be cached before this
1204-
// _ResolvePrim is called.
1203+
// siblings and any parent's purposes should already be cached before this
1204+
// _ResolvePrim is called.
12051205
_ComputePurposeInfo<false>(entry, primContext);
12061206

12071207
// Check if the prim is a model and has extentsHint
@@ -1245,7 +1245,7 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
12451245
if (!_ignoreVisibility) {
12461246
_GetOrCreateVisibilityQuery(prim, &visQuery);
12471247
}
1248-
1248+
12491249
const UsdAttributeQuery& extentQuery =
12501250
_GetOrCreateExtentQuery(prim, &queries[Extent]);
12511251

@@ -1290,26 +1290,26 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
12901290

12911291
// This will be computed below if the prim has children with bounds.
12921292
GfMatrix4d localToComponentXform(1.0);
1293-
1293+
12941294
// Accumulate child bounds:
12951295
//
12961296
// 1) Filter and queue up the children to be processed.
12971297
// 2) Spawn new child tasks and wait for them to complete.
12981298
// 3) Accumulate the results into this cache entry.
12991299
//
1300-
1300+
13011301
// Compute the enclosing model's (or subcomponent's) inverse CTM.
13021302
// This will be used to compute the child bounds in model-space.
13031303
const GfMatrix4d &inverseEnclosingComponentCtm =
13041304
_IsComponentOrSubComponent(prim) ?
13051305
xfCache.GetLocalToWorldTransform(prim).GetInverse() :
13061306
inverseComponentCtm;
1307-
1307+
13081308
std::vector<std::pair<_PrimContext, _BBoxTask> > included;
13091309
// See comment in _Resolve about unloaded prims
13101310
UsdPrimSiblingRange children;
13111311
TfToken childInheritableInstancePurpose;
1312-
1312+
13131313
const bool primIsInstance = prim.IsInstance();
13141314
if (primIsInstance) {
13151315
const UsdPrim prototype = prim.GetPrototype();
@@ -1319,15 +1319,15 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
13191319
// we propagate this instance's inheritable purpose to the
13201320
// prototype's children so they inherit the correct purpose for this
13211321
// instance if needed.
1322-
childInheritableInstancePurpose =
1322+
childInheritableInstancePurpose =
13231323
entry->purposeInfo.GetInheritablePurpose();
13241324
}
13251325
else {
13261326
children = prim.GetFilteredChildren(
13271327
UsdPrimIsActive && UsdPrimIsDefined && !UsdPrimIsAbstract);
13281328
// Otherwise for standard children that are not across an instance
13291329
// boundary, pass this prim's inheritable purpose along to its
1330-
// children.
1330+
// children.
13311331
// XXX: It's worth noting that if a child of a prototype
13321332
// has a purpose opinion, then that child (and its descendants) will
13331333
// have the same computed purpose regardless of the inheritable
@@ -1339,7 +1339,7 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
13391339
// complicate the multithreaded way we resolve bboxes for prototype
13401340
// and sibling prims. This may be something to re-evaluate in the
13411341
// future.
1342-
childInheritableInstancePurpose =
1342+
childInheritableInstancePurpose =
13431343
primContext.instanceInheritablePurpose;
13441344
}
13451345

@@ -1383,7 +1383,7 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
13831383
// child prims will come from its prototype prim. The bboxes
13841384
// for these prims should already have been computed in
13851385
// _Resolve, so we don't need to schedule an additional task.
1386-
included.push_back(std::make_pair(childPrimContext,
1386+
included.push_back(std::make_pair(childPrimContext,
13871387
_BBoxTask()));
13881388
}
13891389
else {
@@ -1513,16 +1513,15 @@ UsdGeomBBoxCache::_ResolvePrim(_BBoxTask* task,
15131513
entry->isVarying ? "true" : "false");
15141514
}
15151515

1516-
std::string
1516+
std::string
15171517
UsdGeomBBoxCache::_PrimContext::ToString() const {
15181518
if (instanceInheritablePurpose.IsEmpty()) {
15191519
return prim.GetPath().GetString();
15201520
} else {
1521-
return TfStringPrintf("[%s]%s",
1522-
instanceInheritablePurpose.GetText(),
1521+
return TfStringPrintf("[%s]%s",
1522+
instanceInheritablePurpose.GetText(),
15231523
prim.GetPath().GetText());
15241524
}
15251525
}
15261526

1527-
PXR_NAMESPACE_CLOSE_SCOPE
1528-
1527+
PXR_NAMESPACE_CLOSE_SCOPE

pxr/usd/usdGeom/pch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@
181181
#include <boost/utility.hpp>
182182
#include <boost/utility/enable_if.hpp>
183183
#include <boost/variant.hpp>
184-
#include <tbb/atomic.h>
185184
#include <tbb/blocked_range.h>
186185
#include <tbb/cache_aligned_allocator.h>
187186
#include <tbb/concurrent_queue.h>

0 commit comments

Comments
 (0)