renderParam.h
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"
28 #include "pxr/imaging/hd/renderDelegate.h"
29 #include "pxr/imaging/hdSt/api.h"
30 
31 #include <atomic>
32 #include <shared_mutex>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
43 class HdStRenderParam final : public HdRenderParam
44 {
45 public:
47  ~HdStRenderParam() override;
48 
49  // ---------------------------------------------------------------------- //
51  // ---------------------------------------------------------------------- //
54  HDST_API
55  void MarkDrawBatchesDirty();
56 
57  HDST_API
58  unsigned int GetDrawBatchesVersion() const;
59 
62  HDST_API
63  void MarkMaterialTagsDirty();
64 
65  HDST_API
66  unsigned int GetMaterialTagsVersion() const;
67 
70  HDST_API
72 
73  HDST_API
74  unsigned int GetGeomSubsetDrawItemsVersion() const;
75 
76  // ---------------------------------------------------------------------- //
78  // ---------------------------------------------------------------------- /
79 
85  HDST_API
86  bool HasMaterialTag(const TfToken &materialTag) const;
87 
89  HDST_API
90  void IncreaseMaterialTagCount(const TfToken &materialTag);
91 
93  HDST_API
94  void DecreaseMaterialTagCount(const TfToken &materialTag);
95 
96  // ---------------------------------------------------------------------- //
98  // ---------------------------------------------------------------------- /
99 
101  HDST_API
102  bool HasAnyRenderTag(const TfTokenVector &renderTags) const;
103 
105  HDST_API
106  void IncreaseRenderTagCount(const TfToken &renderTag);
107 
109  HDST_API
110  void DecreaseRenderTagCount(const TfToken &renderTag);
111 
112  // ---------------------------------------------------------------------- //
114  // ---------------------------------------------------------------------- //
116  _needsGarbageCollection = true;
117  }
118 
119  void ClearGarbageCollectionNeeded() {
120  _needsGarbageCollection = false;
121  }
122 
123  bool IsGarbageCollectionNeeded() const {
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 
154 PXR_NAMESPACE_CLOSE_SCOPE
155 
156 #endif // PXR_IMAGING_PLUGIN_HD_ST_RENDER_PARAM_H
HDST_API void IncreaseRenderTagCount(const TfToken &renderTag)
Register that there is an rprim with given renderTag.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
HDST_API void IncreaseMaterialTagCount(const TfToken &materialTag)
Register that there is an rprim with given materialTag.
HDST_API void DecreaseRenderTagCount(const TfToken &renderTag)
Unregister that there is an rprim with given renderTag.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
HDST_API bool HasAnyRenderTag(const TfTokenVector &renderTags) const
Render tag tracking.
The render delegate can create an object of type HdRenderParam, to pass to each prim during Sync().
Definition: renderParam.h:43
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
void SetGarbageCollectionNeeded()
Garbage collection tracking.
Definition: renderParam.h:115
HDST_API bool HasMaterialTag(const TfToken &materialTag) const
Material tag tracking.
HDST_API void MarkMaterialTagsDirty()
Marks material tags dirty, meaning that the draw items associated with the collection of a render pas...
HDST_API void DecreaseMaterialTagCount(const TfToken &materialTag)
Unregister that there is an rprim with given materialTag.
HDST_API void MarkGeomSubsetDrawItemsDirty()
Marks geom subsets draw items dirty, meaning that the draw items associated with the collection of a ...
HDST_API void MarkDrawBatchesDirty()
Draw items cache and batch invalidation.