All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PCP_CACHE_H
25 #define PCP_CACHE_H
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
29 #include "pxr/usd/pcp/dependency.h"
30 #include "pxr/usd/pcp/errors.h"
31 #include "pxr/usd/pcp/mapFunction.h"
32 #include "pxr/usd/pcp/primIndex.h"
33 #include "pxr/usd/pcp/propertyIndex.h"
34 #include "pxr/usd/sdf/declareHandles.h"
35 #include "pxr/usd/sdf/path.h"
36 #include "pxr/usd/sdf/pathTable.h"
38 #include "pxr/usd/ar/resolverContext.h"
39 #include "pxr/base/tf/declarePtrs.h"
40 #include "pxr/base/tf/hashset.h"
42 #include <memory>
43 #include <string>
44 #include <unordered_set>
45 #include <vector>
49 // Forward declarations:
50 class PcpChanges;
51 class PcpCacheChanges;
52 class Pcp_Dependencies;
54 class PcpLifeboat;
55 class PcpNodeRef;
56 class PcpMapFunction;
59 TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
91 class PcpCache
92 {
93  PcpCache(PcpCache const &) = delete;
94  PcpCache &operator=(PcpCache const &) = delete;
95 public:
106  PCP_API
107  PcpCache(const PcpLayerStackIdentifier & layerStackIdentifier,
108  const std::string& fileFormatTarget = std::string(),
109  bool usd = false);
110  PCP_API ~PcpCache();
116  PCP_API
125  PCP_API
126  PcpLayerStackPtr GetLayerStack() const;
129  PCP_API
130  bool IsUsd() const;
133  PCP_API
134  const std::string& GetFileFormatTarget() const;
138  PCP_API
147  PCP_API
148  void SetVariantFallbacks( const PcpVariantFallbackMap & map,
149  PcpChanges* changes = NULL );
152  PCP_API
153  bool IsPayloadIncluded(const SdfPath &path) const;
156  using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
157  PCP_API
158  PayloadSet const &GetIncludedPayloads() const;
171  PCP_API
172  void RequestPayloads( const SdfPathSet & pathsToInclude,
173  const SdfPathSet & pathsToExclude,
174  PcpChanges* changes = NULL );
203  PCP_API
204  void RequestLayerMuting(const std::vector<std::string>& layersToMute,
205  const std::vector<std::string>& layersToUnmute,
206  PcpChanges* changes = nullptr);
211  PCP_API
212  const std::vector<std::string>& GetMutedLayers() const;
219  PCP_API
220  bool IsLayerMuted(const std::string& layerIdentifier) const;
229  PCP_API
230  bool IsLayerMuted(const SdfLayerHandle& anchorLayer,
231  const std::string& layerIdentifier,
232  std::string* canonicalMutedLayerIdentifier
233  = nullptr) const;
237  PCP_API
250  PCP_API
251  PcpLayerStackRefPtr
252  ComputeLayerStack(const PcpLayerStackIdentifier &identifier,
253  PcpErrorVector *allErrors);
257  PCP_API
258  PcpLayerStackPtr
259  FindLayerStack(const PcpLayerStackIdentifier &identifier) const;
264  PCP_API
265  const PcpPrimIndex &
266  ComputePrimIndex(const SdfPath &primPath, PcpErrorVector *allErrors);
290  template <class ChildrenPredicate, class PayloadPredicate>
292  PcpErrorVector *allErrors,
293  const ChildrenPredicate &childrenPred,
294  const PayloadPredicate &payloadPred) {
295  ComputePrimIndexesInParallel(SdfPathVector(1, path), allErrors,
296  childrenPred, payloadPred,
297  "Pcp", "ComputePrimIndexesInParallel");
298  }
303  template <class ChildrenPredicate, class PayloadPredicate>
305  PcpErrorVector *allErrors,
306  const ChildrenPredicate &childrenPred,
307  const PayloadPredicate &payloadPred,
308  const char *mallocTag1,
309  const char *mallocTag2) {
310  ComputePrimIndexesInParallel(SdfPathVector(1, path), allErrors,
311  childrenPred, payloadPred,
312  mallocTag1, mallocTag2);
313  }
317  template <class ChildrenPredicate, class PayloadPredicate>
318  void ComputePrimIndexesInParallel(const SdfPathVector &paths,
319  PcpErrorVector *allErrors,
320  const ChildrenPredicate &childrenPred,
321  const PayloadPredicate &payloadPred) {
322  _UntypedIndexingChildrenPredicate cp(&childrenPred);
323  _UntypedIndexingPayloadPredicate pp(&payloadPred);
324  _ComputePrimIndexesInParallel(paths, allErrors, cp, pp,
325  "Pcp", "ComputePrimIndexesInParallel");
326  }
331  template <class ChildrenPredicate, class PayloadPredicate>
332  void ComputePrimIndexesInParallel(const SdfPathVector &paths,
333  PcpErrorVector *allErrors,
334  const ChildrenPredicate &childrenPred,
335  const PayloadPredicate &payloadPred,
336  const char *mallocTag1,
337  const char *mallocTag2) {
338  _UntypedIndexingChildrenPredicate cp(&childrenPred);
339  _UntypedIndexingPayloadPredicate pp(&payloadPred);
340  _ComputePrimIndexesInParallel(paths, allErrors, cp, pp,
341  mallocTag1, mallocTag2);
342  }
346  PCP_API
347  const PcpPrimIndex *
348  FindPrimIndex(const SdfPath &primPath) const;
353  PCP_API
354  const PcpPropertyIndex &
355  ComputePropertyIndex(const SdfPath &propPath, PcpErrorVector *allErrors);
359  PCP_API
360  const PcpPropertyIndex *
361  FindPropertyIndex(const SdfPath &propPath) const;
370  PCP_API
371  void
372  ComputeRelationshipTargetPaths(const SdfPath &relationshipPath,
373  SdfPathVector *paths,
374  bool localOnly,
375  const SdfSpecHandle &stopProperty,
376  bool includeStopProperty,
377  PcpErrorVector *allErrors);
386  PCP_API
387  void
388  ComputeAttributeConnectionPaths(const SdfPath &attributePath,
389  SdfPathVector *paths,
390  bool localOnly,
391  const SdfSpecHandle &stopProperty,
392  bool includeStopProperty,
393  PcpErrorVector *allErrors);
400  PCP_API
401  SdfLayerHandleSet GetUsedLayers() const;
404  PCP_API
405  SdfLayerHandleSet GetUsedRootLayers() const;
408  PCP_API
409  const PcpLayerStackPtrVector&
410  FindAllLayerStacksUsingLayer(const SdfLayerHandle& layer) const;
425  PCP_API
426  PcpDependencyVector
427  FindSiteDependencies(const PcpLayerStackPtr& siteLayerStack,
428  const SdfPath& sitePath,
429  PcpDependencyFlags depMask,
430  bool recurseOnSite,
431  bool recurseOnIndex,
432  bool filterForExistingCachesOnly) const;
443  PCP_API
444  PcpDependencyVector
445  FindSiteDependencies(const SdfLayerHandle& siteLayer,
446  const SdfPath& sitePath,
447  PcpDependencyFlags depMask,
448  bool recurseOnSite,
449  bool recurseOnIndex,
450  bool filterForExistingCachesOnly) const;
460  PCP_API
461  bool CanHaveOpinionForSite(const SdfPath& localPcpSitePath,
462  const SdfLayerHandle& layer,
463  SdfPath* allowedPathInLayer) const;
467  PCP_API
468  std::vector<std::string> GetInvalidSublayerIdentifiers() const;
474  PCP_API
475  bool IsInvalidSublayerIdentifier(const std::string& identifier) const;
479  PCP_API
480  std::map<SdfPath, std::vector<std::string>, SdfPath::FastLessThan>
481  GetInvalidAssetPaths() const;
487  PCP_API
488  bool IsInvalidAssetPath(const std::string& resolvedAssetPath) const;
492  PCP_API
498  PCP_API
499  bool IsPossibleDynamicFileFormatArgumentField(const TfToken &field) const;
505  PCP_API
508  const SdfPath &primIndexPath) const;
534  PCP_API
535  void Apply(const PcpCacheChanges& changes, PcpLifeboat* lifeboat);
543  PCP_API
544  void Reload(PcpChanges* changes);
557  PCP_API
558  void ReloadReferences(PcpChanges* changes, const SdfPath& primPath);
566  PCP_API
567  void PrintStatistics() const;
571 private:
572  friend class PcpChanges;
573  friend class Pcp_Statistics;
575  template <class ChildPredicate>
576  friend struct Pcp_ParallelIndexer;
578  // Helper struct to type-erase a children predicate for the duration of
579  // ComputePrimIndexesInParallel.
580  //
581  // This lets us achieve two goals. First, clients may pass any arbitrary
582  // type as a predicate (e.g. they do not have to derive some base class).
583  // Second, it lets us keep the parallel indexing implementation in the .cpp
584  // file, avoiding any large template code instantiation.
585  //
586  // The cost we pay is this very thin indirect call. We instantiate a
587  // function template with the client's predicate type that simply does a
588  // typecast and predicate invocation, and pass that function pointer into
589  // the implementation. There is no heap allocation, no predicate copy, no
590  // argument marshalling, etc.
591  struct _UntypedIndexingChildrenPredicate {
592  template <class Pred>
593  explicit _UntypedIndexingChildrenPredicate(const Pred *pred)
594  : pred(pred), invoke(_Invoke<Pred>) {}
596  inline bool operator()(const PcpPrimIndex &index,
597  TfTokenVector *childNamesToCompose) const {
598  return invoke(pred, index, childNamesToCompose);
599  }
600  private:
601  template <class Pred>
602  static bool _Invoke(const void *pred, const PcpPrimIndex &index,
603  TfTokenVector *namesToCompose) {
604  return (*static_cast<const Pred *>(pred))(index, namesToCompose);
605  }
606  const void *pred;
607  bool (*invoke)(const void *, const PcpPrimIndex &, TfTokenVector *);
608  };
610  // See doc for _UntypedIndexingChildrenPredicate above. This does the same
611  // for the payload inclusion predicate.
612  struct _UntypedIndexingPayloadPredicate {
613  template <class Pred>
614  explicit _UntypedIndexingPayloadPredicate(const Pred *pred)
615  : pred(pred), invoke(_Invoke<Pred>) {}
617  inline bool operator()(const SdfPath &path) const {
618  return invoke(pred, path);
619  }
620  private:
621  template <class Pred>
622  static bool _Invoke(const void *pred, const SdfPath &path) {
623  return (*static_cast<const Pred *>(pred))(path);
624  }
625  const void *pred;
626  bool (*invoke)(const void *, const SdfPath &);
627  };
629  // Internal helper for recursive indexing.
630  const PcpPrimIndex &
631  _ComputePrimIndexWithCompatibleInputs(
632  const SdfPath & path, const PcpPrimIndexInputs &inputs,
633  PcpErrorVector *allErrors);
635  // Friend to allow low-level indexing code access to the above.
636  friend const PcpPrimIndex &
637  Pcp_ComputePrimIndexWithCompatibleInputs(
638  PcpCache &cache,
639  const SdfPath & path, const PcpPrimIndexInputs &inputs,
640  PcpErrorVector *allErrors);
642  // Parallel indexing implementation.
643  PCP_API
644  void _ComputePrimIndexesInParallel(
645  const SdfPathVector &paths,
646  PcpErrorVector *allErrors,
647  _UntypedIndexingChildrenPredicate childrenPred,
648  _UntypedIndexingPayloadPredicate payloadPred,
649  const char *mallocTag1,
650  const char *mallocTag2);
652  void _RemovePrimCache(const SdfPath& primPath, PcpLifeboat* lifeboat);
653  void _RemovePrimAndPropertyCaches(const SdfPath& root,
654  PcpLifeboat* lifeboat);
655  void _RemovePropertyCache(const SdfPath& root, PcpLifeboat* lifeboat);
656  void _RemovePropertyCaches(const SdfPath& root, PcpLifeboat* lifeboat);
658  // Returns the prim index for \p path if it exists, NULL otherwise.
659  PcpPrimIndex* _GetPrimIndex(const SdfPath& path);
660  const PcpPrimIndex* _GetPrimIndex(const SdfPath& path) const;
662  // Returns the property index for \p path if it exists, NULL otherwise.
663  PcpPropertyIndex* _GetPropertyIndex(const SdfPath& path);
664  const PcpPropertyIndex* _GetPropertyIndex(const SdfPath& path) const;
666 private:
667  // Fixed evaluation parameters, set when the cache is created. Note that
668  // _rootLayer and _sessionLayer are not const because we want to mutate them
669  // to enable parallel teardown in the destructor.
670  SdfLayerRefPtr _rootLayer;
671  SdfLayerRefPtr _sessionLayer;
672  const ArResolverContext _pathResolverContext;
674  // Flag that configures PcpCache to use the restricted set of USD features.
675  // Currently it governs whether relocates, inherits, permissions,
676  // symmetry, or payloads are considered, and whether the prim stack
677  // is populated and its depdencies gathered during computation of
678  // prim indices and composition of prim child names.
679  const bool _usd;
681  // File format target for all scene description layers this cache will
682  // find or open during prim index computation.
683  const std::string _fileFormatTarget;
685  // The layer stack for this cache. Holding this by ref ptr means we
686  // hold all of our local layers by ref ptr (including the root and
687  // session layers, again).
688  PcpLayerStackRefPtr _layerStack;
690  // Modifiable evaluation parameters.
691  // Anything that changes these should also yield a PcpChanges
692  // value describing the necessary cache invalidation.
693  PayloadSet _includedPayloads;
694  PcpVariantFallbackMap _variantFallbackMap;
696  // Cached computation types.
697  typedef Pcp_LayerStackRegistryRefPtr _LayerStackCache;
698  typedef SdfPathTable<PcpPrimIndex> _PrimIndexCache;
699  typedef SdfPathTable<PcpPropertyIndex> _PropertyIndexCache;
701  // Cached computations.
702  _LayerStackCache _layerStackCache;
703  _PrimIndexCache _primIndexCache;
704  _PropertyIndexCache _propertyIndexCache;
705  std::unique_ptr<Pcp_Dependencies> _primDependencies;
706 };
710 #endif // PCP_CACHE_H
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 ...
Definition: cache.h:291
PCP_API void RequestLayerMuting(const std::vector< std::string > &layersToMute, const std::vector< std::string > &layersToUnmute, PcpChanges *changes=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...
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
typedef std::map&lt;std::string, std::vector&lt;std::string&gt;&gt; PcpVariantFallbackMap
Definition: types.h:188
PCP_API void PrintStatistics() const
Prints various statistics about the data stored in this cache.
PCP_API bool IsUsd() const
Return true if the cache is configured in Usd mode.
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:77
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 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 PcpPrimIndexInputs GetPrimIndexInputs()
Returns parameter object containing all inputs for the prim index computation used by this cache...
PCP_API void ComputeAttributeConnectionPaths(const SdfPath &attributePath, SdfPathVector *paths, bool localOnly, const SdfSpecHandle &stopProperty, bool includeStopProperty, PcpErrorVector *allErrors)
Compute the attribute connection paths for the attribute at attributePath into paths.
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:65
PCP_API SdfLayerHandleSet GetUsedRootLayers() const
Returns set of all root layers used by this cache.
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...
Definition: cache.h:332
Describes Pcp changes.
Definition: changes.h:171
PCP_API PcpLayerStackPtr FindLayerStack(const PcpLayerStackIdentifier &identifier) const
Returns the layer stack for identifier if it has been computed and cached, otherwise returns NULL...
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:65
PCP_API PcpLayerStackPtr GetLayerStack() const
Get the layer stack for GetLayerStackIdentifier().
PCP_API void Apply(const PcpCacheChanges &changes, PcpLifeboat *lifeboat)
Apply the changes in changes.
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:91
PCP_API bool IsPayloadIncluded(const SdfPath &path) const
Return true if the payload is included for the given path.
PCP_API SdfLayerHandleSet GetUsedLayers() const
Returns set of all layers used by this cache.
Base class for all Sdf spec classes.
Definition: spec.h:51
PCP_API const std::string & GetFileFormatTarget() const
Returns the file format target this cache is configured for.
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
PCP_API void ComputeRelationshipTargetPaths(const SdfPath &relationshipPath, SdfPathVector *paths, bool localOnly, const SdfSpecHandle &stopProperty, bool includeStopProperty, PcpErrorVector *allErrors)
Compute the relationship target paths for the relationship at relationshipPath into paths...
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 std::vector< std::string > GetInvalidSublayerIdentifiers() const
Returns a vector of sublayer asset paths used in the layer stack that didn&#39;t resolve to valid assets...
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...
void ComputePrimIndexesInParallel(const SdfPathVector &paths, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred)
Vectorized form of ComputePrimIndexesInParallel().
Definition: cache.h:318
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&#39;s layer stack can be provide...
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...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
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...
Inputs for the prim indexing procedure.
Definition: primIndex.h:331
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Returns the payloads requested for inclusion.
Definition: cache.h:156
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 PcpLayerStackIdentifier GetLayerStackIdentifier() const
Get the identifier of the layerStack used for composition.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
A function that maps values from one namespace (and time domain) to another.
Definition: mapFunction.h:80
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
PCP_API const std::vector< std::string > & GetMutedLayers() const
Returns the list of canonical identifiers for muted layers in this cache.
Types of changes per cache.
Definition: changes.h:97
PCP_API void ReloadReferences(PcpChanges *changes, const SdfPath &primPath)
Reload every layer used by the prim at primPath that&#39;s across a reference or payload.
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 bool HasAnyDynamicFileFormatArgumentDependencies() const
Returns true if any prim index in this cache has a dependency on a dynamic file format argument field...
PCP_API const PcpLayerStackPtrVector & FindAllLayerStacksUsingLayer(const SdfLayerHandle &layer) const
Returns every computed &amp; cached layer stack that includes layer.
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 bool IsLayerMuted(const std::string &layerIdentifier) const
Returns true if the layer specified by layerIdentifier is muted in this cache, false otherwise...
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 bool IsInvalidAssetPath(const std::string &resolvedAssetPath) const
Returns true if resolvedAssetPath was used by a prim (e.g.
PcpPropertyIndex is an index of all sites in scene description that contribute opinions to a specific...
Definition: propertyIndex.h:65
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...
Definition: cache.h:304
An asset resolver context allows clients to provide additional data to the resolver for use during re...
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...
PCP_API PcpVariantFallbackMap GetVariantFallbacks() const
Get the list of fallbacks to attempt to use when evaluating variant sets that lack an authored select...
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:139
Contains the necessary information for storing a prim index&#39;s dependency on dynamic file format argum...
Arguments used to identify a layer stack.