HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sceneIndexAdapterSceneDelegate.h
Go to the documentation of this file.
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 
29 
30 #include "pxr/usd/sdf/pathTable.h"
31 
33 
34 /// \class HdSceneIndexAdapterSceneDelegate
35 ///
36 /// Scene delegate which observes notices from an HdSceneIndex and applies them
37 /// to an HdRenderIndex. This serves as "back-end" emulation in order for
38 /// scenes described via the HdSceneIndex/HdDataSource APIs to be accessible
39 /// by legacy render delegates.
40 ///
42  : public HdSceneDelegate
43  , public HdSceneIndexObserver
44 {
45 public:
46 
48  HdSceneIndexBaseRefPtr inputSceneIndex,
49  HdRenderIndex *parentIndex,
50  SdfPath const &delegateID);
51 
53 
54  // ------------------------------------------------------------------------
55 
56  /// Returns the end of a scene index chain containing the filters
57  /// necessary for input to an instance of this scene delegate.
58  static HdSceneIndexBaseRefPtr AppendDefaultSceneFilters(
59  HdSceneIndexBaseRefPtr inputSceneIndex, SdfPath const &delegateID);
60 
61  // satisfying HdSceneIndexObserver ----------------------------------------
62  void PrimsAdded(
63  const HdSceneIndexBase &sender,
64  const AddedPrimEntries &entries) override;
65 
66  void PrimsRemoved(
67  const HdSceneIndexBase &sender,
68  const RemovedPrimEntries &entries) override;
69 
70  void PrimsDirtied(
71  const HdSceneIndexBase &sender,
72  const DirtiedPrimEntries &entries) override;
73 
74  void PrimsRenamed(
75  const HdSceneIndexBase &sender,
76  const RenamedPrimEntries &entries) override;
77 
78  // ------------------------------------------------------------------------
79  // HdSceneIndexDelegate API
80 
81  // ------------------------------------------------------------------------
82  // Rprim API
83 
84  HdMeshTopology GetMeshTopology(SdfPath const &id) override;
86  PxOsdSubdivTags GetSubdivTags(SdfPath const &id) override;
87  GfRange3d GetExtent(SdfPath const &id) override;
88  bool GetVisible(SdfPath const &id) override;
89  bool GetDoubleSided(SdfPath const &id) override;
90  HdCullStyle GetCullStyle(SdfPath const &id) override;
91  VtValue GetShadingStyle(SdfPath const &id) override;
92  HdDisplayStyle GetDisplayStyle(SdfPath const &id) override;
93  HdReprSelector GetReprSelector(SdfPath const &id) override;
94  TfToken GetRenderTag(SdfPath const &id) override;
95  VtArray<TfToken> GetCategories(SdfPath const &id) override;
97  SdfPath const &volumeId) override;
98 
99  // ------------------------------------------------------------------------
100  // Transform API
101 
102  GfMatrix4d GetTransform(SdfPath const &id) override;
103  size_t SampleTransform(SdfPath const &id, size_t maxSampleCount,
104  float *sampleTimes, GfMatrix4d *sampleValues) override;
105 
107  SdfPath const &instancerId) override;
108  size_t SampleInstancerTransform(SdfPath const &instancerId,
109  size_t maxSampleCount, float *sampleTimes,
110  GfMatrix4d *sampleValues) override;
111 
112  // ------------------------------------------------------------------------
113  // Primvar API
114 
117  SdfPath const &id, HdInterpolation interpolation) override;
118 
119  VtValue Get(SdfPath const &id, TfToken const &key) override;
120  VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
121  VtIntArray *outIndices) override;
122 
123  size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
124  size_t maxSampleCount, float *sampleTimes,
125  VtValue *sampleValues) override;
126  size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key,
127  size_t maxNumSamples, float *times, VtValue *samples,
128  VtIntArray *sampleIndices) override;
129 
130 
131  // ------------------------------------------------------------------------
132  // Instancer API
133 
134  std::vector<VtArray<TfToken>> GetInstanceCategories(
135  SdfPath const &instancerId) override;
136  VtIntArray GetInstanceIndices(
137  SdfPath const &instancerId, SdfPath const &prototypeId) override;
138  SdfPath GetInstancerId(SdfPath const &primId) override;
139  SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
140 
141  // ------------------------------------------------------------------------
142  // Path Translation API
143 
144  SdfPath GetDataSharingId(SdfPath const& primId) override;
145 
146  // ------------------------------------------------------------------------
147  // Material API
148 
149  SdfPath GetMaterialId(SdfPath const &id) override;
150  VtValue GetMaterialResource(SdfPath const &id) override;
151  HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
152 
153  // ------------------------------------------------------------------------
154  // Renderbuffer API
155 
157  SdfPath const &id) override;
158 
159  // ------------------------------------------------------------------------
160  // Light API
161 
163  TfToken const &paramName) override;
164 
165  // ------------------------------------------------------------------------
166  // Camera API
167 
168  VtValue GetCameraParamValue(SdfPath const &cameraId,
169  TfToken const &paramName) override;
170 
171  // ------------------------------------------------------------------------
172  // ExtComputation API
173 
174  // ... on the rprim
177  SdfPath const &id, HdInterpolation interpolationMode) override;
178 
179  // ... on the sprim
181  SdfPath const &computationId) override;
183  SdfPath const &computationId, TfToken const &input) override;
185  SdfPath const &computationId,
186  TfToken const &input,
187  size_t maxSampleCount,
188  float *sampleTimes,
189  VtValue *sampleValues) override;
190 
192  SdfPath const &computationId) override;
194  SdfPath const &computationId) override;
195 
196  std::string GetExtComputationKernel(SdfPath const &computationId) override;
197  void InvokeExtComputation(SdfPath const &computationId,
198  HdExtComputationContext *context) override;
199 
200  void Sync(HdSyncRequestVector* request) override;
201  void PostSyncCleanup() override;
202 
203  // NOTE: The remaining scene delegate functions aren't used for emulation:
204  // - GetTaskRenderTags
205  // - GetScenePrimPath
206  // - IsEnabled
207 
208 private:
209  void _PrimAdded(
210  const SdfPath &primPath,
211  const TfToken &primType);
212 
213  VtValue _GetPrimvar(SdfPath const &id, TfToken const &key,
214  VtIntArray *outIndices);
215 
216  VtValue _GetPrimvar(
217  const HdContainerDataSourceHandle &primvarsDataSource,
218  TfToken const &key,
219  VtIntArray *outIndices);
220 
221 
222  size_t _SamplePrimvar(SdfPath const &id, TfToken const &key,
223  size_t maxNumSamples, float *times, VtValue *samples,
224  VtIntArray *sampleIndices);
225 
226  HdSceneIndexBaseRefPtr _inputSceneIndex;
227 
228  struct _PrimCacheEntry
229  {
230  _PrimCacheEntry()
231  : primvarDescriptorsState(ReadStateUnread)
232  , extCmpPrimvarDescriptorsState(ReadStateUnread)
233  {}
234 
235  _PrimCacheEntry(const _PrimCacheEntry &rhs)
236  {
237  primType = rhs.primType;
238  primvarDescriptorsState.store(rhs.primvarDescriptorsState.load());
239  extCmpPrimvarDescriptorsState.store(
240  rhs.extCmpPrimvarDescriptorsState.load());
241  }
242 
243  TfToken primType;
244 
245  enum ReadState : unsigned char {
246  ReadStateUnread = 0,
247  ReadStateReading,
248  ReadStateRead,
249  };
250 
251  std::atomic<ReadState> primvarDescriptorsState;
252  std::atomic<ReadState> extCmpPrimvarDescriptorsState;
253  std::map<HdInterpolation, HdPrimvarDescriptorVector>
254  primvarDescriptors;
255  std::map<HdInterpolation, HdExtComputationPrimvarDescriptorVector>
256  extCmpPrimvarDescriptors;
257  };
258 
260  _PrimCacheTable _primCache;
261 
262  bool _sceneDelegatesBuilt;
263  std::vector<HdSceneDelegate*> _sceneDelegates;
264 
265  // Cache for rprim locator set -> dirty bits translation.
266  HdDataSourceLocatorSet _cachedLocatorSet;
267  HdDirtyBits _cachedDirtyBits;
268  TfToken _cachedPrimType;
269 };
270 
272 
273 #endif
std::shared_ptr< SdfPathVector > HdIdVectorSharedPtr
A shared pointer to a vector of id's.
Definition: sceneDelegate.h:55
GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
HdCullStyle
Definition: enums.h:122
VtValue Get(SdfPath const &id, TfToken const &key) override
Returns a named value.
void PrimsDirtied(const HdSceneIndexBase &sender, const DirtiedPrimEntries &entries) override
HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
uint32_t HdDirtyBits
Definition: types.h:158
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId) override
size_t SampleTransform(SdfPath const &id, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
SdfPath GetDataSharingId(SdfPath const &primId) override
VtValue GetLightParamValue(SdfPath const &id, TfToken const &paramName) override
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation) override
Returns descriptors for all primvars of the given interpolation type.
HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override
Gets the topological curve data for a given prim.
std::vector< HdExtComputationOutputDescriptor > HdExtComputationOutputDescriptorVector
HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(SdfPath const &volumeId) override
VtValue GetShadingStyle(SdfPath const &id) override
Returns the shading style for the given prim.
void PrimsRemoved(const HdSceneIndexBase &sender, const RemovedPrimEntries &entries) override
SdfPath GetInstancerId(SdfPath const &primId) override
Returns the parent instancer of the given rprim or instancer.
void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
std::string GetExtComputationKernel(SdfPath const &computationId) override
std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId) override
Returns the categories for all instances in the instancer.
VtValue GetMaterialResource(SdfPath const &id) override
Returns the material ID bound to the rprim rprimId.
GfMatrix4d GetTransform(SdfPath const &id) override
Returns the object space transform, including all parent transforms.
size_t SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
Definition: token.h:87
VtValue GetExtComputationInput(SdfPath const &computationId, TfToken const &input) override
size_t SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
void PrimsAdded(const HdSceneIndexBase &sender, const AddedPrimEntries &entries) override
HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
GfRange3d GetExtent(SdfPath const &id) override
VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) override
size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples, VtIntArray *sampleIndices) override
HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId) override
void PrimsRenamed(const HdSceneIndexBase &sender, const RenamedPrimEntries &entries) override
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
HdSceneIndexAdapterSceneDelegate(HdSceneIndexBaseRefPtr inputSceneIndex, HdRenderIndex *parentIndex, SdfPath const &delegateID)
Definition: path.h:291
std::vector< HdVolumeFieldDescriptor > HdVolumeFieldDescriptorVector
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id) override
Returns the allocation descriptor for a given render buffer prim.
GLsizei samples
Definition: glcorearb.h:1298
static HdSceneIndexBaseRefPtr AppendDefaultSceneFilters(HdSceneIndexBaseRefPtr inputSceneIndex, SdfPath const &delegateID)
VtArray< TfToken > GetCategories(SdfPath const &id) override
Returns the prim categories.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override
bool GetVisible(SdfPath const &id) override
Returns the authored visible state of the prim.
HdInterpolation
Definition: enums.h:194
PxOsdSubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SdfPath GetMaterialId(SdfPath const &id) override
Returns the material ID bound to the rprim rprimId.
TfTokenVector GetExtComputationSceneInputNames(SdfPath const &computationId) override
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
TfToken GetRenderTag(SdfPath const &id) override
bool GetDoubleSided(SdfPath const &id) override
Returns the doubleSided state for the given prim.
HdExtComputationPrimvarDescriptorVector GetExtComputationPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolationMode) override
SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
Definition: value.h:167
VtValue GetCameraParamValue(SdfPath const &cameraId, TfToken const &paramName) override
HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
size_t SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.