Loading...
Searching...
No Matches
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
36PXR_NAMESPACE_OPEN_SCOPE
37
39
40#define HDEMBREE_RENDER_SETTINGS_TOKENS \
41 (enableAmbientOcclusion) \
42 (enableSceneColors) \
43 (ambientOcclusionSamples)
44
45// Also: HdRenderSettingsTokens->convergedSamplesPerPixel
46
47TF_DECLARE_PUBLIC_TOKENS(HdEmbreeRenderSettingsTokens, HDEMBREE_RENDER_SETTINGS_TOKENS);
48
84class HdEmbreeRenderDelegate final : public HdRenderDelegate
85{
86public:
93 HdEmbreeRenderDelegate(HdRenderSettingsMap const& settingsMap);
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
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
165 SdfPath const& rprimId) override;
166
169 void DestroyRprim(HdRprim *rPrim) override;
170
179 SdfPath const& sprimId) override;
180
186 HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
187
190 void DestroySprim(HdSprim *sPrim) override;
191
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
241private:
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
288PXR_NAMESPACE_CLOSE_SCOPE
289
290#endif // PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_DELEGATE_H
Bprim (buffer prim) is a base class of managing a blob of data that is used to communicate between th...
Definition: bprim.h:57
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Definition: changeTracker.h:52
Render delegates provide renderer-specific functionality to the render index, the main hydra state ma...
bool Resume() override
Resume background rendering threads.
void DestroyRprim(HdRprim *rPrim) override
Destroy an Rprim created with CreateRprim.
bool Pause() override
Pause background rendering threads.
~HdEmbreeRenderDelegate() override
Render delegate destructor.
const TfTokenVector & GetSupportedSprimTypes() const override
Return a list of which Sprim types can be created by this class's CreateSprim.
void DestroySprim(HdSprim *sPrim) override
Destroy an Sprim created with CreateSprim or CreateFallbackSprim.
void CommitResources(HdChangeTracker *tracker) override
This function is called after new scene data is pulled during prim Sync(), but before any tasks (such...
HdBprim * CreateFallbackBprim(TfToken const &typeId) override
Create a hydra Bprim using default values, and with no scene graph binding.
HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index, HdRprimCollection const &collection) override
Create a renderpass.
HdSprim * CreateSprim(TfToken const &typeId, SdfPath const &sprimId) override
Create a hydra Sprim, representing scene or viewport state like cameras or lights.
HdSprim * CreateFallbackSprim(TfToken const &typeId) override
Create a hydra Sprim using default values, and with no scene graph binding.
HdRprim * CreateRprim(TfToken const &typeId, SdfPath const &rprimId) override
Create a hydra Rprim, representing scene geometry.
const TfTokenVector & GetSupportedRprimTypes() const override
Return a list of which Rprim types can be created by this class's CreateRprim.
HdBprim * CreateBprim(TfToken const &typeId, SdfPath const &bprimId) override
Create a hydra Bprim, representing data buffers such as textures.
bool IsPauseSupported() const override
Return true to indicate that pausing and resuming are supported.
HdInstancer * CreateInstancer(HdSceneDelegate *delegate, SdfPath const &id) override
Create an instancer.
HdResourceRegistrySharedPtr GetResourceRegistry() const override
Returns the HdResourceRegistry instance used by this render delegate.
HdRenderParam * GetRenderParam() const override
Return this delegate's render param.
HdEmbreeRenderDelegate()
Render delegate constructor.
void DestroyInstancer(HdInstancer *instancer) override
Destroy an instancer created with CreateInstancer.
const TfTokenVector & GetSupportedBprimTypes() const override
Return a list of which Bprim types can be created by this class's CreateBprim.
HdEmbreeRenderDelegate(HdRenderSettingsMap const &settingsMap)
Render delegate constructor.
void DestroyBprim(HdBprim *bPrim) override
Destroy a Bprim created with CreateBprim or CreateFallbackBprim.
TfToken GetMaterialBindingPurpose() const override
This function tells the scene which material variant to reference.
VtDictionary GetRenderStats() const override
This function allows the renderer to report back some useful statistics that the application can disp...
HdRenderSettingDescriptorList GetRenderSettingDescriptors() const override
Returns a list of user-configurable render settings.
HdAovDescriptor GetDefaultAovDescriptor(TfToken const &name) const override
This function returns the default AOV descriptor for a given named AOV.
The render delegate can create an object of type HdRenderParam, to pass to each prim during Sync().
Definition: renderParam.h:43
HdEmbreeRenderer implements a renderer on top of Embree's raycasting abilities.
Definition: renderer.h:55
This class exists to facilitate point cloud style instancing.
Definition: instancer.h:125
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
HdRenderThread is a utility that specific render delegates can choose to use depending on their needs...
Definition: renderThread.h:146
A named, semantic collection of objects.
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:55
Adapter class providing data exchange with the client scene graph.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e....
Definition: sprim.h:52
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
A map with string keys and VtValue values.
Definition: dictionary.h:60
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:98
A bundle of state describing an AOV ("Arbitrary Output Variable") display channel.
Definition: aov.h:47
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457