Loading...
Searching...
No Matches
flatteningSceneIndex.h
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
12#include "pxr/imaging/hd/filteringSceneIndex.h"
13
14#include "pxr/usd/sdf/pathTable.h"
15#include <tbb/concurrent_hash_map.h>
16#include <tbb/concurrent_vector.h>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
20using HdFlattenedDataSourceProviderSharedPtr =
21 std::shared_ptr<class HdFlattenedDataSourceProvider>;
22using HdFlattenedDataSourceProviderSharedPtrVector =
23 std::vector<HdFlattenedDataSourceProviderSharedPtr>;
24
25namespace 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//
34constexpr uint32_t _smallVectorSize = 9;
35
36using _DataSourceLocatorSetVector =
38class _PrimLevelWrappingDataSource;
39}
40
42
56{
57public:
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
81 const TfTokenVector &
83 return _dataSourceNames;
84 }
85
87 const HdFlattenedDataSourceProviderSharedPtrVector &
89 return _dataSourceProviders;
90 }
91
92protected:
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
112private:
113 friend class HdFlatteningSceneIndex_Impl::_PrimLevelWrappingDataSource;
114
115 using _DataSourceLocatorSetVector =
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;
138 HdFlattenedDataSourceProviderSharedPtrVector _dataSourceProviders;
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
165PXR_NAMESPACE_CLOSE_SCOPE
166
167#endif
Represents a set of data source locators closed under descendancy.
A scene index that observes an input scene index and produces a comparable scene in which inherited s...
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
const HdFlattenedDataSourceProviderSharedPtrVector & GetFlattenedDataSourceProviders() const
Providers in the same order as GetFlattenedDataSourceNames.
static HdFlatteningSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs)
Creates a new flattening scene index.
const TfTokenVector & GetFlattenedDataSourceNames() const
Data sources under locator name in a prim source get flattened.
HD_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
Abstract interface to scene data.
Definition: sceneIndex.h:54
An abstract base class for a filtering scene index that observes a single input scene index.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:281
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:66
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
A notice indicating a prim was invalidated.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:437
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440