Loading...
Searching...
No Matches
flatteningSceneIndex.h
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
29#include "pxr/imaging/hd/filteringSceneIndex.h"
30
31#include "pxr/usd/sdf/pathTable.h"
32#include <tbb/concurrent_hash_map.h>
33
34PXR_NAMESPACE_OPEN_SCOPE
35
36using HdFlattenedDataSourceProviderSharedPtr =
37 std::shared_ptr<class HdFlattenedDataSourceProvider>;
38using HdFlattenedDataSourceProviderSharedPtrVector =
39 std::vector<HdFlattenedDataSourceProviderSharedPtr>;
40
41namespace HdFlatteningSceneIndex_Impl
42{
43constexpr uint32_t _smallVectorSize = 8;
44using _DataSourceLocatorSetVector =
46}
47
49
61{
62public:
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
86 const TfTokenVector &
88 return _dataSourceNames;
89 }
90
92 const HdFlattenedDataSourceProviderSharedPtrVector &
94 return _dataSourceProviders;
95 }
96
97protected:
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
117private:
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;
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) for the object at primPath.
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:65
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:291
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:83
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:179
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
A notice indicating a prim was invalidated.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:439
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442