7#ifndef PXR_USD_PCP_CACHE_H
8#define PXR_USD_PCP_CACHE_H
11#include "pxr/usd/pcp/api.h"
12#include "pxr/usd/pcp/dependency.h"
13#include "pxr/usd/pcp/errors.h"
14#include "pxr/usd/pcp/mapFunction.h"
15#include "pxr/usd/pcp/primIndex.h"
16#include "pxr/usd/pcp/propertyIndex.h"
18#include "pxr/usd/sdf/path.h"
19#include "pxr/usd/sdf/pathTable.h"
21#include "pxr/usd/ar/ar.h"
24#include "pxr/base/tf/functionRef.h"
25#include "pxr/base/tf/hashset.h"
29#include <unordered_set>
32PXR_NAMESPACE_OPEN_SCOPE
37class Pcp_Dependencies;
93 const std::string& fileFormatTarget = std::string(),
118 return layerStack == _layerStack;
153 using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
155 PayloadSet const &GetIncludedPayloads()
const;
170 const SdfPathSet & pathsToExclude,
206 const std::vector<std::string>& layersToUnmute,
208 std::vector<std::string>* newLayersMuted =
nullptr,
209 std::vector<std::string>* newLayersUnmuted =
235 const std::string& layerIdentifier,
236 std::string* canonicalMutedLayerIdentifier
257 PcpErrorVector *allErrors);
299 template <
class ChildrenPredicate,
class PayloadPredicate>
301 PcpErrorVector *allErrors,
302 const ChildrenPredicate &childrenPred,
303 const PayloadPredicate &payloadPred) {
305 childrenPred, payloadPred,
306 "Pcp",
"ComputePrimIndexesInParallel");
312 template <
class ChildrenPredicate,
class PayloadPredicate>
314 PcpErrorVector *allErrors,
315 const ChildrenPredicate &childrenPred,
316 const PayloadPredicate &payloadPred,
317 const char *mallocTag1,
318 const char *mallocTag2) {
320 childrenPred, payloadPred,
321 mallocTag1, mallocTag2);
326 template <
class ChildrenPredicate,
class PayloadPredicate>
328 PcpErrorVector *allErrors,
329 const ChildrenPredicate &childrenPred,
330 const PayloadPredicate &payloadPred) {
331 _UntypedIndexingChildrenPredicate cp(&childrenPred);
332 _UntypedIndexingPayloadPredicate pp(&payloadPred);
333 _ComputePrimIndexesInParallel(paths, allErrors, cp, pp,
334 "Pcp",
"ComputePrimIndexesInParallel");
340 template <
class ChildrenPredicate,
class PayloadPredicate>
342 PcpErrorVector *allErrors,
343 const ChildrenPredicate &childrenPred,
344 const PayloadPredicate &payloadPred,
345 const char *mallocTag1,
346 const char *mallocTag2) {
347 _UntypedIndexingChildrenPredicate cp(&childrenPred);
348 _UntypedIndexingPayloadPredicate pp(&payloadPred);
349 _ComputePrimIndexesInParallel(paths, allErrors, cp, pp,
350 mallocTag1, mallocTag2);
361 template <
class Callback>
366 _ForEachPrimIndex(fn);
394 SdfPathVector *paths,
396 const SdfSpecHandle &stopProperty,
397 bool includeStopProperty,
398 SdfPathVector *deletedPaths,
399 PcpErrorVector *allErrors);
413 SdfPathVector *paths,
415 const SdfSpecHandle &stopProperty,
416 bool includeStopProperty,
417 SdfPathVector *deletedPaths,
418 PcpErrorVector *allErrors);
442 const PcpLayerStackPtrVector&
448 template <
class Callback>
453 _ForEachLayerStack(fn);
473 PcpDependencyFlags depMask,
476 bool filterForExistingCachesOnly)
const;
491 PcpDependencyFlags depMask,
494 bool filterForExistingCachesOnly)
const;
506 const SdfLayerHandle& layer,
507 SdfPath* allowedPathInLayer)
const;
524 std::map<SdfPath, std::vector<std::string>, SdfPath::FastLessThan>
555 const TfToken &attributeName)
const;
564 const SdfPath &primIndexPath)
const;
570 const PcpLayerStackPtr &layerStack)
const;
575 const std::unordered_set<std::string>&
578 const PcpLayerStackPtr &layerStack)
const;
643 friend class Pcp_Dependencies;
644 friend class Pcp_Statistics;
646 struct _ParallelIndexer;
661 struct _UntypedIndexingChildrenPredicate {
662 _UntypedIndexingChildrenPredicate() : pred(nullptr), invoke(nullptr) {}
663 template <
class Pred>
664 explicit _UntypedIndexingChildrenPredicate(
const Pred *pred)
665 : pred(pred), invoke(_Invoke<Pred>) {}
669 return invoke(pred, index, childNamesToCompose);
672 template <
class Pred>
673 static bool _Invoke(
const void *pred,
const PcpPrimIndex &index,
675 return (*
static_cast<const Pred *
>(pred))(index, namesToCompose);
683 struct _UntypedIndexingPayloadPredicate {
684 template <
class Pred>
685 explicit _UntypedIndexingPayloadPredicate(
const Pred *pred)
686 : pred(pred), invoke(_Invoke<Pred>) {}
688 inline bool operator()(
const SdfPath &path)
const {
689 return invoke(pred, path);
692 template <
class Pred>
693 static bool _Invoke(
const void *pred,
const SdfPath &path) {
694 return (*
static_cast<const Pred *
>(pred))(path);
697 bool (*invoke)(
const void *,
const SdfPath &);
702 _ComputePrimIndexWithCompatibleInputs(
704 PcpErrorVector *allErrors);
708 Pcp_ComputePrimIndexWithCompatibleInputs(
711 PcpErrorVector *allErrors);
715 void _ComputePrimIndexesInParallel(
716 const SdfPathVector &paths,
717 PcpErrorVector *allErrors,
718 _UntypedIndexingChildrenPredicate childrenPred,
719 _UntypedIndexingPayloadPredicate payloadPred,
720 const char *mallocTag1,
721 const char *mallocTag2);
724 void _RemovePrimAndPropertyCaches(
const SdfPath& root,
738 void _ForEachPrimIndex(
742 void _ForEachLayerStack(
743 const TfFunctionRef<
void(
const PcpLayerStackPtr&)>& fn)
const;
762 const std::string _fileFormatTarget;
767 PcpLayerStackRefPtr _layerStack;
776 typedef Pcp_LayerStackRegistryRefPtr _LayerStackCache;
781 _LayerStackCache _layerStackCache;
782 _PrimIndexCache _primIndexCache;
783 _PropertyIndexCache _propertyIndexCache;
784 std::unique_ptr<Pcp_Dependencies> _primDependencies;
787 std::unique_ptr<_ParallelIndexer> _parallelIndexer;
790PXR_NAMESPACE_CLOSE_SCOPE
Types of changes per cache.
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Returns the payloads requested for inclusion.
void ComputePrimIndexesInParallel(const SdfPathVector &paths, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred, const char *mallocTag1, const char *mallocTag2)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PCP_API void ReloadReferences(PcpChanges *changes, const SdfPath &primPath)
Reload every layer used by the prim at primPath that's across a reference or payload.
PCP_API const std::unordered_set< std::string > & GetExpressionVariablesFromLayerStackUsedByPrim(const SdfPath &primIndexPath, const PcpLayerStackPtr &layerStack) const
Returns the set of expression variables in layerStack that are used by the prim index at primIndexPat...
void ForEachPrimIndex(const Callback &callback) const
Run the given callback on every prim index in the cache.
PCP_API void Reload(PcpChanges *changes)
Reload the layers of the layer stack, except session layers and sublayers of session layers.
PCP_API void RequestPayloads(const SdfPathSet &pathsToInclude, const SdfPathSet &pathsToExclude, PcpChanges *changes=NULL)
Request payloads to be included or excluded from composition.
PCP_API const PcpPropertyIndex & ComputePropertyIndex(const SdfPath &propPath, PcpErrorVector *allErrors)
Compute and return a reference to the cached result for the property index for the given path.
PCP_API const PcpLayerStackIdentifier & GetLayerStackIdentifier() const
Get the identifier of the layerStack used for composition.
PCP_API const PcpPrimIndex & ComputePrimIndex(const SdfPath &primPath, PcpErrorVector *allErrors)
Compute and return a reference to the cached result for the prim index for the given path.
PCP_API void ComputeAttributeConnectionPaths(const SdfPath &attributePath, SdfPathVector *paths, bool localOnly, const SdfSpecHandle &stopProperty, bool includeStopProperty, SdfPathVector *deletedPaths, PcpErrorVector *allErrors)
Compute the attribute connection paths for the attribute at attributePath into paths.
void ComputePrimIndexesInParallel(const SdfPath &path, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred, const char *mallocTag1, const char *mallocTag2)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PCP_API PcpVariantFallbackMap GetVariantFallbacks() const
Get the list of fallbacks to attempt to use when evaluating variant sets that lack an authored select...
PCP_API SdfLayerHandleSet GetUsedRootLayers() const
Returns set of all root layers used by this cache.
PCP_API PcpLayerStackPtr GetLayerStack() const
Get the layer stack for GetLayerStackIdentifier().
PCP_API PcpLayerStackRefPtr ComputeLayerStack(const PcpLayerStackIdentifier &identifier, PcpErrorVector *allErrors)
Returns the layer stack for identifier if it exists, otherwise creates a new layer stack for identifi...
PCP_API void Apply(const PcpCacheChanges &changes, PcpLifeboat *lifeboat)
Apply the changes in changes.
PCP_API void RequestLayerMuting(const std::vector< std::string > &layersToMute, const std::vector< std::string > &layersToUnmute, PcpChanges *changes=nullptr, std::vector< std::string > *newLayersMuted=nullptr, std::vector< std::string > *newLayersUnmuted=nullptr)
Request layers to be muted or unmuted in this cache.
PCP_API const PcpPrimIndex * FindPrimIndex(const SdfPath &primPath) const
Returns a pointer to the cached computed prim index for the given path, or NULL if it has not been co...
PCP_API bool IsPossibleDynamicFileFormatArgumentField(const TfToken &field) const
Returns true if the given field is the name of a field that was composed while generating dynamic fil...
PCP_API const std::vector< std::string > & GetMutedLayers() const
Returns the list of canonical identifiers for muted layers in this cache.
PCP_API bool IsPossibleDynamicFileFormatArgumentAttribute(const TfToken &attributeName) const
Returns true if the given attributeName is the name of an attribute whose default value field was com...
PCP_API const PcpLayerStackPtrVector & FindAllLayerStacksUsingLayer(const SdfLayerHandle &layer) const
Returns every computed & cached layer stack that includes layer.
PCP_API bool IsLayerMuted(const std::string &layerIdentifier) const
Returns true if the layer specified by layerIdentifier is muted in this cache, false otherwise.
bool HasRootLayerStack(PcpLayerStackRefPtr const &layerStack) const
Return true if this cache's root layer stack is layerStack, false otherwise.
PCP_API void SetVariantFallbacks(const PcpVariantFallbackMap &map, PcpChanges *changes=NULL)
Set the list of fallbacks to attempt to use when evaluating variant sets that lack an authored select...
void ComputePrimIndexesInParallel(const SdfPath &path, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred)
Compute PcpPrimIndexes in the subtree rooted at path in parallel, recursing to children based on the ...
PCP_API PcpLayerStackPtr FindLayerStack(const PcpLayerStackIdentifier &identifier) const
Returns the layer stack for identifier if it has been computed and cached, otherwise returns NULL.
PCP_API PcpPrimIndexInputs GetPrimIndexInputs()
Returns parameter object containing all inputs for the prim index computation used by this cache.
PCP_API std::vector< std::string > GetInvalidSublayerIdentifiers() const
Returns a vector of sublayer asset paths used in the layer stack that didn't resolve to valid assets.
PCP_API const PcpPropertyIndex * FindPropertyIndex(const SdfPath &propPath) const
Returns a pointer to the cached computed property index for the given path, or NULL if it has not bee...
PCP_API bool UsesLayerStack(const PcpLayerStackPtr &layerStack) const
Return true if layerStack is used by this cache in its composition, false otherwise.
PCP_API bool IsUsd() const
Return true if the cache is configured in Usd mode.
PCP_API bool HasRootLayerStack(PcpLayerStackPtr const &layerStack) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
PCP_API bool IsInvalidAssetPath(const std::string &resolvedAssetPath) const
Returns true if resolvedAssetPath was used by a prim (e.g.
PCP_API const SdfPathVector & GetPrimsUsingExpressionVariablesFromLayerStack(const PcpLayerStackPtr &layerStack) const
Returns the list of prim index paths that depend on one or more expression variables from layerStack.
PCP_API size_t GetUsedLayersRevision() const
Return a number that can be used to determine whether or not the set of layers used by this cache may...
PCP_API bool CanHaveOpinionForSite(const SdfPath &localPcpSitePath, const SdfLayerHandle &layer, SdfPath *allowedPathInLayer) const
Returns true if an opinion for the site at localPcpSitePath in the cache's layer stack can be provide...
PCP_API const PcpDynamicFileFormatDependencyData & GetDynamicFileFormatArgumentDependencyData(const SdfPath &primIndexPath) const
Returns the dynamic file format dependency data object for the prim index with the given primIndexPat...
PCP_API bool HasAnyDynamicFileFormatArgumentFieldDependencies() const
Returns true if any prim index in this cache has a dependency on a dynamic file format argument field...
PCP_API void ComputeRelationshipTargetPaths(const SdfPath &relationshipPath, SdfPathVector *paths, bool localOnly, const SdfSpecHandle &stopProperty, bool includeStopProperty, SdfPathVector *deletedPaths, PcpErrorVector *allErrors)
Compute the relationship target paths for the relationship at relationshipPath into paths.
void ComputePrimIndexesInParallel(const SdfPathVector &paths, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred)
Vectorized form of ComputePrimIndexesInParallel().
PCP_API PcpDependencyVector FindSiteDependencies(const SdfLayerHandle &siteLayer, const SdfPath &sitePath, PcpDependencyFlags depMask, bool recurseOnSite, bool recurseOnIndex, bool filterForExistingCachesOnly) const
Returns dependencies on the given site of scene description, as discovered by the cached index comput...
PCP_API PcpCache(const PcpLayerStackIdentifier &layerStackIdentifier, const std::string &fileFormatTarget=std::string(), bool usd=false)
Construct a PcpCache to compose results for the layer stack identified by layerStackIdentifier.
PCP_API SdfLayerHandleSet GetUsedLayers() const
Returns set of all layers used by this cache.
PCP_API bool IsPayloadIncluded(const SdfPath &path) const
Return true if the payload is included for the given path.
PCP_API std::map< SdfPath, std::vector< std::string >, SdfPath::FastLessThan > GetInvalidAssetPaths() const
Returns a map of prim paths to asset paths used by that prim (e.g.
PCP_API void PrintStatistics() const
Prints various statistics about the data stored in this cache.
PCP_API bool IsInvalidSublayerIdentifier(const std::string &identifier) const
Returns true if identifier was used as a sublayer path in a layer stack but did not identify a valid ...
PCP_API bool IsLayerMuted(const SdfLayerHandle &anchorLayer, const std::string &layerIdentifier, std::string *canonicalMutedLayerIdentifier=nullptr) const
Returns true if the layer specified by layerIdentifier is muted in this cache, false otherwise.
void ForEachLayerStack(const Callback &callback) const
Run the given callbcack on every layer stack used by prim indexes in the cache.
PCP_API PcpDependencyVector FindSiteDependencies(const PcpLayerStackPtr &siteLayerStack, const SdfPath &sitePath, PcpDependencyFlags depMask, bool recurseOnSite, bool recurseOnIndex, bool filterForExistingCachesOnly) const
Returns dependencies on the given site of scene description, as discovered by the cached index comput...
PCP_API bool HasAnyDynamicFileFormatArgumentAttributeDependencies() const
Returns true if any prim index in this cache has a dependency on a dynamic file format argument attri...
PCP_API const std::string & GetFileFormatTarget() const
Returns the file format target this cache is configured for.
Represents a stack of layers that contribute opinions to composition.
Arguments used to identify a layer stack.
Structure used to temporarily retain layers and layerStacks within a code block.
A function that maps values from one namespace (and time domain) to another.
PcpNode represents a node in an expression tree for compositing scene description.
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
PcpPropertyIndex is an index of all sites in scene description that contribute opinions to a specific...
A path value used to locate objects in layers or scenegraphs.
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Base class for all Sdf spec classes.
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
Token for efficient comparison, assignment, and hashing of known strings.
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
std::vector< TfToken > TfTokenVector
Convenience types.
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap