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
16PXR_NAMESPACE_OPEN_SCOPE
17
26 : public HdSceneDelegate
28{
29public:
30
32 HdSceneIndexBaseRefPtr inputSceneIndex,
33 HdRenderIndex *parentIndex,
34 SdfPath const &delegateID);
35
37
38 // satisfying HdSceneIndexObserver ----------------------------------------
40 const HdSceneIndexBase &sender,
41 const AddedPrimEntries &entries) override;
42
44 const HdSceneIndexBase &sender,
45 const RemovedPrimEntries &entries) override;
46
48 const HdSceneIndexBase &sender,
49 const DirtiedPrimEntries &entries) override;
50
52 const HdSceneIndexBase &sender,
53 const RenamedPrimEntries &entries) override;
54
55 // ------------------------------------------------------------------------
56 // HdSceneIndexDelegate API
57
58 // ------------------------------------------------------------------------
59 // Rprim API
60
64 GfRange3d GetExtent(SdfPath const &id) override;
65 bool GetVisible(SdfPath const &id) override;
66 bool GetDoubleSided(SdfPath const &id) override;
67 HdCullStyle GetCullStyle(SdfPath const &id) override;
68 VtValue GetShadingStyle(SdfPath const &id) override;
71 TfToken GetRenderTag(SdfPath const &id) override;
73 HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
74 SdfPath const &volumeId) override;
75
76 // ------------------------------------------------------------------------
77 // Transform API
78
79 GfMatrix4d GetTransform(SdfPath const &id) override;
80 size_t SampleTransform(SdfPath const &id, size_t maxSampleCount,
81 float *sampleTimes, GfMatrix4d *sampleValues) override;
82 size_t SampleTransform(SdfPath const &id,
83 float startTime, float endTime,
84 size_t maxSampleCount,
85 float *sampleTimes, GfMatrix4d *sampleValues) override;
86
88 SdfPath const &instancerId) override;
89 size_t SampleInstancerTransform(SdfPath const &instancerId,
90 size_t maxSampleCount, float *sampleTimes,
91 GfMatrix4d *sampleValues) override;
92 size_t SampleInstancerTransform(SdfPath const &instancerId,
93 float startTime, float endTime,
94 size_t maxSampleCount, float *sampleTimes,
95 GfMatrix4d *sampleValues) override;
96
97 // ------------------------------------------------------------------------
98 // Primvar API
99
100 HdPrimvarDescriptorVector
102 SdfPath const &id, HdInterpolation interpolation) override;
103
104 VtValue Get(SdfPath const &id, TfToken const &key) override;
105 VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
106 VtIntArray *outIndices) override;
107
108 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
109 size_t maxSampleCount, float *sampleTimes,
110 VtValue *sampleValues) override;
111 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
112 float startTime, float endTime,
113 size_t maxSampleCount, float *sampleTimes,
114 VtValue *sampleValues) override;
115 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
116 size_t maxNumSamples, float *times, VtValue *samples,
117 VtIntArray *sampleIndices) override;
118 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
119 float startTime, float endTime,
120 size_t maxNumSamples, float *times, VtValue *samples,
121 VtIntArray *sampleIndices) override;
122
123 // ------------------------------------------------------------------------
124 // Instancer API
125
126 std::vector<VtArray<TfToken>> GetInstanceCategories(
127 SdfPath const &instancerId) override;
129 SdfPath const &instancerId, SdfPath const &prototypeId) override;
130 SdfPath GetInstancerId(SdfPath const &primId) override;
131 SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
132
133 // ------------------------------------------------------------------------
134 // Material API
135
136 SdfPath GetMaterialId(SdfPath const &id) override;
137 VtValue GetMaterialResource(SdfPath const &id) override;
138 HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
139
140 // ------------------------------------------------------------------------
141 // Renderbuffer API
142
144 SdfPath const &id) override;
145
146 // ------------------------------------------------------------------------
147 // Light API
148
149 VtValue GetLightParamValue(SdfPath const &id,
150 TfToken const &paramName) override;
151
152 // ------------------------------------------------------------------------
153 // Camera API
154
156 TfToken const &paramName) override;
157
158 // ------------------------------------------------------------------------
159 // ExtComputation API
160
161 // ... on the rprim
162 HdExtComputationPrimvarDescriptorVector
164 SdfPath const &id, HdInterpolation interpolationMode) override;
165
166 // ... on the sprim
168 SdfPath const &computationId) override;
170 SdfPath const &computationId, TfToken const &input) override;
172 SdfPath const &computationId,
173 TfToken const &input,
174 size_t maxSampleCount,
175 float *sampleTimes,
176 VtValue *sampleValues) override;
178 SdfPath const &computationId,
179 TfToken const &input,
180 float startTime,
181 float endTime,
182 size_t maxSampleCount,
183 float *sampleTimes,
184 VtValue *sampleValues) override;
185
186 HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(
187 SdfPath const &computationId) override;
188 HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(
189 SdfPath const &computationId) override;
190
191 std::string GetExtComputationKernel(SdfPath const &computationId) override;
192 void InvokeExtComputation(SdfPath const &computationId,
193 HdExtComputationContext *context) override;
194
195 TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override;
196
197 void Sync(HdSyncRequestVector* request) override;
198 void PostSyncCleanup() override;
199
200 // NOTE: The remaining scene delegate functions aren't used for emulation:
201 // - GetScenePrimPath
202 // - IsEnabled
203
204private:
205 // Compute and return an HdSceneIndexPrim from the input scene index.
206 // Uses a per-thread single-entry cache to re-use this computation
207 // across sequential Get...() calls in the public API. This API returns
208 // the prim by value rather than reference because callers may
209 // indirectly re-invoke _GetInputPrim() on the same thread, but with
210 // a different id path, if they make use of a TBB work queue.
211 HdSceneIndexPrim _GetInputPrim(SdfPath const& id);
212
213 using _InputPrimCacheEntry = std::pair<SdfPath, HdSceneIndexPrim>;
214
215 // A cache of the last prim accessed, per thread
216 tbb::concurrent_unordered_map<std::thread::id, _InputPrimCacheEntry,
217 std::hash<std::thread::id> > _inputPrimCache;
218
219 void _PrimAdded(
220 const SdfPath &primPath,
221 const TfToken &primType);
222
223 VtValue _GetPrimvar(SdfPath const &id, TfToken const &key,
224 VtIntArray *outIndices);
225
226 VtValue _GetPrimvar(
227 const HdContainerDataSourceHandle &primvarsDataSource,
228 TfToken const &key,
229 VtIntArray *outIndices);
230
231 VtValue _GetImageShaderValue(
232 HdSceneIndexPrim prim,
233 const TfToken& key);
234
235 size_t _SamplePrimvar(SdfPath const &id, TfToken const &key,
236 float startTime, float endTime,
237 size_t maxNumSamples, float *times, VtValue *samples,
238 VtIntArray *sampleIndices);
239
240 HdSceneIndexBaseRefPtr _inputSceneIndex;
241
242 struct _PrimCacheEntry
243 {
244 TfToken primType;
245
246 using PrimvarDescriptorsArray =
247 std::array<HdPrimvarDescriptorVector, HdInterpolationCount>;
248 std::shared_ptr<PrimvarDescriptorsArray> primvarDescriptors;
249 using ExtCmpPrimvarDescriptorsArray =
250 std::array<HdExtComputationPrimvarDescriptorVector,
251 HdInterpolationCount>;
252 std::shared_ptr<ExtCmpPrimvarDescriptorsArray> extCmpPrimvarDescriptors;
253 };
254
255 using _PrimCacheTable = SdfPathTable<_PrimCacheEntry>;
256 _PrimCacheTable _primCache;
257
258 std::shared_ptr<_PrimCacheEntry::PrimvarDescriptorsArray>
259 _ComputePrimvarDescriptors(
260 const HdContainerDataSourceHandle &primDataSource);
261 std::shared_ptr<_PrimCacheEntry::ExtCmpPrimvarDescriptorsArray>
262 _ComputeExtCmpPrimvarDescriptors(
263 const HdContainerDataSourceHandle &primDataSource);
264
265 bool _sceneDelegatesBuilt;
266 std::vector<HdSceneDelegate*> _sceneDelegates;
267
268 // Hint cache of all prim paths that have been populated with
269 // geomSubset children. This is purely an optimization and
270 // not authoritative -- it may have false positioves, such as
271 // if subsets are removed later. These hints provide a way
272 // to skip the expense of _GatherGeomSubsets() when no subsets
273 // have been populated.
274 std::unordered_set<SdfPath, SdfPath::Hash> _geomSubsetParents;
275
276 // Cache for rprim locator set -> dirty bits translation.
277 HdDataSourceLocatorSet _cachedLocatorSet;
278 HdDirtyBits _cachedDirtyBits;
279 TfToken _cachedPrimType;
280};
281
282PXR_NAMESPACE_CLOSE_SCOPE
283
284#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:152
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:64
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