Loading...
Searching...
No Matches
generativeProceduralResolvingSceneIndex.h
1//
2// Copyright 2022 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_GP_GENERATIVE_PROCEDURAL_RESOLVING_SCENE_INDEX_H
25#define PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_RESOLVING_SCENE_INDEX_H
26
27#include "pxr/imaging/hdGp/generativeProcedural.h"
28#include "pxr/imaging/hd/filteringSceneIndex.h"
30
31#include <tbb/concurrent_unordered_map.h>
32#include <mutex>
33#include <unordered_map>
34#include <unordered_set>
35
36PXR_NAMESPACE_OPEN_SCOPE
37
61
64{
65public:
66
67 static HdGpGenerativeProceduralResolvingSceneIndexRefPtr New(
68 const HdSceneIndexBaseRefPtr &inputScene) {
69 return TfCreateRefPtr(
71 }
72
73 static HdGpGenerativeProceduralResolvingSceneIndexRefPtr New(
74 const HdSceneIndexBaseRefPtr &inputScene,
75 const TfToken &targetPrimTypeName) {
76 return TfCreateRefPtr(
78 inputScene, targetPrimTypeName));
79 }
80
82
83 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
84 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
85
86protected:
87
89 const HdSceneIndexBaseRefPtr &inputScene);
90
92 const HdSceneIndexBaseRefPtr &inputScene,
93 const TfToken &targetPrimTypeName);
94
96
98 const HdSceneIndexBase &sender,
99 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
100
101 void _PrimsRemoved(
102 const HdSceneIndexBase &sender,
103 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
104
105 void _PrimsDirtied(
106 const HdSceneIndexBase &sender,
107 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
108
110
112 const TfToken &messageType,
113 const HdDataSourceBaseHandle &args) override;
114
115private:
116
117 static HdGpGenerativeProcedural *_ConstructProcedural(
118 const TfToken &typeName, const SdfPath &proceduralPrimPath);
119
120
121 // MEMBER TYPES ///////////////////////////////////////////////////////////
122
124
125 static void _CombinePathArrays(const _DensePathSet &s, SdfPathVector *v);
126
127 struct _ProcEntry : public TfWeakBase
128 {
129 enum State : unsigned char {
130 StateUncooked = 0,
131 StateDependenciesCooking,
132 StateDependenciesCooked,
133 StateCooking,
134 StateCooked,
135 };
136
137 using _PathSetMap =
139
140 std::atomic<State> state;
141 TfToken typeName;
142 std::shared_ptr<HdGpGenerativeProcedural> proc;
145 _PathSetMap childHierarchy;
146 std::mutex cookMutex;
147
148
149 _ProcEntry()
150 : state(StateUncooked)
151 {}
152
153 _ProcEntry(const _ProcEntry &rhs)
154 {
155 state.store(rhs.state.load());
156 proc = rhs.proc;
157 typeName = rhs.typeName;
158 childTypes = rhs.childTypes;
159 dependencies = rhs.dependencies;
160 childHierarchy = rhs.childHierarchy;
161 }
162 };
163
164 TF_DECLARE_WEAK_PTRS(_ProcEntry);
165
166 struct _GeneratedPrimEntry
167 {
168 _GeneratedPrimEntry()
169 : responsibleProc(nullptr)
170 {}
171
172 _GeneratedPrimEntry(_ProcEntry * p)
173 : responsibleProc(p)
174 {}
175
176 _GeneratedPrimEntry(const _GeneratedPrimEntry &rhs)
177 {
178 responsibleProc.store(rhs.responsibleProc.load());
179 }
180 std::atomic<_ProcEntry *> responsibleProc;
181 };
182
183 using _GeneratedPrimsMap = tbb::concurrent_unordered_map<
184 SdfPath, _GeneratedPrimEntry, SdfPath::Hash>;
185
186 using _ProcEntryMap =
187 std::unordered_map<SdfPath, _ProcEntry, TfHash>;
188
189 using _WeakProcEntryMap =
190 tbb::concurrent_unordered_map<SdfPath, _ProcEntryPtr, TfHash>;
191
192 using _PathSet = std::unordered_set<SdfPath, TfHash>;
193
194 using _DependencyMap =
195 std::unordered_map<SdfPath, _PathSet, SdfPath::Hash>;
196
197 struct _Notices
198 {
202 };
203
204 // MEMBER FUNCTIONS ///////////////////////////////////////////////////////
205
206 _ProcEntry * _UpdateProceduralDependencies(
207 const SdfPath &proceduralPrimPath) const;
208
209 _ProcEntry * _UpdateProcedural(
210 const SdfPath &proceduralPrimPath,
211 bool forceUpdate,
212 _Notices *outputNotices,
214 *dirtiedDependencies = nullptr
215 ) const;
216
217
218 void _UpdateProceduralResult(
219 _ProcEntry *procEntry,
220 const SdfPath &proceduralPrimPath,
222 _Notices *outputNotices) const;
223
224
225 void _RemoveProcedural(
226 const SdfPath &proceduralPrimPath,
227 _Notices *outputNotices=nullptr) const;
228
229 // XXX Does thread-unsafe deletion.
230 // Removes deleted entries from _generatedPrims.
231 // This is private for now but intended for future use by a discussed formal
232 // method on HdSceneIndexBase itself.
233 void _GarbageCollect();
234
235 // MEMBER VARIABLES ///////////////////////////////////////////////////////
236 // procedural prim path -> entry
237 mutable _ProcEntryMap _procedurals;
238
239 mutable _WeakProcEntryMap _activeSyncProcedurals;
240
241 // reverse mapping of dependency -> dependent roots
242 mutable _DependencyMap _dependencies;
243
244 mutable _GeneratedPrimsMap _generatedPrims;
245
246 // no shared mutex, shared/unique lock is the same
247 using _MapMutex = std::mutex;
248 using _MapLock = std::lock_guard<_MapMutex>;
249 mutable _MapMutex _dependenciesMutex;
250 mutable _MapMutex _proceduralsMutex;
251
252 TfToken _targetPrimTypeName;
253
254 bool _attemptAsync;
255};
256
257PXR_NAMESPACE_CLOSE_SCOPE
258
259#endif
HdGpGenerativeProcedural is the base class for procedurals which have full access to an input scene i...
HdGpGenerativeProceduralResolvingSceneIndex is a scene index which evaluates prims representing gener...
void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
SATISFYING HdSingleInputFilteringSceneIndexBase ///////////////////////.
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
SATISFYING HdSceneIndexBase ///////////////////////////////////////////.
SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
void _SystemMessage(const TfToken &messageType, const HdDataSourceBaseHandle &args) override
Implement in order to react directly to system messages sent from downstream.
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
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
Definition: denseHashMap.h:58
This is a space efficient container that mimics the TfHashSet API that uses a vector for storage when...
Definition: denseHashSet.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition: declarePtrs.h:62
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52