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 
18 
20  std::shared_ptr<class HdFlattenedDataSourceProvider>;
22  std::vector<HdFlattenedDataSourceProviderSharedPtr>;
23 
24 namespace HdFlatteningSceneIndex_Impl
25 {
26 constexpr uint32_t _smallVectorSize = 8;
29 }
30 
32 
33 ///
34 /// \class HdFlatteningSceneIndex
35 ///
36 /// A scene index that observes an input scene index and produces a comparable
37 /// scene in which inherited state is represented at leaf prims.
38 ///
39 /// This kind of representation is useful for render delegates that
40 /// require some/all the information to be available at the leaf prims.
41 /// It is also useful to express scene description composition functionality
42 /// (e.g., material binding resolution that factors inherited opinions) via
43 /// flattened data source provider(s).
44 ///
46 {
47 public:
48  /// Creates a new flattening scene index.
49  /// inputArgs maps names to HdFlattenedDataSourceProviderSharedPtr's.
50  /// That provider flattens the data sources under the locator name
51  /// in each prim source.
52  ///
53  static HdFlatteningSceneIndexRefPtr New(
54  HdSceneIndexBaseRefPtr const &inputScene,
55  HdContainerDataSourceHandle const &inputArgs) {
56  return TfCreateRefPtr(
57  new HdFlatteningSceneIndex(inputScene, inputArgs));
58  }
59 
60  HD_API
61  ~HdFlatteningSceneIndex() override;
62 
63  // satisfying HdSceneIndexBase
64  HD_API
65  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
66 
67  HD_API
68  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
69 
70  /// Data sources under locator name in a prim source get flattened.
71  const TfTokenVector &
73  return _dataSourceNames;
74  }
75 
76  /// Providers in the same order as GetFlattenedDataSourceNames.
79  return _dataSourceProviders;
80  }
81 
82 protected:
83 
84  HD_API
86  HdSceneIndexBaseRefPtr const &inputScene,
87  HdContainerDataSourceHandle const &inputArgs);
88 
89  // satisfying HdSingleInputFilteringSceneIndexBase
90  void _PrimsAdded(
91  const HdSceneIndexBase &sender,
92  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
93 
94  void _PrimsRemoved(
95  const HdSceneIndexBase &sender,
96  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
97 
98  void _PrimsDirtied(
99  const HdSceneIndexBase &sender,
100  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
101 
102 private:
103  using _DataSourceLocatorSetVector =
105 
106  // Consolidate _recentPrims into _prims.
107  void _ConsolidateRecentPrims();
108 
109  void _DirtyHierarchy(
110  const SdfPath &primPath,
111  const _DataSourceLocatorSetVector &relativeDirtyLocators,
112  const HdDataSourceLocatorSet &dirtyLocators,
114 
115  void _PrimDirtied(
118 
119  // _dataSourceNames and _dataSourceProviders run in parallel
120  // and indicate that a data source at locator name in a prim data
121  // source gets flattened by provider.
122  TfTokenVector _dataSourceNames;
124 
125  // Stores all data source names - convenient to quickly send out
126  // dirty messages for ancestors of resynced prims.
127  HdDataSourceLocatorSet _dataSourceLocatorSet;
128  // Stores universal set for each name in data source names - convenient
129  // to quickly invalidate all relevant data sourced of ancestors of
130  // resynced prim.
131  _DataSourceLocatorSetVector _relativeDataSourceLocators;
132 
133  // members
134  using _PrimTable = SdfPathTable<HdSceneIndexPrim>;
135  _PrimTable _prims;
136 
137  struct _PathHashCompare {
138  static bool equal(const SdfPath &a, const SdfPath &b) {
139  return a == b;
140  }
141  static size_t hash(const SdfPath &path) {
142  return hash_value(path);
143  }
144  };
145  using _RecentPrimTable =
146  tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
147  mutable _RecentPrimTable _recentPrims;
148 };
149 
151 
152 #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
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:273
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
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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)