Loading...
Searching...
No Matches
stageData.h
Go to the documentation of this file.
1//
2// Copyright 2026 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_EXEC_ESF_USD_STAGE_DATA_H
8#define PXR_EXEC_ESF_USD_STAGE_DATA_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/esfUsd/api.h"
15
17#include "pxr/base/tf/hash.h"
18#include "pxr/usd/sdf/path.h"
19
20#ifdef TBB_PREVIEW_CONCURRENT_ORDERED_CONTAINERS
21#include <tbb/concurrent_map.h>
22#else
23#define TBB_PREVIEW_CONCURRENT_ORDERED_CONTAINERS 1
24#include <tbb/concurrent_map.h>
25#undef TBB_PREVIEW_CONCURRENT_ORDERED_CONTAINERS
26#endif
27
28#include <tbb/concurrent_unordered_map.h>
29#include <tbb/concurrent_unordered_set.h>
30#include <tbb/concurrent_vector.h>
31
32#include <memory>
33
34PXR_NAMESPACE_OPEN_SCOPE
35
36class UsdAttribute;
37class UsdPrim;
38
40
52{
53 EsfUsdStageData(const UsdStageConstPtr &stage);
54
55public:
56
57 ESFUSD_API
59
64 ESFUSD_API
65 static std::shared_ptr<EsfUsdStageData> RegisterStage(
66 const UsdStageConstPtr &stage);
67
76 ESFUSD_API
78 const UsdStageConstPtr &stage);
79
83 using ChangedPathSet = tbb::concurrent_unordered_set<SdfPath, TfHash>;
84
91 ESFUSD_API
93 const SdfPath &attrPath,
94 ChangedPathSet *incomingConnectionsChanged);
95
99 ESFUSD_API
101 const SdfPath &resyncedPath,
102 ChangedPathSet *incomingConnectionsChanged);
103
107 ESFUSD_API
108 static const SdfPathVector &GetOutgoingConnections(
109 const UsdStageConstPtr &stage,
110 const SdfPath &attrPath);
111
115 ESFUSD_API
116 static SdfPathVector GetIncomingConnections(
117 const UsdStageConstPtr &stage,
118 const SdfPath &targetPath);
119
120private:
121 const SdfPathVector &_GetOutgoingConnections(
122 const SdfPath &targetPath);
123
124 SdfPathVector _GetIncomingConnections(
125 const SdfPath &targetPath);
126
127 void _PopulateConnectionTables();
128
129 // Define a type and a corresponding transparent comparator so that we can
130 // use lower_bound to find the end of a map range with keys that are paths
131 // with a given prefix.
132
133 struct _PathPrefix
134 {
135 SdfPath prefix;
136 };
137
138 struct _PathRangeLessThan
139 {
140 using is_transparent = void;
141
142 bool operator()(const SdfPath &lhs, const SdfPath &rhs) const {
143 return lhs < rhs;
144 }
145
146 bool operator()(const SdfPath &lhs, const _PathPrefix& rhs) const {
147 return lhs < rhs.prefix || lhs.HasPrefix(rhs.prefix);
148 }
149 };
150
151 // A concurrent map from owning attribute paths to target object paths.
152 using _OutgoingPathTable =
153 tbb::concurrent_map<SdfPath, SdfPathVector, _PathRangeLessThan>;
154
155 // A concurent map from target object paths to owning attribute paths.
156 using _IncomingPathTable =
157 tbb::concurrent_unordered_map<
158 SdfPath, tbb::concurrent_vector<SdfPath>, TfHash>;
159
160 // Gets the new (i.e., current) connections for the given attribute and
161 // computes the added and removed target paths, relative to what was
162 // previously stored in the outgoing connection paths table.
163 //
164 void _GetChangedConnectionTargets(
165 const SdfPath &attrPath,
166 const UsdAttribute &attribute,
167 SdfPathVector *newConnections,
168 SdfPathVector *addedTargetPaths,
169 SdfPathVector *removedTargetPaths) const;
170
171 // Updates outgoing and incoming connection tables for any changes to the
172 // given prim.
173 //
174 // New incoming connections are added immediately; new outgoing connections
175 // and removed incoming connections are queued up for deferred processing,
176 // to allow this method to be called in parallel.
177 //
178 void _UpdateForChangedPrim(
179 const UsdPrim &prim,
180 _IncomingPathTable *incomingToRemove,
181 ChangedPathSet *incomingConnectionsChanged);
182
183 // Find entries in the outgoing connections map for attributes on the
184 // resynced prim and its descendants that no longer exist in the scene,
185 // populating \p ownerAttrsToRemove and \p incomingToRemove.
186 //
187 void _UpdateForRemovedAttributes(
188 const SdfPath &resyncedPath,
189 _IncomingPathTable *incomingToRemove,
190 tbb::concurrent_vector<SdfPath> *ownerAttrsToRemove) const;
191
192 // Removes the entries indicated by \p incomingToRemove from _incoming.
193 //
194 void _RemoveIncomingTableEntries(
195 const _IncomingPathTable &incomingToRemove);
196
197private:
198 const UsdStageConstPtr _stage;
199
200 _OutgoingPathTable _outgoing;
201
202 _IncomingPathTable _incoming;
203};
204
205PXR_NAMESPACE_CLOSE_SCOPE
206
207#endif
Class that holds data that is cached per-stage.
Definition: stageData.h:52
static ESFUSD_API const SdfPathVector & GetOutgoingConnections(const UsdStageConstPtr &stage, const SdfPath &attrPath)
Returns the paths of all objects that are targets of connections owned by the attribute at attrPath.
static ESFUSD_API SdfPathVector GetIncomingConnections(const UsdStageConstPtr &stage, const SdfPath &targetPath)
Returns the paths of all attributes that own connections that target the object at targetPath.
static ESFUSD_API std::shared_ptr< EsfUsdStageData > RegisterStage(const UsdStageConstPtr &stage)
Registers stage as a stage for which cached data should be held, returning a strong reference the cli...
tbb::concurrent_unordered_set< SdfPath, TfHash > ChangedPathSet
A concurent set of paths, used to indicate the set of targets for which incoming connections have cha...
Definition: stageData.h:83
ESFUSD_API void UpdateForResync(const SdfPath &resyncedPath, ChangedPathSet *incomingConnectionsChanged)
Updates attribute connection caches for connections owned by attribute at or under resyncedPath.
static ESFUSD_API EsfUsdStageData & GetStageData(const UsdStageConstPtr &stage)
Get the cached stage data for stage.
ESFUSD_API void UpdateForChangedAttributeConnections(const SdfPath &attrPath, ChangedPathSet *incomingConnectionsChanged)
Updates attribute connection caches for connections owned by the attribute at attrPath.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:281
SDF_API bool HasPrefix(const SdfPath &prefix) const
Return true if both this path and prefix are not the empty path and this path has prefix as a prefix.
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:472
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:183
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:135
Standard pointer typedefs.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition: declarePtrs.h:45