HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flatteningSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_IMAGING_HD_FLATTENING_SCENE_H
8 #define PXR_IMAGING_HD_FLATTENING_SCENE_H
9 
10 #include "pxr/imaging/hd/api.h"
11 
13 
14 #include "pxr/usd/sdf/pathTable.h"
15 #include <tbb/concurrent_hash_map.h>
16 #include <tbb/concurrent_vector.h>
17 
19 
21  std::shared_ptr<class HdFlattenedDataSourceProvider>;
23  std::vector<HdFlattenedDataSourceProviderSharedPtr>;
24 
25 namespace HdFlatteningSceneIndex_Impl
26 {
27 // The value 9 was chosen to accommodate the following flattened data
28 // source providers without spilling to heap allocation:
29 //
30 // hd: coordSysBindings, primvars, purpose, visibility, xform
31 // usdImaging: geomModel, model, usdMaterialBindings
32 // usdSkelImaging: skelBindings
33 //
34 constexpr uint32_t _smallVectorSize = 9;
35 
38 class _PrimLevelWrappingDataSource;
39 }
40 
42 
43 ///
44 /// \class HdFlatteningSceneIndex
45 ///
46 /// A scene index that observes an input scene index and produces a comparable
47 /// scene in which inherited state is represented at leaf prims.
48 ///
49 /// This kind of representation is useful for render delegates that
50 /// require some/all the information to be available at the leaf prims.
51 /// It is also useful to express scene description composition functionality
52 /// (e.g., material binding resolution that factors inherited opinions) via
53 /// flattened data source provider(s).
54 ///
56 {
57 public:
58  /// Creates a new flattening scene index.
59  /// inputArgs maps names to HdFlattenedDataSourceProviderSharedPtr's.
60  /// That provider flattens the data sources under the locator name
61  /// in each prim source.
62  ///
63  static HdFlatteningSceneIndexRefPtr New(
64  HdSceneIndexBaseRefPtr const &inputScene,
65  HdContainerDataSourceHandle const &inputArgs) {
66  return TfCreateRefPtr(
67  new HdFlatteningSceneIndex(inputScene, inputArgs));
68  }
69 
70  HD_API
71  ~HdFlatteningSceneIndex() override;
72 
73  // satisfying HdSceneIndexBase
74  HD_API
75  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
76 
77  HD_API
78  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
79 
80  /// Data sources under locator name in a prim source get flattened.
81  const TfTokenVector &
83  return _dataSourceNames;
84  }
85 
86  /// Providers in the same order as GetFlattenedDataSourceNames.
89  return _dataSourceProviders;
90  }
91 
92 protected:
93 
94  HD_API
96  HdSceneIndexBaseRefPtr const &inputScene,
97  HdContainerDataSourceHandle const &inputArgs);
98 
99  // satisfying HdSingleInputFilteringSceneIndexBase
100  void _PrimsAdded(
101  const HdSceneIndexBase &sender,
102  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
103 
104  void _PrimsRemoved(
105  const HdSceneIndexBase &sender,
106  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
107 
108  void _PrimsDirtied(
109  const HdSceneIndexBase &sender,
110  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
111 
112 private:
114 
117 
118  // Consolidate _recentPrims into _prims.
119  void _ConsolidateRecentPrims();
120 
121  using _AdditionalDirtiedVector =
122  tbb::concurrent_vector<HdSceneIndexObserver::DirtiedPrimEntry>;
123 
124  void _DirtyHierarchy(
125  const SdfPath &primPath,
126  const _DataSourceLocatorSetVector &relativeDirtyLocators,
127  const HdDataSourceLocatorSet &dirtyLocators,
128  _AdditionalDirtiedVector *additionalDirty) const;
129 
130  void _PrimDirtied(
132  _AdditionalDirtiedVector *additionalDirty) const;
133 
134  // _dataSourceNames and _dataSourceProviders run in parallel
135  // and indicate that a data source at locator name in a prim data
136  // source gets flattened by provider.
137  TfTokenVector _dataSourceNames;
139 
140  // Stores all data source names - convenient to quickly send out
141  // dirty messages for ancestors of resynced prims.
142  HdDataSourceLocatorSet _dataSourceLocatorSet;
143  // Stores universal set for each name in data source names - convenient
144  // to quickly invalidate all relevant data sourced of ancestors of
145  // resynced prim.
146  _DataSourceLocatorSetVector _relativeDataSourceLocators;
147 
148  // members
150  _PrimTable _prims;
151 
152  struct _PathHashCompare {
153  static bool equal(const SdfPath &a, const SdfPath &b) {
154  return a == b;
155  }
156  static size_t hash(const SdfPath &path) {
157  return hash_value(path);
158  }
159  };
160  using _RecentPrimTable =
161  tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
162  mutable _RecentPrimTable _recentPrims;
163 };
164 
166 
167 #endif
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries) override
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define HD_API
Definition: api.h:23
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
Definition: ImathFun.h:105
std::shared_ptr< class HdFlattenedDataSourceProvider > HdFlattenedDataSourceProviderSharedPtr
HD_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries) override
TF_DECLARE_REF_PTRS(HdFlatteningSceneIndex)
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
std::vector< class SdfPath > SdfPathVector
HD_API HdFlatteningSceneIndex(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs)
const HdFlattenedDataSourceProviderSharedPtrVector & GetFlattenedDataSourceProviders() const
Providers in the same order as GetFlattenedDataSourceNames.
std::vector< HdFlattenedDataSourceProviderSharedPtr > HdFlattenedDataSourceProviderSharedPtrVector
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:280
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
const TfTokenVector & GetFlattenedDataSourceNames() const
Data sources under locator name in a prim source get flattened.
TfSmallVector< HdDataSourceLocatorSet, _smallVectorSize > _DataSourceLocatorSetVector
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
friend class HdFlatteningSceneIndex_Impl::_PrimLevelWrappingDataSource
static HdFlatteningSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs)
HD_API ~HdFlatteningSceneIndex() override
constexpr uint32_t _smallVectorSize
size_t hash_value(const CH_ChannelRef &ref)