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