Loading...
Searching...
No Matches
primUtils.h
1//
2// Copyright 2019 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HD_ST_PRIM_UTILS_H
25#define PXR_IMAGING_HD_ST_PRIM_UTILS_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hdSt/resourceRegistry.h"
30#include "pxr/imaging/hd/sceneDelegate.h"
31#include "pxr/imaging/hd/rprim.h"
32
33#include <memory>
34#include <string>
35#include <vector>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
39class HdChangeTracker;
40class HdDrawItem;
41class HdRenderIndex;
42class HdRenderParam;
43class HdRprim;
44struct HdRprimSharedData;
45class HdStDrawItem;
46class HdStInstancer;
47
48using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
49
50using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
51using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
52using HdSt_MaterialNetworkShaderSharedPtr =
53 std::shared_ptr<class HdSt_MaterialNetworkShader>;
54
55using HdStComputationSharedPtr = std::shared_ptr<class HdStComputation>;
56
57using HdStResourceRegistrySharedPtr =
58 std::shared_ptr<HdStResourceRegistry>;
59
60// -----------------------------------------------------------------------------
61// Draw invalidation and garbage collection utilities
62// -----------------------------------------------------------------------------
63HDST_API
64void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam);
65
66HDST_API
67void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam);
68
69HDST_API
70void HdStMarkGeomSubsetDrawItemsDirty(HdRenderParam *renderParam);
71
72HDST_API
73void HdStMarkGarbageCollectionNeeded(HdRenderParam *renderParam);
74
75// -----------------------------------------------------------------------------
76// Primvar descriptor filtering utilities
77// -----------------------------------------------------------------------------
78// Get filtered primvar descriptors for drawItem
79HDST_API
80HdPrimvarDescriptorVector
81HdStGetPrimvarDescriptors(
82 HdRprim const * prim,
83 HdStDrawItem const * drawItem,
84 HdSceneDelegate * delegate,
85 HdInterpolation interpolation,
86 const HdReprSharedPtr &repr = nullptr,
87 HdMeshGeomStyle descGeomStyle = HdMeshGeomStyleInvalid,
88 int geomSubsetDescIndex = 0,
89 size_t numGeomSubsets = 0);
90
91// Get filtered instancer primvar descriptors for drawItem
92HDST_API
93HdPrimvarDescriptorVector
94HdStGetInstancerPrimvarDescriptors(
95 HdStInstancer const * instancer,
96 HdSceneDelegate * delegate);
97
98// -----------------------------------------------------------------------------
99// Tracking render tag changes
100// -----------------------------------------------------------------------------
101
102HDST_API
103void HdStUpdateRenderTag(HdSceneDelegate *delegate,
104 HdRenderParam *renderParam,
105 HdRprim *rprim);
106
107// -----------------------------------------------------------------------------
108// Material processing utilities
109// -----------------------------------------------------------------------------
110HDST_API
111void HdStSetMaterialId(HdSceneDelegate *delegate,
112 HdRenderParam *renderParam,
113 HdRprim *rprim);
114
115HDST_API
116void HdStSetMaterialTag(HdRenderParam *renderParam,
117 HdDrawItem *drawItem,
118 const TfToken &materialTag);
119
120HDST_API
121void HdStSetMaterialTag(HdSceneDelegate *delegate,
122 HdRenderParam *renderParam,
123 HdDrawItem *drawItem,
124 SdfPath const & materialId,
125 bool hasDisplayOpacityPrimvar,
126 bool occludedSelectionShowsThrough);
127// Resolves the material network shader for the given prim (using a fallback
128// material as necessary).
129HDST_API
130HdSt_MaterialNetworkShaderSharedPtr
131HdStGetMaterialNetworkShader(
132 HdRprim const * prim,
133 HdSceneDelegate * delegate);
134
135HDST_API
136HdSt_MaterialNetworkShaderSharedPtr
137HdStGetMaterialNetworkShader(
138 HdRprim const * prim,
139 HdSceneDelegate * delegate,
140 SdfPath const & materialId);
141
142// -----------------------------------------------------------------------------
143// Primvar processing and BAR allocation utilities
144// -----------------------------------------------------------------------------
145// Returns true if range is non-empty and valid.
146HDST_API
147bool HdStIsValidBAR(HdBufferArrayRangeSharedPtr const& range);
148
149// Returns true if curRange can be used as-is (even if it's empty) during
150// primvar processing.
151HDST_API
152bool HdStCanSkipBARAllocationOrUpdate(
153 HdBufferSourceSharedPtrVector const& sources,
154 HdStComputationComputeQueuePairVector const& computations,
155 HdBufferArrayRangeSharedPtr const& curRange,
156 HdDirtyBits dirtyBits);
157
158HDST_API
159bool HdStCanSkipBARAllocationOrUpdate(
160 HdBufferSourceSharedPtrVector const& sources,
161 HdBufferArrayRangeSharedPtr const& curRange,
162 HdDirtyBits dirtyBits);
163
164// Returns the buffer specs that have been removed from curRange based on the
165// new primvar descriptors and internally generated primvar names.
166//
167// Internally generated primvar names will never be among the specs returned,
168HDST_API
169HdBufferSpecVector
170HdStGetRemovedPrimvarBufferSpecs(
171 HdBufferArrayRangeSharedPtr const& curRange,
172 HdPrimvarDescriptorVector const& newPrimvarDescs,
173 HdExtComputationPrimvarDescriptorVector const& newCompPrimvarDescs,
174 TfTokenVector const& internallyGeneratedPrimvarNames,
175 SdfPath const& rprimId);
176
177HDST_API
178HdBufferSpecVector
179HdStGetRemovedPrimvarBufferSpecs(
180 HdBufferArrayRangeSharedPtr const& curRange,
181 HdPrimvarDescriptorVector const& newPrimvarDescs,
182 TfTokenVector const& internallyGeneratedPrimvarNames,
183 SdfPath const& rprimId);
184
185// Returns the buffer specs that have been removed from curRange based on the
186// new primvar descriptors, updated specs and internally generated primvar names. Buffer
187// specs with updated types will be replaced.
188// This overload handles primvar type changes and should be preferred over
189// HdStGetRemovedPrimvarBufferSpecs.
190//
191HDST_API
192HdBufferSpecVector
193HdStGetRemovedOrReplacedPrimvarBufferSpecs(
194 HdBufferArrayRangeSharedPtr const& curRange,
195 HdPrimvarDescriptorVector const& newPrimvarDescs,
196 TfTokenVector const& internallyGeneratedPrimvarNames,
197 HdBufferSpecVector const& updatedSpecs,
198 SdfPath const& rprimId);
199
200// Updates the existing range at drawCoordIndex with newRange and flags garbage
201// collection (for the existing range) and rebuild of all draw batches when
202// necessary.
203HDST_API
204void HdStUpdateDrawItemBAR(
205 HdBufferArrayRangeSharedPtr const& newRange,
206 int drawCoordIndex,
207 HdRprimSharedData *sharedData,
208 HdRenderParam *renderParam,
209 HdChangeTracker *changeTracker);
210
211// Returns true if primvar with primvarName exists within primvar descriptor
212// vector primvars and primvar has a valid value
213HDST_API
214bool HdStIsPrimvarExistentAndValid(
215 HdRprim *prim,
216 HdSceneDelegate *delegate,
217 HdPrimvarDescriptorVector const& primvars,
218 TfToken const& primvarName);
219
220// -----------------------------------------------------------------------------
221// Constant primvar processing utilities
222// -----------------------------------------------------------------------------
223// Returns whether constant primvars need to be populated/updated based on the
224// dirty bits for a given rprim.
225HDST_API
226bool HdStShouldPopulateConstantPrimvars(
227 HdDirtyBits const *dirtyBits,
228 SdfPath const& id);
229
230// Given prim information it will create sources representing
231// constant primvars and hand it to the resource registry.
232// If transforms are dirty, updates the optional bool.
233HDST_API
234void HdStPopulateConstantPrimvars(
235 HdRprim *prim,
236 HdRprimSharedData *sharedData,
237 HdSceneDelegate *delegate,
238 HdRenderParam *renderParam,
239 HdStDrawItem *drawItem,
240 HdDirtyBits *dirtyBits,
241 HdPrimvarDescriptorVector const& constantPrimvars,
242 bool *hasMirroredTransform = nullptr);
243
244// -----------------------------------------------------------------------------
245// Instancer processing utilities
246// -----------------------------------------------------------------------------
247
248// Updates drawItem bindings for changes to instance topology/primvars.
249HDST_API
250void HdStUpdateInstancerData(
251 HdRenderIndex &renderIndex,
252 HdRenderParam *renderParam,
253 HdRprim *prim,
254 HdStDrawItem *drawItem,
255 HdRprimSharedData *sharedData,
256 HdDirtyBits rprimDirtyBits);
257
258// Returns true if primvar with primvarName exists among instance primvar
259// descriptors.
260HDST_API
261bool HdStIsInstancePrimvarExistentAndValid(
262 HdRenderIndex &renderIndex,
263 HdRprim *prim,
264 TfToken const& primvarName);
265
266// -----------------------------------------------------------------------------
267// Topological visibility processing utility
268// -----------------------------------------------------------------------------
269// Creates/Updates/Migrates the topology visiblity BAR with element and point
270// visibility encoded using one bit per element/point of the topology.
271HDST_API
272void HdStProcessTopologyVisibility(
273 VtIntArray invisibleElements,
274 int numTotalElements,
275 VtIntArray invisiblePoints,
276 int numTotalPoints,
277 HdRprimSharedData *sharedData,
278 HdStDrawItem *drawItem,
279 HdRenderParam *renderParam,
280 HdChangeTracker *changeTracker,
281 HdStResourceRegistrySharedPtr const &resourceRegistry,
282 SdfPath const& rprimId);
283
284//
285// De-duplicating and sharing immutable primvar data.
286//
287// Primvar data is identified using a hash computed from the
288// sources of the primvar data, of which there are generally
289// two kinds:
290// - data provided by the scene delegate
291// - data produced by computations
292//
293// Immutable and mutable buffer data is managed using distinct
294// heaps in the resource registry. Aggregation of buffer array
295// ranges within each heap is managed separately.
296//
297// We attempt to balance the benefits of sharing vs efficient
298// varying update using the following simple strategy:
299//
300// - When populating the first repr for an rprim, allocate
301// the primvar range from the immutable heap and attempt
302// to deduplicate the data by looking up the primvarId
303// in the primvar instance registry.
304//
305// - When populating an additional repr for an rprim using
306// an existing immutable primvar range, compute an updated
307// primvarId and allocate from the immutable heap, again
308// attempting to deduplicate.
309//
310// - Otherwise, migrate the primvar data to the mutable heap
311// and abandon further attempts to deduplicate.
312//
313// - The computation of the primvarId for an rprim is cumulative
314// and includes the new sources of data being committed
315// during each successive update.
316//
317// - Once we have migrated a primvar allocation to the mutable
318// heap we will no longer spend time computing a primvarId.
319//
320
321HDST_API
322bool HdStIsEnabledSharedVertexPrimvar();
323
324HDST_API
325uint64_t HdStComputeSharedPrimvarId(
326 uint64_t baseId,
327 HdBufferSourceSharedPtrVector const &sources,
328 HdStComputationComputeQueuePairVector const &computations);
329
330HDST_API
331void HdStGetBufferSpecsFromCompuations(
332 HdStComputationComputeQueuePairVector const& computations,
333 HdBufferSpecVector *bufferSpecs);
334
335PXR_NAMESPACE_CLOSE_SCOPE
336
337#endif // PXR_IMAGING_HD_ST_PRIM_UTILS_H
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Definition: changeTracker.h:52
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
Definition: drawItem.h:65
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
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:55
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:68
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457