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 typically required for legacy-style
57 /// render delegates that require all the information to be available at the
58 /// leaf prims.
59 ///
61 {
62 public:
63  /// Creates a new flattening scene index.
64  /// inputArgs maps names to HdFlattenedDataSourceProviderSharedPtr's.
65  /// That provider flattens the data sources under the locator name
66  /// in each prim source.
67  ///
68  static HdFlatteningSceneIndexRefPtr New(
69  HdSceneIndexBaseRefPtr const &inputScene,
70  HdContainerDataSourceHandle const &inputArgs) {
71  return TfCreateRefPtr(
72  new HdFlatteningSceneIndex(inputScene, inputArgs));
73  }
74 
75  HD_API
76  ~HdFlatteningSceneIndex() override;
77 
78  // satisfying HdSceneIndexBase
79  HD_API
80  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
81 
82  HD_API
83  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
84 
85  /// Data sources under locator name in a prim source get flattened.
86  const TfTokenVector &
88  return _dataSourceNames;
89  }
90 
91  /// Providers in the same order as GetFlattenedDataSourceNames.
94  return _dataSourceProviders;
95  }
96 
97 protected:
98 
99  HD_API
101  HdSceneIndexBaseRefPtr const &inputScene,
102  HdContainerDataSourceHandle const &inputArgs);
103 
104  // satisfying HdSingleInputFilteringSceneIndexBase
105  void _PrimsAdded(
106  const HdSceneIndexBase &sender,
107  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
108 
109  void _PrimsRemoved(
110  const HdSceneIndexBase &sender,
111  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
112 
113  void _PrimsDirtied(
114  const HdSceneIndexBase &sender,
115  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
116 
117 private:
118  using _DataSourceLocatorSetVector =
120 
121  // Consolidate _recentPrims into _prims.
122  void _ConsolidateRecentPrims();
123 
124  void _DirtyHierarchy(
125  const SdfPath &primPath,
126  const _DataSourceLocatorSetVector &relativeDirtyLocators,
127  const HdDataSourceLocatorSet &dirtyLocators,
129 
130  void _PrimDirtied(
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
149  using _PrimTable = SdfPathTable<HdSceneIndexPrim>;
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:1198
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:442
Definition: path.h:291
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
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:1441
#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)