HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_ST_PRIM_UTILS_H
8 #define PXR_IMAGING_HD_ST_PRIM_UTILS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
14 #include "pxr/imaging/hd/rprim.h"
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
21 
22 class HdChangeTracker;
23 class HdDrawItem;
24 class HdRenderIndex;
25 class HdRenderParam;
26 class HdRprim;
27 struct HdRprimSharedData;
28 class HdStDrawItem;
29 class HdStInstancer;
30 
31 using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
32 
33 using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
34 using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
36  std::shared_ptr<class HdSt_MaterialNetworkShader>;
37 
38 using HdStComputationSharedPtr = std::shared_ptr<class HdStComputation>;
39 
41  std::shared_ptr<HdStResourceRegistry>;
42 
43 // -----------------------------------------------------------------------------
44 // Draw invalidation and garbage collection utilities
45 // -----------------------------------------------------------------------------
47 void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam);
48 
50 void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam);
51 
54 
57 
58 // -----------------------------------------------------------------------------
59 // Primvar descriptor filtering utilities
60 // -----------------------------------------------------------------------------
61 // Get filtered primvar descriptors for drawItem
65  HdRprim const * prim,
66  HdStDrawItem const * drawItem,
67  HdSceneDelegate * delegate,
68  HdInterpolation interpolation,
69  const HdReprSharedPtr &repr = nullptr,
71  int geomSubsetDescIndex = 0,
72  size_t numGeomSubsets = 0);
73 
74 // Get filtered instancer primvar descriptors for drawItem
78  HdStInstancer const * instancer,
79  HdSceneDelegate * delegate);
80 
81 // -----------------------------------------------------------------------------
82 // Tracking render tag changes
83 // -----------------------------------------------------------------------------
84 
87  HdRenderParam *renderParam,
88  HdRprim *rprim);
89 
90 // -----------------------------------------------------------------------------
91 // Material processing utilities
92 // -----------------------------------------------------------------------------
94 void HdStSetMaterialId(HdSceneDelegate *delegate,
95  HdRenderParam *renderParam,
96  HdRprim *rprim);
97 
99 void HdStSetMaterialTag(HdRenderParam *renderParam,
100  HdDrawItem *drawItem,
101  const TfToken &materialTag);
102 
103 HDST_API
104 void HdStSetMaterialTag(HdSceneDelegate *delegate,
105  HdRenderParam *renderParam,
106  HdDrawItem *drawItem,
107  SdfPath const & materialId,
108  const bool hasDisplayOpacityPrimvar,
109  const bool displayInOverlay,
110  const bool occludedSelectionShowsThrough);
111 // Resolves the material network shader for the given prim (using a fallback
112 // material as necessary).
113 HDST_API
116  HdRprim const * prim,
117  HdSceneDelegate * delegate);
118 
119 HDST_API
122  HdRprim const * prim,
123  HdSceneDelegate * delegate,
124  SdfPath const & materialId);
125 
126 // -----------------------------------------------------------------------------
127 // Primvar processing and BAR allocation utilities
128 // -----------------------------------------------------------------------------
129 // Returns true if range is non-empty and valid.
130 HDST_API
132 
133 // Returns true if curRange can be used as-is (even if it's empty) during
134 // primvar processing.
135 HDST_API
138  HdStComputationComputeQueuePairVector const& computations,
139  HdBufferArrayRangeSharedPtr const& curRange,
140  HdDirtyBits dirtyBits);
141 
142 HDST_API
145  HdBufferArrayRangeSharedPtr const& curRange,
146  HdDirtyBits dirtyBits);
147 
148 // Returns the buffer specs that have been removed from curRange based on the
149 // new primvar descriptors and internally generated primvar names.
150 //
151 // Internally generated primvar names will never be among the specs returned,
152 HDST_API
155  HdBufferArrayRangeSharedPtr const& curRange,
156  HdPrimvarDescriptorVector const& newPrimvarDescs,
157  HdExtComputationPrimvarDescriptorVector const& newCompPrimvarDescs,
158  TfTokenVector const& internallyGeneratedPrimvarNames,
159  SdfPath const& rprimId);
160 
161 HDST_API
164  HdBufferArrayRangeSharedPtr const& curRange,
165  HdPrimvarDescriptorVector const& newPrimvarDescs,
166  TfTokenVector const& internallyGeneratedPrimvarNames,
167  SdfPath const& rprimId);
168 
169 // Returns the buffer specs that have been removed from curRange based on the
170 // new primvar descriptors, updated specs and internally generated primvar names. Buffer
171 // specs with updated types will be replaced.
172 // This overload handles primvar type changes and should be preferred over
173 // HdStGetRemovedPrimvarBufferSpecs.
174 //
175 HDST_API
178  HdBufferArrayRangeSharedPtr const& curRange,
179  HdPrimvarDescriptorVector const& newPrimvarDescs,
180  TfTokenVector const& internallyGeneratedPrimvarNames,
181  HdBufferSpecVector const& updatedSpecs,
182  SdfPath const& rprimId);
183 
184 // Updates the existing range at drawCoordIndex with newRange and flags garbage
185 // collection (for the existing range) and rebuild of all draw batches when
186 // necessary.
187 HDST_API
189  HdBufferArrayRangeSharedPtr const& newRange,
190  int drawCoordIndex,
191  HdRprimSharedData *sharedData,
192  HdRenderParam *renderParam,
193  HdChangeTracker *changeTracker);
194 
195 // Returns true if primvar with primvarName exists within primvar descriptor
196 // vector primvars and primvar has a valid value
197 HDST_API
199  HdRprim *prim,
200  HdSceneDelegate *delegate,
201  HdPrimvarDescriptorVector const& primvars,
202  TfToken const& primvarName);
203 
204 HDST_API
206  const HdStDrawItem *drawItem,
207  TfToken const &primvarName,
208  VtValue const &primvarValue);
209 
210 // -----------------------------------------------------------------------------
211 // Constant primvar processing utilities
212 // -----------------------------------------------------------------------------
213 // Returns whether constant primvars need to be populated/updated based on the
214 // dirty bits for a given rprim.
215 HDST_API
217  HdDirtyBits const *dirtyBits,
218  SdfPath const& id);
219 
220 // Given prim information it will create sources representing
221 // constant primvars and hand it to the resource registry.
222 // If transforms are dirty, updates the optional bool.
223 HDST_API
225  HdRprim *prim,
226  HdRprimSharedData *sharedData,
227  HdSceneDelegate *delegate,
228  HdRenderParam *renderParam,
229  HdStDrawItem *drawItem,
230  HdDirtyBits *dirtyBits,
231  HdReprSharedPtr const &repr,
232  HdMeshGeomStyle descGeomStyle,
233  int geomSubsetDescIndex,
234  size_t numGeomSubsets,
235  bool *hasMirroredTransform = nullptr,
236  bool *hasDisplayOpacity = nullptr,
237  bool *hasNormals = nullptr);
238 
239 // -----------------------------------------------------------------------------
240 // Instancer processing utilities
241 // -----------------------------------------------------------------------------
242 
243 // Updates drawItem bindings for changes to instance topology/primvars.
244 HDST_API
246  HdRenderIndex &renderIndex,
247  HdRenderParam *renderParam,
248  HdRprim *prim,
249  HdStDrawItem *drawItem,
250  HdRprimSharedData *sharedData,
251  HdDirtyBits rprimDirtyBits,
252  bool *hasDisplayOpacity = nullptr,
253  bool *hasNormals = nullptr);
254 
255 // Returns true if primvar with primvarName exists among instance primvar
256 // descriptors.
257 HDST_API
259  HdRenderIndex &renderIndex,
260  HdRprim *prim,
261  TfToken const& primvarName);
262 
263 // -----------------------------------------------------------------------------
264 // Topological visibility processing utility
265 // -----------------------------------------------------------------------------
266 // Creates/Updates/Migrates the topology visiblity BAR with element and point
267 // visibility encoded using one bit per element/point of the topology.
268 HDST_API
270  VtIntArray invisibleElements,
271  int numTotalElements,
272  VtIntArray invisiblePoints,
273  int numTotalPoints,
274  HdRprimSharedData *sharedData,
275  HdStDrawItem *drawItem,
276  HdRenderParam *renderParam,
277  HdChangeTracker *changeTracker,
278  HdStResourceRegistrySharedPtr const &resourceRegistry,
279  SdfPath const& rprimId);
280 
281 //
282 // De-duplicating and sharing immutable primvar data.
283 //
284 // Primvar data is identified using a hash computed from the
285 // sources of the primvar data, of which there are generally
286 // two kinds:
287 // - data provided by the scene delegate
288 // - data produced by computations
289 //
290 // Immutable and mutable buffer data is managed using distinct
291 // heaps in the resource registry. Aggregation of buffer array
292 // ranges within each heap is managed separately.
293 //
294 // We attempt to balance the benefits of sharing vs efficient
295 // varying update using the following simple strategy:
296 //
297 // - When populating the first repr for an rprim, allocate
298 // the primvar range from the immutable heap and attempt
299 // to deduplicate the data by looking up the primvarId
300 // in the primvar instance registry.
301 //
302 // - When populating an additional repr for an rprim using
303 // an existing immutable primvar range, compute an updated
304 // primvarId and allocate from the immutable heap, again
305 // attempting to deduplicate.
306 //
307 // - Otherwise, migrate the primvar data to the mutable heap
308 // and abandon further attempts to deduplicate.
309 //
310 // - The computation of the primvarId for an rprim is cumulative
311 // and includes the new sources of data being committed
312 // during each successive update.
313 //
314 // - Once we have migrated a primvar allocation to the mutable
315 // heap we will no longer spend time computing a primvarId.
316 //
317 
318 HDST_API
320 
321 HDST_API
323  uint64_t baseId,
325  HdStComputationComputeQueuePairVector const &computations);
326 
327 HDST_API
329  HdStComputationComputeQueuePairVector const& computations,
330  HdBufferSpecVector *bufferSpecs);
331 
333 
334 #endif // PXR_IMAGING_HD_ST_PRIM_UTILS_H
HDST_API uint64_t HdStComputeSharedPrimvarId(uint64_t baseId, HdBufferSourceSharedPtrVector const &sources, HdStComputationComputeQueuePairVector const &computations)
GLenum GLint * range
Definition: glcorearb.h:1925
HDST_API void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam)
HDST_API bool HdStCanSkipBARAllocationOrUpdate(HdBufferSourceSharedPtrVector const &sources, HdStComputationComputeQueuePairVector const &computations, HdBufferArrayRangeSharedPtr const &curRange, HdDirtyBits dirtyBits)
uint32_t HdDirtyBits
Definition: types.h:143
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
std::shared_ptr< class HdSt_MaterialNetworkShader > HdSt_MaterialNetworkShaderSharedPtr
Definition: drawItem.h:21
HDST_API bool HdStShouldPopulateConstantPrimvars(HdDirtyBits const *dirtyBits, SdfPath const &id)
HDST_API void HdStSetMaterialId(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdRprim *rprim)
HDST_API void HdStUpdateInstancerData(HdRenderIndex &renderIndex, HdRenderParam *renderParam, HdRprim *prim, HdStDrawItem *drawItem, HdRprimSharedData *sharedData, HdDirtyBits rprimDirtyBits, bool *hasDisplayOpacity=nullptr, bool *hasNormals=nullptr)
std::shared_ptr< HdRepr > HdReprSharedPtr
Definition: rprim.h:30
std::vector< HdBufferSourceSharedPtr > HdBufferSourceSharedPtrVector
Definition: bufferSource.h:27
HDST_API void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam)
HDST_API void HdStMarkGarbageCollectionNeeded(HdRenderParam *renderParam)
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:70
HDST_API void HdStSetMaterialTag(HdRenderParam *renderParam, HdDrawItem *drawItem, const TfToken &materialTag)
Definition: rprim.h:37
HDST_API void HdStPopulateConstantPrimvars(HdRprim *prim, HdRprimSharedData *sharedData, HdSceneDelegate *delegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits, HdReprSharedPtr const &repr, HdMeshGeomStyle descGeomStyle, int geomSubsetDescIndex, size_t numGeomSubsets, bool *hasMirroredTransform=nullptr, bool *hasDisplayOpacity=nullptr, bool *hasNormals=nullptr)
HDST_API bool HdStIsValidBAR(HdBufferArrayRangeSharedPtr const &range)
HDST_API HdBufferSpecVector HdStGetRemovedPrimvarBufferSpecs(HdBufferArrayRangeSharedPtr const &curRange, HdPrimvarDescriptorVector const &newPrimvarDescs, HdExtComputationPrimvarDescriptorVector const &newCompPrimvarDescs, TfTokenVector const &internallyGeneratedPrimvarNames, SdfPath const &rprimId)
HDST_API HdSt_MaterialNetworkShaderSharedPtr HdStGetMaterialNetworkShader(HdRprim const *prim, HdSceneDelegate *delegate)
std::shared_ptr< class HdStComputation > HdStComputationSharedPtr
Definition: computation.h:24
HdMeshGeomStyle
Definition: enums.h:130
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:280
std::vector< struct HdBufferSpec > HdBufferSpecVector
HDST_API void HdStMarkGeomSubsetDrawItemsDirty(HdRenderParam *renderParam)
HDST_API bool HdStIsEnabledSharedVertexPrimvar()
HDST_API void HdStProcessTopologyVisibility(VtIntArray invisibleElements, int numTotalElements, VtIntArray invisiblePoints, int numTotalPoints, HdRprimSharedData *sharedData, HdStDrawItem *drawItem, HdRenderParam *renderParam, HdChangeTracker *changeTracker, HdStResourceRegistrySharedPtr const &resourceRegistry, SdfPath const &rprimId)
std::vector< std::pair< HdStComputationSharedPtr, HdStComputeQueue >> HdStComputationComputeQueuePairVector
HDST_API HdBufferSpecVector HdStGetRemovedOrReplacedPrimvarBufferSpecs(HdBufferArrayRangeSharedPtr const &curRange, HdPrimvarDescriptorVector const &newPrimvarDescs, TfTokenVector const &internallyGeneratedPrimvarNames, HdBufferSpecVector const &updatedSpecs, SdfPath const &rprimId)
#define HDST_API
Definition: api.h:23
HDST_API bool HdStIsInstancePrimvarExistentAndValid(HdRenderIndex &renderIndex, HdRprim *prim, TfToken const &primvarName)
HdInterpolation
Definition: enums.h:177
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:27
HDST_API void HdStGetBufferSpecsFromCompuations(HdStComputationComputeQueuePairVector const &computations, HdBufferSpecVector *bufferSpecs)
HDST_API HdPrimvarDescriptorVector HdStGetPrimvarDescriptors(HdRprim const *prim, HdStDrawItem const *drawItem, HdSceneDelegate *delegate, HdInterpolation interpolation, const HdReprSharedPtr &repr=nullptr, HdMeshGeomStyle descGeomStyle=HdMeshGeomStyleInvalid, int geomSubsetDescIndex=0, size_t numGeomSubsets=0)
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
HDST_API bool HdStIsPrimvarExistentAndValid(HdRprim *prim, HdSceneDelegate *delegate, HdPrimvarDescriptorVector const &primvars, TfToken const &primvarName)
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:30
HDST_API void HdStUpdateRenderTag(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdRprim *rprim)
Definition: value.h:89
HDST_API void HdStUpdateDrawItemBAR(HdBufferArrayRangeSharedPtr const &newRange, int drawCoordIndex, HdRprimSharedData *sharedData, HdRenderParam *renderParam, HdChangeTracker *changeTracker)
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
HDST_API bool HdStIsPrimvarValidForDrawItem(const HdStDrawItem *drawItem, TfToken const &primvarName, VtValue const &primvarValue)
HDST_API HdPrimvarDescriptorVector HdStGetInstancerPrimvarDescriptors(HdStInstancer const *instancer, HdSceneDelegate *delegate)