Loading...
Searching...
No Matches
changes.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_PCP_CHANGES_H
8#define PXR_USD_PCP_CHANGES_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/pcp/api.h"
14#include "pxr/usd/pcp/dependency.h"
15#include "pxr/usd/pcp/errors.h"
19#include "pxr/usd/sdf/path.h"
20#include "pxr/usd/sdf/types.h"
22
23#include <map>
24#include <set>
25#include <unordered_set>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29SDF_DECLARE_HANDLES(SdfLayer);
31
32class PcpCache;
33class PcpSite;
34
40public:
43
46
49
52
59
66 SdfRelocatesMap newRelocatesSourceToTarget;
67 SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
68 SdfRelocatesMap newIncrementalRelocatesTargetToSource;
69 SdfPathVector newRelocatesPrimPaths;
70 PcpErrorVector newRelocatesErrors;
71
74
77
79 : didChangeLayers(false)
81 , didChangeRelocates(false)
84 , _didChangeExpressionVariablesSource(false)
85 {}
86
87private:
88 friend class PcpChanges;
89 friend class PcpLayerStack;
90
91 // Expression variables source has changed.
92 bool _didChangeExpressionVariablesSource;
93
94 // New source for expression variables for this layer stack.
95 PcpExpressionVariablesSource _newExpressionVariablesSource;
96};
97
103public:
104 enum TargetType {
105 TargetTypeConnection = 1 << 0,
106 TargetTypeRelationshipTarget = 1 << 1
107 };
108
113
115 SdfPathSet didChangeSpecs;
116
119 SdfPathSet didChangePrims;
120
122 std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
123
128 std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
129
132
135 std::unordered_set<SdfLayerHandle, TfHash> layersAffectedByMutingOrRemoval;
136
137 // Holds all the diff changelists that were computed when adding/removing
138 // sublayers or muting/unmuting layers.
139 SdfLayerChangeListVec layerChangeListVec;
140
141private:
142 friend class PcpCache;
143 friend class PcpChanges;
144
145 using _ProcessedLayerSublayerPathPairsKey =
146 std::pair<SdfLayerHandle, std::string>;
147
148 using _LayerToLayerStacks =
149 std::unordered_map<SdfLayerHandle, PcpLayerStackPtrVector, TfHash>;
150
154 void _SetLayerStacksUsingLayerOverride(
155 const SdfLayerHandle& layer,
156 const PcpLayerStackPtrVector& layerStacks);
157
159 const PcpLayerStackPtrVector&
160 _GetLayerStacksUsingLayerOverride(const SdfLayerHandle& layer) const;
161
162 // Set of hashed layer / sublayer path pairs that have been processed in
163 // in this round of changes. These values are checked in order to avoid
164 // recursively processing cycles created in layer stacks.
165 std::unordered_set<_ProcessedLayerSublayerPathPairsKey, TfHash>
166 _processedLayerSublayerPathPairs;
167
168 // Must rebuild the prim/property stacks at each path due to a change
169 // that only affects the internal representation of the stack and
170 // not its contents. Because this causes no externally-observable
171 // changes in state, clients do not need to be aware of these changes.
172 SdfPathSet _didChangeSpecsInternal;
173
174 // This set serves a similar purpose to _didChangeSpecsInternal above,
175 // however, during processing descendants of the specs in this set will also
176 // be marked as changed. A performance gain is accomplished by placing the
177 // ancestor specs in this set and processing children iteratively when
178 // applying changes to the cache.
179 SdfPathSet _didChangePrimSpecsAndChildrenInternal;
180
181 // Holds layer stack overrides set for individual layers
182 _LayerToLayerStacks _layerToLayerStackOverrides;
183};
184
188public:
189 PcpLifeboat();
190 ~PcpLifeboat();
191
193 void Retain(const SdfLayerRefPtr& layer);
194
196 void Retain(const PcpLayerStackRefPtr& layerStack);
197
200 const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
201
203 void Swap(PcpLifeboat& other);
204
205private:
206 std::set<SdfLayerRefPtr> _layers;
207 std::set<PcpLayerStackRefPtr> _layerStacks;
208};
209
220public:
221 PCP_API PcpChanges();
222 PCP_API ~PcpChanges();
223
231 PCP_API
232 void DidChange(const PcpCache* cache,
233 const SdfLayerChangeListVec& changes);
234
239 PCP_API
240 void DidMaybeFixSublayer(const PcpCache* cache,
241 const SdfLayerHandle& layer,
242 const std::string& assetPath);
243
246 PCP_API
247 void DidMaybeFixAsset(const PcpCache* cache,
248 const PcpSite& site,
249 const SdfLayerHandle& srcLayer,
250 const std::string& assetPath);
251
253 PCP_API
254 void _DidMuteLayer(const PcpCache* cache, const std::string& layerId);
255
257 PCP_API
258 void _DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
259
266 const std::vector<std::string>& layersToMute,
267 const std::vector<std::string>& layersToUnmute);
268
273 PCP_API
274 void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
275
276 enum ChangeSpecsType {
277 ChangeSpecsTypeRemoved,
278 ChangeSpecsTypeAdded
279 };
280
286 PCP_API
287 void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
288 const SdfLayerHandle& changedLayer,
289 const SdfPath& changedPath, ChangeSpecsType changeType);
290
293 PCP_API
294 void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
295
298 PCP_API
299 void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
300 PcpCacheChanges::TargetType targetType);
301
307 PCP_API
308 void DidChangePaths(const PcpCache* cache,
309 const SdfPath& oldPath, const SdfPath& newPath);
310
312 PCP_API
313 void DidDestroyCache(const PcpCache* cache);
314
319 PCP_API
321
323 PCP_API
324 void Swap(PcpChanges& other);
325
327 PCP_API
328 bool IsEmpty() const;
329
330 typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
331 typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
332
335 PCP_API
336 const LayerStackChanges& GetLayerStackChanges() const;
337
339 PCP_API
340 const CacheChanges& GetCacheChanges() const;
341
346 PCP_API
347 const PcpLifeboat& GetLifeboat() const;
348
350 PCP_API
351 void Apply() const;
352
357 PCP_API
358 PcpDependencyVector
360 const SdfLayerHandle& siteLayer,
361 const SdfPath& sitePath,
362 PcpDependencyFlags depMask,
363 bool recurseOnSite,
364 bool recurseOnIndex,
365 bool filterForExistingCachesOnly) const;
366
371 PCP_API
372 const PcpLayerStackPtrVector&
374 const SdfLayerHandle& layer) const;
375
376private:
377 // Internal data types for namespace edits from Sd.
378 typedef std::map<SdfPath, SdfPath> _PathEditMap;
379 typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
380
381 // Returns the PcpLayerStackChanges for the given layer stack.
382 PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
383
384 // Returns the PcpCacheChanges for the given cache.
385 PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
386
387 // Returns the _PathEditMap for the given cache.
388 _PathEditMap& _GetRenameChanges(const PcpCache* cache);
389
390
391 // Optimize the changes.
392 void _Optimize() const;
393
394 // Optimize the changes.
395 void _Optimize();
396
397 // Optimize the changes for a given cache.
398 void _Optimize(PcpCacheChanges*);
399
400 // Optimize path changes.
401 void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
402 const _PathEditMap* pathChanges);
403
404 // Sublayer change type for _DidChangeSublayer.
405 enum _SublayerChangeType {
406 _SublayerAdded,
407 _SublayerRemoved
408 };
409
410 // Helper function for loading a sublayer of \p layer at \p sublayerPath
411 // for processing changes described by \p sublayerChange.
412 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
413 const SdfLayerHandle& layer,
414 const std::string& sublayerPath,
415 _SublayerChangeType changeType) const;
416
417 // Helper function for loading a sublayer at \p sublayerPath
418 // for processing changes described by \p sublayerChange.
419 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
420 const std::string& sublayerPath,
421 _SublayerChangeType changeType) const;
422
423 // Propagates changes to \p sublayer specified by \p sublayerChange to
424 // the dependents of that sublayer. This includes all layer stacks
425 // that include the sublayer.
426 void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
427 const PcpLayerStackPtrVector& stacks,
428 const std::string& sublayerPath,
429 const SdfLayerHandle& sublayer,
430 _SublayerChangeType sublayerChange,
431 std::string* debugSummary);
432
433 // Propagates changes to \p sublayer specified by \p sublayerChange to
434 // the dependents of that sublayer.
435 void _DidChangeSublayer(const PcpCache* cache,
436 const PcpLayerStackPtrVector& layerStacks,
437 const std::string& sublayerPath,
438 const SdfLayerHandle& sublayer,
439 _SublayerChangeType sublayerChange,
440 std::string* debugSummary,
441 bool *significant);
442
443 // Propagates changes due to the addition/removal of the sublayer
444 // at the given \p sublayerPath to/from the parent \p layer.
445 void _DidAddOrRemoveSublayer(const PcpCache* cache,
446 const PcpLayerStackPtrVector& layerStacks,
447 const SdfLayerHandle& layer,
448 const std::string& sublayerPath,
449 _SublayerChangeType sublayerChange,
450 std::string* debugSummary,
451 std::vector<bool> *significant);
452
453 // Mark the layer stack as having changed.
454 void _DidChangeLayerStack(
455 const PcpCache* cache,
456 const PcpLayerStackPtr& layerStack,
457 bool requiresLayerStackChange,
458 bool requiresLayerStackOffsetsChange,
459 bool requiresSignificantChange);
460
461 // Mark the layer stack's relocations as having changed.
462 // Recompute the new relocations, storing the result in the Changes,
463 // so that change-processing can determine which other caches it
464 // needs to invalidate.
465 void _DidChangeLayerStackRelocations(
466 const PcpCache* cache,
467 const PcpLayerStackPtr& layerStack,
468 std::string* debugSummary);
469
470 // Register changes to any prim indexes in \p caches that are affected
471 // by a change to a layer's resolved path used by \p layerStack.
472 void _DidChangeLayerStackResolvedPath(
473 const PcpCache* cache,
474 const PcpLayerStackPtr& layerStack,
475 bool requiresLayerStackChange,
476 std::string* debugSummary);
477
478 // Register changes to layer stacks and prim indexes in \p cache that are
479 // affected by a change to a layer's expression variables used by
480 // \p layerStack.
481 void _DidChangeLayerStackExpressionVariables(
482 const PcpCache* cache,
483 const PcpLayerStackPtr& layerStack,
484 std::string* debugSummary);
485
486 // The spec stack for the prim or property index at \p path must be
487 // recomputed due to a change that affects only the internal representation
488 // of the stack and not its contents.
489 void _DidChangeSpecStackInternal(
490 const PcpCache* cache, const SdfPath& path);
491
492 void _DidChangeSpecStackAndChildrenInternal(
493 const PcpCache* cache, const SdfPath& path);
494
495 // This method is used when processing layer operations. It ensures that
496 // affected layer stacks and their dependent spec stacks are marked as
497 // changed.
498 void _ProcessLayerStackAndDependencyChanges(
499 const PcpCache* cache,
500 const PcpLayerStackPtrVector& layerStacks);
501
502 // When muting or unmuting a layer that is being referenced or payloaded,
503 // we need to ensure that all the relevant sites are recomposed. This
504 // function searches site dependencies of the provided layer stacks and
505 // marks those that are introduced via reference or payload arcs as
506 // significantly changed.
507 void _MarkReferencingSitesAsSignificantlyChanged(
508 const PcpCache* cache,
509 const PcpLayerStackPtrVector& layerStacks);
510
511private:
512 LayerStackChanges _layerStackChanges;
513 CacheChanges _cacheChanges;
514 _RenameChanges _renameChanges;
515 mutable PcpLifeboat _lifeboat;
516};
517
518PXR_NAMESPACE_CLOSE_SCOPE
519
520#endif // PXR_USD_PCP_CHANGES_H
Types of changes per cache.
Definition: changes.h:102
std::vector< std::pair< SdfPath, SdfPath > > didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:128
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:119
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:115
std::unordered_set< SdfLayerHandle, TfHash > layersAffectedByMutingOrRemoval
Set of layers that were explicitly muted or removed from a sublayer list and all sublayers of those l...
Definition: changes.h:135
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:112
bool didMaybeChangeLayers
Layers used in the composition may have changed.
Definition: changes.h:131
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:122
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:77
Describes Pcp changes.
Definition: changes.h:219
PCP_API void DidChangeSignificantly(const PcpCache *cache, const SdfPath &path)
The object at path changed significantly enough to require recomputing the entire prim or property in...
PCP_API void DidChangeSpecs(const PcpCache *cache, const SdfPath &path, const SdfLayerHandle &changedLayer, const SdfPath &changedPath, ChangeSpecsType changeType)
The spec stack for the prim or property has changed, due to the addition or removal of the spec in ch...
PCP_API void DidChangeAssetResolver(const PcpCache *cache)
The asset resolver has changed, invalidating previously-resolved asset paths.
PCP_API bool IsEmpty() const
Returns true iff there are no changes.
PCP_API void _DidMuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was muted in cache.
PCP_API void DidMaybeFixSublayer(const PcpCache *cache, const SdfLayerHandle &layer, const std::string &assetPath)
Tries to load the sublayer of layer at sublayerPath.
PCP_API void DidChangePaths(const PcpCache *cache, const SdfPath &oldPath, const SdfPath &newPath)
The composed object at oldPath was moved to newPath.
PCP_API void DidChangeSpecStack(const PcpCache *cache, const SdfPath &path)
The spec stack for the prim or property at path in cache has changed.
PCP_API void Apply() const
Applies the changes to the layer stacks and caches.
PCP_API const CacheChanges & GetCacheChanges() const
Returns a map of all of the cache changes.
PCP_API void DidMaybeFixAsset(const PcpCache *cache, const PcpSite &site, const SdfLayerHandle &srcLayer, const std::string &assetPath)
Tries to load the asset at assetPath.
PCP_API void DidChangeTargets(const PcpCache *cache, const SdfPath &path, PcpCacheChanges::TargetType targetType)
The connections on the attribute or targets on the relationship have changed.
PCP_API void _DidUnmuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was unmuted in cache.
PCP_API const LayerStackChanges & GetLayerStackChanges() const
Returns a map of all of the layer stack changes.
PCP_API void Swap(PcpChanges &other)
Swap the contents of this and other.
PCP_API PcpDependencyVector FindSiteDependencies(const PcpCache *cache, const SdfLayerHandle &siteLayer, const SdfPath &sitePath, PcpDependencyFlags depMask, bool recurseOnSite, bool recurseOnIndex, bool filterForExistingCachesOnly) const
Returns dependencies of the given site of scene description.
PCP_API const PcpLifeboat & GetLifeboat() const
Returns the lifeboat responsible for maintaining the lifetime of layers and layer stacks during chang...
PCP_API void DidChange(const PcpCache *cache, const SdfLayerChangeListVec &changes)
Breaks down changes into individual changes on cache.
void DidMuteAndUnmuteLayers(const PcpCache *cache, const std::vector< std::string > &layersToMute, const std::vector< std::string > &layersToUnmute)
Sets the list of layers that will ultimately be muted and unmuted for this round of changes.
PCP_API void DidDestroyCache(const PcpCache *cache)
Remove any changes for cache.
PCP_API const PcpLayerStackPtrVector & FindAllLayerStacksUsingLayer(const PcpCache *cache, const SdfLayerHandle &layer) const
Returns every layer stack that includes layer.
Represents the layer stack associated with a set of expression variables.
Types of changes per layer stack.
Definition: changes.h:39
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:65
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:42
bool didChangeExpressionVariables
Must rebuild expression variables.
Definition: changes.h:51
VtDictionary newExpressionVariables
New expression variables for this layer stack.
Definition: changes.h:76
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:45
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:58
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:73
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:48
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:50
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:187
void Retain(const PcpLayerStackRefPtr &layerStack)
Ensure that layerStack exists until this object is destroyed.
void Swap(PcpLifeboat &other)
Swap the contents of this and other.
void Retain(const SdfLayerRefPtr &layer)
Ensure that layer exists until this object is destroyed.
const std::set< PcpLayerStackRefPtr > & GetLayerStacks() const
Returns reference to the set of layer stacks currently being held in the lifeboat.
A site specifies a path in a layer stack of scene description.
Definition: site.h:29
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A map with string keys and VtValue values.
Definition: dictionary.h:52
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
Basic Sdf data types.
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:267