HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderParam.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_PLUGIN_HD_ST_RENDER_PARAM_H
8 #define PXR_IMAGING_PLUGIN_HD_ST_RENDER_PARAM_H
9 
10 #include "pxr/pxr.h"
12 #include "pxr/imaging/hdSt/api.h"
13 
14 #include <atomic>
15 #include <shared_mutex>
16 
18 
19 ///
20 /// \class HdStRenderParam
21 ///
22 /// The render delegate can create an object of type HdRenderParam, to pass
23 /// to each prim during Sync(). Storm uses this class to house global
24 /// counters amd flags that assist invalidation of draw batch caches.
25 ///
26 class HdStRenderParam final : public HdRenderParam
27 {
28 public:
30  ~HdStRenderParam() override;
31 
32  // ---------------------------------------------------------------------- //
33  /// Draw items cache and batch invalidation
34  // ---------------------------------------------------------------------- //
35  /// Marks all batches dirty, meaning they need to be validated and
36  /// potentially rebuilt.
37  HDST_API
38  void MarkDrawBatchesDirty();
39 
40  HDST_API
41  unsigned int GetDrawBatchesVersion() const;
42 
43  /// Marks material tags dirty, meaning that the draw items associated with
44  /// the collection of a render pass need to be re-gathered.
45  HDST_API
46  void MarkMaterialTagsDirty();
47 
48  HDST_API
49  unsigned int GetMaterialTagsVersion() const;
50 
51  /// Marks geom subsets draw items dirty, meaning that the draw items
52  /// associated with the collection of a render pass need to be re-gathered.
53  HDST_API
55 
56  HDST_API
57  unsigned int GetGeomSubsetDrawItemsVersion() const;
58 
59  // ---------------------------------------------------------------------- //
60  /// Material tag tracking
61  // ---------------------------------------------------------------------- /
62 
63  /// Does render index have rprims with given materialTag? Note
64  /// that for performance reasons and ease of implementation
65  /// (HdRprimSharedData::materialTag initializes to the default
66  /// material tag), this always returns true for the default (and
67  /// empty) material tag.
68  HDST_API
69  bool HasMaterialTag(const TfToken &materialTag) const;
70 
71  /// Register that there is an rprim with given materialTag.
72  HDST_API
73  void IncreaseMaterialTagCount(const TfToken &materialTag);
74 
75  /// Unregister that there is an rprim with given materialTag.
76  HDST_API
77  void DecreaseMaterialTagCount(const TfToken &materialTag);
78 
79  // ---------------------------------------------------------------------- //
80  /// Render tag tracking
81  // ---------------------------------------------------------------------- /
82 
83  /// Does render index have rprims with given renderTag?
84  HDST_API
85  bool HasAnyRenderTag(const TfTokenVector &renderTags) const;
86 
87  /// Register that there is an rprim with given renderTag.
88  HDST_API
89  void IncreaseRenderTagCount(const TfToken &renderTag);
90 
91  /// Unregister that there is an rprim with given renderTag.
92  HDST_API
93  void DecreaseRenderTagCount(const TfToken &renderTag);
94 
95  // ---------------------------------------------------------------------- //
96  /// Draw targets.
97  // ---------------------------------------------------------------------- //
98  /// Marks all draw targets dirty, meaning that clients that keep track of
99  /// the set of active draw targets needs to refresh that set.
100  HDST_API
102 
103  HDST_API
104  unsigned int GetActiveDrawTargetSetVersion() const;
105 
106  // ---------------------------------------------------------------------- //
107  /// Garbage collection tracking
108  // ---------------------------------------------------------------------- //
110  _needsGarbageCollection = true;
111  }
112 
114  _needsGarbageCollection = false;
115  }
116 
118  return _needsGarbageCollection;
119  }
120 
121 private:
122  typedef std::unordered_map<TfToken, std::atomic_int, TfHash> _TagToCountMap;
123 
124  void _AdjustTagCount(
125  std::shared_timed_mutex *mutex,
126  _TagToCountMap *tagToCountMap,
127  const TfToken &tag,
128  const int increment);
129 
130  bool _HasTag(
131  std::shared_timed_mutex *mutex,
132  const _TagToCountMap *tagToCountMap,
133  const TfToken &tag) const;
134 
135  std::atomic_uint _drawBatchesVersion;
136  std::atomic_uint _materialTagsVersion;
137  std::atomic_uint _geomSubsetDrawItemsVersion;
138  std::atomic_uint _activeDrawTargetSetVersion;
139  bool _needsGarbageCollection; // Doesn't need to be atomic since parallel
140  // sync might only set it (and not clear).
141 
142  mutable std::shared_timed_mutex _materialTagToCountMutex;
143  _TagToCountMap _materialTagToCount;
144 
145  mutable std::shared_timed_mutex _renderTagToCountMutex;
146  _TagToCountMap _renderTagToCount;
147 };
148 
150 
151 #endif // PXR_IMAGING_PLUGIN_HD_ST_RENDER_PARAM_H
~HdStRenderParam() override
HDST_API void MarkDrawBatchesDirty()
Draw items cache and batch invalidation.
HDST_API void DecreaseRenderTagCount(const TfToken &renderTag)
Unregister that there is an rprim with given renderTag.
HDST_API unsigned int GetDrawBatchesVersion() const
HDST_API void MarkMaterialTagsDirty()
Definition: token.h:70
HDST_API void DecreaseMaterialTagCount(const TfToken &materialTag)
Unregister that there is an rprim with given materialTag.
bool IsGarbageCollectionNeeded() const
Definition: renderParam.h:117
HDST_API void MarkGeomSubsetDrawItemsDirty()
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
void ClearGarbageCollectionNeeded()
Definition: renderParam.h:113
HDST_API unsigned int GetActiveDrawTargetSetVersion() const
HDST_API unsigned int GetGeomSubsetDrawItemsVersion() const
HDST_API bool HasAnyRenderTag(const TfTokenVector &renderTags) const
Render tag tracking.
HDST_API bool HasMaterialTag(const TfToken &materialTag) const
Material tag tracking.
HDST_API void IncreaseMaterialTagCount(const TfToken &materialTag)
Register that there is an rprim with given materialTag.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HDST_API void IncreaseRenderTagCount(const TfToken &renderTag)
Register that there is an rprim with given renderTag.
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDST_API unsigned int GetMaterialTagsVersion() const
HDST_API void MarkActiveDrawTargetSetDirty()
Draw targets.
void SetGarbageCollectionNeeded()
Garbage collection tracking.
Definition: renderParam.h:109