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 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"
31 
32 #include <memory>
33 #include <string>
34 #include <vector>
35 
37 
38 class HdChangeTracker;
39 class HdDrawItem;
40 class HdRenderIndex;
41 class HdRenderParam;
42 class HdRprim;
43 struct HdRprimSharedData;
44 class HdStDrawItem;
45 class HdStInstancer;
46 
47 using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
48 
49 using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
50 using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
51 using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
52 
53 using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
54 
56  std::shared_ptr<HdStResourceRegistry>;
57 
58 // -----------------------------------------------------------------------------
59 // Draw invalidation and garbage collection utilities
60 // -----------------------------------------------------------------------------
62 void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam);
63 
65 void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam);
66 
69 
70 // -----------------------------------------------------------------------------
71 // Primvar descriptor filtering utilities
72 // -----------------------------------------------------------------------------
73 // Get filtered primvar descriptors for drawItem
77  HdRprim const * prim,
78  HdStDrawItem const * drawItem,
79  HdSceneDelegate * delegate,
80  HdInterpolation interpolation);
81 
82 // Get filtered instancer primvar descriptors for drawItem
86  HdStInstancer const * instancer,
87  HdSceneDelegate * delegate);
88 
89 // -----------------------------------------------------------------------------
90 // Material processing utilities
91 // -----------------------------------------------------------------------------
93 void HdStSetMaterialId(HdSceneDelegate *delegate,
94  HdRenderParam *renderParam,
95  HdRprim *rprim);
96 
98 void HdStSetMaterialTag(HdSceneDelegate *delegate,
99  HdRenderParam *renderParam,
100  HdRprim *rprim,
101  bool hasDisplayOpacityPrimvar,
102  bool occludedSelectionShowsThrough);
103 // Resolves the material shader for the given prim (using a fallback
104 // material as necessary).
105 HDST_API
108  HdRprim const * prim,
109  HdSceneDelegate * delegate);
110 
111 // -----------------------------------------------------------------------------
112 // Primvar processing and BAR allocation utilities
113 // -----------------------------------------------------------------------------
114 // Returns true if range is non-empty and valid.
115 HDST_API
117 
118 // Returns true if curRange can be used as-is (even if it's empty) during
119 // primvar processing.
120 HDST_API
123  HdStComputationSharedPtrVector const& computations,
124  HdBufferArrayRangeSharedPtr const& curRange,
125  HdDirtyBits dirtyBits);
126 
127 HDST_API
130  HdBufferArrayRangeSharedPtr const& curRange,
131  HdDirtyBits dirtyBits);
132 
133 // Returns the buffer specs that have been removed from curRange based on the
134 // new primvar descriptors and internally generated primvar names.
135 //
136 // Internally generated primvar names will never be among the specs returned,
137 HDST_API
140  HdBufferArrayRangeSharedPtr const& curRange,
141  HdPrimvarDescriptorVector const& newPrimvarDescs,
142  HdExtComputationPrimvarDescriptorVector const& newCompPrimvarDescs,
143  TfTokenVector const& internallyGeneratedPrimvarNames,
144  SdfPath const& rprimId);
145 
146 HDST_API
149  HdBufferArrayRangeSharedPtr const& curRange,
150  HdPrimvarDescriptorVector const& newPrimvarDescs,
151  TfTokenVector const& internallyGeneratedPrimvarNames,
152  SdfPath const& rprimId);
153 
154 // Updates the existing range at drawCoordIndex with newRange and flags garbage
155 // collection (for the existing range) and rebuild of all draw batches when
156 // necessary.
157 HDST_API
159  HdBufferArrayRangeSharedPtr const& newRange,
160  int drawCoordIndex,
161  HdRprimSharedData *sharedData,
162  HdRenderParam *renderParam,
163  HdChangeTracker *changeTracker);
164 
165 // Returns true if primvar with primvarName exists within primvar descriptor
166 // vector primvars and primvar has a valid value
167 HDST_API
169  HdRprim *prim,
170  HdSceneDelegate *delegate,
171  HdPrimvarDescriptorVector const& primvars,
172  TfToken const& primvarName);
173 
174 // -----------------------------------------------------------------------------
175 // Constant primvar processing utilities
176 // -----------------------------------------------------------------------------
177 // Returns whether constant primvars need to be populated/updated based on the
178 // dirty bits for a given rprim.
179 HDST_API
181  HdDirtyBits const *dirtyBits,
182  SdfPath const& id);
183 
184 // Given prim information it will create sources representing
185 // constant primvars and hand it to the resource registry.
186 // If transforms are dirty, updates the optional bool.
187 HDST_API
189  HdRprim *prim,
190  HdRprimSharedData *sharedData,
191  HdSceneDelegate *delegate,
192  HdRenderParam *renderParam,
193  HdDrawItem *drawItem,
194  HdDirtyBits *dirtyBits,
195  HdPrimvarDescriptorVector const& constantPrimvars,
196  bool *hasMirroredTransform = nullptr);
197 
198 // -----------------------------------------------------------------------------
199 // Instancer processing utilities
200 // -----------------------------------------------------------------------------
201 
202 // Updates drawItem bindings for changes to instance topology/primvars.
203 HDST_API
205  HdRenderIndex &renderIndex,
206  HdRenderParam *renderParam,
207  HdRprim *prim,
208  HdStDrawItem *drawItem,
209  HdRprimSharedData *sharedData,
210  HdDirtyBits rprimDirtyBits);
211 
212 // Returns true if primvar with primvarName exists among instance primvar
213 // descriptors.
214 HDST_API
216  HdRenderIndex &renderIndex,
217  HdRprim *prim,
218  TfToken const& primvarName);
219 
220 // -----------------------------------------------------------------------------
221 // Topological visibility processing utility
222 // -----------------------------------------------------------------------------
223 // Creates/Updates/Migrates the topology visiblity BAR with element and point
224 // visibility encoded using one bit per element/point of the topology.
225 HDST_API
227  VtIntArray invisibleElements,
228  int numTotalElements,
229  VtIntArray invisiblePoints,
230  int numTotalPoints,
231  HdRprimSharedData *sharedData,
232  HdStDrawItem *drawItem,
233  HdRenderParam *renderParam,
234  HdChangeTracker *changeTracker,
235  HdStResourceRegistrySharedPtr const &resourceRegistry,
236  SdfPath const& rprimId);
237 
238 //
239 // De-duplicating and sharing immutable primvar data.
240 //
241 // Primvar data is identified using a hash computed from the
242 // sources of the primvar data, of which there are generally
243 // two kinds:
244 // - data provided by the scene delegate
245 // - data produced by computations
246 //
247 // Immutable and mutable buffer data is managed using distinct
248 // heaps in the resource registry. Aggregation of buffer array
249 // ranges within each heap is managed separately.
250 //
251 // We attempt to balance the benefits of sharing vs efficient
252 // varying update using the following simple strategy:
253 //
254 // - When populating the first repr for an rprim, allocate
255 // the primvar range from the immutable heap and attempt
256 // to deduplicate the data by looking up the primvarId
257 // in the primvar instance registry.
258 //
259 // - When populating an additional repr for an rprim using
260 // an existing immutable primvar range, compute an updated
261 // primvarId and allocate from the immutable heap, again
262 // attempting to deduplicate.
263 //
264 // - Otherwise, migrate the primvar data to the mutable heap
265 // and abandon further attempts to deduplicate.
266 //
267 // - The computation of the primvarId for an rprim is cumulative
268 // and includes the new sources of data being committed
269 // during each successive update.
270 //
271 // - Once we have migrated a primvar allocation to the mutable
272 // heap we will no longer spend time computing a primvarId.
273 //
274 
275 HDST_API
277 
278 HDST_API
280  uint64_t baseId,
282  HdStComputationSharedPtrVector const &computations);
283 
284 HDST_API
286  HdStComputationSharedPtrVector const& computations,
287  HdBufferSpecVector *bufferSpecs);
288 
290 
291 #endif // PXR_IMAGING_HD_ST_PRIM_UTILS_H
HDST_API void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam)
uint32_t HdDirtyBits
Definition: types.h:127
HDST_API HdStShaderCodeSharedPtr HdStGetMaterialShader(HdRprim const *prim, HdSceneDelegate *delegate)
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)
HDST_API void HdStGetBufferSpecsFromCompuations(HdStComputationSharedPtrVector const &computations, HdBufferSpecVector *bufferSpecs)
std::vector< HdBufferSourceSharedPtr > HdBufferSourceSharedPtrVector
Definition: bufferSource.h:44
HDST_API void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam)
HDST_API void HdStMarkGarbageCollectionNeeded(HdRenderParam *renderParam)
GLsizei GLenum * sources
Definition: glcorearb.h:2541
Definition: token.h:87
Definition: rprim.h:68
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 bool HdStCanSkipBARAllocationOrUpdate(HdBufferSourceSharedPtrVector const &sources, HdStComputationSharedPtrVector const &computations, HdBufferArrayRangeSharedPtr const &curRange, HdDirtyBits dirtyBits)
std::shared_ptr< class HdComputation > HdComputationSharedPtr
Definition: computation.h:41
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Definition: path.h:288
std::vector< std::pair< HdComputationSharedPtr, HdStComputeQueue >> HdStComputationSharedPtrVector
std::vector< struct HdBufferSpec > HdBufferSpecVector
HDST_API HdPrimvarDescriptorVector HdStGetPrimvarDescriptors(HdRprim const *prim, HdStDrawItem const *drawItem, HdSceneDelegate *delegate, HdInterpolation interpolation)
HDST_API uint64_t HdStComputeSharedPrimvarId(uint64_t baseId, HdBufferSourceSharedPtrVector const &sources, HdStComputationSharedPtrVector const &computations)
HDST_API bool HdStIsEnabledSharedVertexPrimvar()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
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)
#define HDST_API
Definition: api.h:40
HDST_API bool HdStIsInstancePrimvarExistentAndValid(HdRenderIndex &renderIndex, HdRprim *prim, TfToken const &primvarName)
HdInterpolation
Definition: enums.h:194
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:45
GLenum GLint * range
Definition: glcorearb.h:1924
HDST_API void HdStSetMaterialTag(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdRprim *rprim, bool hasDisplayOpacityPrimvar, bool occludedSelectionShowsThrough)
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
HDST_API bool HdStIsPrimvarExistentAndValid(HdRprim *prim, HdSceneDelegate *delegate, HdPrimvarDescriptorVector const &primvars, TfToken const &primvarName)
HDST_API void HdStPopulateConstantPrimvars(HdRprim *prim, HdRprimSharedData *sharedData, HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDrawItem *drawItem, HdDirtyBits *dirtyBits, HdPrimvarDescriptorVector const &constantPrimvars, bool *hasMirroredTransform=nullptr)
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:47
std::shared_ptr< class HdStShaderCode > HdStShaderCodeSharedPtr
Definition: drawItem.h:34
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)