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
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.
209HDST_API
210bool HdStShouldPopulateConstantPrimvars(
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.
217HDST_API
218void HdStPopulateConstantPrimvars(
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.
233HDST_API
234void HdStUpdateInstancerData(
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.
244HDST_API
245bool HdStIsInstancePrimvarExistentAndValid(
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.
255HDST_API
256void HdStProcessTopologyVisibility(
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
305HDST_API
306bool HdStIsEnabledSharedVertexPrimvar();
307
308HDST_API
309uint64_t HdStComputeSharedPrimvarId(
310 uint64_t baseId,
311 HdBufferSourceSharedPtrVector const &sources,
312 HdStComputationComputeQueuePairVector const &computations);
313
314HDST_API
315void HdStGetBufferSpecsFromCompuations(
316 HdStComputationComputeQueuePairVector const& computations,
317 HdBufferSpecVector *bufferSpecs);
318
319PXR_NAMESPACE_CLOSE_SCOPE
320
321#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
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440