Loading...
Searching...
No Matches
primUtils.h
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"
12#include "pxr/imaging/hdSt/resourceRegistry.h"
13#include "pxr/imaging/hd/sceneDelegate.h"
14#include "pxr/imaging/hd/rprim.h"
15
16#include <memory>
17#include <string>
18#include <vector>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22class HdChangeTracker;
23class HdDrawItem;
24class HdRenderIndex;
25class HdRenderParam;
26class HdRprim;
27struct HdRprimSharedData;
28class HdStDrawItem;
29class HdStInstancer;
30
31using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
32
33using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
34using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
35using HdSt_MaterialNetworkShaderSharedPtr =
36 std::shared_ptr<class HdSt_MaterialNetworkShader>;
37
38using HdStComputationSharedPtr = std::shared_ptr<class HdStComputation>;
39
40using HdStResourceRegistrySharedPtr =
41 std::shared_ptr<HdStResourceRegistry>;
42
43// -----------------------------------------------------------------------------
44// Draw invalidation and garbage collection utilities
45// -----------------------------------------------------------------------------
46HDST_API
47void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam);
48
49HDST_API
50void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam);
51
52HDST_API
53void HdStMarkGeomSubsetDrawItemsDirty(HdRenderParam *renderParam);
54
55HDST_API
56void HdStMarkGarbageCollectionNeeded(HdRenderParam *renderParam);
57
58// -----------------------------------------------------------------------------
59// Primvar descriptor filtering utilities
60// -----------------------------------------------------------------------------
61// Get filtered primvar descriptors for drawItem
62HDST_API
63HdPrimvarDescriptorVector
64HdStGetPrimvarDescriptors(
65 HdRprim const * prim,
66 HdStDrawItem const * drawItem,
67 HdSceneDelegate * delegate,
68 HdInterpolation interpolation,
69 const HdReprSharedPtr &repr = nullptr,
70 HdMeshGeomStyle descGeomStyle = HdMeshGeomStyleInvalid,
71 int geomSubsetDescIndex = 0,
72 size_t numGeomSubsets = 0);
73
74// Get filtered instancer primvar descriptors for drawItem
75HDST_API
76HdPrimvarDescriptorVector
77HdStGetInstancerPrimvarDescriptors(
78 HdStInstancer const * instancer,
79 HdSceneDelegate * delegate);
80
81// -----------------------------------------------------------------------------
82// Tracking render tag changes
83// -----------------------------------------------------------------------------
84
85HDST_API
86void HdStUpdateRenderTag(HdSceneDelegate *delegate,
87 HdRenderParam *renderParam,
88 HdRprim *rprim);
89
90// -----------------------------------------------------------------------------
91// Material processing utilities
92// -----------------------------------------------------------------------------
93HDST_API
94void HdStSetMaterialId(HdSceneDelegate *delegate,
95 HdRenderParam *renderParam,
96 HdRprim *rprim);
97
98HDST_API
99void HdStSetMaterialTag(HdRenderParam *renderParam,
100 HdDrawItem *drawItem,
101 const TfToken &materialTag);
102
103HDST_API
104void 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).
113HDST_API
114HdSt_MaterialNetworkShaderSharedPtr
115HdStGetMaterialNetworkShader(
116 HdRprim const * prim,
117 HdSceneDelegate * delegate);
118
119HDST_API
120HdSt_MaterialNetworkShaderSharedPtr
121HdStGetMaterialNetworkShader(
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.
130HDST_API
131bool HdStIsValidBAR(HdBufferArrayRangeSharedPtr const& range);
132
133// Returns true if curRange can be used as-is (even if it's empty) during
134// primvar processing.
135HDST_API
136bool HdStCanSkipBARAllocationOrUpdate(
137 HdBufferSourceSharedPtrVector const& sources,
138 HdStComputationComputeQueuePairVector const& computations,
139 HdBufferArrayRangeSharedPtr const& curRange,
140 HdDirtyBits dirtyBits);
141
142HDST_API
143bool HdStCanSkipBARAllocationOrUpdate(
144 HdBufferSourceSharedPtrVector const& sources,
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,
152HDST_API
153HdBufferSpecVector
154HdStGetRemovedPrimvarBufferSpecs(
155 HdBufferArrayRangeSharedPtr const& curRange,
156 HdPrimvarDescriptorVector const& newPrimvarDescs,
157 HdExtComputationPrimvarDescriptorVector const& newCompPrimvarDescs,
158 TfTokenVector const& internallyGeneratedPrimvarNames,
159 SdfPath const& rprimId);
160
161HDST_API
162HdBufferSpecVector
163HdStGetRemovedPrimvarBufferSpecs(
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//
175HDST_API
176HdBufferSpecVector
177HdStGetRemovedOrReplacedPrimvarBufferSpecs(
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.
187HDST_API
188void HdStUpdateDrawItemBAR(
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
197HDST_API
198bool HdStIsPrimvarExistentAndValid(
199 HdRprim *prim,
200 HdSceneDelegate *delegate,
201 HdPrimvarDescriptorVector const& primvars,
202 TfToken const& primvarName);
203
204HDST_API
205bool HdStIsPrimvarValidForDrawItem(
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.
215HDST_API
216bool HdStShouldPopulateConstantPrimvars(
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.
223HDST_API
224void HdStPopulateConstantPrimvars(
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.
244HDST_API
245void HdStUpdateInstancerData(
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.
257HDST_API
258bool HdStIsInstancePrimvarExistentAndValid(
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.
268HDST_API
269void HdStProcessTopologyVisibility(
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
318HDST_API
319bool HdStIsEnabledSharedVertexPrimvar();
320
321HDST_API
322uint64_t HdStComputeSharedPrimvarId(
323 uint64_t baseId,
324 HdBufferSourceSharedPtrVector const &sources,
325 HdStComputationComputeQueuePairVector const &computations);
326
327HDST_API
328void HdStGetBufferSpecsFromCompuations(
329 HdStComputationComputeQueuePairVector const& computations,
330 HdBufferSpecVector *bufferSpecs);
331
332PXR_NAMESPACE_CLOSE_SCOPE
333
334#endif // PXR_IMAGING_HD_ST_PRIM_UTILS_H
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Definition: changeTracker.h:35
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
Definition: drawItem.h:48
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:38
Adapter class providing data exchange with the client scene graph.
HdSt implements instancing by drawing each proto multiple times with a single draw call.
Definition: instancer.h:51
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440