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 //
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
27 #include "pxr/imaging/hd/sceneDelegate.h"
28 #include "pxr/imaging/hd/sceneIndex.h"
30 #include "pxr/usd/sdf/pathTable.h"
42  : public HdSceneDelegate
43  , public HdSceneIndexObserver
44 {
45 public:
48  HdSceneIndexBaseRefPtr inputSceneIndex,
49  HdRenderIndex *parentIndex,
50  SdfPath const &delegateID);
54  // ------------------------------------------------------------------------
58  static HdSceneIndexBaseRefPtr AppendDefaultSceneFilters(
59  HdSceneIndexBaseRefPtr inputSceneIndex, SdfPath const &delegateID);
61  // satisfying HdSceneIndexObserver ----------------------------------------
62  void PrimsAdded(
63  const HdSceneIndexBase &sender,
64  const AddedPrimEntries &entries) override;
66  void PrimsRemoved(
67  const HdSceneIndexBase &sender,
68  const RemovedPrimEntries &entries) override;
70  void PrimsDirtied(
71  const HdSceneIndexBase &sender,
72  const DirtiedPrimEntries &entries) override;
74  // ------------------------------------------------------------------------
75  // HdSceneIndexDelegate API
77  // ------------------------------------------------------------------------
78  // Rprim API
80  HdMeshTopology GetMeshTopology(SdfPath const &id) override;
82  PxOsdSubdivTags GetSubdivTags(SdfPath const &id) override;
83  GfRange3d GetExtent(SdfPath const &id) override;
84  bool GetVisible(SdfPath const &id) override;
85  bool GetDoubleSided(SdfPath const &id) override;
86  HdCullStyle GetCullStyle(SdfPath const &id) override;
87  VtValue GetShadingStyle(SdfPath const &id) override;
88  HdDisplayStyle GetDisplayStyle(SdfPath const &id) override;
89  HdReprSelector GetReprSelector(SdfPath const &id) override;
90  TfToken GetRenderTag(SdfPath const &id) override;
91  VtArray<TfToken> GetCategories(SdfPath const &id) override;
92  HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
93  SdfPath const &volumeId) override;
95  // ------------------------------------------------------------------------
96  // Transform API
98  GfMatrix4d GetTransform(SdfPath const &id) override;
99  size_t SampleTransform(SdfPath const &id, size_t maxSampleCount,
100  float *sampleTimes, GfMatrix4d *sampleValues) override;
103  SdfPath const &instancerId) override;
104  size_t SampleInstancerTransform(SdfPath const &instancerId,
105  size_t maxSampleCount, float *sampleTimes,
106  GfMatrix4d *sampleValues) override;
108  // ------------------------------------------------------------------------
109  // Primvar API
111  HdPrimvarDescriptorVector
113  SdfPath const &id, HdInterpolation interpolation) override;
115  VtValue Get(SdfPath const &id, TfToken const &key) override;
116  VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key,
117  VtIntArray *outIndices) override;
119  size_t SamplePrimvar(SdfPath const &id, TfToken const &key,
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;
127  // ------------------------------------------------------------------------
128  // Instancer API
130  std::vector<VtArray<TfToken>> GetInstanceCategories(
131  SdfPath const &instancerId) override;
132  VtIntArray GetInstanceIndices(
133  SdfPath const &instancerId, SdfPath const &prototypeId) override;
134  SdfPath GetInstancerId(SdfPath const &primId) override;
135  SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
137  // ------------------------------------------------------------------------
138  // Material API
140  SdfPath GetMaterialId(SdfPath const &id) override;
141  VtValue GetMaterialResource(SdfPath const &id) override;
142  HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override;
144  // ------------------------------------------------------------------------
145  // Renderbuffer API
148  SdfPath const &id) override;
150  // ------------------------------------------------------------------------
151  // Light API
153  VtValue GetLightParamValue(SdfPath const &id,
154  TfToken const &paramName) override;
156  // ------------------------------------------------------------------------
157  // Camera API
159  VtValue GetCameraParamValue(SdfPath const &cameraId,
160  TfToken const &paramName) override;
162  // ------------------------------------------------------------------------
163  // ExtComputation API
165  // ... on the rprim
166  HdExtComputationPrimvarDescriptorVector
168  SdfPath const &id, HdInterpolation interpolationMode) override;
170  // ... on the sprim
172  SdfPath const &computationId) override;
174  SdfPath const &computationId, TfToken const &input) override;
176  SdfPath const &computationId,
177  TfToken const &input,
178  size_t maxSampleCount,
179  float *sampleTimes,
180  VtValue *sampleValues) override;
182  HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(
183  SdfPath const &computationId) override;
184  HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(
185  SdfPath const &computationId) override;
187  std::string GetExtComputationKernel(SdfPath const &computationId) override;
188  void InvokeExtComputation(SdfPath const &computationId,
189  HdExtComputationContext *context) override;
191  void Sync(HdSyncRequestVector* request) override;
192  void PostSyncCleanup() override;
194  // NOTE: The remaining scene delegate functions aren't used for emulation:
195  // - GetTaskRenderTags
196  // - GetScenePrimPath
197  // - IsEnabled
199 private:
200  void _PrimAdded(
201  const SdfPath &primPath,
202  const TfToken &primType);
204  VtValue _GetPrimvar(SdfPath const &id, TfToken const &key,
205  VtIntArray *outIndices);
207  VtValue _GetPrimvar(
208  const HdContainerDataSourceHandle &primvarsDataSource,
209  TfToken const &key,
210  VtIntArray *outIndices);
213  size_t _SamplePrimvar(SdfPath const &id, TfToken const &key,
214  size_t maxNumSamples, float *times, VtValue *samples,
215  VtIntArray *sampleIndices);
217  HdSceneIndexBaseRefPtr _inputSceneIndex;
219  struct _PrimCacheEntry
220  {
221  _PrimCacheEntry()
222  : primvarDescriptorsState(ReadStateUnread)
223  , extCmpPrimvarDescriptorsState(ReadStateUnread)
224  {}
226  _PrimCacheEntry(const _PrimCacheEntry &rhs)
227  {
228  primType = rhs.primType;
231  rhs.extCmpPrimvarDescriptorsState.load());
232  }
234  TfToken primType;
236  enum ReadState : unsigned char {
237  ReadStateUnread = 0,
238  ReadStateReading,
239  ReadStateRead,
240  };
242  std::atomic<ReadState> primvarDescriptorsState;
243  std::atomic<ReadState> extCmpPrimvarDescriptorsState;
244  std::map<HdInterpolation, HdPrimvarDescriptorVector>
245  primvarDescriptors;
246  std::map<HdInterpolation, HdExtComputationPrimvarDescriptorVector>
247  extCmpPrimvarDescriptors;
248  };
251  _PrimCacheTable _primCache;
253  bool _sceneDelegatesBuilt;
254  std::vector<HdSceneDelegate*> _sceneDelegates;
256  // Cache for rprim locator set -> dirty bits translation.
257  HdDataSourceLocatorSet _cachedLocatorSet;
258  HdDirtyBits _cachedDirtyBits;
259  TfToken _cachedPrimType;
260 };
264 #endif
void PrimsDirtied(const HdSceneIndexBase &sender, const DirtiedPrimEntries &entries) override
A notification indicating prim datasources have been invalidated.
Interface class that defines the execution environment for the client to run a computation.
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...
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:120
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
size_t SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
Store up to maxSampleCount transform samples in *sampleValues.
HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
VtValue GetCameraParamValue(SdfPath const &cameraId, TfToken const &paramName) override
Returns a single value for a given camera and parameter.
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...
GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:80
VtValue Get(SdfPath const &id, TfToken const &key) override
Returns a named value.
SdfPath GetMaterialId(SdfPath const &id) override
Returns the material ID bound to the rprim rprimId.
VtValue GetExtComputationInput(SdfPath const &computationId, TfToken const &input) override
Returns a single value for a given computation id and input token.
Describes the allocation structure of a render buffer bprim.
Definition: aov.h:84
VtArray< TfToken > GetCategories(SdfPath const &id) override
Returns the prim categories.
bool GetVisible(SdfPath const &id) override
Returns the authored visible state of the prim.
HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation) override
Returns descriptors for all primvars of the given interpolation type.
HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
PxOsdSubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.
bool GetDoubleSided(SdfPath const &id) override
Returns the doubleSided state for the given prim.
HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation input descriptors.
size_t SampleTransform(SdfPath const &id, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) override
Store up to maxSampleCount transform samples in *sampleValues.
VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId) override
Gets the extracted indices array of the prototype id used in the instancer.
HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation output descriptors.
Scene delegate which observes notices from an HdSceneIndex and applies them to an HdRenderIndex.
HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
Returns the refinement level for the given prim in the range [0,8].
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Observer of scene data.
VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) override
Returns a named primvar value.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
Adapter class providing data exchange with the client scene graph.
Abstract interface to scene data.
Definition: sceneIndex.h:62
Represents a set of data source locators closed under descendancy.
HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override
Gets the topological curve data for a given prim.
VtValue GetShadingStyle(SdfPath const &id) override
Returns the shading style for the given prim.
void PostSyncCleanup() override
Opportunity for the delegate to clean itself up after performing parallel work during sync phase.
void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
TfTokenVector GetExtComputationSceneInputNames(SdfPath const &computationId) override
For the given computation id, returns a list of inputs which will be requested from the scene delegat...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
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.
GfRange3d GetExtent(SdfPath const &id) override
Gets the axis aligned bounds of a prim.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Topology data for basisCurves.
The SceneDelegate is requested to synchronize prims as the result of executing a specific render pass...
Definition: sceneDelegate.h:68
Describes one or more authored display representations for an rprim.
Definition: repr.h:48
void PrimsAdded(const HdSceneIndexBase &sender, const AddedPrimEntries &entries) override
A notification indicating prims have been added to the scene.
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.
HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id) override
Returns the allocation descriptor for a given render buffer prim.
TfToken GetRenderTag(SdfPath const &id) override
Returns the render tag that will be used to bucket prims during render pass bucketing.
Topology data for meshes.
Definition: meshTopology.h:55
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.
std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId) override
Returns the categories for all instances in the instancer.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override
Requests the scene delegate run the ExtComputation with the given id.
std::string GetExtComputationKernel(SdfPath const &computationId) override
Returns the kernel source assigned to the computation at the path id.
SdfPath GetInstancerId(SdfPath const &primId) override
Returns the parent instancer of the given rprim or instancer.
SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
Returns a list of prototypes of this instancer.
void PrimsRemoved(const HdSceneIndexBase &sender, const RemovedPrimEntries &entries) override
A notification indicating prims have been removed from the scene.
GfMatrix4d GetTransform(SdfPath const &id) override
Returns the object space transform, including all parent transforms.