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 VtValue GetVolumeParamValue(SdfPath const &id,
94 TfToken const &paramName) override;
95
96 // ------------------------------------------------------------------------
97 // Transform API
98
99 GfMatrix4d GetTransform(SdfPath const &id) override;
100 size_t SampleTransform(SdfPath const &id, size_t maxSampleCount,
101 float *sampleTimes, GfMatrix4d *sampleValues) override;
102 size_t SampleTransform(SdfPath const &id,
103 float startTime, float endTime,
104 size_t maxSampleCount,
105 float *sampleTimes, GfMatrix4d *sampleValues) override;
106
108 SdfPath const &instancerId) override;
109 size_t SampleInstancerTransform(SdfPath const &instancerId,
110 size_t maxSampleCount, float *sampleTimes,
111 GfMatrix4d *sampleValues) override;
112 size_t SampleInstancerTransform(SdfPath const &instancerId,
113 float startTime, float endTime,
114 size_t maxSampleCount, float *sampleTimes,
115 GfMatrix4d *sampleValues) override;
116
117 // ------------------------------------------------------------------------
118 // Primvar API
119
120 HdPrimvarDescriptorVector
122 SdfPath const &id, HdInterpolation interpolation) override;
123
124 VtValue Get(SdfPath const &id, TfToken const &key) override;
125 VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
126 VtIntArray *outIndices) override;
127
128 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
129 size_t maxSampleCount, float *sampleTimes,
130 VtValue *sampleValues) override;
131 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
132 float startTime, float endTime,
133 size_t maxSampleCount, float *sampleTimes,
134 VtValue *sampleValues) override;
135 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
136 size_t maxNumSamples, float *times, VtValue *samples,
137 VtIntArray *sampleIndices) override;
138 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
139 float startTime, float endTime,
140 size_t maxNumSamples, float *times, VtValue *samples,
141 VtIntArray *sampleIndices) override;
142
143 // ------------------------------------------------------------------------
144 // Instancer API
145
146 std::vector<VtArray<TfToken>> GetInstanceCategories(
147 SdfPath const &instancerId) override;
149 SdfPath const &instancerId, SdfPath const &prototypeId) override;
150 SdfPath GetInstancerId(SdfPath const &primId) override;
151 SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
152
153 // ------------------------------------------------------------------------
154 // Material API
155
156 SdfPath GetMaterialId(SdfPath const &id) override;
157 VtValue GetMaterialResource(SdfPath const &id) override;
158 HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
159
160 // ------------------------------------------------------------------------
161 // Renderbuffer API
162
164 SdfPath const &id) override;
165
166 // ------------------------------------------------------------------------
167 // Light API
168
169 VtValue GetLightParamValue(SdfPath const &id,
170 TfToken const &paramName) override;
171
172 // ------------------------------------------------------------------------
173 // Camera API
174
176 TfToken const &paramName) override;
177
178 // ------------------------------------------------------------------------
179 // ExtComputation API
180
181 // ... on the rprim
182 HdExtComputationPrimvarDescriptorVector
184 SdfPath const &id, HdInterpolation interpolationMode) override;
185
186 // ... on the sprim
188 SdfPath const &computationId) override;
190 SdfPath const &computationId, TfToken const &input) override;
192 SdfPath const &computationId,
193 TfToken const &input,
194 size_t maxSampleCount,
195 float *sampleTimes,
196 VtValue *sampleValues) override;
198 SdfPath const &computationId,
199 TfToken const &input,
200 float startTime,
201 float endTime,
202 size_t maxSampleCount,
203 float *sampleTimes,
204 VtValue *sampleValues) override;
205
206 HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(
207 SdfPath const &computationId) override;
208 HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(
209 SdfPath const &computationId) override;
210
211 std::string GetExtComputationKernel(SdfPath const &computationId) override;
212 void InvokeExtComputation(SdfPath const &computationId,
213 HdExtComputationContext *context) override;
214
215 TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override;
216
217 void Sync(HdSyncRequestVector* request) override;
218 void PostSyncCleanup() override;
219
220 // NOTE: The remaining scene delegate functions aren't used for emulation:
221 // - GetScenePrimPath
222 // - IsEnabled
223
224private:
225 // Compute and return an HdSceneIndexPrim from the input scene index.
226 // Uses a per-thread single-entry cache to re-use this computation
227 // across sequential Get...() calls in the public API. This API returns
228 // the prim by value rather than reference because callers may
229 // indirectly re-invoke _GetInputPrim() on the same thread, but with
230 // a different id path, if they make use of a TBB work queue.
231 HdSceneIndexPrim _GetInputPrim(SdfPath const& id);
232
233 using _InputPrimCacheEntry = std::pair<SdfPath, HdSceneIndexPrim>;
234
235 // A cache of the last prim accessed, per thread
236 tbb::concurrent_unordered_map<std::thread::id, _InputPrimCacheEntry,
237 std::hash<std::thread::id> > _inputPrimCache;
238
239 void _PrimAdded(
240 const SdfPath &primPath,
241 const TfToken &primType);
242
243 VtValue _GetPrimvar(SdfPath const &id, TfToken const &key,
244 VtIntArray *outIndices);
245
246 VtValue _GetPrimvar(
247 const HdContainerDataSourceHandle &primvarsDataSource,
248 TfToken const &key,
249 VtIntArray *outIndices);
250
251 VtValue _GetImageShaderValue(
252 HdSceneIndexPrim prim,
253 const TfToken& key);
254
255 size_t _SamplePrimvar(SdfPath const &id, TfToken const &key,
256 float startTime, float endTime,
257 size_t maxNumSamples, float *times, VtValue *samples,
258 VtIntArray *sampleIndices);
259
260 HdSceneIndexBaseRefPtr _inputSceneIndex;
261
262 struct _PrimCacheEntry
263 {
264 TfToken primType;
265
266 using PrimvarDescriptorsArray =
267 std::array<HdPrimvarDescriptorVector, HdInterpolationCount>;
268 std::shared_ptr<PrimvarDescriptorsArray> primvarDescriptors;
269 using ExtCmpPrimvarDescriptorsArray =
270 std::array<HdExtComputationPrimvarDescriptorVector,
271 HdInterpolationCount>;
272 std::shared_ptr<ExtCmpPrimvarDescriptorsArray> extCmpPrimvarDescriptors;
273 };
274
275 using _PrimCacheTable = SdfPathTable<_PrimCacheEntry>;
276 _PrimCacheTable _primCache;
277
278 std::shared_ptr<_PrimCacheEntry::PrimvarDescriptorsArray>
279 _ComputePrimvarDescriptors(
280 const HdContainerDataSourceHandle &primDataSource);
281 std::shared_ptr<_PrimCacheEntry::ExtCmpPrimvarDescriptorsArray>
282 _ComputeExtCmpPrimvarDescriptors(
283 const HdContainerDataSourceHandle &primDataSource);
284
285 bool _sceneDelegatesBuilt;
286 std::vector<HdSceneDelegate*> _sceneDelegates;
287
288 // Hint cache of all prim paths that have been populated with
289 // geomSubset children. This is purely an optimization and
290 // not authoritative -- it may have false positioves, such as
291 // if subsets are removed later. These hints provide a way
292 // to skip the expense of _GatherGeomSubsets() when no subsets
293 // have been populated.
294 std::unordered_set<SdfPath, SdfPath::Hash> _geomSubsetParents;
295
296 // Cache for rprim locator set -> dirty bits translation.
297 HdDataSourceLocatorSet _cachedLocatorSet;
298 HdDirtyBits _cachedDirtyBits;
299 TfToken _cachedPrimType;
300};
301
302PXR_NAMESPACE_CLOSE_SCOPE
303
304#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:281
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