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
63{
64public:
70 static HdFlatteningSceneIndexRefPtr New(
71 HdSceneIndexBaseRefPtr const &inputScene,
72 HdContainerDataSourceHandle const &inputArgs) {
73 return TfCreateRefPtr(
74 new HdFlatteningSceneIndex(inputScene, inputArgs));
75 }
76
77 HD_API
78 ~HdFlatteningSceneIndex() override;
79
80 // satisfying HdSceneIndexBase
81 HD_API
82 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
83
84 HD_API
85 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
86
88 const TfTokenVector &
90 return _dataSourceNames;
91 }
92
94 const HdFlattenedDataSourceProviderSharedPtrVector &
96 return _dataSourceProviders;
97 }
98
99protected:
100
101 HD_API
103 HdSceneIndexBaseRefPtr const &inputScene,
104 HdContainerDataSourceHandle const &inputArgs);
105
106 // satisfying HdSingleInputFilteringSceneIndexBase
107 void _PrimsAdded(
108 const HdSceneIndexBase &sender,
109 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
110
111 void _PrimsRemoved(
112 const HdSceneIndexBase &sender,
113 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
114
115 void _PrimsDirtied(
116 const HdSceneIndexBase &sender,
117 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
118
119private:
120 using _DataSourceLocatorSetVector =
122
123 // Consolidate _recentPrims into _prims.
124 void _ConsolidateRecentPrims();
125
126 void _DirtyHierarchy(
127 const SdfPath &primPath,
128 const _DataSourceLocatorSetVector &relativeDirtyLocators,
129 const HdDataSourceLocatorSet &dirtyLocators,
131
132 void _PrimDirtied(
135
136 // _dataSourceNames and _dataSourceProviders run in parallel
137 // and indicate that a data source at locator name in a prim data
138 // source gets flattened by provider.
139 TfTokenVector _dataSourceNames;
140 HdFlattenedDataSourceProviderSharedPtrVector _dataSourceProviders;
141
142 // Stores all data source names - convenient to quickly send out
143 // dirty messages for ancestors of resynced prims.
144 HdDataSourceLocatorSet _dataSourceLocatorSet;
145 // Stores universal set for each name in data source names - convenient
146 // to quickly invalidate all relevant data sourced of ancestors of
147 // resynced prim.
148 _DataSourceLocatorSetVector _relativeDataSourceLocators;
149
150 // members
151 using _PrimTable = SdfPathTable<HdSceneIndexPrim>;
152 _PrimTable _prims;
153
154 struct _PathHashCompare {
155 static bool equal(const SdfPath &a, const SdfPath &b) {
156 return a == b;
157 }
158 static size_t hash(const SdfPath &path) {
159 return hash_value(path);
160 }
161 };
162 using _RecentPrimTable =
163 tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
164 mutable _RecentPrimTable _recentPrims;
165};
166
167PXR_NAMESPACE_CLOSE_SCOPE
168
169#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:290
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:454
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457