HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primTypeNoticeBatchingSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HDSI_PRIMTYPE_NOTICE_BATCHING_SCENE_INDEX_H
25 #define PXR_IMAGING_HDSI_PRIMTYPE_NOTICE_BATCHING_SCENE_INDEX_H
26 
27 /// \file hdsi/primTypeNoticeBatchingSceneIndex.h
28 
29 #include "pxr/imaging/hdsi/api.h"
30 
32 
33 #include <variant>
34 
36 
37 #define HDSI_PRIM_TYPE_NOTICE_BATCHING_SCENE_INDEX_TOKENS \
38  (primTypePriorityFunctor)
39 
40 TF_DECLARE_PUBLIC_TOKENS(HdsiPrimTypeNoticeBatchingSceneIndexTokens, HDSI_API,
42 
44 
45 /// \class HdsiPrimTypeNoticeBatchingSceneIndex
46 ///
47 /// A filtering scene index batching prim notices by type using a given
48 /// priority functor. The notices are held back until a call to Flush.
49 ///
50 /// The scene index consolidates prim notices.
51 /// For example, if we get a several prim dirtied entries for the same path, it
52 /// will turn into a single entry with the dirty locator set being the union.
53 /// If we get several prim added and dirtied entries for the same path, it
54 /// results in a single prim added entry. Added and dirtied entries for paths
55 /// prefixed by a later prim removed entry will be effectively ignored. A
56 /// removed entry for a name space ancestor of another removed entry will also
57 /// be effectively removed.
58 ///
59 /// When Flush is called all removed entries are sent out and then followed
60 /// by the cummulated added and dirtied prim entries grouped by their prim
61 /// priority.
62 ///
63 /// The filtering scene index is empty until the first call to Flush.
64 ///
67 {
68 public:
69  /// \class HdsiPrimTypeNoticeBatchingSceneIndex::PrimTypePriorityFunctor
70  ///
71  /// Base class for functor mapping prim types to priorities.
72  ///
74  {
75  public:
76  HDSI_API
77  virtual ~PrimTypePriorityFunctor();
78 
79  /// Priority for given prim type. Prims with lower priority number
80  /// are handled before prims with higher priority number.
81  /// Result must be less than GetNumPriorities().
82  ///
83  virtual size_t GetPriorityForPrimType(
84  const TfToken &primType) const = 0;
85 
86  /// Number of priorities - that is 1 + the highest number ever
87  /// returned by GetPriorityForPrimType().
88  ///
89  /// This number should be small as it affects the pre-allocation
90  /// in Flush().
91  ///
92  virtual size_t GetNumPriorities() const = 0;
93  };
95  std::shared_ptr<PrimTypePriorityFunctor>;
96 
97  /// Creates a new notice batching scene index. It expects a priority functor
98  /// in a PrimTypePriorityFunctorHandle typed data source at
99  /// HdsiPrimTypeNoticeBatchingSceneIndexTokens->primTypePriorityFunctor in
100  /// the given inputArgs.
101  ///
102  static HdsiPrimTypeNoticeBatchingSceneIndexRefPtr New(
103  HdSceneIndexBaseRefPtr const &inputScene,
104  HdContainerDataSourceHandle const &inputArgs) {
105  return TfCreateRefPtr(
107  inputScene,
108  inputArgs));
109  }
110 
111  HDSI_API
113 
114  /// Forwards to input scene after first call to Flush. Empty before that.
115  ///
116  HDSI_API
117  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
118 
119  /// Forwards to input scene after first call to Flush. Empty before that.
120  ///
121  HDSI_API
122  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
123 
124  /// Sends out all notices queued and commulated since the last call to
125  /// Flush. The first call to Flush will also send out notices for prims
126  /// that were in the input scene index when it was added to this filtering
127  /// scene index.
128  ///
129  HDSI_API
130  void Flush();
131 
132 protected:
133 
134  HDSI_API
136  HdSceneIndexBaseRefPtr const &inputScene,
137  HdContainerDataSourceHandle const &inputArgs);
138 
139  // satisfying HdSingleInputFilteringSceneIndexBase
140  void _PrimsAdded(
141  const HdSceneIndexBase &sender,
142  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
143 
144  void _PrimsRemoved(
145  const HdSceneIndexBase &sender,
146  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
147 
148  void _PrimsDirtied(
149  const HdSceneIndexBase &sender,
150  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
151 
152  // Removes items from _addedOrDirtiedPrims prefixed by path.
154  // Adds path to _removedPrims and normalizes _removedPrims if necessary.
155  void _AddPathToRemovedPrims(const SdfPath &path);
156 
157  size_t _GetPriority(const TfToken &primType) const;
158 
160  const size_t _numPriorities;
161 
163  {
165  };
166 
168  {
170  };
171 
172  // True after first call to flush.
174 
175  // Default constructored _PrimAddedOrDirtiedEntry contains a
176  // _PrimDirtiedEntry. This is used by _addedOrDirtiedPrims.
178  std::variant<_PrimDirtiedEntry, _PrimAddedEntry>;
179 
180  std::map<SdfPath, _PrimAddedOrDirtiedEntry> _addedOrDirtiedPrims;
181 
182  // Normalized, so a prefix of an element in _removedPrims will never be in
183  // _removedPrims.
184  std::set<SdfPath> _removedPrims;
185 };
186 
187 
189 
190 
191 #endif
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1223
void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
size_t _GetPriority(const TfToken &primType) const
HDSI_API ~HdsiPrimTypeNoticeBatchingSceneIndex() override
#define HDSI_PRIM_TYPE_NOTICE_BATCHING_SCENE_INDEX_TOKENS
PrimTypePriorityFunctorHandle const _primTypePriorityFunctor
TF_DECLARE_REF_PTRS(HdsiPrimTypeNoticeBatchingSceneIndex)
void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries) override
static HdsiPrimTypeNoticeBatchingSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs)
std::map< SdfPath, _PrimAddedOrDirtiedEntry > _addedOrDirtiedPrims
Definition: token.h:87
HdDataSourceLocatorSet dirtyLocators
std::variant< _PrimDirtiedEntry, _PrimAddedEntry > _PrimAddedOrDirtiedEntry
virtual size_t GetPriorityForPrimType(const TfToken &primType) const =0
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Definition: path.h:290
HDSI_API HdsiPrimTypeNoticeBatchingSceneIndex(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs)
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
#define HDSI_API
Definition: api.h:40
void _AddPathToRemovedPrims(const SdfPath &path)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
TF_DECLARE_PUBLIC_TOKENS(HdsiPrimTypeNoticeBatchingSceneIndexTokens, HDSI_API, HDSI_PRIM_TYPE_NOTICE_BATCHING_SCENE_INDEX_TOKENS)
std::shared_ptr< PrimTypePriorityFunctor > PrimTypePriorityFunctorHandle
TfToken primType
void _RemovePathFromAddedOrDirtiedPrims(const SdfPath &path)
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries) override