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