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
17PXR_NAMESPACE_OPEN_SCOPE
18
19using HdFlattenedDataSourceProviderSharedPtr =
20 std::shared_ptr<class HdFlattenedDataSourceProvider>;
21using HdFlattenedDataSourceProviderSharedPtrVector =
22 std::vector<HdFlattenedDataSourceProviderSharedPtr>;
23
24namespace HdFlatteningSceneIndex_Impl
25{
26constexpr uint32_t _smallVectorSize = 8;
27using _DataSourceLocatorSetVector =
29class _PrimLevelWrappingDataSource;
30}
31
33
47{
48public:
54 static HdFlatteningSceneIndexRefPtr New(
55 HdSceneIndexBaseRefPtr const &inputScene,
56 HdContainerDataSourceHandle const &inputArgs) {
57 return TfCreateRefPtr(
58 new HdFlatteningSceneIndex(inputScene, inputArgs));
59 }
60
61 HD_API
62 ~HdFlatteningSceneIndex() override;
63
64 // satisfying HdSceneIndexBase
65 HD_API
66 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
67
68 HD_API
69 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
70
72 const TfTokenVector &
74 return _dataSourceNames;
75 }
76
78 const HdFlattenedDataSourceProviderSharedPtrVector &
80 return _dataSourceProviders;
81 }
82
83protected:
84
85 HD_API
87 HdSceneIndexBaseRefPtr const &inputScene,
88 HdContainerDataSourceHandle const &inputArgs);
89
90 // satisfying HdSingleInputFilteringSceneIndexBase
91 void _PrimsAdded(
92 const HdSceneIndexBase &sender,
93 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
94
95 void _PrimsRemoved(
96 const HdSceneIndexBase &sender,
97 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
98
99 void _PrimsDirtied(
100 const HdSceneIndexBase &sender,
101 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
102
103private:
104 friend class HdFlatteningSceneIndex_Impl::_PrimLevelWrappingDataSource;
105
106 using _DataSourceLocatorSetVector =
108
109 // Consolidate _recentPrims into _prims.
110 void _ConsolidateRecentPrims();
111
112 void _DirtyHierarchy(
113 const SdfPath &primPath,
114 const _DataSourceLocatorSetVector &relativeDirtyLocators,
115 const HdDataSourceLocatorSet &dirtyLocators,
117
118 void _PrimDirtied(
121
122 // _dataSourceNames and _dataSourceProviders run in parallel
123 // and indicate that a data source at locator name in a prim data
124 // source gets flattened by provider.
125 TfTokenVector _dataSourceNames;
126 HdFlattenedDataSourceProviderSharedPtrVector _dataSourceProviders;
127
128 // Stores all data source names - convenient to quickly send out
129 // dirty messages for ancestors of resynced prims.
130 HdDataSourceLocatorSet _dataSourceLocatorSet;
131 // Stores universal set for each name in data source names - convenient
132 // to quickly invalidate all relevant data sourced of ancestors of
133 // resynced prim.
134 _DataSourceLocatorSetVector _relativeDataSourceLocators;
135
136 // members
137 using _PrimTable = SdfPathTable<HdSceneIndexPrim>;
138 _PrimTable _prims;
139
140 struct _PathHashCompare {
141 static bool equal(const SdfPath &a, const SdfPath &b) {
142 return a == b;
143 }
144 static size_t hash(const SdfPath &path) {
145 return hash_value(path);
146 }
147 };
148 using _RecentPrimTable =
149 tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
150 mutable _RecentPrimTable _recentPrims;
151};
152
153PXR_NAMESPACE_CLOSE_SCOPE
154
155#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:274
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