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 // ------------------------------------------------------------------------
39
42 static HdSceneIndexBaseRefPtr AppendDefaultSceneFilters(
43 HdSceneIndexBaseRefPtr inputSceneIndex, SdfPath const &delegateID);
44
45 // satisfying HdSceneIndexObserver ----------------------------------------
47 const HdSceneIndexBase &sender,
48 const AddedPrimEntries &entries) override;
49
51 const HdSceneIndexBase &sender,
52 const RemovedPrimEntries &entries) override;
53
55 const HdSceneIndexBase &sender,
56 const DirtiedPrimEntries &entries) override;
57
59 const HdSceneIndexBase &sender,
60 const RenamedPrimEntries &entries) override;
61
62 // ------------------------------------------------------------------------
63 // HdSceneIndexDelegate API
64
65 // ------------------------------------------------------------------------
66 // Rprim API
67
71 GfRange3d GetExtent(SdfPath const &id) override;
72 bool GetVisible(SdfPath const &id) override;
73 bool GetDoubleSided(SdfPath const &id) override;
74 HdCullStyle GetCullStyle(SdfPath const &id) override;
75 VtValue GetShadingStyle(SdfPath const &id) override;
78 TfToken GetRenderTag(SdfPath const &id) override;
80 HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
81 SdfPath const &volumeId) override;
82
83 // ------------------------------------------------------------------------
84 // Transform API
85
86 GfMatrix4d GetTransform(SdfPath const &id) override;
87 size_t SampleTransform(SdfPath const &id, size_t maxSampleCount,
88 float *sampleTimes, GfMatrix4d *sampleValues) override;
89 size_t SampleTransform(SdfPath const &id,
90 float startTime, float endTime,
91 size_t maxSampleCount,
92 float *sampleTimes, GfMatrix4d *sampleValues) override;
93
95 SdfPath const &instancerId) override;
96 size_t SampleInstancerTransform(SdfPath const &instancerId,
97 size_t maxSampleCount, float *sampleTimes,
98 GfMatrix4d *sampleValues) override;
99 size_t SampleInstancerTransform(SdfPath const &instancerId,
100 float startTime, float endTime,
101 size_t maxSampleCount, float *sampleTimes,
102 GfMatrix4d *sampleValues) override;
103
104 // ------------------------------------------------------------------------
105 // Primvar API
106
107 HdPrimvarDescriptorVector
109 SdfPath const &id, HdInterpolation interpolation) override;
110
111 VtValue Get(SdfPath const &id, TfToken const &key) override;
112 VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
113 VtIntArray *outIndices) override;
114
115 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
116 size_t maxSampleCount, float *sampleTimes,
117 VtValue *sampleValues) override;
118 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
119 float startTime, float endTime,
120 size_t maxSampleCount, float *sampleTimes,
121 VtValue *sampleValues) override;
122 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
123 size_t maxNumSamples, float *times, VtValue *samples,
124 VtIntArray *sampleIndices) override;
125 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
126 float startTime, float endTime,
127 size_t maxNumSamples, float *times, VtValue *samples,
128 VtIntArray *sampleIndices) override;
129
130 // ------------------------------------------------------------------------
131 // Instancer API
132
133 std::vector<VtArray<TfToken>> GetInstanceCategories(
134 SdfPath const &instancerId) override;
136 SdfPath const &instancerId, SdfPath const &prototypeId) override;
137 SdfPath GetInstancerId(SdfPath const &primId) override;
138 SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
139
140 // ------------------------------------------------------------------------
141 // Material API
142
143 SdfPath GetMaterialId(SdfPath const &id) override;
144 VtValue GetMaterialResource(SdfPath const &id) override;
145 HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
146
147 // ------------------------------------------------------------------------
148 // Renderbuffer API
149
151 SdfPath const &id) override;
152
153 // ------------------------------------------------------------------------
154 // Light API
155
156 VtValue GetLightParamValue(SdfPath const &id,
157 TfToken const &paramName) override;
158
159 // ------------------------------------------------------------------------
160 // Camera API
161
163 TfToken const &paramName) override;
164
165 // ------------------------------------------------------------------------
166 // ExtComputation API
167
168 // ... on the rprim
169 HdExtComputationPrimvarDescriptorVector
171 SdfPath const &id, HdInterpolation interpolationMode) override;
172
173 // ... on the sprim
175 SdfPath const &computationId) override;
177 SdfPath const &computationId, TfToken const &input) override;
179 SdfPath const &computationId,
180 TfToken const &input,
181 size_t maxSampleCount,
182 float *sampleTimes,
183 VtValue *sampleValues) override;
185 SdfPath const &computationId,
186 TfToken const &input,
187 float startTime,
188 float endTime,
189 size_t maxSampleCount,
190 float *sampleTimes,
191 VtValue *sampleValues) override;
192
193 HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(
194 SdfPath const &computationId) override;
195 HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(
196 SdfPath const &computationId) override;
197
198 std::string GetExtComputationKernel(SdfPath const &computationId) override;
199 void InvokeExtComputation(SdfPath const &computationId,
200 HdExtComputationContext *context) override;
201
202 void Sync(HdSyncRequestVector* request) override;
203 void PostSyncCleanup() override;
204
205 // NOTE: The remaining scene delegate functions aren't used for emulation:
206 // - GetTaskRenderTags
207 // - GetScenePrimPath
208 // - IsEnabled
209
210private:
211 // Compute and return an HdSceneIndexPrim from the input scene index.
212 // Uses a per-thread single-entry cache to re-use this computation
213 // across sequential Get...() calls in the public API. This API returns
214 // the prim by value rather than reference because callers may
215 // indirectly re-invoke _GetInputPrim() on the same thread, but with
216 // a different id path, if they make use of a TBB work queue.
217 HdSceneIndexPrim _GetInputPrim(SdfPath const& id);
218
219 using _InputPrimCacheEntry = std::pair<SdfPath, HdSceneIndexPrim>;
220
221 // A cache of the last prim accessed, per thread
222 tbb::concurrent_unordered_map<std::thread::id, _InputPrimCacheEntry,
223 std::hash<std::thread::id> > _inputPrimCache;
224
225 void _PrimAdded(
226 const SdfPath &primPath,
227 const TfToken &primType);
228
229 VtValue _GetPrimvar(SdfPath const &id, TfToken const &key,
230 VtIntArray *outIndices);
231
232 VtValue _GetPrimvar(
233 const HdContainerDataSourceHandle &primvarsDataSource,
234 TfToken const &key,
235 VtIntArray *outIndices);
236
237 VtValue _GetImageShaderValue(
238 HdSceneIndexPrim prim,
239 const TfToken& key);
240
241 size_t _SamplePrimvar(SdfPath const &id, TfToken const &key,
242 float startTime, float endTime,
243 size_t maxNumSamples, float *times, VtValue *samples,
244 VtIntArray *sampleIndices);
245
246 HdSceneIndexBaseRefPtr _inputSceneIndex;
247
248 struct _PrimCacheEntry
249 {
250 TfToken primType;
251
252 using PrimvarDescriptorsArray =
253 std::array<HdPrimvarDescriptorVector, HdInterpolationCount>;
254 std::shared_ptr<PrimvarDescriptorsArray> primvarDescriptors;
255 using ExtCmpPrimvarDescriptorsArray =
256 std::array<HdExtComputationPrimvarDescriptorVector,
257 HdInterpolationCount>;
258 std::shared_ptr<ExtCmpPrimvarDescriptorsArray> extCmpPrimvarDescriptors;
259 };
260
261 using _PrimCacheTable = SdfPathTable<_PrimCacheEntry>;
262 _PrimCacheTable _primCache;
263
264 std::shared_ptr<_PrimCacheEntry::PrimvarDescriptorsArray>
265 _ComputePrimvarDescriptors(
266 const HdContainerDataSourceHandle &primDataSource);
267 std::shared_ptr<_PrimCacheEntry::ExtCmpPrimvarDescriptorsArray>
268 _ComputeExtCmpPrimvarDescriptors(
269 const HdContainerDataSourceHandle &primDataSource);
270
271 bool _sceneDelegatesBuilt;
272 std::vector<HdSceneDelegate*> _sceneDelegates;
273
274 // Cache for rprim locator set -> dirty bits translation.
275 HdDataSourceLocatorSet _cachedLocatorSet;
276 HdDirtyBits _cachedDirtyBits;
277 TfToken _cachedPrimType;
278};
279
280PXR_NAMESPACE_CLOSE_SCOPE
281
282#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:104
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, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
Store up to maxSampleCount transform samples in *sampleValues.
HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
Returns the refinement level for the given prim in the range [0,8].
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 all 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.
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.
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.
static HdSceneIndexBaseRefPtr AppendDefaultSceneFilters(HdSceneIndexBaseRefPtr inputSceneIndex, SdfPath const &delegateID)
Returns the end of a scene index chain containing the filters necessary for input to an instance of t...
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.
GfRange3d GetExtent(SdfPath const &id) override
Gets the axis aligned bounds of a prim.
Abstract interface to scene data.
Definition: sceneIndex.h:48
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:211
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
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