Loading...
Searching...
No Matches
sceneIndexAdapterSceneDelegate.h
1//
2// Copyright 2021 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_SCENE_INDEX_ADAPTER_SCENE_DELEGATE_H
8#define PXR_IMAGING_HD_SCENE_INDEX_ADAPTER_SCENE_DELEGATE_H
9
10#include "pxr/imaging/hd/sceneDelegate.h"
11#include "pxr/imaging/hd/sceneIndex.h"
12#include "pxr/usd/sdf/pathTable.h"
13#include <thread>
14#include <tbb/concurrent_unordered_map.h>
15
18
19PXR_NAMESPACE_OPEN_SCOPE
20
23HD_API
25HdExtComputationPrimvarDescriptorFromSchema(
26 TfToken const& name,
27 HdExtComputationPrimvarSchema primvar);
28
30HD_API
32HdPrimvarDescriptorFromSchema(
33 TfToken const& name,
34 HdPrimvarSchema primvar);
35
44 : public HdSceneDelegate
46{
47public:
48
50 HdSceneIndexBaseRefPtr inputSceneIndex,
51 HdRenderIndex *parentIndex,
52 SdfPath const &delegateID);
53
55
56 // satisfying HdSceneIndexObserver ----------------------------------------
58 const HdSceneIndexBase &sender,
59 const AddedPrimEntries &entries) override;
60
62 const HdSceneIndexBase &sender,
63 const RemovedPrimEntries &entries) override;
64
66 const HdSceneIndexBase &sender,
67 const DirtiedPrimEntries &entries) override;
68
70 const HdSceneIndexBase &sender,
71 const RenamedPrimEntries &entries) override;
72
73 // ------------------------------------------------------------------------
74 // HdSceneIndexDelegate API
75
76 // ------------------------------------------------------------------------
77 // Rprim API
78
82 GfRange3d GetExtent(SdfPath const &id) override;
83 bool GetVisible(SdfPath const &id) override;
84 bool GetDoubleSided(SdfPath const &id) override;
85 HdCullStyle GetCullStyle(SdfPath const &id) override;
86 VtValue GetShadingStyle(SdfPath const &id) override;
89 TfToken GetRenderTag(SdfPath const &id) override;
91 HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
92 SdfPath const &volumeId) override;
93
94 // ------------------------------------------------------------------------
95 // Transform API
96
97 GfMatrix4d GetTransform(SdfPath const &id) override;
98 size_t SampleTransform(SdfPath const &id, size_t maxSampleCount,
99 float *sampleTimes, GfMatrix4d *sampleValues) override;
100 size_t SampleTransform(SdfPath const &id,
101 float startTime, float endTime,
102 size_t maxSampleCount,
103 float *sampleTimes, GfMatrix4d *sampleValues) override;
104
106 SdfPath const &instancerId) override;
107 size_t SampleInstancerTransform(SdfPath const &instancerId,
108 size_t maxSampleCount, float *sampleTimes,
109 GfMatrix4d *sampleValues) override;
110 size_t SampleInstancerTransform(SdfPath const &instancerId,
111 float startTime, float endTime,
112 size_t maxSampleCount, float *sampleTimes,
113 GfMatrix4d *sampleValues) override;
114
115 // ------------------------------------------------------------------------
116 // Primvar API
117
118 HdPrimvarDescriptorVector
120 SdfPath const &id, HdInterpolation interpolation) override;
121
122 VtValue Get(SdfPath const &id, TfToken const &key) override;
123 VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
124 VtIntArray *outIndices) override;
125
126 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
127 size_t maxSampleCount, float *sampleTimes,
128 VtValue *sampleValues) override;
129 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
130 float startTime, float endTime,
131 size_t maxSampleCount, float *sampleTimes,
132 VtValue *sampleValues) override;
133 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
134 size_t maxNumSamples, float *times, VtValue *samples,
135 VtIntArray *sampleIndices) override;
136 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
137 float startTime, float endTime,
138 size_t maxNumSamples, float *times, VtValue *samples,
139 VtIntArray *sampleIndices) override;
140
141 // ------------------------------------------------------------------------
142 // Instancer API
143
144 std::vector<VtArray<TfToken>> GetInstanceCategories(
145 SdfPath const &instancerId) override;
147 SdfPath const &instancerId, SdfPath const &prototypeId) override;
148 SdfPath GetInstancerId(SdfPath const &primId) override;
149 SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
150
151 // ------------------------------------------------------------------------
152 // Material API
153
154 SdfPath GetMaterialId(SdfPath const &id) override;
155 VtValue GetMaterialResource(SdfPath const &id) override;
156 HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
157
158 // ------------------------------------------------------------------------
159 // Renderbuffer API
160
162 SdfPath const &id) override;
163
164 // ------------------------------------------------------------------------
165 // Light API
166
167 VtValue GetLightParamValue(SdfPath const &id,
168 TfToken const &paramName) override;
169
170 // ------------------------------------------------------------------------
171 // Camera API
172
174 TfToken const &paramName) override;
175
176 // ------------------------------------------------------------------------
177 // ExtComputation API
178
179 // ... on the rprim
180 HdExtComputationPrimvarDescriptorVector
182 SdfPath const &id, HdInterpolation interpolationMode) override;
183
184 // ... on the sprim
186 SdfPath const &computationId) override;
188 SdfPath const &computationId, TfToken const &input) override;
190 SdfPath const &computationId,
191 TfToken const &input,
192 size_t maxSampleCount,
193 float *sampleTimes,
194 VtValue *sampleValues) override;
196 SdfPath const &computationId,
197 TfToken const &input,
198 float startTime,
199 float endTime,
200 size_t maxSampleCount,
201 float *sampleTimes,
202 VtValue *sampleValues) override;
203
204 HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(
205 SdfPath const &computationId) override;
206 HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(
207 SdfPath const &computationId) override;
208
209 std::string GetExtComputationKernel(SdfPath const &computationId) override;
210 void InvokeExtComputation(SdfPath const &computationId,
211 HdExtComputationContext *context) override;
212
213 TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override;
214
215 void Sync(HdSyncRequestVector* request) override;
216 void PostSyncCleanup() override;
217
218 // NOTE: The remaining scene delegate functions aren't used for emulation:
219 // - GetScenePrimPath
220 // - IsEnabled
221
222private:
223 // Compute and return an HdSceneIndexPrim from the input scene index.
224 // Uses a per-thread single-entry cache to re-use this computation
225 // across sequential Get...() calls in the public API. This API returns
226 // the prim by value rather than reference because callers may
227 // indirectly re-invoke _GetInputPrim() on the same thread, but with
228 // a different id path, if they make use of a TBB work queue.
229 HdSceneIndexPrim _GetInputPrim(SdfPath const& id);
230
231 using _InputPrimCacheEntry = std::pair<SdfPath, HdSceneIndexPrim>;
232
233 // A cache of the last prim accessed, per thread
234 tbb::concurrent_unordered_map<std::thread::id, _InputPrimCacheEntry,
235 std::hash<std::thread::id> > _inputPrimCache;
236
237 void _PrimAdded(
238 const SdfPath &primPath,
239 const TfToken &primType);
240
241 VtValue _GetPrimvar(SdfPath const &id, TfToken const &key,
242 VtIntArray *outIndices);
243
244 VtValue _GetPrimvar(
245 const HdContainerDataSourceHandle &primvarsDataSource,
246 TfToken const &key,
247 VtIntArray *outIndices);
248
249 VtValue _GetImageShaderValue(
250 HdSceneIndexPrim prim,
251 const TfToken& key);
252
253 size_t _SamplePrimvar(SdfPath const &id, TfToken const &key,
254 float startTime, float endTime,
255 size_t maxNumSamples, float *times, VtValue *samples,
256 VtIntArray *sampleIndices);
257
258 HdSceneIndexBaseRefPtr _inputSceneIndex;
259
260 struct _PrimCacheEntry
261 {
262 TfToken primType;
263
264 using PrimvarDescriptorsArray =
265 std::array<HdPrimvarDescriptorVector, HdInterpolationCount>;
266 std::shared_ptr<PrimvarDescriptorsArray> primvarDescriptors;
267 using ExtCmpPrimvarDescriptorsArray =
268 std::array<HdExtComputationPrimvarDescriptorVector,
269 HdInterpolationCount>;
270 std::shared_ptr<ExtCmpPrimvarDescriptorsArray> extCmpPrimvarDescriptors;
271 };
272
273 using _PrimCacheTable = SdfPathTable<_PrimCacheEntry>;
274 _PrimCacheTable _primCache;
275
276 std::shared_ptr<_PrimCacheEntry::PrimvarDescriptorsArray>
277 _ComputePrimvarDescriptors(
278 const HdContainerDataSourceHandle &primDataSource);
279 std::shared_ptr<_PrimCacheEntry::ExtCmpPrimvarDescriptorsArray>
280 _ComputeExtCmpPrimvarDescriptors(
281 const HdContainerDataSourceHandle &primDataSource);
282
283 bool _sceneDelegatesBuilt;
284 std::vector<HdSceneDelegate*> _sceneDelegates;
285
286 // Hint cache of all prim paths that have been populated with
287 // geomSubset children. This is purely an optimization and
288 // not authoritative -- it may have false positioves, such as
289 // if subsets are removed later. These hints provide a way
290 // to skip the expense of _GatherGeomSubsets() when no subsets
291 // have been populated.
292 std::unordered_set<SdfPath, SdfPath::Hash> _geomSubsetParents;
293
294 // Cache for rprim locator set -> dirty bits translation.
295 HdDataSourceLocatorSet _cachedLocatorSet;
296 HdDirtyBits _cachedDirtyBits;
297 TfToken _cachedPrimType;
298};
299
300PXR_NAMESPACE_CLOSE_SCOPE
301
302#endif
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Topology data for basisCurves.
Represents a set of data source locators closed under descendancy.
Interface class that defines the execution environment for the client to run a computation.
Topology data for meshes.
Definition: meshTopology.h:38
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
Describes one or more authored display representations for an rprim.
Definition: repr.h:32
Adapter class providing data exchange with the client scene graph.
Scene delegate which observes notices from an HdSceneIndex and applies them to an HdRenderIndex.
TfToken GetRenderTag(SdfPath const &id) override
Returns the render tag that will be used to bucket prims during render pass bucketing.
void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
size_t SampleInstancerTransform(SdfPath const &instancerId, float startTime, float endTime, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
An overload of SampleInstancerTransform that takes frame-relative startTime and endTime,...
size_t SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
Store up to maxSampleCount transform samples in *sampleValues.
HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
Returns the display style for the given prim.
TfTokenVector GetExtComputationSceneInputNames(SdfPath const &computationId) override
For the given computation id, returns a list of inputs which will be requested from the scene delegat...
HdExtComputationPrimvarDescriptorVector GetExtComputationPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolationMode) override
Returns a list of primvar names that should be bound to a generated output from an ExtComputation for...
void PrimsRemoved(const HdSceneIndexBase &sender, const RemovedPrimEntries &entries) override
A notification indicating prims have been removed from the scene.
HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id) override
Returns the allocation descriptor for a given render buffer prim.
void PrimsRenamed(const HdSceneIndexBase &sender, const RenamedPrimEntries &entries) override
A notification indicating prims (and their descendants) have been renamed or reparented.
size_t SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
Return up to maxSampleCount samples for a given computation id and input token.
HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples, VtIntArray *sampleIndices) override
SamplePrimvar() for getting an unflattened primvar and its indices.
void PostSyncCleanup() override
Opportunity for the delegate to clean itself up after performing parallel work during sync phase.
bool GetDoubleSided(SdfPath const &id) override
Returns the doubleSided state for the given prim.
HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation) override
Returns descriptors for all primvars of the given interpolation type.
SdfPath GetMaterialId(SdfPath const &id) override
Returns the material ID bound to the rprim rprimId.
HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation input descriptors.
HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.
HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation output descriptors.
std::string GetExtComputationKernel(SdfPath const &computationId) override
Returns the kernel source assigned to the computation at the path id.
std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId) override
Returns the categories for each of the instances in the instancer.
void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override
Requests the scene delegate run the ExtComputation with the given id.
void PrimsAdded(const HdSceneIndexBase &sender, const AddedPrimEntries &entries) override
A notification indicating prims have been added to the scene.
GfMatrix4d GetTransform(SdfPath const &id) override
Returns the object space transform, including all parent transforms.
HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override
Gets the topological curve data for a given prim.
SdfPath GetInstancerId(SdfPath const &primId) override
Returns the parent instancer of the given rprim or instancer.
PxOsdSubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
Returns a list of prototypes of this instancer.
size_t SampleTransform(SdfPath const &id, float startTime, float endTime, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
An overload of SampleTransform that takes frame-relative startTime and endTime, rather than relying o...
void PrimsDirtied(const HdSceneIndexBase &sender, const DirtiedPrimEntries &entries) override
A notification indicating prim datasources have been invalidated.
VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId) override
Gets the extracted indices array of the prototype id used in the instancer.
bool GetVisible(SdfPath const &id) override
Returns the authored visible state of the prim.
VtValue GetCameraParamValue(SdfPath const &cameraId, TfToken const &paramName) override
Returns a single value for a given camera and parameter.
VtValue GetExtComputationInput(SdfPath const &computationId, TfToken const &input) override
Returns a single value for a given computation id and input token.
size_t SampleTransform(SdfPath const &id, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
Store up to maxSampleCount transform samples in *sampleValues.
size_t SamplePrimvar(SdfPath const &id, TfToken const &key, float startTime, float endTime, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
An overload of SamplePrimvar that takes frame-relative startTime and endTime, rather than relying on ...
VtValue Get(SdfPath const &id, TfToken const &key) override
Returns a named value.
VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) override
Returns a named primvar value.
VtArray< TfToken > GetCategories(SdfPath const &id) override
Returns the prim categories.
size_t SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
Store up to maxSampleCount primvar samples in *samplesValues.
VtValue GetShadingStyle(SdfPath const &id) override
Returns the shading style for the given prim.
size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, float startTime, float endTime, size_t maxNumSamples, float *times, VtValue *samples, VtIntArray *sampleIndices) override
An overload of SampleIndexedPrimvar that takes frame-relative startTime and endTime,...
GfRange3d GetExtent(SdfPath const &id) override
Gets the axis aligned bounds of a prim.
Abstract interface to scene data.
Definition: sceneIndex.h:54
Observer of scene data.
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:26
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:66
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:213
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:64
Extends HdPrimvarDescriptor to describe a primvar that takes data from the output of an ExtComputatio...
Describes a primvar.
Describes the allocation structure of a render buffer bprim.
Definition: aov.h:67
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
The SceneDelegate is requested to synchronize prims as the result of executing a specific render pass...
Definition: sceneDelegate.h:52
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440