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"
32 
33 #include <mutex>
34 #include <embree3/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 
148  virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
149  SdfPath const& id) override;
150 
153  virtual void DestroyInstancer(HdInstancer *instancer) override;
154 
163  virtual HdRprim *CreateRprim(TfToken const& typeId,
164  SdfPath const& rprimId) override;
165 
168  virtual void DestroyRprim(HdRprim *rPrim) override;
169 
177  virtual HdSprim *CreateSprim(TfToken const& typeId,
178  SdfPath const& sprimId) override;
179 
185  virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
186 
189  virtual void DestroySprim(HdSprim *sPrim) override;
190 
197  virtual HdBprim *CreateBprim(TfToken const& typeId,
198  SdfPath const& bprimId) override;
199 
205  virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) override;
206 
209  virtual void DestroyBprim(HdBprim *bPrim) override;
210 
216  virtual void CommitResources(HdChangeTracker *tracker) override;
217 
223  virtual TfToken GetMaterialBindingPurpose() const override {
224  return HdTokens->full;
225  }
226 
233  virtual HdAovDescriptor
234  GetDefaultAovDescriptor(TfToken const& name) const override;
235 
238  virtual VtDictionary GetRenderStats() const override;
239 
240 private:
241  static const TfTokenVector SUPPORTED_RPRIM_TYPES;
242  static const TfTokenVector SUPPORTED_SPRIM_TYPES;
243  static const TfTokenVector SUPPORTED_BPRIM_TYPES;
244 
246  static std::mutex _mutexResourceRegistry;
247  static std::atomic_int _counterResourceRegistry;
248  static HdResourceRegistrySharedPtr _resourceRegistry;
249 
250  // This class does not support copying.
252  HdEmbreeRenderDelegate &operator =(const HdEmbreeRenderDelegate &) = delete;
253 
254  // Embree initialization routine.
255  void _Initialize();
256 
257  // Handle for an embree "device", or library state.
258  RTCDevice _rtcDevice;
259 
260  // Handle for the top-level embree scene, mirroring the Hydra scene.
261  RTCScene _rtcScene;
262 
263  // A version counter for edits to _scene.
264  std::atomic<int> _sceneVersion;
265 
266  // A shared HdEmbreeRenderParam object that stores top-level embree state;
267  // passed to prims during Sync().
268  std::shared_ptr<HdEmbreeRenderParam> _renderParam;
269 
270  // A background render thread for running the actual renders in. The
271  // render thread object manages synchronization between the scene data
272  // and the background-threaded renderer.
273  HdRenderThread _renderThread;
274 
275  // An embree renderer object, to perform the actual raytracing.
276  HdEmbreeRenderer _renderer;
277 
278  // A list of render setting exports.
279  HdRenderSettingDescriptorList _settingDescriptors;
280 
281  // A callback that interprets embree error codes and injects them into
282  // the hydra logging system.
283  static void HandleRtcError(void* userPtr, RTCError code, const char *msg);
284 };
285 
286 
287 PXR_NAMESPACE_CLOSE_SCOPE
288 
289 #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:116
virtual ~HdEmbreeRenderDelegate()
Render delegate destructor.
virtual bool Pause() override
Pause background rendering threads.
virtual const TfTokenVector & GetSupportedSprimTypes() const override
Return a list of which Sprim types can be created by this class&#39;s CreateSprim.
virtual HdRprim * CreateRprim(TfToken const &typeId, SdfPath const &rprimId) override
Create a hydra Rprim, representing scene geometry.
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine...
Definition: changeTracker.h:50
This class exists to facilitate point cloud style instancing.
Definition: instancer.h:124
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.
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:442
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
virtual void DestroyInstancer(HdInstancer *instancer) override
Destroy an instancer created with CreateInstancer.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e...
Definition: sprim.h:52
virtual HdInstancer * CreateInstancer(HdSceneDelegate *delegate, SdfPath const &id) override
Create an instancer.
virtual HdBprim * CreateFallbackBprim(TfToken const &typeId) override
Create a hydra Bprim using default values, and with no scene graph binding.
This file defines some macros that are useful for declaring and using static TfTokens.
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;Arbitrary Output Variable&quot;) display channel.
Definition: aov.h:46
virtual HdRenderSettingDescriptorList GetRenderSettingDescriptors() const override
Returns a list of user-configurable render settings.
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.