All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderDelegate.h
1 //
2 // Copyright 2017 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 HDEMBREE_RENDER_DELEGATE_H
25 #define HDEMBREE_RENDER_DELEGATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/renderDelegate.h"
29 #include "pxr/imaging/hd/renderThread.h"
30 #include "pxr/imaging/hdEmbree/renderer.h"
31 #include "pxr/base/tf/staticTokens.h"
32 
33 #include <mutex>
34 #include <embree2/rtcore.h>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
39 
40 #define HDEMBREE_RENDER_SETTINGS_TOKENS \
41  (enableAmbientOcclusion) \
42  (enableSceneColors) \
43  (ambientOcclusionSamples)
44 
45 // Also: HdRenderSettingsTokens->convergedSamplesPerPixel
46 
47 TF_DECLARE_PUBLIC_TOKENS(HdEmbreeRenderSettingsTokens, HDEMBREE_RENDER_SETTINGS_TOKENS);
48 
83 class HdEmbreeRenderDelegate final : public HdRenderDelegate {
84 public:
91  HdEmbreeRenderDelegate(HdRenderSettingsMap const& settingsMap);
94  virtual ~HdEmbreeRenderDelegate();
95 
98  virtual HdRenderParam *GetRenderParam() const override;
99 
102  virtual const TfTokenVector &GetSupportedRprimTypes() const override;
105  virtual const TfTokenVector &GetSupportedSprimTypes() const override;
108  virtual const TfTokenVector &GetSupportedBprimTypes() const override;
109 
111  virtual HdResourceRegistrySharedPtr GetResourceRegistry() const override;
112 
117  virtual HdRenderSettingDescriptorList
118  GetRenderSettingDescriptors() const override;
119 
121  virtual bool IsPauseSupported() const override;
122 
124  virtual bool Pause() override;
125 
127  virtual bool Resume() override;
128 
137  virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
138  HdRprimCollection const& collection) override;
139 
149  virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
150  SdfPath const& id,
151  SdfPath const& instancerId);
152 
155  virtual void DestroyInstancer(HdInstancer *instancer);
156 
167  virtual HdRprim *CreateRprim(TfToken const& typeId,
168  SdfPath const& rprimId,
169  SdfPath const& instancerId) override;
170 
173  virtual void DestroyRprim(HdRprim *rPrim) override;
174 
182  virtual HdSprim *CreateSprim(TfToken const& typeId,
183  SdfPath const& sprimId) override;
184 
190  virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
191 
194  virtual void DestroySprim(HdSprim *sPrim) override;
195 
202  virtual HdBprim *CreateBprim(TfToken const& typeId,
203  SdfPath const& bprimId) override;
204 
210  virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) override;
211 
214  virtual void DestroyBprim(HdBprim *bPrim) override;
215 
221  virtual void CommitResources(HdChangeTracker *tracker) override;
222 
228  virtual TfToken GetMaterialBindingPurpose() const override {
229  return HdTokens->full;
230  }
231 
238  virtual HdAovDescriptor
239  GetDefaultAovDescriptor(TfToken const& name) const override;
240 
243  virtual VtDictionary GetRenderStats() const override;
244 
245 private:
246  static const TfTokenVector SUPPORTED_RPRIM_TYPES;
247  static const TfTokenVector SUPPORTED_SPRIM_TYPES;
248  static const TfTokenVector SUPPORTED_BPRIM_TYPES;
249 
251  static std::mutex _mutexResourceRegistry;
252  static std::atomic_int _counterResourceRegistry;
253  static HdResourceRegistrySharedPtr _resourceRegistry;
254 
255  // This class does not support copying.
257  HdEmbreeRenderDelegate &operator =(const HdEmbreeRenderDelegate &) = delete;
258 
259  // Embree initialization routine.
260  void _Initialize();
261 
262  // Handle for an embree "device", or library state.
263  RTCDevice _rtcDevice;
264 
265  // Handle for the top-level embree scene, mirroring the Hydra scene.
266  RTCScene _rtcScene;
267 
268  // A version counter for edits to _scene.
269  std::atomic<int> _sceneVersion;
270 
271  // A shared HdEmbreeRenderParam object that stores top-level embree state;
272  // passed to prims during Sync().
273  std::shared_ptr<HdEmbreeRenderParam> _renderParam;
274 
275  // A background render thread for running the actual renders in. The
276  // render thread object manages synchronization between the scene data
277  // and the background-threaded renderer.
278  HdRenderThread _renderThread;
279 
280  // An embree renderer object, to perform the actual raytracing.
281  HdEmbreeRenderer _renderer;
282 
283  // A list of render setting exports.
284  HdRenderSettingDescriptorList _settingDescriptors;
285 
286  // A callback that interprets embree error codes and injects them into
287  // the hydra logging system.
288  static void HandleRtcError(const RTCError code, const char *msg);
289 };
290 
291 
292 PXR_NAMESPACE_CLOSE_SCOPE
293 
294 #endif // HDEMBREE_RENDER_DELEGATE_H
virtual bool Resume() override
Resume background rendering threads.
virtual void DestroySprim(HdSprim *sPrim) override
Destroy an Sprim created with CreateSprim or CreateFallbackSprim.
virtual HdBprim * CreateBprim(TfToken const &typeId, SdfPath const &bprimId) override
Create a hydra Bprim, representing data buffers such as textures.
The render delegate can create an object of type HdRenderParam, to pass to each prim during Sync()...
Definition: renderParam.h:42
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
virtual ~HdEmbreeRenderDelegate()
Render delegate destructor.
virtual bool Pause() override
Pause background rendering threads.
virtual HdInstancer * CreateInstancer(HdSceneDelegate *delegate, SdfPath const &id, SdfPath const &instancerId)
Create an instancer.
virtual const TfTokenVector & GetSupportedSprimTypes() const override
Return a list of which Sprim types can be created by this class&#39;s CreateSprim.
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine...
Definition: changeTracker.h:55
This class exists to facilitate point cloud style instancing.
Definition: instancer.h:119
A map with string keys and VtValue values.
Definition: dictionary.h:61
virtual void DestroyBprim(HdBprim *bPrim) override
Destroy a Bprim created with CreateBprim or CreateFallbackBprim.
virtual HdResourceRegistrySharedPtr GetResourceRegistry() const override
Returns the HdResourceRegistry instance used by this render delegate.
virtual void DestroyInstancer(HdInstancer *instancer)
Destroy an instancer created with CreateInstancer.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
virtual HdSprim * CreateSprim(TfToken const &typeId, SdfPath const &sprimId) override
Create a hydra Sprim, representing scene or viewport state like cameras or lights.
virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index, HdRprimCollection const &collection) override
Create a renderpass.
virtual VtDictionary GetRenderStats() const override
This function allows the renderer to report back some useful statistics that the application can disp...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:67
virtual void CommitResources(HdChangeTracker *tracker) override
This function is called after new scene data is pulled during prim Sync(), but before any tasks (such...
Render delegates provide renderer-specific functionality to the render index, the main hydra state ma...
Adapter class providing data exchange with the client scene graph.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
virtual HdAovDescriptor GetDefaultAovDescriptor(TfToken const &name) const override
This function returns the default AOV descriptor for a given named AOV.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
A named, semantic collection of objects.
virtual bool IsPauseSupported() const override
Return true to indicate that pausing and resuming are supported.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e...
Definition: sprim.h:54
virtual HdBprim * CreateFallbackBprim(TfToken const &typeId) override
Create a hydra Bprim using default values, and with no scene graph binding.
HdEmbreeRenderer implements a renderer on top of Embree&#39;s raycasting abilities.
Definition: renderer.h:54
Bprim (buffer prim) is a base class of managing a blob of data that is used to communicate between th...
Definition: bprim.h:56
virtual const TfTokenVector & GetSupportedBprimTypes() const override
Return a list of which Bprim types can be created by this class&#39;s CreateBprim.
virtual const TfTokenVector & GetSupportedRprimTypes() const override
Return a list of which Rprim types can be created by this class&#39;s CreateRprim.
A bundle of state describing an AOV (&quot;Alternate Output Value&quot;) display channel.
Definition: aov.h:46
virtual HdRenderSettingDescriptorList GetRenderSettingDescriptors() const override
Returns a list of user-configurable render settings.
virtual HdRprim * CreateRprim(TfToken const &typeId, SdfPath const &rprimId, SdfPath const &instancerId) override
Create a hydra Rprim, representing scene geometry.
virtual void DestroyRprim(HdRprim *rPrim) override
Destroy an Rprim created with CreateRprim.
HdRenderThread is a utility that specific render delegates can choose to use depending on their needs...
Definition: renderThread.h:146
virtual TfToken GetMaterialBindingPurpose() const override
This function tells the scene which material variant to reference.
HdEmbreeRenderDelegate()
Render delegate constructor.
virtual HdRenderParam * GetRenderParam() const override
Return this delegate&#39;s render param.
virtual HdSprim * CreateFallbackSprim(TfToken const &typeId) override
Create a hydra Sprim using default values, and with no scene graph binding.