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 {
86 public:
93  HdEmbreeRenderDelegate(HdRenderSettingsMap const& settingsMap);
96  ~HdEmbreeRenderDelegate() override;
97 
100  HdRenderParam *GetRenderParam() const override;
101 
104  const TfTokenVector &GetSupportedRprimTypes() const override;
107  const TfTokenVector &GetSupportedSprimTypes() const override;
110  const TfTokenVector &GetSupportedBprimTypes() const override;
111 
113  HdResourceRegistrySharedPtr GetResourceRegistry() const override;
114 
119  HdRenderSettingDescriptorList
120  GetRenderSettingDescriptors() const override;
121 
123  bool IsPauseSupported() const override;
124 
126  bool Pause() override;
127 
129  bool Resume() override;
130 
139  HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
140  HdRprimCollection const& collection) override;
141 
150  SdfPath const& id) override;
151 
154  void DestroyInstancer(HdInstancer *instancer) override;
155 
164  HdRprim *CreateRprim(TfToken const& typeId,
165  SdfPath const& rprimId) override;
166 
169  void DestroyRprim(HdRprim *rPrim) override;
170 
178  HdSprim *CreateSprim(TfToken const& typeId,
179  SdfPath const& sprimId) override;
180 
186  HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
187 
190  void DestroySprim(HdSprim *sPrim) override;
191 
198  HdBprim *CreateBprim(TfToken const& typeId,
199  SdfPath const& bprimId) override;
200 
206  HdBprim *CreateFallbackBprim(TfToken const& typeId) override;
207 
210  void DestroyBprim(HdBprim *bPrim) override;
211 
217  void CommitResources(HdChangeTracker *tracker) override;
218 
225  return HdTokens->full;
226  }
227 
235  GetDefaultAovDescriptor(TfToken const& name) const override;
236 
239  VtDictionary GetRenderStats() const override;
240 
241 private:
242  static const TfTokenVector SUPPORTED_RPRIM_TYPES;
243  static const TfTokenVector SUPPORTED_SPRIM_TYPES;
244  static const TfTokenVector SUPPORTED_BPRIM_TYPES;
245 
247  static std::mutex _mutexResourceRegistry;
248  static std::atomic_int _counterResourceRegistry;
249  static HdResourceRegistrySharedPtr _resourceRegistry;
250 
251  // This class does not support copying.
253  HdEmbreeRenderDelegate &operator =(const HdEmbreeRenderDelegate &) = delete;
254 
255  // Embree initialization routine.
256  void _Initialize();
257 
258  // Handle for an embree "device", or library state.
259  RTCDevice _rtcDevice;
260 
261  // Handle for the top-level embree scene, mirroring the Hydra scene.
262  RTCScene _rtcScene;
263 
264  // A version counter for edits to _scene.
265  std::atomic<int> _sceneVersion;
266 
267  // A shared HdEmbreeRenderParam object that stores top-level embree state;
268  // passed to prims during Sync().
269  std::shared_ptr<HdEmbreeRenderParam> _renderParam;
270 
271  // A background render thread for running the actual renders in. The
272  // render thread object manages synchronization between the scene data
273  // and the background-threaded renderer.
274  HdRenderThread _renderThread;
275 
276  // An embree renderer object, to perform the actual raytracing.
277  HdEmbreeRenderer _renderer;
278 
279  // A list of render setting exports.
280  HdRenderSettingDescriptorList _settingDescriptors;
281 
282  // A callback that interprets embree error codes and injects them into
283  // the hydra logging system.
284  static void HandleRtcError(void* userPtr, RTCError code, const char *msg);
285 };
286 
287 
288 PXR_NAMESPACE_CLOSE_SCOPE
289 
290 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_DELEGATE_H
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:120
bool Pause() override
Pause background rendering threads.
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Definition: changeTracker.h:51
HdSprim * CreateFallbackSprim(TfToken const &typeId) override
Create a hydra Sprim using default values, and with no scene graph binding.
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
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
void DestroyBprim(HdBprim *bPrim) override
Destroy a Bprim created with CreateBprim or CreateFallbackBprim.
HdRenderSettingDescriptorList GetRenderSettingDescriptors() const override
Returns a list of user-configurable render settings.
const TfTokenVector & GetSupportedSprimTypes() const override
Return a list of which Sprim types can be created by this class's CreateSprim.
HdBprim * CreateFallbackBprim(TfToken const &typeId) override
Create a hydra Bprim using default values, and with no scene graph binding.
void DestroyRprim(HdRprim *rPrim) override
Destroy an Rprim created with CreateRprim.
const TfTokenVector & GetSupportedRprimTypes() const override
Return a list of which Rprim types can be created by this class's CreateRprim.
void DestroyInstancer(HdInstancer *instancer) override
Destroy an instancer created with CreateInstancer.
HdRenderParam * GetRenderParam() const override
Return this delegate's render param.
HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index, HdRprimCollection const &collection) override
Create a renderpass.
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:54
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
HdAovDescriptor GetDefaultAovDescriptor(TfToken const &name) const override
This function returns the default AOV descriptor for a given named AOV.
TfToken GetMaterialBindingPurpose() const override
This function tells the scene which material variant to reference.
HdInstancer * CreateInstancer(HdSceneDelegate *delegate, SdfPath const &id) override
Create an instancer.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A named, semantic collection of objects.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
void CommitResources(HdChangeTracker *tracker) override
This function is called after new scene data is pulled during prim Sync(), but before any tasks (such...
HdBprim * CreateBprim(TfToken const &typeId, SdfPath const &bprimId) override
Create a hydra Bprim, representing data buffers such as textures.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e....
Definition: sprim.h:51
bool IsPauseSupported() const override
Return true to indicate that pausing and resuming are supported.
const TfTokenVector & GetSupportedBprimTypes() const override
Return a list of which Bprim types can be created by this class's CreateBprim.
This file defines some macros that are useful for declaring and using static TfTokens.
HdResourceRegistrySharedPtr GetResourceRegistry() const override
Returns the HdResourceRegistry instance used by this render delegate.
HdEmbreeRenderer implements a renderer on top of Embree's raycasting abilities.
Definition: renderer.h:54
bool Resume() override
Resume background rendering threads.
Bprim (buffer prim) is a base class of managing a blob of data that is used to communicate between th...
Definition: bprim.h:56
~HdEmbreeRenderDelegate() override
Render delegate destructor.
VtDictionary GetRenderStats() const override
This function allows the renderer to report back some useful statistics that the application can disp...
HdRprim * CreateRprim(TfToken const &typeId, SdfPath const &rprimId) override
Create a hydra Rprim, representing scene geometry.
A bundle of state describing an AOV ("Arbitrary Output Variable") display channel.
Definition: aov.h:46
HdRenderThread is a utility that specific render delegates can choose to use depending on their needs...
Definition: renderThread.h:146
void DestroySprim(HdSprim *sPrim) override
Destroy an Sprim created with CreateSprim or CreateFallbackSprim.
HdEmbreeRenderDelegate()
Render delegate constructor.
HdSprim * CreateSprim(TfToken const &typeId, SdfPath const &sprimId) override
Create a hydra Sprim, representing scene or viewport state like cameras or lights.