HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderDelegate.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_HD_RENDER_DELEGATE_H
25 #define PXR_IMAGING_HD_RENDER_DELEGATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/aov.h"
31 #include "pxr/imaging/hd/command.h"
32 #include "pxr/base/vt/dictionary.h"
33 #include "pxr/base/tf/token.h"
34 
35 #include <memory>
36 
38 
39 class SdfPath;
40 class HdRprim;
41 class HdSprim;
42 class HdBprim;
43 class HdSceneDelegate;
44 class HdRenderIndex;
45 class HdRenderPass;
46 class HdInstancer;
47 class HdDriver;
48 
49 using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
50 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
51 using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
52 using HdDriverVector = std::vector<HdDriver*>;
53 
54 ///
55 /// The HdRenderParam is an opaque (to core Hydra) handle, to an object
56 /// that is obtained from the render delegate and passed to each prim
57 /// during Sync processing.
58 ///
60 {
61 public:
63  HD_API
64  virtual ~HdRenderParam();
65 
66 private:
67  // Hydra will not attempt to copy the class.
68  HdRenderParam(const HdRenderParam &) = delete;
69  HdRenderParam &operator =(const HdRenderParam &) = delete;
70 };
71 
73 
74 ///
75 /// HdRenderSettingDescriptor represents a render setting that a render delegate
76 /// wants to export (e.g. to UI).
77 ///
79 {
80  // A human readable name.
82  // The key for HdRenderDelegate::SetRenderSetting/GetRenderSetting.
84  // The default value.
86 };
87 
88 typedef std::vector<HdRenderSettingDescriptor> HdRenderSettingDescriptorList;
89 
90 /// \class HdRenderDelegate
91 ///
93 {
94 public:
95  HD_API
96  virtual ~HdRenderDelegate();
97 
98  ///
99  /// Set list of driver objects, such as a rendering context / devices.
100  /// This is automatically called from HdRenderIndex when a HdDriver is
101  /// provided during its construction. Default implementation does nothing.
102  ///
103  HD_API
104  virtual void SetDrivers(HdDriverVector const& drivers);
105 
106  ///
107  /// Returns a list of typeId's of all supported Rprims by this render
108  /// delegate.
109  ///
110  virtual const TfTokenVector &GetSupportedRprimTypes() const = 0;
111 
112  ///
113  /// Returns a list of typeId's of all supported Sprims by this render
114  /// delegate.
115  ///
116  virtual const TfTokenVector &GetSupportedSprimTypes() const = 0;
117 
118 
119  ///
120  /// Returns a list of typeId's of all supported Bprims by this render
121  /// delegate.
122  ///
123  virtual const TfTokenVector &GetSupportedBprimTypes() const = 0;
124 
125  ///
126  /// Returns an opaque handle to a render param, that in turn is
127  /// passed to each prim created by the render delegate during sync
128  /// processing. This avoids the need to store a global state pointer
129  /// in each prim.
130  ///
131  /// The typical lifetime of the renderParam would match that of the
132  /// RenderDelegate, however the minimal lifetime is that of the Sync
133  /// processing. The param maybe queried multiple times during sync.
134  ///
135  /// A render delegate may return null for the param.
136  ///
137  HD_API
138  virtual HdRenderParam *GetRenderParam() const;
139 
140  ///
141  /// Returns a shared ptr to the resource registry of the current render
142  /// delegate.
143  ///
145 
146  ///
147  /// Set a custom render setting on this render delegate.
148  ///
149  HD_API
150  virtual void SetRenderSetting(TfToken const& key, VtValue const& value);
151 
152  ///
153  /// Get the current value for a render setting.
154  ///
155  HD_API
156  virtual VtValue GetRenderSetting(TfToken const& key) const;
157 
158  ///
159  /// Get the current value for a render setting, taking a desired type
160  /// and a fallback value in case of type mismatch.
161  ///
162  template<typename T>
163  T GetRenderSetting(TfToken const& key, T const& defValue) const {
164  return GetRenderSetting(key).Cast<T>().GetWithDefault(defValue);
165  }
166 
167  ///
168  /// Get the backend-exported render setting descriptors.
169  ///
170  HD_API
172 
173  ///
174  /// Get the current version of the render settings dictionary.
175  ///
176  HD_API
177  virtual unsigned int GetRenderSettingsVersion() const;
178 
179  ///
180  /// Returns an open-format dictionary of render statistics
181  ///
182  HD_API
183  virtual VtDictionary GetRenderStats() const;
184 
185  ////////////////////////////////////////////////////////////////////////////
186  ///
187  /// Control of background rendering threads.
188  ///
189  ////////////////////////////////////////////////////////////////////////////
190 
191  ///
192  /// Advertise whether this delegate supports pausing and resuming of
193  /// background render threads. Default implementation returns false.
194  ///
195  HD_API
196  virtual bool IsPauseSupported() const;
197 
198  ///
199  /// Pause all of this delegate's background rendering threads. Default
200  /// implementation does nothing.
201  ///
202  /// Returns \c true if successful.
203  ///
204  HD_API
205  virtual bool Pause();
206 
207  ///
208  /// Resume all of this delegate's background rendering threads previously
209  /// paused by a call to Pause. Default implementation does nothing.
210  ///
211  /// Returns \c true if successful.
212  ///
213  HD_API
214  virtual bool Resume();
215 
216  ///
217  /// Advertise whether this delegate supports stopping and restarting of
218  /// background render threads. Default implementation returns false.
219  ///
220  HD_API
221  virtual bool IsStopSupported() const;
222 
223  ///
224  /// Stop all of this delegate's background rendering threads. Default
225  /// implementation does nothing.
226  ///
227  /// Returns \c true if successful.
228  ///
229  HD_API
230  virtual bool Stop();
231 
232  ///
233  /// Restart all of this delegate's background rendering threads previously
234  /// stopped by a call to Stop. Default implementation does nothing.
235  ///
236  /// Returns \c true if successful.
237  ///
238  HD_API
239  virtual bool Restart();
240 
241  ////////////////////////////////////////////////////////////////////////////
242  ///
243  /// Renderpass Factory
244  ///
245  ////////////////////////////////////////////////////////////////////////////
246 
247  ///
248  /// Request to create a new renderpass.
249  /// \param index the render index to bind to the new renderpass.
250  /// \param collection the rprim collection to bind to the new renderpass.
251  /// \return A shared pointer to the new renderpass or empty on error.
252  ///
254  HdRprimCollection const& collection) = 0;
255 
256  ///
257  /// Request to create a new renderpass state.
258  /// The default implementation creates an HdRenderPassState instance,
259  /// but derived render delegates may instantiate their own state type.
260  /// \param shader The render pass shader to use. If null, a new
261  /// HdRenderPassShared will be created.
262  /// \return A shared pointer to the new renderpass state.
263  ///
264  HD_API
266 
267  ////////////////////////////////////////////////////////////////////////////
268  ///
269  /// Instancer Factory
270  ///
271  ////////////////////////////////////////////////////////////////////////////
272 
273  ///
274  /// Request to create a new instancer.
275  /// \param id The unique identifier of this instancer.
276  /// \return A pointer to the new instancer or nullptr on error.
277  ///
278  virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
279  SdfPath const& id) = 0;
280 
281  virtual void DestroyInstancer(HdInstancer *instancer) = 0;
282 
283  ////////////////////////////////////////////////////////////////////////////
284  ///
285  /// Prim Factories
286  ///
287  ////////////////////////////////////////////////////////////////////////////
288 
289 
290  ///
291  /// Request to Allocate and Construct a new Rprim.
292  /// \param typeId the type identifier of the prim to allocate
293  /// \param rprimId a unique identifier for the prim
294  /// \return A pointer to the new prim or nullptr on error.
295  ///
296  virtual HdRprim *CreateRprim(TfToken const& typeId,
297  SdfPath const& rprimId) = 0;
298 
299  ///
300  /// Request to Destruct and deallocate the prim.
301  ///
302  virtual void DestroyRprim(HdRprim *rPrim) = 0;
303 
304  ///
305  /// Request to Allocate and Construct a new Sprim.
306  /// \param typeId the type identifier of the prim to allocate
307  /// \param sprimId a unique identifier for the prim
308  /// \return A pointer to the new prim or nullptr on error.
309  ///
310  virtual HdSprim *CreateSprim(TfToken const& typeId,
311  SdfPath const& sprimId) = 0;
312 
313  ///
314  /// Request to Allocate and Construct an Sprim to use as a standin, if there
315  /// if an error with another another Sprim of the same type. For example,
316  /// if another prim references a non-exisiting Sprim, the fallback could
317  /// be used.
318  ///
319  /// \param typeId the type identifier of the prim to allocate
320  /// \return A pointer to the new prim or nullptr on error.
321  ///
322  virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) = 0;
323 
324  ///
325  /// Request to Destruct and deallocate the prim.
326  ///
327  virtual void DestroySprim(HdSprim *sprim) = 0;
328 
329  ///
330  /// Request to Allocate and Construct a new Bprim.
331  /// \param typeId the type identifier of the prim to allocate
332  /// \param sprimId a unique identifier for the prim
333  /// \return A pointer to the new prim or nullptr on error.
334  ///
335  virtual HdBprim *CreateBprim(TfToken const& typeId,
336  SdfPath const& bprimId) = 0;
337 
338 
339  ///
340  /// Request to Allocate and Construct a Bprim to use as a standin, if there
341  /// if an error with another another Bprim of the same type. For example,
342  /// if another prim references a non-exisiting Bprim, the fallback could
343  /// be used.
344  ///
345  /// \param typeId the type identifier of the prim to allocate
346  /// \return A pointer to the new prim or nullptr on error.
347  ///
348  virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) = 0;
349 
350  ///
351  /// Request to Destruct and deallocate the prim.
352  ///
353  virtual void DestroyBprim(HdBprim *bprim) = 0;
354 
355  ////////////////////////////////////////////////////////////////////////////
356  ///
357  /// Sync, Execute & Dispatch Hooks
358  ///
359  ////////////////////////////////////////////////////////////////////////////
360 
361  ///
362  /// Notification point from the Engine to the delegate.
363  /// This notification occurs after all Sync's have completed and
364  /// before task execution.
365  ///
366  /// This notification gives the Render Delegate a chance to
367  /// update and move memory that the render may need.
368  ///
369  /// For example, the render delegate might fill primvar buffers or texture
370  /// memory.
371  ///
372  virtual void CommitResources(HdChangeTracker *tracker) = 0;
373 
374  ////////////////////////////////////////////////////////////////////////////
375  ///
376  /// Materials
377  ///
378  ////////////////////////////////////////////////////////////////////////////
379 
380  ///
381  /// Returns a token that indicates material bindings should be used,
382  /// based on the indicated purpose. The default purpose is
383  /// HdTokens->preview.
384  ///
385  HD_API
386  virtual TfToken GetMaterialBindingPurpose() const;
387 
388 
389  /// \deprecated use GetMaterialRenderContexts()
390  HD_API
391  virtual TfToken GetMaterialNetworkSelector() const;
392 
393  ///
394  /// Returns a list, in descending order of preference, that can be used to
395  /// select among multiple material network implementations. The default
396  /// list contains an empty token.
397  ///
398  HD_API
400 
401  ///
402  /// Return true to indicate that the render delegate wants rprim primvars
403  /// to be filtered by the scene delegate to reduce the amount of primvars
404  /// that are send to the render delegate. For example the scene delegate
405  /// may check the bound material primvar requirements and send only those
406  /// to the render delegate. Return false to not apply primvar filtering in
407  /// the scene delegate. Defaults to false.
408  ///
409  HD_API
410  virtual bool IsPrimvarFilteringNeeded() const;
411 
412  ///
413  /// Returns the ordered list of shader source types that the render delegate
414  /// supports.
415  ///
416  HD_API
417  virtual TfTokenVector GetShaderSourceTypes() const;
418 
419  ////////////////////////////////////////////////////////////////////////////
420  ///
421  /// AOVs
422  ///
423  ////////////////////////////////////////////////////////////////////////////
424 
425  ///
426  /// Returns a default AOV descriptor for the given named AOV, specifying
427  /// things like preferred format.
428  ///
429  HD_API
430  virtual HdAovDescriptor GetDefaultAovDescriptor(TfToken const& name) const;
431 
432  ////////////////////////////////////////////////////////////////////////////
433  ///
434  /// Commands API
435  ///
436  ////////////////////////////////////////////////////////////////////////////
437 
438  ///
439  /// Get the descriptors for the commands supported by this render delegate.
440  ///
441  HD_API
443 
444  ///
445  /// Invokes the command described by the token \p command with optional
446  /// \p args.
447  ///
448  /// If the command succeeds, returns \c true, otherwise returns \c false.
449  /// A command will generally fail if it is not among those returned by
450  /// GetCommandDescriptors().
451  ///
452  HD_API
453  virtual bool InvokeCommand(
454  const TfToken &command,
455  const HdCommandArgs &args = HdCommandArgs());
456 
457 
458 protected:
459  /// This class must be derived from.
460  HD_API
462  /// Allow derived classes to pass construction-time render settings.
463  HD_API
464  HdRenderDelegate(HdRenderSettingsMap const& settingsMap);
465 
466  ///
467  /// This class is not intended to be copied.
468  ///
469  HdRenderDelegate(const HdRenderDelegate &) = delete;
470  HdRenderDelegate &operator=(const HdRenderDelegate &) = delete;
471 
472  HD_API
474  HdRenderSettingDescriptorList const& defaultSettings);
475 
476  /// Render settings state.
478  unsigned int _settingsVersion;
479 };
480 
482 
483 #endif //PXR_IMAGING_HD_RENDER_DELEGATE_H
virtual HD_API void SetRenderSetting(TfToken const &key, VtValue const &value)
virtual void DestroyRprim(HdRprim *rPrim)=0
virtual const TfTokenVector & GetSupportedSprimTypes() const =0
virtual void DestroySprim(HdSprim *sprim)=0
virtual HD_API TfTokenVector GetMaterialRenderContexts() const
std::shared_ptr< class HdRenderPassState > HdRenderPassStateSharedPtr
Definition: engine.h:42
virtual HdResourceRegistrySharedPtr GetResourceRegistry() const =0
virtual HdSprim * CreateSprim(TfToken const &typeId, SdfPath const &sprimId)=0
virtual HD_API ~HdRenderDelegate()
virtual HD_API VtValue GetRenderSetting(TfToken const &key) const
std::shared_ptr< class HdRenderPass > HdRenderPassSharedPtr
Definition: engine.h:41
std::shared_ptr< class HdResourceRegistry > HdResourceRegistrySharedPtr
std::vector< HdRenderSettingDescriptor > HdRenderSettingDescriptorList
virtual HdBprim * CreateFallbackBprim(TfToken const &typeId)=0
virtual HD_API bool Resume()
virtual HD_API void SetDrivers(HdDriverVector const &drivers)
virtual HdBprim * CreateBprim(TfToken const &typeId, SdfPath const &bprimId)=0
#define HD_API
Definition: api.h:40
virtual HD_API bool IsStopSupported() const
virtual HD_API bool InvokeCommand(const TfToken &command, const HdCommandArgs &args=HdCommandArgs())
virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index, HdRprimCollection const &collection)=0
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual HD_API HdRenderSettingDescriptorList GetRenderSettingDescriptors() const
HdRenderSettingsMap _settingsMap
Render settings state.
virtual const TfTokenVector & GetSupportedRprimTypes() const =0
virtual HD_API TfToken GetMaterialNetworkSelector() const
virtual HD_API bool IsPrimvarFilteringNeeded() const
unsigned int _settingsVersion
Definition: token.h:87
std::vector< HdDriver * > HdDriverVector
Definition: rprim.h:68
std::vector< HdCommandDescriptor > HdCommandDescriptors
Definition: command.h:108
HdRenderDelegate & operator=(const HdRenderDelegate &)=delete
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
virtual HD_API HdCommandDescriptors GetCommandDescriptors() const
Definition: path.h:288
virtual HdRprim * CreateRprim(TfToken const &typeId, SdfPath const &rprimId)=0
virtual void DestroyBprim(HdBprim *bprim)=0
virtual HD_API HdAovDescriptor GetDefaultAovDescriptor(TfToken const &name) const
virtual HD_API ~HdRenderParam()
virtual HD_API TfTokenVector GetShaderSourceTypes() const
virtual HD_API HdRenderPassStateSharedPtr CreateRenderPassState() const
Definition: sprim.h:52
virtual HdSprim * CreateFallbackSprim(TfToken const &typeId)=0
virtual HD_API bool Pause()
virtual HD_API bool Restart()
HD_API void _PopulateDefaultSettings(HdRenderSettingDescriptorList const &defaultSettings)
virtual void DestroyInstancer(HdInstancer *instancer)=0
virtual HdInstancer * CreateInstancer(HdSceneDelegate *delegate, SdfPath const &id)=0
virtual void CommitResources(HdChangeTracker *tracker)=0
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
VtDictionary HdCommandArgs
Definition: command.h:71
T GetRenderSetting(TfToken const &key, T const &defValue) const
static VtValue Cast(VtValue const &val)
Definition: value.h:1152
virtual HD_API bool Stop()
GLuint index
Definition: glcorearb.h:785
HD_API HdRenderDelegate()
This class must be derived from.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: bprim.h:56
GLsizei const GLfloat * value
Definition: glcorearb.h:823
virtual const TfTokenVector & GetSupportedBprimTypes() const =0
TfHashMap< TfToken, VtValue, TfToken::HashFunctor > HdRenderSettingsMap
**If you just want to fire and args
Definition: thread.h:615
virtual HD_API TfToken GetMaterialBindingPurpose() const
virtual HD_API bool IsPauseSupported() const
virtual HD_API VtDictionary GetRenderStats() const
virtual HD_API HdRenderParam * GetRenderParam() const
virtual HD_API unsigned int GetRenderSettingsVersion() const
Definition: value.h:168