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/errors.h"
18#include "pxr/usd/sdf/path.h"
19#include "pxr/usd/sdf/types.h"
21
22#include <map>
23#include <set>
24#include <unordered_set>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
28SDF_DECLARE_HANDLES(SdfLayer);
30
31class PcpCache;
32class PcpSite;
33
39public:
42
45
48
51
58
65 SdfRelocatesMap newRelocatesSourceToTarget;
66 SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
67 SdfRelocatesMap newIncrementalRelocatesTargetToSource;
68 SdfPathVector newRelocatesPrimPaths;
69 PcpErrorVector newRelocatesErrors;
70
73
76
78 : didChangeLayers(false)
80 , didChangeRelocates(false)
83 , _didChangeExpressionVariablesSource(false)
84 {}
85
86private:
87 friend class PcpChanges;
88 friend class PcpLayerStack;
89
90 // Expression variables source has changed.
91 bool _didChangeExpressionVariablesSource;
92
93 // New source for expression variables for this layer stack.
94 PcpExpressionVariablesSource _newExpressionVariablesSource;
95};
96
102public:
103 enum TargetType {
104 TargetTypeConnection = 1 << 0,
105 TargetTypeRelationshipTarget = 1 << 1
106 };
107
112
114 SdfPathSet didChangeSpecs;
115
118 SdfPathSet didChangePrims;
119
121 std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
122
127 std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
128
131
134
137
140 std::unordered_set<SdfLayerHandle, TfHash> layersAffectedByMutingOrRemoval;
141
142 // Holds all the diff changelists that were computed when adding/removing
143 // sublayers or muting/unmuting layers.
144 SdfLayerChangeListVec layerChangeListVec;
145
146private:
147 friend class PcpCache;
148 friend class PcpChanges;
149
150 using _ProcessedLayerSublayerPathPairsKey =
151 std::pair<SdfLayerHandle, std::string>;
152
153 // Set of hashed layer / sublayer path pairs that have been processed in
154 // in this round of changes. These values are checked in order to avoid
155 // recursively processing cycles created in layer stacks.
156 std::unordered_set<_ProcessedLayerSublayerPathPairsKey, TfHash>
157 _processedLayerSublayerPathPairs;
158
159 // Must rebuild the prim/property stacks at each path due to a change
160 // that only affects the internal representation of the stack and
161 // not its contents. Because this causes no externally-observable
162 // changes in state, clients do not need to be aware of these changes.
163 SdfPathSet _didChangeSpecsInternal;
164
165 // This set serves a similar purpose to _didChangeSpecsInternal above,
166 // however, during processing descendants of the specs in this set will also
167 // be marked as changed. A performance gain is accomplished by placing the
168 // ancestor specs in this set and processing children iteratively when
169 // applying changes to the cache.
170 SdfPathSet _didChangePrimSpecsAndChildrenInternal;
171};
172
176public:
177 PcpLifeboat();
178 ~PcpLifeboat();
179
181 void Retain(const SdfLayerRefPtr& layer);
182
184 void Retain(const PcpLayerStackRefPtr& layerStack);
185
188 const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
189
191 void Swap(PcpLifeboat& other);
192
193private:
194 std::set<SdfLayerRefPtr> _layers;
195 std::set<PcpLayerStackRefPtr> _layerStacks;
196};
197
208public:
209 PCP_API PcpChanges();
210 PCP_API ~PcpChanges();
211
219 PCP_API
220 void DidChange(const PcpCache* cache,
221 const SdfLayerChangeListVec& changes);
222
227 PCP_API
228 void DidMaybeFixSublayer(const PcpCache* cache,
229 const SdfLayerHandle& layer,
230 const std::string& assetPath);
231
234 PCP_API
235 void DidMaybeFixAsset(const PcpCache* cache,
236 const PcpSite& site,
237 const SdfLayerHandle& srcLayer,
238 const std::string& assetPath);
239
241 PCP_API
242 void _DidMuteLayer(const PcpCache* cache, const std::string& layerId);
243
245 PCP_API
246 void _DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
247
254 const std::vector<std::string>& layersToMute,
255 const std::vector<std::string>& layersToUnmute);
256
261 PCP_API
262 void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
263
264 enum ChangeSpecsType {
265 ChangeSpecsTypeRemoved,
266 ChangeSpecsTypeAdded
267 };
268
274 PCP_API
275 void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
276 const SdfLayerHandle& changedLayer,
277 const SdfPath& changedPath, ChangeSpecsType changeType);
278
281 PCP_API
282 void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
283
286 PCP_API
287 void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
288 PcpCacheChanges::TargetType targetType);
289
295 PCP_API
296 void DidChangePaths(const PcpCache* cache,
297 const SdfPath& oldPath, const SdfPath& newPath);
298
300 PCP_API
301 void DidDestroyCache(const PcpCache* cache);
302
307 PCP_API
309
311 PCP_API
312 void Swap(PcpChanges& other);
313
315 PCP_API
316 bool IsEmpty() const;
317
318 typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
319 typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
320
323 PCP_API
324 const LayerStackChanges& GetLayerStackChanges() const;
325
327 PCP_API
328 const CacheChanges& GetCacheChanges() const;
329
334 PCP_API
335 const PcpLifeboat& GetLifeboat() const;
336
338 PCP_API
339 void Apply() const;
340
341private:
342 // Internal data types for namespace edits from Sd.
343 typedef std::map<SdfPath, SdfPath> _PathEditMap;
344 typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
345
346 // Returns the PcpLayerStackChanges for the given layer stack.
347 PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
348
349 // Returns the PcpCacheChanges for the given cache.
350 PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
351
352 // Returns the _PathEditMap for the given cache.
353 _PathEditMap& _GetRenameChanges(const PcpCache* cache);
354
355
356 // Optimize the changes.
357 void _Optimize() const;
358
359 // Optimize the changes.
360 void _Optimize();
361
362 // Optimize the changes for a given cache.
363 void _Optimize(PcpCacheChanges*);
364
365 // Optimize path changes.
366 void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
367 const _PathEditMap* pathChanges);
368
369 // Sublayer change type for _DidChangeSublayer.
370 enum _SublayerChangeType {
371 _SublayerAdded,
372 _SublayerRemoved
373 };
374
375 // Helper function for loading a sublayer of \p layer at \p sublayerPath
376 // for processing changes described by \p sublayerChange.
377 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
378 const SdfLayerHandle& layer,
379 const std::string& sublayerPath,
380 _SublayerChangeType changeType) const;
381
382 // Helper function for loading a sublayer at \p sublayerPath
383 // for processing changes described by \p sublayerChange.
384 SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
385 const std::string& sublayerPath,
386 _SublayerChangeType changeType) const;
387
388 // Propagates changes to \p sublayer specified by \p sublayerChange to
389 // the dependents of that sublayer. This includes all layer stacks
390 // that include the sublayer.
391 void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
392 const PcpLayerStackPtrVector& stacks,
393 const std::string& sublayerPath,
394 const SdfLayerHandle& sublayer,
395 _SublayerChangeType sublayerChange,
396 std::string* debugSummary);
397
398 // Propagates changes to \p sublayer specified by \p sublayerChange to
399 // the dependents of that sublayer.
400 void _DidChangeSublayer(const PcpCache* cache,
401 const PcpLayerStackPtrVector& layerStacks,
402 const std::string& sublayerPath,
403 const SdfLayerHandle& sublayer,
404 _SublayerChangeType sublayerChange,
405 std::string* debugSummary,
406 bool *significant);
407
408 // Propagates changes due to the addition/removal of the sublayer
409 // at the given \p sublayerPath to/from the parent \p layer.
410 void _DidAddOrRemoveSublayer(const PcpCache* cache,
411 const PcpLayerStackPtrVector& layerStacks,
412 const SdfLayerHandle& layer,
413 const std::string& sublayerPath,
414 _SublayerChangeType sublayerChange,
415 std::string* debugSummary,
416 std::vector<bool> *significant);
417
418 // Mark the layer stack as having changed.
419 void _DidChangeLayerStack(
420 const PcpCache* cache,
421 const PcpLayerStackPtr& layerStack,
422 bool requiresLayerStackChange,
423 bool requiresLayerStackOffsetsChange,
424 bool requiresSignificantChange);
425
426 // Mark the layer stack's relocations as having changed.
427 // Recompute the new relocations, storing the result in the Changes,
428 // so that change-processing can determine which other caches it
429 // needs to invalidate.
430 void _DidChangeLayerStackRelocations(
431 const PcpCache* cache,
432 const PcpLayerStackPtr& layerStack,
433 std::string* debugSummary);
434
435 // Register changes to any prim indexes in \p caches that are affected
436 // by a change to a layer's resolved path used by \p layerStack.
437 void _DidChangeLayerStackResolvedPath(
438 const PcpCache* cache,
439 const PcpLayerStackPtr& layerStack,
440 bool requiresLayerStackChange,
441 std::string* debugSummary);
442
443 // Register changes to layer stacks and prim indexes in \p cache that are
444 // affected by a change to a layer's expression variables used by
445 // \p layerStack.
446 void _DidChangeLayerStackExpressionVariables(
447 const PcpCache* cache,
448 const PcpLayerStackPtr& layerStack,
449 std::string* debugSummary);
450
451 // The spec stack for the prim or property index at \p path must be
452 // recomputed due to a change that affects only the internal representation
453 // of the stack and not its contents.
454 void _DidChangeSpecStackInternal(
455 const PcpCache* cache, const SdfPath& path);
456
457 void _DidChangeSpecStackAndChildrenInternal(
458 const PcpCache* cache, const SdfPath& path);
459
460 // This method is used when processing layer operations. It ensures that
461 // affected layer stacks and their dependent spec stacks are marked as
462 // changed.
463 void _ProcessLayerStackAndDependencyChanges(
464 const PcpCache* cache,
465 const PcpLayerStackPtrVector& layerStacks);
466
467 // When muting or unmuting a layer that is being referenced or payloaded,
468 // we need to ensure that all the relevant sites are recomposed. This
469 // function searches site dependencies of the provided layer stacks and
470 // marks those that are introduced via reference or payload arcs as
471 // significantly changed.
472 void _MarkReferencingSitesAsSignificantlyChanged(
473 const PcpCache* cache,
474 const PcpLayerStackPtrVector& layerStacks);
475
476private:
477 LayerStackChanges _layerStackChanges;
478 CacheChanges _cacheChanges;
479 _RenameChanges _renameChanges;
480 mutable PcpLifeboat _lifeboat;
481};
482
483PXR_NAMESPACE_CLOSE_SCOPE
484
485#endif // PXR_USD_PCP_CHANGES_H
Types of changes per cache.
Definition: changes.h:101
std::vector< std::pair< SdfPath, SdfPath > > didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:127
bool didMuteOrUnmuteNonEmptyLayer
Will be true if a muting operation took place on a non empty layer.
Definition: changes.h:133
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:118
bool didAddOrRemoveNonEmptySublayer
Will be true if a non empty sublayer was added or removed.
Definition: changes.h:136
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:114
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:140
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:111
bool didMaybeChangeLayers
Layers used in the composition may have changed.
Definition: changes.h:130
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:121
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:207
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 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.
Represents the layer stack associated with a set of expression variables.
Types of changes per layer stack.
Definition: changes.h:38
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:64
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:41
bool didChangeExpressionVariables
Must rebuild expression variables.
Definition: changes.h:50
VtDictionary newExpressionVariables
New expression variables for this layer stack.
Definition: changes.h:75
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:44
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:57
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:72
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:47
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:175
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:43
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