Loading...
Searching...
No Matches
sceneIndexAdapterSceneDelegate.h
1//
2// Copyright 2021 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_SCENE_INDEX_ADAPTER_SCENE_DELEGATE_H
25#define PXR_IMAGING_HD_SCENE_INDEX_ADAPTER_SCENE_DELEGATE_H
26
27#include "pxr/imaging/hd/sceneDelegate.h"
28#include "pxr/imaging/hd/sceneIndex.h"
29#include "pxr/usd/sdf/pathTable.h"
30#include <thread>
31#include <tbb/concurrent_unordered_map.h>
32
33PXR_NAMESPACE_OPEN_SCOPE
34
43 : public HdSceneDelegate
45{
46public:
47
49 HdSceneIndexBaseRefPtr inputSceneIndex,
50 HdRenderIndex *parentIndex,
51 SdfPath const &delegateID);
52
54
55 // ------------------------------------------------------------------------
56
59 static HdSceneIndexBaseRefPtr AppendDefaultSceneFilters(
60 HdSceneIndexBaseRefPtr inputSceneIndex, SdfPath const &delegateID);
61
62 // satisfying HdSceneIndexObserver ----------------------------------------
64 const HdSceneIndexBase &sender,
65 const AddedPrimEntries &entries) override;
66
68 const HdSceneIndexBase &sender,
69 const RemovedPrimEntries &entries) override;
70
72 const HdSceneIndexBase &sender,
73 const DirtiedPrimEntries &entries) override;
74
76 const HdSceneIndexBase &sender,
77 const RenamedPrimEntries &entries) override;
78
79 // ------------------------------------------------------------------------
80 // HdSceneIndexDelegate API
81
82 // ------------------------------------------------------------------------
83 // Rprim API
84
88 GfRange3d GetExtent(SdfPath const &id) override;
89 bool GetVisible(SdfPath const &id) override;
90 bool GetDoubleSided(SdfPath const &id) override;
91 HdCullStyle GetCullStyle(SdfPath const &id) override;
92 VtValue GetShadingStyle(SdfPath const &id) override;
95 TfToken GetRenderTag(SdfPath const &id) override;
97 HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
98 SdfPath const &volumeId) override;
99
100 // ------------------------------------------------------------------------
101 // Transform API
102
103 GfMatrix4d GetTransform(SdfPath const &id) override;
104 size_t SampleTransform(SdfPath const &id, 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
113 // ------------------------------------------------------------------------
114 // Primvar API
115
116 HdPrimvarDescriptorVector
118 SdfPath const &id, HdInterpolation interpolation) override;
119
120 VtValue Get(SdfPath const &id, TfToken const &key) override;
121 VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
122 VtIntArray *outIndices) override;
123
124 size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
125 size_t maxSampleCount, float *sampleTimes,
126 VtValue *sampleValues) override;
127 size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
128 size_t maxNumSamples, float *times, VtValue *samples,
129 VtIntArray *sampleIndices) override;
130
131
132 // ------------------------------------------------------------------------
133 // Instancer API
134
135 std::vector<VtArray<TfToken>> GetInstanceCategories(
136 SdfPath const &instancerId) override;
138 SdfPath const &instancerId, SdfPath const &prototypeId) override;
139 SdfPath GetInstancerId(SdfPath const &primId) override;
140 SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
141
142 // ------------------------------------------------------------------------
143 // Material API
144
145 SdfPath GetMaterialId(SdfPath const &id) override;
146 VtValue GetMaterialResource(SdfPath const &id) override;
147 HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
148
149 // ------------------------------------------------------------------------
150 // Renderbuffer API
151
153 SdfPath const &id) override;
154
155 // ------------------------------------------------------------------------
156 // Light API
157
158 VtValue GetLightParamValue(SdfPath const &id,
159 TfToken const &paramName) override;
160
161 // ------------------------------------------------------------------------
162 // Camera API
163
165 TfToken const &paramName) override;
166
167 // ------------------------------------------------------------------------
168 // ExtComputation API
169
170 // ... on the rprim
171 HdExtComputationPrimvarDescriptorVector
173 SdfPath const &id, HdInterpolation interpolationMode) override;
174
175 // ... on the sprim
177 SdfPath const &computationId) override;
179 SdfPath const &computationId, TfToken const &input) override;
181 SdfPath const &computationId,
182 TfToken const &input,
183 size_t maxSampleCount,
184 float *sampleTimes,
185 VtValue *sampleValues) override;
186
187 HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(
188 SdfPath const &computationId) override;
189 HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(
190 SdfPath const &computationId) override;
191
192 std::string GetExtComputationKernel(SdfPath const &computationId) override;
193 void InvokeExtComputation(SdfPath const &computationId,
194 HdExtComputationContext *context) override;
195
196 void Sync(HdSyncRequestVector* request) override;
197 void PostSyncCleanup() override;
198
199 // NOTE: The remaining scene delegate functions aren't used for emulation:
200 // - GetTaskRenderTags
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 size_t maxNumSamples, float *times, VtValue *samples,
237 VtIntArray *sampleIndices);
238
239 HdSceneIndexBaseRefPtr _inputSceneIndex;
240
241 struct _PrimCacheEntry
242 {
243 _PrimCacheEntry()
244 : primvarDescriptorsState(ReadStateUnread)
245 , extCmpPrimvarDescriptorsState(ReadStateUnread)
246 {}
247
248 _PrimCacheEntry(const _PrimCacheEntry &rhs)
249 {
250 primType = rhs.primType;
251 primvarDescriptorsState.store(rhs.primvarDescriptorsState.load());
252 extCmpPrimvarDescriptorsState.store(
253 rhs.extCmpPrimvarDescriptorsState.load());
254 }
255
256 TfToken primType;
257
258 enum ReadState : unsigned char {
259 ReadStateUnread = 0,
260 ReadStateReading,
261 ReadStateRead,
262 };
263
264 std::atomic<ReadState> primvarDescriptorsState;
265 std::atomic<ReadState> extCmpPrimvarDescriptorsState;
266 std::map<HdInterpolation, HdPrimvarDescriptorVector>
267 primvarDescriptors;
268 std::map<HdInterpolation, HdExtComputationPrimvarDescriptorVector>
269 extCmpPrimvarDescriptors;
270 };
271
272 using _PrimCacheTable = SdfPathTable<_PrimCacheEntry>;
273 _PrimCacheTable _primCache;
274
275 bool _sceneDelegatesBuilt;
276 std::vector<HdSceneDelegate*> _sceneDelegates;
277
278 // Cache for rprim locator set -> dirty bits translation.
279 HdDataSourceLocatorSet _cachedLocatorSet;
280 HdDirtyBits _cachedDirtyBits;
281 TfToken _cachedPrimType;
282};
283
284PXR_NAMESPACE_CLOSE_SCOPE
285
286#endif
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
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:55
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
Describes one or more authored display representations for an rprim.
Definition: repr.h:49
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:65
Observer of scene data.
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:83
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:228
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:81
Describes the allocation structure of a render buffer bprim.
Definition: aov.h:84
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52
The SceneDelegate is requested to synchronize prims as the result of executing a specific render pass...
Definition: sceneDelegate.h:69
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457