HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cachingSceneIndex.h
Go to the documentation of this file.
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"
12 
13 #include "pxr/usd/sdf/pathTable.h"
14 
15 #include <tbb/concurrent_hash_map.h>
16 
17 #include <optional>
18 
20 
22 
23 ///
24 /// \class HdCachingSceneIndex
25 ///
26 /// A scene index that caches the prim data source and child prim paths.
27 ///
29 {
30 public:
31  /// Creates a new caching scene index.
32  ///
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 
48 protected:
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 
66 private:
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 
104 
105 #endif
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
static HdCachingSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries) override
HD_API ~HdCachingSceneIndex() override
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define HD_API
Definition: api.h:23
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
Definition: ImathFun.h:105
std::vector< class SdfPath > SdfPathVector
Definition: path.h:280
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(HdCachingSceneIndex)
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
HD_API HdCachingSceneIndex(HdSceneIndexBaseRefPtr const &inputScene)
void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries) override
size_t hash_value(const CH_ChannelRef &ref)
void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override