Skip to content

Commit

Permalink
Merge pull request #775 from marktucker/dev_houdini_stagecache_anonymous
Browse files Browse the repository at this point in the history
[Houdini] Provide support for adding in-memory stages to the GusdStageCache

(Internal change: 1947497)
  • Loading branch information
pixar-oss committed Mar 14, 2019
2 parents 424b48a + 9a41a30 commit 92c870c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
14 changes: 12 additions & 2 deletions third_party/houdini/lib/gusd/USD_DataCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ GusdUSD_DataCache::ShouldClearPrim(
// Always clear expired prims.
return true;
}
const std::string& path = prim.GetStage()->GetRootLayer()->GetRealPath();
return stagesToClear.contains(path);
if (prim.GetStage()->GetRootLayer()->IsAnonymous())
{
const std::string& path =
prim.GetStage()->GetRootLayer()->GetIdentifier();
return stagesToClear.contains(path);
}
else
{
const std::string& path =
prim.GetStage()->GetRootLayer()->GetRealPath();
return stagesToClear.contains(path);
}
}


Expand Down
4 changes: 3 additions & 1 deletion third_party/houdini/lib/gusd/boundsCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ GusdBoundsCache::_ComputeBound(
if( !prim.IsValid() )
return false;

TfToken stageId( prim.GetStage()->GetRootLayer()->GetRealPath() );
TfToken stageId( prim.GetStage()->GetRootLayer()->IsAnonymous()
? prim.GetStage()->GetRootLayer()->GetIdentifier()
: prim.GetStage()->GetRootLayer()->GetRealPath() );

MapType::accessor accessor;
if( !m_map.find( accessor, Key( stageId, includedPurposes ))) {
Expand Down
31 changes: 31 additions & 0 deletions third_party/houdini/lib/gusd/stageCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ class GusdStageCache::_Impl
void FindStages(const UT_StringSet& paths,
UT_Set<UsdStageRefPtr>& stages) const;

void InsertStage(UsdStageRefPtr &stage,
const UT_StringRef& path,
const GusdStageOpts& opts,
const GusdStageEditPtr& edit);

/// Load a range of [start,end) prims from the cache. The range corresponds
/// to a *subset* of the prims in \p primPaths.
/// The \p rangeFn functor must implement `operator()(exint)` which, given
Expand Down Expand Up @@ -1324,6 +1329,23 @@ GusdStageCache::_Impl::FindStages(const UT_StringSet& paths,
}


void
GusdStageCache::_Impl::InsertStage(UsdStageRefPtr &stage,
const UT_StringRef& path,
const GusdStageOpts& opts,
const GusdStageEditPtr& edit)
{
TF_DEBUG(GUSD_STAGECACHE).Msg(
"[GusdStageCache::InsertStage] Inserting stage @%s@\n",
path.c_str());

_StageMap::accessor a;
if(stage && _stageMap.insert(a, _StageKey(path, opts, edit))) {
a->second = stage;
}
}


UsdStageRefPtr
GusdStageCache::_MaskedStageCache::FindStage(const SdfPath& primPath)
{
Expand Down Expand Up @@ -1743,6 +1765,15 @@ GusdStageCacheWriter::FindStages(const UT_StringSet& paths,
}


void
GusdStageCacheWriter::InsertStage(UsdStageRefPtr &stage,
const UT_StringRef& path,
const GusdStageOpts& opts,
const GusdStageEditPtr& edit)
{
_cache._impl->InsertStage(stage, path, opts, edit);
}

void
GusdStageCacheWriter::ReloadStages(const UT_StringSet& paths)
{
Expand Down
10 changes: 10 additions & 0 deletions third_party/houdini/lib/gusd/stageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ class GUSD_API GusdStageCacheWriter : public GusdStageCacheReader
void FindStages(const UT_StringSet& paths,
UT_Set<UsdStageRefPtr>& stages);

/// Insert a stage into our cache. The lifetime of this stage is not
/// fully controlled by this cache. The cache is just a holder for the
/// stage for as long as the gusd library is allowed access to it (until
/// it is destroyed by the external owner, which must then call Clear
/// with the same path.
void InsertStage(UsdStageRefPtr &stage,
const UT_StringRef& path,
const GusdStageOpts& opts,
const GusdStageEditPtr& edit);

/// \section GusdStageCacheWriter_ReloadAndClear Reloading And Clearing
///
/// During active sessions, the contents of a cache may be refreshed
Expand Down

0 comments on commit 92c870c

Please sign in to comment.