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
141{
142public:
147 HD_API
148 static HdSceneIndexBaseRefPtr
150 HdSceneIndexBaseRefPtr const& inputScene,
151 HdDataSourceLocator const& locatorToCache,
152 TfToken const& primTypeToCache);
153
166 HD_API
167 static HdsiLocatorCachingSceneIndexRefPtr
168 New(HdSceneIndexBaseRefPtr const& inputScene,
169 HdDataSourceLocator const& locatorToCache,
170 TfToken const& primTypeToCache);
171
172 HD_API
174
175 HD_API
176 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
177
178 HD_API
179 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
180
181protected:
182 HD_API
184 HdSceneIndexBaseRefPtr const& inputScene,
185 HdDataSourceLocator const& locatorToCache,
186 TfToken const& primTypeToCache);
187
188 void _PrimsAdded(
189 const HdSceneIndexBase &sender,
190 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
191 void _PrimsRemoved(
192 const HdSceneIndexBase &sender,
193 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
194 void _PrimsDirtied(
195 const HdSceneIndexBase &sender,
196 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
197
198 // A data source that delegates back to HdsiLocatorCachingSceneIndex, allowing
199 // it to manage invalidation.
200 class _DataSource : public HdContainerDataSource
201 {
202 public:
203 HD_DECLARE_DATASOURCE(_DataSource);
204
205 TfTokenVector GetNames() override;
206 HdDataSourceBaseHandle Get(const TfToken &name) override;
207
208 private:
209 _DataSource(
210 HdsiLocatorCachingSceneIndex const* cachingSceneIndex,
211 SdfPath const& primPath,
212 HdDataSourceLocator const& locator,
213 HdContainerDataSourceHandle const& inputDataSource);
214
215 const HdsiLocatorCachingSceneIndex& _cachingSceneIndex;
216 const SdfPath _primPath;
217 const HdDataSourceLocator _locator;
218 const HdContainerDataSourceHandle _inputDataSource;
219 };
220
221 // Retrieve data for the requested locator, populating and
222 // re-using cached data sources as appropriate.
223 HdDataSourceBaseHandle
224 _GetWithCache(
225 SdfPath const& primPath,
226 HdDataSourceLocator const& locator,
227 HdContainerDataSourceHandle const& inputDataSource) const;
228
229private: // data
230
231 // Cache of data sources within a prim, by locator
232 using _LocatorDataSourceMap =
234
235 // Cache of data sources, by prim
236 using _PrimCache = SdfPathTable<_LocatorDataSourceMap>;
237
238 // Cache strategy parameters.
239 const HdDataSourceLocator _locatorToCache;
240 const TfToken _primTypeToCache;
241
242 // Cache contents.
243 mutable _PrimCache _primDsCache;
244 mutable std::mutex _cacheMutex;
245};
246
247PXR_NAMESPACE_CLOSE_SCOPE
248
249#endif
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:99
Represents an object that can identify the location of a data source.
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 scene index that caches data sources for specified locators on specified prim types.
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)
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.
static HD_API HdSceneIndexBaseRefPtr AddDependencyForwardingAndCache(HdSceneIndexBaseRefPtr const &inputScene, HdDataSourceLocator const &locatorToCache, TfToken const &primTypeToCache)
Creates a new HdDependencyForwardingSceneIndex followed by a HdsiLocatorCachingSceneIndex.
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
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
Definition: denseHashMap.h:41
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
#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:35
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440