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