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 bool hasDisplayOpacityPrimvar,
109 bool occludedSelectionShowsThrough);
110// Resolves the material network shader for the given prim (using a fallback
111// material as necessary).
112HDST_API
113HdSt_MaterialNetworkShaderSharedPtr
114HdStGetMaterialNetworkShader(
115 HdRprim const * prim,
116 HdSceneDelegate * delegate);
117
118HDST_API
119HdSt_MaterialNetworkShaderSharedPtr
120HdStGetMaterialNetworkShader(
121 HdRprim const * prim,
122 HdSceneDelegate * delegate,
123 SdfPath const & materialId);
124
125// -----------------------------------------------------------------------------
126// Primvar processing and BAR allocation utilities
127// -----------------------------------------------------------------------------
128// Returns true if range is non-empty and valid.
129HDST_API
130bool HdStIsValidBAR(HdBufferArrayRangeSharedPtr const& range);
131
132// Returns true if curRange can be used as-is (even if it's empty) during
133// primvar processing.
134HDST_API
135bool HdStCanSkipBARAllocationOrUpdate(
136 HdBufferSourceSharedPtrVector const& sources,
137 HdStComputationComputeQueuePairVector const& computations,
138 HdBufferArrayRangeSharedPtr const& curRange,
139 HdDirtyBits dirtyBits);
140
141HDST_API
142bool HdStCanSkipBARAllocationOrUpdate(
143 HdBufferSourceSharedPtrVector const& sources,
144 HdBufferArrayRangeSharedPtr const& curRange,
145 HdDirtyBits dirtyBits);
146
147// Returns the buffer specs that have been removed from curRange based on the
148// new primvar descriptors and internally generated primvar names.
149//
150// Internally generated primvar names will never be among the specs returned,
151HDST_API
152HdBufferSpecVector
153HdStGetRemovedPrimvarBufferSpecs(
154 HdBufferArrayRangeSharedPtr const& curRange,
155 HdPrimvarDescriptorVector const& newPrimvarDescs,
156 HdExtComputationPrimvarDescriptorVector const& newCompPrimvarDescs,
157 TfTokenVector const& internallyGeneratedPrimvarNames,
158 SdfPath const& rprimId);
159
160HDST_API
161HdBufferSpecVector
162HdStGetRemovedPrimvarBufferSpecs(
163 HdBufferArrayRangeSharedPtr const& curRange,
164 HdPrimvarDescriptorVector const& newPrimvarDescs,
165 TfTokenVector const& internallyGeneratedPrimvarNames,
166 SdfPath const& rprimId);
167
168// Returns the buffer specs that have been removed from curRange based on the
169// new primvar descriptors, updated specs and internally generated primvar names. Buffer
170// specs with updated types will be replaced.
171// This overload handles primvar type changes and should be preferred over
172// HdStGetRemovedPrimvarBufferSpecs.
173//
174HDST_API
175HdBufferSpecVector
176HdStGetRemovedOrReplacedPrimvarBufferSpecs(
177 HdBufferArrayRangeSharedPtr const& curRange,
178 HdPrimvarDescriptorVector const& newPrimvarDescs,
179 TfTokenVector const& internallyGeneratedPrimvarNames,
180 HdBufferSpecVector const& updatedSpecs,
181 SdfPath const& rprimId);
182
183// Updates the existing range at drawCoordIndex with newRange and flags garbage
184// collection (for the existing range) and rebuild of all draw batches when
185// necessary.
186HDST_API
187void HdStUpdateDrawItemBAR(
188 HdBufferArrayRangeSharedPtr const& newRange,
189 int drawCoordIndex,
190 HdRprimSharedData *sharedData,
191 HdRenderParam *renderParam,
192 HdChangeTracker *changeTracker);
193
194// Returns true if primvar with primvarName exists within primvar descriptor
195// vector primvars and primvar has a valid value
196HDST_API
197bool HdStIsPrimvarExistentAndValid(
198 HdRprim *prim,
199 HdSceneDelegate *delegate,
200 HdPrimvarDescriptorVector const& primvars,
201 TfToken const& primvarName);
202
203// -----------------------------------------------------------------------------
204// Constant primvar processing utilities
205// -----------------------------------------------------------------------------
206// Returns whether constant primvars need to be populated/updated based on the
207// dirty bits for a given rprim.
208HDST_API
209bool HdStShouldPopulateConstantPrimvars(
210 HdDirtyBits const *dirtyBits,
211 SdfPath const& id);
212
213// Given prim information it will create sources representing
214// constant primvars and hand it to the resource registry.
215// If transforms are dirty, updates the optional bool.
216HDST_API
217void HdStPopulateConstantPrimvars(
218 HdRprim *prim,
219 HdRprimSharedData *sharedData,
220 HdSceneDelegate *delegate,
221 HdRenderParam *renderParam,
222 HdStDrawItem *drawItem,
223 HdDirtyBits *dirtyBits,
224 HdPrimvarDescriptorVector const& constantPrimvars,
225 bool *hasMirroredTransform = nullptr);
226
227// -----------------------------------------------------------------------------
228// Instancer processing utilities
229// -----------------------------------------------------------------------------
230
231// Updates drawItem bindings for changes to instance topology/primvars.
232HDST_API
233void HdStUpdateInstancerData(
234 HdRenderIndex &renderIndex,
235 HdRenderParam *renderParam,
236 HdRprim *prim,
237 HdStDrawItem *drawItem,
238 HdRprimSharedData *sharedData,
239 HdDirtyBits rprimDirtyBits);
240
241// Returns true if primvar with primvarName exists among instance primvar
242// descriptors.
243HDST_API
244bool HdStIsInstancePrimvarExistentAndValid(
245 HdRenderIndex &renderIndex,
246 HdRprim *prim,
247 TfToken const& primvarName);
248
249// -----------------------------------------------------------------------------
250// Topological visibility processing utility
251// -----------------------------------------------------------------------------
252// Creates/Updates/Migrates the topology visiblity BAR with element and point
253// visibility encoded using one bit per element/point of the topology.
254HDST_API
255void HdStProcessTopologyVisibility(
256 VtIntArray invisibleElements,
257 int numTotalElements,
258 VtIntArray invisiblePoints,
259 int numTotalPoints,
260 HdRprimSharedData *sharedData,
261 HdStDrawItem *drawItem,
262 HdRenderParam *renderParam,
263 HdChangeTracker *changeTracker,
264 HdStResourceRegistrySharedPtr const &resourceRegistry,
265 SdfPath const& rprimId);
266
267//
268// De-duplicating and sharing immutable primvar data.
269//
270// Primvar data is identified using a hash computed from the
271// sources of the primvar data, of which there are generally
272// two kinds:
273// - data provided by the scene delegate
274// - data produced by computations
275//
276// Immutable and mutable buffer data is managed using distinct
277// heaps in the resource registry. Aggregation of buffer array
278// ranges within each heap is managed separately.
279//
280// We attempt to balance the benefits of sharing vs efficient
281// varying update using the following simple strategy:
282//
283// - When populating the first repr for an rprim, allocate
284// the primvar range from the immutable heap and attempt
285// to deduplicate the data by looking up the primvarId
286// in the primvar instance registry.
287//
288// - When populating an additional repr for an rprim using
289// an existing immutable primvar range, compute an updated
290// primvarId and allocate from the immutable heap, again
291// attempting to deduplicate.
292//
293// - Otherwise, migrate the primvar data to the mutable heap
294// and abandon further attempts to deduplicate.
295//
296// - The computation of the primvarId for an rprim is cumulative
297// and includes the new sources of data being committed
298// during each successive update.
299//
300// - Once we have migrated a primvar allocation to the mutable
301// heap we will no longer spend time computing a primvarId.
302//
303
304HDST_API
305bool HdStIsEnabledSharedVertexPrimvar();
306
307HDST_API
308uint64_t HdStComputeSharedPrimvarId(
309 uint64_t baseId,
310 HdBufferSourceSharedPtrVector const &sources,
311 HdStComputationComputeQueuePairVector const &computations);
312
313HDST_API
314void HdStGetBufferSpecsFromCompuations(
315 HdStComputationComputeQueuePairVector const& computations,
316 HdBufferSpecVector *bufferSpecs);
317
318PXR_NAMESPACE_CLOSE_SCOPE
319
320#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:104
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