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 // -----------------------------------------------------------------------------
205 // Constant primvar processing utilities
206 // -----------------------------------------------------------------------------
207 // Returns whether constant primvars need to be populated/updated based on the
208 // dirty bits for a given rprim.
209 HDST_API
211  HdDirtyBits const *dirtyBits,
212  SdfPath const& id);
213 
214 // Given prim information it will create sources representing
215 // constant primvars and hand it to the resource registry.
216 // If transforms are dirty, updates the optional bool.
217 HDST_API
219  HdRprim *prim,
220  HdRprimSharedData *sharedData,
221  HdSceneDelegate *delegate,
222  HdRenderParam *renderParam,
223  HdStDrawItem *drawItem,
224  HdDirtyBits *dirtyBits,
225  HdPrimvarDescriptorVector const& constantPrimvars,
226  bool *hasMirroredTransform = nullptr);
227 
228 // -----------------------------------------------------------------------------
229 // Instancer processing utilities
230 // -----------------------------------------------------------------------------
231 
232 // Updates drawItem bindings for changes to instance topology/primvars.
233 HDST_API
235  HdRenderIndex &renderIndex,
236  HdRenderParam *renderParam,
237  HdRprim *prim,
238  HdStDrawItem *drawItem,
239  HdRprimSharedData *sharedData,
240  HdDirtyBits rprimDirtyBits);
241 
242 // Returns true if primvar with primvarName exists among instance primvar
243 // descriptors.
244 HDST_API
246  HdRenderIndex &renderIndex,
247  HdRprim *prim,
248  TfToken const& primvarName);
249 
250 // -----------------------------------------------------------------------------
251 // Topological visibility processing utility
252 // -----------------------------------------------------------------------------
253 // Creates/Updates/Migrates the topology visiblity BAR with element and point
254 // visibility encoded using one bit per element/point of the topology.
255 HDST_API
257  VtIntArray invisibleElements,
258  int numTotalElements,
259  VtIntArray invisiblePoints,
260  int numTotalPoints,
261  HdRprimSharedData *sharedData,
262  HdStDrawItem *drawItem,
263  HdRenderParam *renderParam,
264  HdChangeTracker *changeTracker,
265  HdStResourceRegistrySharedPtr const &resourceRegistry,
266  SdfPath const& rprimId);
267 
268 //
269 // De-duplicating and sharing immutable primvar data.
270 //
271 // Primvar data is identified using a hash computed from the
272 // sources of the primvar data, of which there are generally
273 // two kinds:
274 // - data provided by the scene delegate
275 // - data produced by computations
276 //
277 // Immutable and mutable buffer data is managed using distinct
278 // heaps in the resource registry. Aggregation of buffer array
279 // ranges within each heap is managed separately.
280 //
281 // We attempt to balance the benefits of sharing vs efficient
282 // varying update using the following simple strategy:
283 //
284 // - When populating the first repr for an rprim, allocate
285 // the primvar range from the immutable heap and attempt
286 // to deduplicate the data by looking up the primvarId
287 // in the primvar instance registry.
288 //
289 // - When populating an additional repr for an rprim using
290 // an existing immutable primvar range, compute an updated
291 // primvarId and allocate from the immutable heap, again
292 // attempting to deduplicate.
293 //
294 // - Otherwise, migrate the primvar data to the mutable heap
295 // and abandon further attempts to deduplicate.
296 //
297 // - The computation of the primvarId for an rprim is cumulative
298 // and includes the new sources of data being committed
299 // during each successive update.
300 //
301 // - Once we have migrated a primvar allocation to the mutable
302 // heap we will no longer spend time computing a primvarId.
303 //
304 
305 HDST_API
307 
308 HDST_API
310  uint64_t baseId,
312  HdStComputationComputeQueuePairVector const &computations);
313 
314 HDST_API
316  HdStComputationComputeQueuePairVector const& computations,
317  HdBufferSpecVector *bufferSpecs);
318 
320 
321 #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
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)
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 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:273
std::vector< struct HdBufferSpec > HdBufferSpecVector
HDST_API void HdStPopulateConstantPrimvars(HdRprim *prim, HdRprimSharedData *sharedData, HdSceneDelegate *delegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, HdDirtyBits *dirtyBits, HdPrimvarDescriptorVector const &constantPrimvars, bool *hasMirroredTransform=nullptr)
HDST_API void HdStMarkGeomSubsetDrawItemsDirty(HdRenderParam *renderParam)
HDST_API bool HdStIsEnabledSharedVertexPrimvar()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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)
HDST_API void HdStUpdateDrawItemBAR(HdBufferArrayRangeSharedPtr const &newRange, int drawCoordIndex, HdRprimSharedData *sharedData, HdRenderParam *renderParam, HdChangeTracker *changeTracker)
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
HDST_API HdPrimvarDescriptorVector HdStGetInstancerPrimvarDescriptors(HdStInstancer const *instancer, HdSceneDelegate *delegate)