Loading...
Searching...
No Matches
cachingSceneIndex.h
1//
2// Copyright 2025 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_HD_CACHING_SCENE_H
8#define PXR_IMAGING_HD_CACHING_SCENE_H
9
10#include "pxr/imaging/hd/api.h"
11#include "pxr/imaging/hd/filteringSceneIndex.h"
12
13#include "pxr/usd/sdf/pathTable.h"
14
15#include <tbb/concurrent_hash_map.h>
16
17#include <optional>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
22
29{
30public:
33 static HdCachingSceneIndexRefPtr New(
34 HdSceneIndexBaseRefPtr const &inputScene) {
35 return TfCreateRefPtr(
36 new HdCachingSceneIndex(inputScene));
37 }
38
39 HD_API
40 ~HdCachingSceneIndex() override;
41
42 HD_API
43 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
44
45 HD_API
46 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
47
48protected:
49
50 HD_API
52 HdSceneIndexBaseRefPtr const &inputScene);
53
54 void _PrimsAdded(
55 const HdSceneIndexBase &sender,
56 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
57
58 void _PrimsRemoved(
59 const HdSceneIndexBase &sender,
60 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
61
62 void _PrimsDirtied(
63 const HdSceneIndexBase &sender,
64 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
65
66private:
67 // Implemented similarly to HdFlatteningSceneIndex - without flattening.
68
69 // Consolidate _recentPrims into _prims.
70 void _ConsolidateRecentPrims();
71
72 // Consolidate _recentChildPaths into _childPaths.
73 void _ConsolidateRecentChildPaths();
74
75 // Consolidate both.
76 void _ConsolidateRecent();
77
78 struct _PathHashCompare {
79 static bool equal(const SdfPath &a, const SdfPath &b) {
80 return a == b;
81 }
82 static size_t hash(const SdfPath &path) {
83 return hash_value(path);
84 }
85 };
86
87 // members
89 _PrimTable _prims;
90
91 using _RecentPrimTable =
92 tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
93 mutable _RecentPrimTable _recentPrims;
94
95 using _ChildPathsTable = SdfPathTable<std::optional<SdfPathVector>>;
96 _ChildPathsTable _childPaths;
97
98 using _RecentChildPathsTable =
99 tbb::concurrent_hash_map<SdfPath, SdfPathVector, _PathHashCompare>;
100 mutable _RecentChildPathsTable _recentChildPaths;
101};
102
103PXR_NAMESPACE_CLOSE_SCOPE
104
105#endif
A scene index that caches the prim data source and child prim paths.
static HdCachingSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene)
Creates a new caching scene index.
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
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:54
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:274
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:66
#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
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:437