renderPassPruneSceneIndex.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 #ifndef PXR_IMAGING_HDSI_RENDER_PASS_PRUNE_SCENE_INDEX_H
7 #define PXR_IMAGING_HDSI_RENDER_PASS_PRUNE_SCENE_INDEX_H
8 
9 #include "pxr/pxr.h"
10 #if PXR_VERSION >= 2408
11 #include "pxr/imaging/hd/collectionExpressionEvaluator.h"
12 #include "pxr/imaging/hd/collectionPredicateLibrary.h"
13 #include "pxr/imaging/hd/filteringSceneIndex.h"
14 #include "pxr/imaging/hdsi/api.h"
15 #include "pxr/usd/sdf/pathTable.h"
16 #include <mutex>
17 #include <optional>
18 
19 PXR_NAMESPACE_OPEN_SCOPE
20 
21 TF_DECLARE_WEAK_AND_REF_PTRS(HdsiRenderPassPruneSceneIndex);
22 
29 class HdsiRenderPassPruneSceneIndex :
31 {
32 public:
33  // New signature that takes a predicate library to use for evaluating
34  // the collection path expressions.
35  HDSI_API
36  static HdsiRenderPassPruneSceneIndexRefPtr
37  New(const HdSceneIndexBaseRefPtr& inputSceneIndex,
38  const HdCollectionPredicateLibrary &predicateLibrary);
39 
43  HDSI_API
44  static HdsiRenderPassPruneSceneIndexRefPtr
45  New(const HdSceneIndexBaseRefPtr& inputSceneIndex);
46 
47  HDSI_API
48  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
49  HDSI_API
50  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
51 
52 protected:
53  HDSI_API
54  HdsiRenderPassPruneSceneIndex(
55  const HdSceneIndexBaseRefPtr& inputSceneIndex,
56  const HdCollectionPredicateLibrary &predicateLibrary);
57 
58  HDSI_API
59  ~HdsiRenderPassPruneSceneIndex() override;
60 
61  HDSI_API
62  void _PrimsAdded(
63  const HdSceneIndexBase &sender,
64  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
65  HDSI_API
66  void _PrimsRemoved(
67  const HdSceneIndexBase &sender,
68  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
69  HDSI_API
70  void _PrimsDirtied(
71  const HdSceneIndexBase &sender,
72  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
73 
74 private:
75  // Prune state specified by a render pass.
76  struct _RenderPassPruneState {
77  SdfPath renderPassPath;
78 
79  // Retain the expression so we can compare old vs. new state.
80  SdfPathExpression pruneExpr;
81 
82  // Evalulator for the pattern expression.
83  std::optional<HdCollectionExpressionEvaluator> pruneEval;
84 
85  bool DoesPrune(const SdfPath &primPath) const;
86  };
87 
88  // Pull on the scene globals schema for the active render pass,
89  // computing and caching its prune state in _activeRenderPass.
90  void _UpdateActiveRenderPassState(
93 
94  HdCollectionPredicateLibrary _predicateLibrary;
95 
96  // Prune state for the active render pass.
97  _RenderPassPruneState _activeRenderPass;
98 
99  // Flag used to track the first time prims have been added.
100  bool _hasPopulated = false;
101 
102  // Maps each instance location path to the set of instancer paths that
103  // reference it. Populated lazily in GetPrim() and used to find only the
104  // instancers affected by a prune change (via FindSubtreeRange), rather
105  // than dirtying all known instancers.
106  using InstanceToInstancerMap = SdfPathTable<SdfPathSet>;
107  mutable InstanceToInstancerMap _instanceToInstancerMap;
108  mutable std::mutex _instancerMutex;
109 };
110 
111 PXR_NAMESPACE_CLOSE_SCOPE
112 
113 #endif
114 #endif // PXR_VERSION >= 2408
An abstract base class for a filtering scene index that observes a single input scene index.
Represents a library of predicate functions for use with SdfPredicateExpression.
virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const =0
Returns a pair of (prim type, datasource).
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
Objects of this class represent a logical expression syntax tree consisting of SdfPathPattern s,...
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const =0
Returns the paths of all scene index prims located immediately below primPath.
Abstract interface to scene data.
Definition: sceneIndex.h:54
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:65