Loading...
Searching...
No Matches
locatorCachingSceneIndex.h
1//
2// Copyright 2026 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_HDSI_LOCATOR_CACHING_SCENE_INDEX
8#define PXR_IMAGING_HDSI_LOCATOR_CACHING_SCENE_INDEX
9
10#include "pxr/imaging/hd/api.h"
11#include "pxr/imaging/hd/filteringSceneIndex.h"
12#include "pxr/usd/sdf/pathTable.h"
14#include <mutex>
15
16PXR_NAMESPACE_OPEN_SCOPE
17
19
143{
144public:
149 HD_API
150 static HdSceneIndexBaseRefPtr
152 HdSceneIndexBaseRefPtr const& inputScene,
153 HdDataSourceLocator const& locatorToCache,
154 TfToken const& primTypeToCache,
155 bool const& cacheDescendants = true);
156
169 HD_API
170 static HdsiLocatorCachingSceneIndexRefPtr
171 New(HdSceneIndexBaseRefPtr const& inputScene,
172 HdDataSourceLocator const& locatorToCache,
173 TfToken const& primTypeToCache,
174 bool const& cacheDescendants = true);
175
176 HD_API
178
179 HD_API
180 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
181
182 HD_API
183 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
184
185protected:
186 HD_API
188 HdSceneIndexBaseRefPtr const& inputScene,
189 HdDataSourceLocator const& locatorToCache,
190 TfToken const& primTypeToCache,
191 bool const& cacheDescendants);
192
193 void _PrimsAdded(
194 const HdSceneIndexBase &sender,
195 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
196 void _PrimsRemoved(
197 const HdSceneIndexBase &sender,
198 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
199 void _PrimsDirtied(
200 const HdSceneIndexBase &sender,
201 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
203 const TfToken& messageType,
204 const HdDataSourceBaseHandle& args) override;
205
206 // A data source that delegates back to HdsiLocatorCachingSceneIndex, allowing
207 // it to manage invalidation.
208 class _DataSource : public HdContainerDataSource
209 {
210 public:
211 HD_DECLARE_DATASOURCE(_DataSource);
212
213 TfTokenVector GetNames() override;
214 HdDataSourceBaseHandle Get(const TfToken &name) override;
215
216 private:
217 _DataSource(
218 HdsiLocatorCachingSceneIndex const* cachingSceneIndex,
219 SdfPath const& primPath,
220 HdDataSourceLocator const& locator,
221 HdContainerDataSourceHandle const& inputDataSource);
222
223 const HdsiLocatorCachingSceneIndex& _cachingSceneIndex;
224 const SdfPath _primPath;
225 const HdDataSourceLocator _locator;
226 const HdContainerDataSourceHandle _inputDataSource;
227 };
228
229 // Retrieve data for the requested locator, populating and
230 // re-using cached data sources as appropriate.
231 HdDataSourceBaseHandle
232 _GetWithCache(
233 SdfPath const& primPath,
234 HdDataSourceLocator const& locator,
235 HdContainerDataSourceHandle const& inputDataSource) const;
236
237private: // data
238
239 // Cache of data sources within a prim, by locator
240 using _LocatorDataSourceMap =
242
243 // Cache of data sources, by prim
244 using _PrimCache = SdfPathTable<_LocatorDataSourceMap>;
245
246 // Cache strategy parameters.
247 const HdDataSourceLocator _locatorToCache;
248 const TfToken _primTypeToCache;
249 const bool _cacheDescendants;
250
251 // Cache contents.
252 mutable _PrimCache _primDsCache;
253 mutable std::mutex _cacheMutex;
254};
255
256PXR_NAMESPACE_CLOSE_SCOPE
257
258#endif
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition dataSource.h:148
Represents an object that can identify the location of a data source.
Abstract interface to scene data.
Definition sceneIndex.h:55
An abstract base class for a filtering scene index that observes a single input scene index.
A scene index that caches data sources for specified locators on specified prim types.
static HD_API HdSceneIndexBaseRefPtr AddDependencyForwardingAndCache(HdSceneIndexBaseRefPtr const &inputScene, HdDataSourceLocator const &locatorToCache, TfToken const &primTypeToCache, bool const &cacheDescendants=true)
Creates a new HdDependencyForwardingSceneIndex followed by a HdsiLocatorCachingSceneIndex.
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
static HD_API HdsiLocatorCachingSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene, HdDataSourceLocator const &locatorToCache, TfToken const &primTypeToCache, bool const &cacheDescendants=true)
Creates a new HdsiLocatorCachingSceneIndex.
HD_API 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.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition pathTable.h:66
A hash map with contiguous storage, suitable for use with TfSpan, e.g.
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition declarePtrs.h:58
Small struct representing a 'prim' in the Hydra scene index.
Definition sceneIndex.h:36
std::vector< TfToken > TfTokenVector
Convenience types.
Definition token.h:489