HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cache.h
Go to the documentation of this file.
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 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
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 PXR_USD_PCP_CACHE_H
25 #define PXR_USD_PCP_CACHE_H
26 
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"
32 #include "pxr/usd/pcp/primIndex.h"
35 #include "pxr/usd/sdf/path.h"
36 #include "pxr/usd/sdf/pathTable.h"
37 
40 #include "pxr/base/tf/hashset.h"
41 
42 #include <memory>
43 #include <string>
44 #include <unordered_set>
45 #include <vector>
46 
48 
49 // Forward declarations:
50 class PcpChanges;
51 class PcpCacheChanges;
52 class Pcp_Dependencies;
54 class PcpLifeboat;
55 class PcpNodeRef;
56 class PcpMapFunction;
57 
59 TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
61 
62 /// \class PcpCache
63 ///
64 /// PcpCache is the context required to make requests of the Pcp
65 /// composition algorithm and cache the results.
66 ///
67 /// Because the algorithms are recursive -- making a request typically
68 /// makes other internal requests to solve subproblems -- caching
69 /// subproblem results is required for reasonable performance, and
70 /// so this cache is the only entrypoint to the algorithms.
71 ///
72 /// There is a set of parameters that affect the composition results:
73 ///
74 /// \li variant fallbacks: per named variant set, an ordered list of
75 /// fallback values to use when composing a prim that defines
76 /// a variant set but does not specify a selection
77 /// \li payload inclusion set: an SdfPath set used to identify which
78 /// prims should have their payloads included during composition;
79 /// this is the basis for explicit control over the "working set"
80 /// of composition
81 /// \li file format target: the file format target that Pcp will request
82 /// when opening scene description layers
83 /// \li "USD mode" configures the Pcp composition algorithm to provide
84 /// only a custom, lighter subset of the full feature set, as needed
85 /// by the Universal Scene Description system
86 ///
87 /// There are a number of different computations that can be requested.
88 /// These include computing a layer stack from a PcpLayerStackIdentifier,
89 /// computing a prim index or prim stack, and computing a property index.
90 ///
91 class PcpCache
92 {
93  PcpCache(PcpCache const &) = delete;
94  PcpCache &operator=(PcpCache const &) = delete;
95 public:
96  /// Construct a PcpCache to compose results for the layer stack identified
97  /// by \a layerStackIdentifier.
98  ///
99  /// If \p fileFormatTarget is given, Pcp will specify \p fileFormatTarget
100  /// as the file format target when searching for or opening a layer.
101  ///
102  /// If \p usd is true, computation of prim indices and composition of prim
103  /// child names are performed without relocates, inherits, permissions,
104  /// symmetry, or payloads, and without populating the prim stack and
105  /// gathering its dependencies.
106  PCP_API
107  PcpCache(const PcpLayerStackIdentifier & layerStackIdentifier,
108  const std::string& fileFormatTarget = std::string(),
109  bool usd = false);
110  PCP_API ~PcpCache();
111 
112  /// \name Parameters
113  /// @{
114 
115  /// Get the identifier of the layerStack used for composition.
116  PCP_API
118 
119  /// Get the layer stack for GetLayerStackIdentifier(). Note that
120  /// this will neither compute the layer stack nor report errors.
121  /// So if the layer stack has not been computed yet this will
122  /// return \c NULL. Use ComputeLayerStack() if you need to
123  /// compute the layer stack if it hasn't been computed already
124  /// and/or get errors caused by computing the layer stack.
125  PCP_API
126  PcpLayerStackPtr GetLayerStack() const;
127 
128  /// Return true if the cache is configured in Usd mode.
129  PCP_API
130  bool IsUsd() const;
131 
132  /// Returns the file format target this cache is configured for.
133  PCP_API
134  const std::string& GetFileFormatTarget() const;
135 
136  /// Get the list of fallbacks to attempt to use when evaluating
137  /// variant sets that lack an authored selection.
138  PCP_API
140 
141  /// Set the list of fallbacks to attempt to use when evaluating
142  /// variant sets that lack an authored selection.
143  ///
144  /// If \p changes is not \c NULL then it's adjusted to reflect the
145  /// changes necessary to see the change in standin preferences,
146  /// otherwise those changes are applied immediately.
147  PCP_API
148  void SetVariantFallbacks( const PcpVariantFallbackMap & map,
149  PcpChanges* changes = NULL );
150 
151  /// Return true if the payload is included for the given path.
152  PCP_API
153  bool IsPayloadIncluded(const SdfPath &path) const;
154 
155  /// Returns the payloads requested for inclusion.
156  using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
157  PCP_API
158  PayloadSet const &GetIncludedPayloads() const;
159 
160  /// Request payloads to be included or excluded from composition.
161  /// \param pathsToInclude is a set of paths to add to the set for
162  /// payload inclusion.
163  /// \param pathsToExclude is a set of paths to remove from the set for
164  /// payload inclusion.
165  /// \param changes if not \c NULL, is adjusted to reflect the changes
166  /// necessary to see the change in payloads; otherwise those
167  /// changes are applied immediately.
168  /// \note If a path is listed in both pathsToInclude and pathsToExclude,
169  /// it will be treated as an inclusion only.
170  ///
171  PCP_API
172  void RequestPayloads( const SdfPathSet & pathsToInclude,
173  const SdfPathSet & pathsToExclude,
174  PcpChanges* changes = NULL );
175 
176  /// Request layers to be muted or unmuted in this cache. Muted layers
177  /// are ignored during composition and do not appear in any layer
178  /// stacks. The root layer of this stage may not be muted; attempting
179  /// to do so will generate a coding error. If the root layer of a
180  /// reference or payload layer stack is muted, the behavior is as if
181  /// the muted layer did not exist, which means a composition error will
182  /// be generated.
183  ///
184  /// A canonical identifier for each layer in \p layersToMute will be
185  /// computed using ArResolver::ComputeRepositoryPath. Any layer
186  /// encountered during composition with the same repository path will
187  /// be considered muted and ignored. Relative paths will be assumed to
188  /// be relative to the cache's root layer. Search paths are immediately
189  /// resolved and the result is used for computing the canonical path.
190  ///
191  /// Note that muting a layer will cause this cache to release all
192  /// references to that layer. If no other client is holding on to
193  /// references to that layer, it will be unloaded. In this case, if
194  /// there are unsaved edits to the muted layer, those edits are lost.
195  /// Since anonymous layers are not serialized, muting an anonymous
196  /// layer will cause that layer and its contents to be lost in this
197  /// case.
198  ///
199  /// If \p changes is not \c nullptr, it is adjusted to reflect the
200  /// changes necessary to see the change in muted layers. Otherwise,
201  /// those changes are applied immediately.
202  ///
203  PCP_API
204  void RequestLayerMuting(const std::vector<std::string>& layersToMute,
205  const std::vector<std::string>& layersToUnmute,
206  PcpChanges* changes = nullptr);
207 
208  /// Returns the list of canonical identifiers for muted layers
209  /// in this cache. See documentation on RequestLayerMuting for
210  /// more details.
211  PCP_API
212  const std::vector<std::string>& GetMutedLayers() const;
213 
214  /// Returns true if the layer specified by \p layerIdentifier is
215  /// muted in this cache, false otherwise. If \p layerIdentifier
216  /// is relative, it is assumed to be relative to this cache's
217  /// root layer. See documentation on RequestLayerMuting for
218  /// more details.
219  PCP_API
220  bool IsLayerMuted(const std::string& layerIdentifier) const;
221 
222  /// Returns true if the layer specified by \p layerIdentifier is
223  /// muted in this cache, false otherwise. If \p layerIdentifier
224  /// is relative, it is assumed to be relative to \p anchorLayer.
225  /// If \p canonicalMutedLayerIdentifier is supplied, it will be
226  /// populated with the canonical identifier of the muted layer if this
227  /// function returns true. See documentation on RequestLayerMuting
228  /// for more details.
229  PCP_API
230  bool IsLayerMuted(const SdfLayerHandle& anchorLayer,
231  const std::string& layerIdentifier,
232  std::string* canonicalMutedLayerIdentifier
233  = nullptr) const;
234 
235  /// Returns parameter object containing all inputs for the prim index
236  /// computation used by this cache.
237  PCP_API
239 
240  /// @}
241 
242  /// \name Computations
243  /// @{
244 
245  /// Returns the layer stack for \p identifier if it exists, otherwise
246  /// creates a new layer stack for \p identifier. This returns \c NULL
247  /// if \p identifier is invalid (i.e. its root layer is \c NULL).
248  /// \p allErrors will contain any errors encountered while creating a
249  /// new layer stack. It'll be unchanged if the layer stack already existed.
250  PCP_API
251  PcpLayerStackRefPtr
252  ComputeLayerStack(const PcpLayerStackIdentifier &identifier,
253  PcpErrorVector *allErrors);
254 
255  /// Returns the layer stack for \p identifier if it has been computed
256  /// and cached, otherwise returns \c NULL.
257  PCP_API
258  PcpLayerStackPtr
259  FindLayerStack(const PcpLayerStackIdentifier &identifier) const;
260 
261  /// Compute and return a reference to the cached result for the
262  /// prim index for the given path. \p allErrors will contain any errors
263  /// encountered while performing this operation.
264  PCP_API
265  const PcpPrimIndex &
266  ComputePrimIndex(const SdfPath &primPath, PcpErrorVector *allErrors);
267 
268  /// Compute PcpPrimIndexes in the subtree rooted at path in parallel,
269  /// recursing to children based on the supplied \p childrenPred. Also
270  /// include payloads not already in this cache's included payloads (see
271  /// GetIncludedPayloads()) according to \p payloadPred.
272  ///
273  /// This is similar to ComputePrimIndex(), except it computes an entire
274  /// subtree of indexes in parallel so it can be much more efficient. This
275  /// function invokes both \p childrenPred and \p payloadPred concurrently,
276  /// so it must be safe to do so.
277  ///
278  /// When a PcpPrimIndex computation completes invoke \p childrenPred,
279  /// passing it the PcpPrimIndex. If \p childrenPred returns true, continue
280  /// indexing children prim indexes. In this case, \p childrenPred may
281  /// provide a list of names of the children prim indexes to compute.
282  /// If it does not, all children prim indexes will be computed.
283  /// If \p childrenPred returns false, stop indexing in that subtree.
284  ///
285  /// If payloads discovered during indexing do not already appear in this
286  /// cache's set of included payloads, invoke \p payloadPred, passing it the
287  /// path for the prim with the payload. If \p payloadPred returns true,
288  /// include its payload and add it to the cache's set of included payloads
289  /// upon completion.
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  }
299 
300  /// \overload
301  /// XXX Do not add new callers of this method. It is needed as a workaround
302  /// for bug #132031, which we hope to tackle soon (as of 6/2016)
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  }
314 
315  /// Vectorized form of ComputePrimIndexesInParallel(). Equivalent to
316  /// invoking that method for each path in \p paths, but more efficient.
317  template <class ChildrenPredicate, class PayloadPredicate>
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  }
327 
328  /// \overload
329  /// XXX Do not add new callers of this method. It is needed as a workaround
330  /// for bug #132031, which we hope to tackle soon (as of 6/2016)
331  template <class ChildrenPredicate, class PayloadPredicate>
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  }
343 
344  /// Returns a pointer to the cached computed prim index for the given
345  /// path, or NULL if it has not been computed.
346  PCP_API
347  const PcpPrimIndex *
348  FindPrimIndex(const SdfPath &primPath) const;
349 
350  /// Compute and return a reference to the cached result for the
351  /// property index for the given path. \p allErrors will contain any
352  /// errors encountered while performing this operation.
353  PCP_API
354  const PcpPropertyIndex &
355  ComputePropertyIndex(const SdfPath &propPath, PcpErrorVector *allErrors);
356 
357  /// Returns a pointer to the cached computed property index for the given
358  /// path, or NULL if it has not been computed.
359  PCP_API
360  const PcpPropertyIndex *
361  FindPropertyIndex(const SdfPath &propPath) const;
362 
363  /// Compute the relationship target paths for the relationship at
364  /// \p relationshipPath into \p paths. If \p localOnly is \c true then
365  /// this will compose relationship targets from local nodes only. If
366  /// \p stopProperty is not \c NULL then this will stop composing
367  /// relationship targets at \p stopProperty, including \p stopProperty
368  /// iff \p includeStopProperty is \c true. If not \c NULL, \p deletedPaths
369  /// will be populated with target paths whose deletion contributed to
370  /// the computed result. \p allErrors will contain any errors encountered
371  /// while performing this operation.
372  PCP_API
373  void
374  ComputeRelationshipTargetPaths(const SdfPath &relationshipPath,
376  bool localOnly,
377  const SdfSpecHandle &stopProperty,
378  bool includeStopProperty,
379  SdfPathVector *deletedPaths,
380  PcpErrorVector *allErrors);
381 
382  /// Compute the attribute connection paths for the attribute at
383  /// \p attributePath into \p paths. If \p localOnly is \c true then
384  /// this will compose attribute connections from local nodes only. If
385  /// \p stopProperty is not \c NULL then this will stop composing
386  /// attribute connections at \p stopProperty, including \p stopProperty
387  /// iff \p includeStopProperty is \c true. If not \c NULL, \p deletedPaths
388  /// will be populated with connection paths whose deletion contributed to
389  /// the computed result. \p allErrors will contain any errors encountered
390  /// while performing this operation.
391  PCP_API
392  void
393  ComputeAttributeConnectionPaths(const SdfPath &attributePath,
395  bool localOnly,
396  const SdfSpecHandle &stopProperty,
397  bool includeStopProperty,
398  SdfPathVector *deletedPaths,
399  PcpErrorVector *allErrors);
400 
401  /// @}
402  /// \name Dependencies
403  /// @{
404 
405  /// Returns set of all layers used by this cache.
406  PCP_API
408 
409  /// Returns set of all root layers used by this cache.
410  PCP_API
412 
413  /// Returns every computed & cached layer stack that includes \p layer.
414  PCP_API
415  const PcpLayerStackPtrVector&
416  FindAllLayerStacksUsingLayer(const SdfLayerHandle& layer) const;
417 
418  /// Returns dependencies on the given site of scene description,
419  /// as discovered by the cached index computations.
420  ///
421  /// \param depMask specifies what classes of dependency to include;
422  /// see PcpDependencyFlags for details
423  /// \param recurseOnSite includes incoming dependencies on
424  /// children of sitePath
425  /// \param recurseOnIndex extends the result to include all PcpCache
426  /// child indexes below discovered results
427  /// \param filterForExistingCachesOnly filters the results to only
428  /// paths representing computed prim and property index caches;
429  /// otherwise a recursively-expanded result can include
430  /// un-computed paths that are expected to depend on the site
431  PCP_API
433  FindSiteDependencies(const PcpLayerStackPtr& siteLayerStack,
434  const SdfPath& sitePath,
435  PcpDependencyFlags depMask,
436  bool recurseOnSite,
437  bool recurseOnIndex,
438  bool filterForExistingCachesOnly) const;
439 
440  /// Returns dependencies on the given site of scene description,
441  /// as discovered by the cached index computations.
442  ///
443  /// This method overload takes a site layer rather than a layer
444  /// stack. It will check every layer stack using that layer, and
445  /// apply any relevant sublayer offsets to the map functions in the
446  /// returned PcpDependencyVector.
447  ///
448  /// See the other method for parameter details.
449  PCP_API
451  FindSiteDependencies(const SdfLayerHandle& siteLayer,
452  const SdfPath& sitePath,
453  PcpDependencyFlags depMask,
454  bool recurseOnSite,
455  bool recurseOnIndex,
456  bool filterForExistingCachesOnly) const;
457 
458  /// Returns \c true if an opinion for the site at \p localPcpSitePath
459  /// in the cache's layer stack can be provided by an opinion in \p layer,
460  /// \c false otherwise. If \c true and \p allowedPathInLayer is not
461  /// \c NULL then it's set to a path in \p layer that would provide an
462  /// opinion.
463  ///
464  /// This returns \c false if no prim index has yet been computed for
465  /// \p localPcpSitePath.
466  PCP_API
467  bool CanHaveOpinionForSite(const SdfPath& localPcpSitePath,
468  const SdfLayerHandle& layer,
469  SdfPath* allowedPathInLayer) const;
470 
471  /// Returns a vector of sublayer asset paths used in the layer stack
472  /// that didn't resolve to valid assets.
473  PCP_API
474  std::vector<std::string> GetInvalidSublayerIdentifiers() const;
475 
476  /// Returns true if \p identifier was used as a sublayer path in a
477  /// layer stack but did not identify a valid layer. This is functionally
478  /// equivalent to examining the values in the vector returned by
479  /// GetInvalidSublayerIdentifiers, but more efficient.
480  PCP_API
481  bool IsInvalidSublayerIdentifier(const std::string& identifier) const;
482 
483  /// Returns a map of prim paths to asset paths used by that prim
484  /// (e.g. in a reference) that didn't resolve to valid assets.
485  PCP_API
486  std::map<SdfPath, std::vector<std::string>, SdfPath::FastLessThan>
487  GetInvalidAssetPaths() const;
488 
489  /// Returns true if \p resolvedAssetPath was used by a prim (e.g. in
490  /// a reference) but did not resolve to a valid asset. This is
491  /// functionally equivalent to examining the values in the map returned
492  /// by GetInvalidAssetPaths, but more efficient.
493  PCP_API
494  bool IsInvalidAssetPath(const std::string& resolvedAssetPath) const;
495 
496  /// Returns true if any prim index in this cache has a dependency on a
497  /// dynamic file format argument field.
498  PCP_API
500 
501  /// Returns true if the given \p field is the name of a field that
502  /// was composed while generating dynamic file format arguments for any prim
503  /// index in this cache.
504  PCP_API
505  bool IsPossibleDynamicFileFormatArgumentField(const TfToken &field) const;
506 
507  /// Returns the dynamic file format dependency data object for the prim
508  /// index with the given \p primIndexPath. This will return an empty
509  /// dependency data if either there is no cache prim index for the path or
510  /// if the prim index has no dynamic file formats that it depends on.
511  PCP_API
514  const SdfPath &primIndexPath) const;
515 
516  /// @}
517 
518  /// \name Change handling
519  /// @{
520 
521  /// Apply the changes in \p changes. This blows caches. It's up to
522  /// the client to pull on those caches again as needed.
523  ///
524  /// Objects that are no longer needed and would be destroyed are
525  /// retained in \p lifeboat and won't be destroyed until \p lifeboat is
526  /// itself destroyed. This gives the client control over the timing
527  /// of the destruction of those objects. Clients may choose to pull
528  /// on the caches before destroying \p lifeboat. That may cause the
529  /// caches to again retain the objects, meaning they won't be destroyed
530  /// when \p lifeboat is destroyed.
531  ///
532  /// For example, if blowing a cache means an SdfLayer is no longer
533  /// needed then \p lifeboat will hold an SdfLayerRefPtr to that layer.
534  /// The client can then pull on that cache, which could cause the
535  /// cache to hold an SdfLayerRefPtr to the layer again. If so then
536  /// destroying \p changes will not destroy the layer. In any case,
537  /// we don't destroy the layer and then read it again. However, if
538  /// the client destroys \p lifeboat before pulling on the cache then
539  /// we would destroy the layer then read it again.
540  PCP_API
541  void Apply(const PcpCacheChanges& changes, PcpLifeboat* lifeboat);
542 
543  /// Reload the layers of the layer stack, except session layers
544  /// and sublayers of session layers. This will also try to load
545  /// sublayers in this cache's layer stack that could not be loaded
546  /// previously. It will also try to load any referenced or payloaded
547  /// layer that could not be loaded previously. Clients should
548  /// subsequently \c Apply() \p changes to use any now-valid layers.
549  PCP_API
550  void Reload(PcpChanges* changes);
551 
552  /// Reload every layer used by the prim at \p primPath that's across
553  /// a reference or payload. Clients should subsequently apply the
554  /// changes to use any now valid layers.
555  ///
556  /// Note: If a reference or payload was to an invalid asset and this
557  /// asset is valid upon reloading then this call will not necessarily
558  /// reload every layer accessible across the reference or payload.
559  /// For example, say prim R has an invalid reference and prim Q has a
560  /// valid reference to layer X with sublayer Y. If on reload R now
561  /// has a valid reference to layer Z with sublayer Y, we will load Z
562  /// but we will not reload Y.
563  PCP_API
564  void ReloadReferences(PcpChanges* changes, const SdfPath& primPath);
565 
566  /// @}
567 
568  /// \name Diagnostics
569  /// @{
570 
571  /// Prints various statistics about the data stored in this cache.
572  PCP_API
573  void PrintStatistics() const;
574 
575  /// @}
576 
577 private:
578  friend class PcpChanges;
579  friend class Pcp_Statistics;
580 
581  struct _ParallelIndexer;
582 
583  // Helper struct to type-erase a children predicate for the duration of
584  // ComputePrimIndexesInParallel.
585  //
586  // This lets us achieve two goals. First, clients may pass any arbitrary
587  // type as a predicate (e.g. they do not have to derive some base class).
588  // Second, it lets us keep the parallel indexing implementation in the .cpp
589  // file, avoiding any large template code instantiation.
590  //
591  // The cost we pay is this very thin indirect call. We instantiate a
592  // function template with the client's predicate type that simply does a
593  // typecast and predicate invocation, and pass that function pointer into
594  // the implementation. There is no heap allocation, no predicate copy, no
595  // argument marshalling, etc.
596  struct _UntypedIndexingChildrenPredicate {
597  _UntypedIndexingChildrenPredicate() : pred(nullptr), invoke(nullptr) {}
598  template <class Pred>
599  explicit _UntypedIndexingChildrenPredicate(const Pred *pred)
600  : pred(pred), invoke(_Invoke<Pred>) {}
601 
602  inline bool operator()(const PcpPrimIndex &index,
603  TfTokenVector *childNamesToCompose) const {
604  return invoke(pred, index, childNamesToCompose);
605  }
606  private:
607  template <class Pred>
608  static bool _Invoke(const void *pred, const PcpPrimIndex &index,
609  TfTokenVector *namesToCompose) {
610  return (*static_cast<const Pred *>(pred))(index, namesToCompose);
611  }
612  const void *pred;
613  bool (*invoke)(const void *, const PcpPrimIndex &, TfTokenVector *);
614  };
615 
616  // See doc for _UntypedIndexingChildrenPredicate above. This does the same
617  // for the payload inclusion predicate.
618  struct _UntypedIndexingPayloadPredicate {
619  template <class Pred>
620  explicit _UntypedIndexingPayloadPredicate(const Pred *pred)
621  : pred(pred), invoke(_Invoke<Pred>) {}
622 
623  inline bool operator()(const SdfPath &path) const {
624  return invoke(pred, path);
625  }
626  private:
627  template <class Pred>
628  static bool _Invoke(const void *pred, const SdfPath &path) {
629  return (*static_cast<const Pred *>(pred))(path);
630  }
631  const void *pred;
632  bool (*invoke)(const void *, const SdfPath &);
633  };
634 
635  // Internal helper for recursive indexing.
636  const PcpPrimIndex &
637  _ComputePrimIndexWithCompatibleInputs(
638  const SdfPath & path, const PcpPrimIndexInputs &inputs,
639  PcpErrorVector *allErrors);
640 
641  // Friend to allow low-level indexing code access to the above.
642  friend const PcpPrimIndex &
644  PcpCache &cache,
645  const SdfPath & path, const PcpPrimIndexInputs &inputs,
646  PcpErrorVector *allErrors);
647 
648  // Parallel indexing implementation.
649  PCP_API
650  void _ComputePrimIndexesInParallel(
651  const SdfPathVector &paths,
652  PcpErrorVector *allErrors,
653  _UntypedIndexingChildrenPredicate childrenPred,
654  _UntypedIndexingPayloadPredicate payloadPred,
655  const char *mallocTag1,
656  const char *mallocTag2);
657 
658  void _RemovePrimCache(const SdfPath& primPath, PcpLifeboat* lifeboat);
659  void _RemovePrimAndPropertyCaches(const SdfPath& root,
660  PcpLifeboat* lifeboat);
661  void _RemovePropertyCache(const SdfPath& root, PcpLifeboat* lifeboat);
662  void _RemovePropertyCaches(const SdfPath& root, PcpLifeboat* lifeboat);
663 
664  // Returns the prim index for \p path if it exists, NULL otherwise.
665  PcpPrimIndex* _GetPrimIndex(const SdfPath& path);
666  const PcpPrimIndex* _GetPrimIndex(const SdfPath& path) const;
667 
668  // Returns the property index for \p path if it exists, NULL otherwise.
669  PcpPropertyIndex* _GetPropertyIndex(const SdfPath& path);
670  const PcpPropertyIndex* _GetPropertyIndex(const SdfPath& path) const;
671 
672 private:
673  // Fixed evaluation parameters, set when the cache is created. Note that
674  // _rootLayer and _sessionLayer are not const because we want to mutate them
675  // to enable parallel teardown in the destructor.
676  SdfLayerRefPtr _rootLayer;
677  SdfLayerRefPtr _sessionLayer;
678  const ArResolverContext _pathResolverContext;
679 
680  // Flag that configures PcpCache to use the restricted set of USD features.
681  // Currently it governs whether relocates, inherits, permissions,
682  // symmetry, or payloads are considered, and whether the prim stack
683  // is populated and its depdencies gathered during computation of
684  // prim indices and composition of prim child names.
685  const bool _usd;
686 
687  // File format target for all scene description layers this cache will
688  // find or open during prim index computation.
689  const std::string _fileFormatTarget;
690 
691  // The layer stack for this cache. Holding this by ref ptr means we
692  // hold all of our local layers by ref ptr (including the root and
693  // session layers, again).
694  PcpLayerStackRefPtr _layerStack;
695 
696  // Modifiable evaluation parameters.
697  // Anything that changes these should also yield a PcpChanges
698  // value describing the necessary cache invalidation.
699  PayloadSet _includedPayloads;
700  PcpVariantFallbackMap _variantFallbackMap;
701 
702  // Cached computation types.
703  typedef Pcp_LayerStackRegistryRefPtr _LayerStackCache;
704  typedef SdfPathTable<PcpPrimIndex> _PrimIndexCache;
705  typedef SdfPathTable<PcpPropertyIndex> _PropertyIndexCache;
706 
707  // Cached computations.
708  _LayerStackCache _layerStackCache;
709  _PrimIndexCache _primIndexCache;
710  _PropertyIndexCache _propertyIndexCache;
711  std::unique_ptr<Pcp_Dependencies> _primDependencies;
712 
713  // Parallel indexer state.
714  std::unique_ptr<_ParallelIndexer> _parallelIndexer;
715 };
716 
718 
719 #endif // PXR_USD_PCP_CACHE_H
PCP_API bool CanHaveOpinionForSite(const SdfPath &localPcpSitePath, const SdfLayerHandle &layer, SdfPath *allowedPathInLayer) const
void ComputePrimIndexesInParallel(const SdfPathVector &paths, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred)
Definition: cache.h:318
PCP_API bool IsPayloadIncluded(const SdfPath &path) const
Return true if the payload is included for the given path.
PCP_API void Reload(PcpChanges *changes)
PCP_API bool IsLayerMuted(const std::string &layerIdentifier) const
GLuint index
Definition: glew.h:1814
PCP_API const PcpPropertyIndex & ComputePropertyIndex(const SdfPath &propPath, PcpErrorVector *allErrors)
PCP_API const std::string & GetFileFormatTarget() const
Returns the file format target this cache is configured for.
PCP_API PcpDependencyVector FindSiteDependencies(const PcpLayerStackPtr &siteLayerStack, const SdfPath &sitePath, PcpDependencyFlags depMask, bool recurseOnSite, bool recurseOnIndex, bool filterForExistingCachesOnly) const
PCP_API ~PcpCache()
PCP_API bool HasAnyDynamicFileFormatArgumentDependencies() const
Definition: cache.h:91
PCP_API void RequestLayerMuting(const std::vector< std::string > &layersToMute, const std::vector< std::string > &layersToUnmute, PcpChanges *changes=nullptr)
Definition: spec.h:51
PCP_API SdfLayerHandleSet GetUsedRootLayers() const
Returns set of all root layers used by this cache.
std::set< SdfHandleTo< SdfLayer >::Handle > SdfLayerHandleSet
PCP_API bool IsUsd() const
Return true if the cache is configured in Usd mode.
PCP_API const std::vector< std::string > & GetMutedLayers() const
PCP_API const PcpPrimIndex & ComputePrimIndex(const SdfPath &primPath, PcpErrorVector *allErrors)
PCP_API std::vector< std::string > GetInvalidSublayerIdentifiers() const
void ComputePrimIndexesInParallel(const SdfPath &path, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred, const char *mallocTag1, const char *mallocTag2)
Definition: cache.h:304
std::vector< PcpDependency > PcpDependencyVector
Definition: dependency.h:127
PCP_API const PcpDynamicFileFormatDependencyData & GetDynamicFileFormatArgumentDependencyData(const SdfPath &primIndexPath) const
PCP_API bool IsInvalidAssetPath(const std::string &resolvedAssetPath) const
friend const PcpPrimIndex & Pcp_ComputePrimIndexWithCompatibleInputs(PcpCache &cache, const SdfPath &path, const PcpPrimIndexInputs &inputs, PcpErrorVector *allErrors)
void ComputePrimIndexesInParallel(const SdfPathVector &paths, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred, const char *mallocTag1, const char *mallocTag2)
Definition: cache.h:332
PCP_API void ComputeAttributeConnectionPaths(const SdfPath &attributePath, SdfPathVector *paths, bool localOnly, const SdfSpecHandle &stopProperty, bool includeStopProperty, SdfPathVector *deletedPaths, PcpErrorVector *allErrors)
Definition: token.h:87
PCP_API const PcpPropertyIndex * FindPropertyIndex(const SdfPath &propPath) const
PCP_API void Apply(const PcpCacheChanges &changes, PcpLifeboat *lifeboat)
std::unordered_set< SdfPath, SdfPath::Hash > PayloadSet
Returns the payloads requested for inclusion.
Definition: cache.h:156
PCP_API PcpLayerStackRefPtr ComputeLayerStack(const PcpLayerStackIdentifier &identifier, PcpErrorVector *allErrors)
PCP_API void RequestPayloads(const SdfPathSet &pathsToInclude, const SdfPathSet &pathsToExclude, PcpChanges *changes=NULL)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:446
PCP_API void ReloadReferences(PcpChanges *changes, const SdfPath &primPath)
friend class Pcp_Statistics
Definition: cache.h:579
PCP_API const PcpLayerStackPtrVector & FindAllLayerStacksUsingLayer(const SdfLayerHandle &layer) const
Returns every computed & cached layer stack that includes layer.
PCP_API bool IsInvalidSublayerIdentifier(const std::string &identifier) const
SDF_DECLARE_HANDLES(SdfSpec)
std::vector< PcpErrorBasePtr > PcpErrorVector
Definition: errors.h:79
Definition: path.h:288
PCP_API PcpLayerStackPtr GetLayerStack() const
PCP_API PcpLayerStackPtr FindLayerStack(const PcpLayerStackIdentifier &identifier) const
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:209
PCP_API const PcpPrimIndex * FindPrimIndex(const SdfPath &primPath) const
PCP_API void SetVariantFallbacks(const PcpVariantFallbackMap &map, PcpChanges *changes=NULL)
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:207
GLsizei const GLchar *const * path
Definition: glew.h:6461
PCP_API std::map< SdfPath, std::vector< std::string >, SdfPath::FastLessThan > GetInvalidAssetPaths() const
GLsizei const GLchar *const * string
Definition: glew.h:1844
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
PCP_API PcpVariantFallbackMap GetVariantFallbacks() const
PCP_API PcpLayerStackIdentifier GetLayerStackIdentifier() const
Get the identifier of the layerStack used for composition.
PCP_API SdfLayerHandleSet GetUsedLayers() const
Returns set of all layers used by this cache.
GLint GLboolean GLint layer
Definition: glew.h:3601
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
PCP_API PcpPrimIndexInputs GetPrimIndexInputs()
PCP_API bool IsPossibleDynamicFileFormatArgumentField(const TfToken &field) const
void ComputePrimIndexesInParallel(const SdfPath &path, PcpErrorVector *allErrors, const ChildrenPredicate &childrenPred, const PayloadPredicate &payloadPred)
Definition: cache.h:291
PCP_API void ComputeRelationshipTargetPaths(const SdfPath &relationshipPath, SdfPathVector *paths, bool localOnly, const SdfSpecHandle &stopProperty, bool includeStopProperty, SdfPathVector *deletedPaths, PcpErrorVector *allErrors)
PCP_API PayloadSet const & GetIncludedPayloads() const
Returns the payloads requested for inclusion.
unsigned int PcpDependencyFlags
A typedef for a bitmask of flags from PcpDependencyType.
Definition: dependency.h:104
PCP_API void PrintStatistics() const
Prints various statistics about the data stored in this cache.
std::map< std::string, std::vector< std::string > > PcpVariantFallbackMap
Definition: types.h:188
#define PCP_API
Definition: api.h:40
GLenum const void * paths
Definition: glew.h:13589