HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dirtyList.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_DIRTY_LIST_H
8 #define PXR_IMAGING_HD_DIRTY_LIST_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/version.h"
13 #include "pxr/imaging/hd/repr.h"
15 #include "pxr/imaging/hd/types.h"
16 
17 #include <memory>
18 
20 
21 class HdRenderIndex;
22 class HdChangeTracker;
23 using HdReprSelectorVector = std::vector<HdReprSelector>;
24 
25 /// \class HdDirtyList
26 ///
27 /// Used for faster iteration of dirty Rprims by the render index.
28 ///
29 /// GetDirtyRprims() implicitly refreshes and caches the list if needed.
30 /// The returning prims list will be used for sync.
31 ///
32 /// DirtyList construction can expensive. We have 3 layer
33 /// versioning to make it efficient.
34 ///
35 /// 1. Nothing changed since last time (super fast),
36 /// no prims need to be synced.
37 /// DirtyList returns empty vector GetDirtyRprims.
38 /// This can be detected by HdChangeTracker::GetSceneStateVersion.
39 /// It's incremented when any change made on any prim.
40 ///
41 /// 2. Constantly updating Prims in a stable set (fast)
42 /// when munging or playing back, the same set of prims are being updated,
43 /// while the remaining prims (could be huge -- for example a large set)
44 /// are static.
45 /// Those animating prims can be distinguished by the Varying bit. The Varying
46 /// bit is set on a prim when any dirty bit is set, and stays even after
47 /// cleaning the scene dirty bits, until HdChangeTracker::ResetVaryingState
48 /// clears it out.
49 ///
50 /// DirtyList caches those prims in a list at the first time (described in 3),
51 /// and returns the list for the subsequent queries. Since that list is
52 /// conservatively picked by the Varying bit instead of the actual DirtyBits
53 /// needed for various reprs, consumer of DirtyList needs to check the
54 /// dirtybits again (this is a common pattern in HdRprim, HdMesh and other).
55 ///
56 /// 3. Varying state changed (medium cost)
57 /// when a exisitng prim newly starts updating (start munging), or when
58 /// a majority of the dirtylist stop updating, we need to reconstruct
59 /// the dirtylist. HdChangeTracker::GetVaryingStateVersion() tells the
60 /// right timing to refresh, by comparing the cached version number in
61 /// the dirtylist.
62 ///
63 /// To construct a dirtylist, the Varying bit is checked instead of other
64 /// dirtybits, since effective dirtybits may differ over prims, by prim
65 /// type (mesh vs curve) or by per-prim repr style (flat vs smooth)
66 ///
67 /// example: [x]=Varying [x*]=Dirty,Varying
68 ///
69 /// say in change tracker:
70 /// A B C D E [F*] [G] [H*] [I*] [J] [K] L M N ...
71 /// then the dirtylist will be:
72 /// F*, G, H*, I*, J, K
73 ///
74 /// Note that G, J and K are not dirty, but it exists in the dirtylist.
75 /// This optimization gives the maximum efficiency when all of Varying
76 /// prims are being updated.
77 ///
78 /// 4. Initial creation, filter changes (most expensive)
79 /// If we fail to early out all the above condition, such as when we add
80 /// new prims or switch the render tag set, all prims should be
81 /// passed down to HdRenderIndex::Sync, except ones we know that are
82 /// completely clean. Although it requires to sweep all prims in the
83 /// render index, this traversal has already been optimized
84 /// using the Gather utility.
85 ///
86 class HdDirtyList {
87 public:
88  HD_API
89  explicit HdDirtyList(HdRenderIndex &index);
90 
91  /// Returns a reference of dirty rprim ids.
92  /// If the change tracker hasn't changed any state since the last time
93  /// GetDirtyRprims gets called, and if the tracked filtering parameters
94  /// (set via UpdateRenderTagsAndReprSelectors) are the same, it simply
95  /// returns an empty list.
96  /// Otherwise depending on what changed, it will return a list of
97  /// Rprim ids to be synced.
98  /// Therefore, it is expected that GetDirtyRprims is called _only once_
99  /// per render index sync.
100  HD_API
101  SdfPathVector const& GetDirtyRprims();
102 
103  /// Updates the tracked filtering parameters.
104  /// This typically comes from the tasks submitted to HdEngine::Execute.
105  HD_API
107  TfTokenVector const &tags, HdReprSelectorVector const &reprs);
108 
109  /// Sets the flag to prune to dirty list to just the varying Rprims on
110  /// the next call to GetDirtyRprims.
112  _pruneDirtyList = true;
113  }
114 
115 private:
116  HdChangeTracker & _GetChangeTracker() const;
117  void _UpdateDirtyIdsIfNeeded();
118 
119  // Note: Can't use a const ref to the renderIndex because
120  // HdRenderIndex::GetRprimIds() isn't a const member fn.
121  HdRenderIndex &_renderIndex;
122  TfTokenVector _trackedRenderTags;
123  HdReprSelectorVector _trackedReprs;
124  SdfPathVector _dirtyIds;
125 
126  unsigned int _sceneStateVersion;
127  unsigned int _rprimIndexVersion;
128  unsigned int _rprimRenderTagVersion;
129  unsigned int _varyingStateVersion;
130 
131  bool _rebuildDirtyList;
132  bool _pruneDirtyList;
133 };
134 
136 
137 #endif // PXR_IMAGING_HD_DIRTY_LIST_H
void PruneToVaryingRprims()
Definition: dirtyList.h:111
#define HD_API
Definition: api.h:23
HD_API HdDirtyList(HdRenderIndex &index)
HD_API SdfPathVector const & GetDirtyRprims()
std::vector< class SdfPath > SdfPathVector
std::vector< HdReprSelector > HdReprSelectorVector
Definition: dirtyList.h:23
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API void UpdateRenderTagsAndReprSelectors(TfTokenVector const &tags, HdReprSelectorVector const &reprs)