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 PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_DELEGATE_H
25 #define PXR_IMAGING_PLUGIN_HD_EMBREE_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/plugin/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 
84 class HdEmbreeRenderDelegate final : public HdRenderDelegate {
85 public:
92  HdEmbreeRenderDelegate(HdRenderSettingsMap const& settingsMap);
95  virtual ~HdEmbreeRenderDelegate();
96 
99  virtual HdRenderParam *GetRenderParam() const override;
100 
103  virtual const TfTokenVector &GetSupportedRprimTypes() const override;
106  virtual const TfTokenVector &GetSupportedSprimTypes() const override;
109  virtual const TfTokenVector &GetSupportedBprimTypes() const override;
110 
112  virtual HdResourceRegistrySharedPtr GetResourceRegistry() const override;
113 
118  virtual HdRenderSettingDescriptorList
119  GetRenderSettingDescriptors() const override;
120 
122  virtual bool IsPauseSupported() const override;
123 
125  virtual bool Pause() override;
126 
128  virtual bool Resume() override;
129 
138  virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
139  HdRprimCollection const& collection) override;
140 
150  virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
151  SdfPath const& id,
152  SdfPath const& instancerId);
153 
156  virtual void DestroyInstancer(HdInstancer *instancer);
157 
168  virtual HdRprim *CreateRprim(TfToken const& typeId,
169  SdfPath const& rprimId,
170  SdfPath const& instancerId) override;
171 
174  virtual void DestroyRprim(HdRprim *rPrim) override;
175 
183  virtual HdSprim *CreateSprim(TfToken const& typeId,
184  SdfPath const& sprimId) override;
185 
191  virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
192 
195  virtual void DestroySprim(HdSprim *sPrim) override;
196 
203  virtual HdBprim *CreateBprim(TfToken const& typeId,
204  SdfPath const& bprimId) override;
205 
211  virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) override;
212 
215  virtual void DestroyBprim(HdBprim *bPrim) override;
216 
222  virtual void CommitResources(HdChangeTracker *tracker) override;
223 
229  virtual TfToken GetMaterialBindingPurpose() const override {
230  return HdTokens->full;
231  }
232 
239  virtual HdAovDescriptor
240  GetDefaultAovDescriptor(TfToken const& name) const override;
241 
244  virtual VtDictionary GetRenderStats() const override;
245 
246 private:
247  static const TfTokenVector SUPPORTED_RPRIM_TYPES;
248  static const TfTokenVector SUPPORTED_SPRIM_TYPES;
249  static const TfTokenVector SUPPORTED_BPRIM_TYPES;
250 
252  static std::mutex _mutexResourceRegistry;
253  static std::atomic_int _counterResourceRegistry;
254  static HdResourceRegistrySharedPtr _resourceRegistry;
255 
256  // This class does not support copying.
258  HdEmbreeRenderDelegate &operator =(const HdEmbreeRenderDelegate &) = delete;
259 
260  // Embree initialization routine.
261  void _Initialize();
262 
263  // Handle for an embree "device", or library state.
264  RTCDevice _rtcDevice;
265 
266  // Handle for the top-level embree scene, mirroring the Hydra scene.
267  RTCScene _rtcScene;
268 
269  // A version counter for edits to _scene.
270  std::atomic<int> _sceneVersion;
271 
272  // A shared HdEmbreeRenderParam object that stores top-level embree state;
273  // passed to prims during Sync().
274  std::shared_ptr<HdEmbreeRenderParam> _renderParam;
275 
276  // A background render thread for running the actual renders in. The
277  // render thread object manages synchronization between the scene data
278  // and the background-threaded renderer.
279  HdRenderThread _renderThread;
280 
281  // An embree renderer object, to perform the actual raytracing.
282  HdEmbreeRenderer _renderer;
283 
284  // A list of render setting exports.
285  HdRenderSettingDescriptorList _settingDescriptors;
286 
287  // A callback that interprets embree error codes and injects them into
288  // the hydra logging system.
289  static void HandleRtcError(const RTCError code, const char *msg);
290 };
291 
292 
293 PXR_NAMESPACE_CLOSE_SCOPE
294 
295 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_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:121
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:52
This class exists to facilitate point cloud style instancing.
Definition: instancer.h:119
A map with string keys and VtValue values.
Definition: dictionary.h:63
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:87
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:68
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:431
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:288
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e...
Definition: sprim.h:52
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.