HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
indexProxy.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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_IMAGING_USD_IMAGING_INDEX_PROXY_H
8 #define PXR_USD_IMAGING_USD_IMAGING_INDEX_PROXY_H
9 
10 /// \file usdImaging/indexProxy.h
11 
12 #include "pxr/pxr.h"
15 
16 #include "pxr/usd/sdf/path.h"
17 #include "pxr/usd/usd/prim.h"
18 
19 #include "pxr/base/tf/token.h"
20 
21 
23 
24 
25 /// \class UsdImagingIndexProxy
26 ///
27 /// This proxy class exposes a subset of the private Delegate API to
28 /// PrimAdapters.
29 ///
31 public:
32  /// A note on paths/prims: the core function of UsdImagingIndexProxy and
33  /// UsdImagingDelegate is to maintain a set of mappings between USD prims
34  /// and hydra prims (and a set of adapters that know how to translate
35  /// USD properties to hydra buffers). A USD prim can represent multiple
36  /// hydra prims (e.g. point instancer prototypes that are referenced twice),
37  /// and a hydra prim can represent multiple USD prims (e.g. a single hydra
38  /// instancer prim representing multiple native instances).
39  ///
40  /// There are three different prim "namespaces" that the delegate works
41  /// with: "USD paths", which represent paths to USD prims; "index paths",
42  /// which represent paths to hydra prims in the render index; and
43  /// "cache paths", which represent paths to buffers in the value cache
44  /// backing hydra prims. Cache paths and index paths are the same,
45  /// except that index paths have the "delegateID" prefixed onto their path.
46  ///
47  /// Index paths are only used in the interface to hydra. In IndexProxy
48  /// and the adapters, the pattern is to use "cachePath" as a key to look
49  /// up state for a hydra prim; and pass "usdPrim" when we additionally
50  /// need to specify the related USD prim. The naming helps clarify them,
51  /// and the fact that we pass a UsdPrim and not an SdfPath further ensures
52  /// that we pass valid USD paths instead of passing cache paths by mistake.
53 
54 
55  /// Adds a dependency from the given usdPrim to the given cache path.
56  /// Insert* will automatically add a dependency, so this is for hydra prims
57  /// that may depend on more than one usd prim (e.g. subsets, instancers)
59  void AddDependency(SdfPath const& cachePath,
60  UsdPrim const& usdPrim);
61 
62  /// Insert a hydra prim with the specified cache path. As mentioned above,
63  /// the delegateID will be prepended before adding the prim in hydra, but
64  /// cachePath will be the key into all internal usdImaging datastructures.
65  /// usdPrim is the USD prim this hydra prim is representing (e.g. the
66  /// UsdGeomMesh for which we are inserting a hydra mesh). If no
67  /// adapter is specified, UsdImagingDelegate will choose based on Usd
68  /// prim type; some clients (e.g. instancing) want to override the adapter
69  /// choice but this should be used sparingly.
70  ///
71  /// For Rprims and Instancers, "parentPath" is the parent instancer.
73  void InsertRprim(TfToken const& primType,
74  SdfPath const& cachePath,
75  UsdPrim const& usdPrim,
78 
80  void InsertSprim(TfToken const& primType,
81  SdfPath const& cachePath,
82  UsdPrim const& usdPrim,
85 
87  void InsertBprim(TfToken const& primType,
88  SdfPath const& cachePath,
89  UsdPrim const& usdPrim,
92 
94  void InsertInstancer(SdfPath const& cachePath,
95  UsdPrim const& usdPrim,
98 
99  // Mark a prim as needing follow-up work by the delegate, either
100  // TrackVariability or UpdateForTime. Both of these are automatically
101  // called on Insert*, but sometimes need to be manually triggered as well.
103  void RequestTrackVariability(SdfPath const& cachePath);
104 
106  void RequestUpdateForTime(SdfPath const& cachePath);
107 
108  //
109  // All removals are deferred to avoid surprises during change processing.
110  //
111 
112  // Removes the Rprim at the specified cache path.
113  void RemoveRprim(SdfPath const& cachePath) {
114  _rprimsToRemove.push_back(cachePath);
115  _hdPrimInfoToRemove.push_back(cachePath);
116  _RemoveDependencies(cachePath);
117  }
118 
119  // Removes the Sprim at the specified cache path.
120  void RemoveSprim(TfToken const& primType, SdfPath const& cachePath) {
121  _TypeAndPath primToRemove = {primType, cachePath};
122  _sprimsToRemove.push_back(primToRemove);
123  _hdPrimInfoToRemove.push_back(cachePath);
124  _RemoveDependencies(cachePath);
125  }
126 
127  // Removes the Bprim at the specified cache path.
128  void RemoveBprim(TfToken const& primType, SdfPath const& cachePath) {
129  _TypeAndPath primToRemove = {primType, cachePath};
130  _bprimsToRemove.push_back(primToRemove);
131  _hdPrimInfoToRemove.push_back(cachePath);
132  _RemoveDependencies(cachePath);
133  }
134 
135  // Removes the HdInstancer at the specified cache path.
136  void RemoveInstancer(SdfPath const& cachePath) {
137  _instancersToRemove.push_back(cachePath);
138  _hdPrimInfoToRemove.push_back(cachePath);
139  _RemoveDependencies(cachePath);
140  }
141 
143  void MarkRprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
144 
146  void MarkSprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
147 
149  void MarkBprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
150 
152  void MarkInstancerDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
153 
155  bool IsRprimTypeSupported(TfToken const& typeId) const;
156 
158  bool IsSprimTypeSupported(TfToken const& typeId) const;
159 
161  bool IsBprimTypeSupported(TfToken const& typeId) const;
162 
163  // Check if the given path has been populated yet.
165  bool IsPopulated(SdfPath const& cachePath) const;
166 
167  // Recursively repopulate the specified usdPath into the render index.
169  void Repopulate(SdfPath const& usdPath);
170 
173  UsdPrim const& materialPrim);
174 
175  // XXX: This is a workaround for some bugs in USD edit processing, and
176  // the weird use of HdPrimInfo by instanced prims. It removes the dependency
177  // between a hydra prim and whatever USD prim is in its primInfo, since this
178  // dependency is automatically inserted and for instanced prims will
179  // erroneously add a dependency between a hydra prototype and
180  // a USD instancer.
181  //
182  // Pending some refactoring, hopefully this API will disappear.
184  void RemovePrimInfoDependency(SdfPath const& cachePath);
185 
186 private:
187  friend class UsdImagingDelegate;
189  UsdImagingDelegate::_Worker* worker)
190  : _delegate(delegate)
191  , _worker(worker)
192  {}
193 
194  // Sort and de-duplicate "repopulate" paths to prevent double-inserts.
195  // Called by UsdImagingDelegate::ApplyPendingUpdates.
196  void _UniqueifyPathsToRepopulate();
197 
198  UsdImagingDelegate::_HdPrimInfo*
199  _AddHdPrimInfo(SdfPath const& cachePath,
200  UsdPrim const& usdPrim,
201  UsdImagingPrimAdapterSharedPtr const& adapter);
202 
204  void _RemoveDependencies(SdfPath const& cachePath);
205 
206  SdfPathVector const& _GetUsdPathsToRepopulate() {
207  return _usdPathsToRepopulate;
208  }
209  void _ProcessRemovals();
210 
211  void _AddTask(SdfPath const& usdPath);
212 
213  struct _TypeAndPath {
214  TfToken primType;
215  SdfPath cachePath;
216  };
217 
218  typedef std::vector<_TypeAndPath> _TypeAndPathVector;
219 
220  typedef std::vector<UsdImagingDelegate::_DependencyMap::value_type>
221  _DependencyVector;
222 
223  UsdImagingDelegate* _delegate;
224  UsdImagingDelegate::_Worker* _worker;
225  SdfPathVector _usdPathsToRepopulate;
226  SdfPathVector _rprimsToRemove;
227  _TypeAndPathVector _sprimsToRemove;
228  _TypeAndPathVector _bprimsToRemove;
229  SdfPathVector _instancersToRemove;
230  SdfPathVector _hdPrimInfoToRemove;
231  _DependencyVector _dependenciesToRemove;
232 };
233 
234 
236 
237 #endif //PXR_USD_IMAGING_USD_IMAGING_INDEX_PROXY_H
USDIMAGING_API bool IsSprimTypeSupported(TfToken const &typeId) const
#define USDIMAGING_API
Definition: api.h:23
USDIMAGING_API void InsertSprim(TfToken const &primType, SdfPath const &cachePath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
void RemoveInstancer(SdfPath const &cachePath)
Definition: indexProxy.h:136
USDIMAGING_API void RequestTrackVariability(SdfPath const &cachePath)
uint32_t HdDirtyBits
Definition: types.h:143
USDIMAGING_API void MarkInstancerDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
friend class UsdImagingIndexProxy
Definition: delegate.h:514
void RemoveRprim(SdfPath const &cachePath)
Definition: indexProxy.h:113
USDIMAGING_API UsdImagingPrimAdapterSharedPtr GetMaterialAdapter(UsdPrim const &materialPrim)
Definition: token.h:70
USDIMAGING_API void InsertBprim(TfToken const &primType, SdfPath const &cachePath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
std::vector< class SdfPath > SdfPathVector
USDIMAGING_API bool IsRprimTypeSupported(TfToken const &typeId) const
Definition: prim.h:116
USDIMAGING_API void RequestUpdateForTime(SdfPath const &cachePath)
USDIMAGING_API void AddDependency(SdfPath const &cachePath, UsdPrim const &usdPrim)
USDIMAGING_API void MarkRprimDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
Definition: path.h:273
void RemoveBprim(TfToken const &primType, SdfPath const &cachePath)
Definition: indexProxy.h:128
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
void RemoveSprim(TfToken const &primType, SdfPath const &cachePath)
Definition: indexProxy.h:120
USDIMAGING_API bool IsPopulated(SdfPath const &cachePath) const
USDIMAGING_API void RemovePrimInfoDependency(SdfPath const &cachePath)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
USDIMAGING_API void InsertRprim(TfToken const &primType, SdfPath const &cachePath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
USDIMAGING_API void MarkSprimDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
USDIMAGING_API void MarkBprimDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
USDIMAGING_API void InsertInstancer(SdfPath const &cachePath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
USDIMAGING_API void Repopulate(SdfPath const &usdPath)
USDIMAGING_API bool IsBprimTypeSupported(TfToken const &typeId) const