Skip to content

Commit

Permalink
usdShade: Use TfStaticData for shared UsdStageCache
Browse files Browse the repository at this point in the history
Besides being recommended practice, this avoids a hang on
Windows that could occur when the static UsdStageCache member
was destroyed during process teardown. The UsdStage objects
stored in the cache would try to use TBB in their d'tors
after the TBB library had been unloaded and its worker
threads destroyed, leading to odd deadlocks. This most
recently showed up in testUsdChecker* but also affected
imaging tests, which were disabled primarily because of
this issue.

(Internal change: 2353331)
  • Loading branch information
sunyab authored and pixar-oss committed Jan 13, 2025
1 parent 06a9c5e commit 7579b91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 5 additions & 4 deletions pxr/usd/usdShade/shaderDefParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "pxr/usd/usd/stageCache.h"

#include "pxr/base/tf/staticData.h"

PXR_NAMESPACE_OPEN_SCOPE

TF_DEFINE_PRIVATE_TOKENS(
Expand All @@ -22,7 +24,7 @@ TF_DEFINE_PRIVATE_TOKENS(
(usd)
);

UsdStageCache UsdShadeShaderDefParserPlugin::_cache;
static TfStaticData<UsdStageCache> _StageCache;

static
NdrTokenMap
Expand Down Expand Up @@ -52,11 +54,10 @@ UsdShadeShaderDefParserPlugin::Parse(
const std::string &rootLayerPath = discoveryResult.resolvedUri;

SdfLayerRefPtr rootLayer = SdfLayer::FindOrOpen(rootLayerPath);
UsdStageRefPtr stage =
UsdShadeShaderDefParserPlugin::_cache.FindOneMatching(rootLayer);
UsdStageRefPtr stage = _StageCache->FindOneMatching(rootLayer);
if (!stage) {
stage = UsdStage::Open(rootLayer);
UsdShadeShaderDefParserPlugin::_cache.Insert(stage);
_StageCache->Insert(stage);
}

if (!stage) {
Expand Down
5 changes: 0 additions & 5 deletions pxr/usd/usdShade/shaderDefParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

PXR_NAMESPACE_OPEN_SCOPE

class UsdStageCache;

/// \class UsdShadeShaderDefParserPlugin
///
/// Parses shader definitions represented using USD scene description using the
Expand All @@ -40,9 +38,6 @@ class UsdShadeShaderDefParserPlugin : public NdrParserPlugin

USDSHADE_API
const TfToken &GetSourceType() const override;

private:
static UsdStageCache _cache;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down

0 comments on commit 7579b91

Please sign in to comment.