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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_FLATTENING_SCENE_H
25 #define PXR_IMAGING_HD_FLATTENING_SCENE_H
26 
27 #include "pxr/imaging/hd/api.h"
28 
30 
31 #include "pxr/usd/sdf/pathTable.h"
32 #include <tbb/concurrent_hash_map.h>
33 
35 
37  std::shared_ptr<class HdFlattenedDataSourceProvider>;
39  std::vector<HdFlattenedDataSourceProviderSharedPtr>;
40 
41 namespace HdFlatteningSceneIndex_Impl
42 {
43 constexpr uint32_t _smallVectorSize = 8;
46 }
47 
49 
50 ///
51 /// \class HdFlatteningSceneIndex
52 ///
53 /// A scene index that observes an input scene index and produces a comparable
54 /// scene in which inherited state is represented at leaf prims.
55 ///
56 /// This kind of representation is useful for render delegates that
57 /// require some/all the information to be available at the leaf prims.
58 /// It is also useful to express scene description composition functionality
59 /// (e.g., material binding resolution that factors inherited opinions) via
60 /// flattened data source provider(s).
61 ///
63 {
64 public:
65  /// Creates a new flattening scene index.
66  /// inputArgs maps names to HdFlattenedDataSourceProviderSharedPtr's.
67  /// That provider flattens the data sources under the locator name
68  /// in each prim source.
69  ///
70  static HdFlatteningSceneIndexRefPtr New(
71  HdSceneIndexBaseRefPtr const &inputScene,
72  HdContainerDataSourceHandle const &inputArgs) {
73  return TfCreateRefPtr(
74  new HdFlatteningSceneIndex(inputScene, inputArgs));
75  }
76 
77  HD_API
78  ~HdFlatteningSceneIndex() override;
79 
80  // satisfying HdSceneIndexBase
81  HD_API
82  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
83 
84  HD_API
85  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
86 
87  /// Data sources under locator name in a prim source get flattened.
88  const TfTokenVector &
90  return _dataSourceNames;
91  }
92 
93  /// Providers in the same order as GetFlattenedDataSourceNames.
96  return _dataSourceProviders;
97  }
98 
99 protected:
100 
101  HD_API
103  HdSceneIndexBaseRefPtr const &inputScene,
104  HdContainerDataSourceHandle const &inputArgs);
105 
106  // satisfying HdSingleInputFilteringSceneIndexBase
107  void _PrimsAdded(
108  const HdSceneIndexBase &sender,
109  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
110 
111  void _PrimsRemoved(
112  const HdSceneIndexBase &sender,
113  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
114 
115  void _PrimsDirtied(
116  const HdSceneIndexBase &sender,
117  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
118 
119 private:
120  using _DataSourceLocatorSetVector =
122 
123  // Consolidate _recentPrims into _prims.
124  void _ConsolidateRecentPrims();
125 
126  void _DirtyHierarchy(
127  const SdfPath &primPath,
128  const _DataSourceLocatorSetVector &relativeDirtyLocators,
129  const HdDataSourceLocatorSet &dirtyLocators,
131 
132  void _PrimDirtied(
135 
136  // _dataSourceNames and _dataSourceProviders run in parallel
137  // and indicate that a data source at locator name in a prim data
138  // source gets flattened by provider.
139  TfTokenVector _dataSourceNames;
141 
142  // Stores all data source names - convenient to quickly send out
143  // dirty messages for ancestors of resynced prims.
144  HdDataSourceLocatorSet _dataSourceLocatorSet;
145  // Stores universal set for each name in data source names - convenient
146  // to quickly invalidate all relevant data sourced of ancestors of
147  // resynced prim.
148  _DataSourceLocatorSetVector _relativeDataSourceLocators;
149 
150  // members
151  using _PrimTable = SdfPathTable<HdSceneIndexPrim>;
152  _PrimTable _prims;
153 
154  struct _PathHashCompare {
155  static bool equal(const SdfPath &a, const SdfPath &b) {
156  return a == b;
157  }
158  static size_t hash(const SdfPath &path) {
159  return hash_value(path);
160  }
161  };
162  using _RecentPrimTable =
163  tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
164  mutable _RecentPrimTable _recentPrims;
165 };
166 
168 
169 #endif
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1223
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:40
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
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:457
Definition: path.h:290
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
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:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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)