HDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_RendererInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_RendererInfo_h__
19 #define __HUSD_RendererInfo_h__
20 
21 #include "HUSD_API.h"
22 #include <UT/UT_OptionEntry.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_StringArray.h>
25 #include <UT/UT_StringMap.h>
26 
27 class UT_Options;
28 class UT_JSONValue;
29 
31 {
36 };
37 
38 /// Parse and provide information from UsdRenderers.json
40 {
41 public:
44 
45  // Constructs a default invalid renderer info.
47  : myMenuPriority(0)
48  , myDrawComplexityMultiplier(1.0)
49  , myIsValid(false)
50  , myIsNativeRenderer(false)
51  , myDepthStyle(HUSD_DEPTH_NORMALIZED)
52  , myNeedsNativeDepthPass(false)
53  , myNeedsNativeSelectionPass(false)
54  , myAllowBackgroundUpdate(false)
55  , myDestroyIfDeactivated(false)
56  , myPauseOnUpdate(false)
57  , myAovSupport(false)
58  , myViewportRenderer(false)
59  , myDrawModeSupport(false)
60  , myHuskFastExit(false)
61  , myHuskVerboseInterval(0)
62  { }
63  // Constructs a renderer info with all required information.
65  const UT_StringHolder &displayname,
66  const UT_StringHolder &menulabel,
67  int menupriority,
68  fpreal complexitymultiplier,
69  bool isnative,
70  HUSD_DepthStyle depth_style,
71  const UT_StringArray &defaultpurposes,
72  const UT_StringArray &restartrendersettings,
73  const UT_StringArray &restartcamerasettings,
74  const UT_StringArray &renderstats,
75  const HuskMetadata &husk_metadata,
76  const UT_StringHolder &husk_stats_metadata,
77  const StatsDataPaths &statsdatapaths,
78  const UT_StringHolder &husk_verbose_script,
79  fpreal husk_verbose_interval,
80  const UT_StringArray &preload_libraries,
81  bool needsnativedepth,
82  bool needsnativeselection,
83  bool allowbackgroundupdate,
84  bool destroyifdeactivated,
85  bool pauseonupdate,
86  bool aovsupport,
87  bool viewportrenderer,
88  bool drawmodesupport,
89  bool husk_fastexit)
90  : myName(name)
91  , myDisplayName(displayname)
92  , myMenuLabel(menulabel)
93  , myMenuPriority(menupriority)
94  , myDrawComplexityMultiplier(complexitymultiplier)
95  , myIsValid(true)
96  , myIsNativeRenderer(isnative)
97  , myDepthStyle(depth_style)
98  , myDefaultPurposes(defaultpurposes)
99  , myRestartRenderSettings(restartrendersettings)
100  , myRestartCameraSettings(restartcamerasettings)
101  , myRenderViewStats(renderstats)
102  , myHuskMetadata(husk_metadata)
103  , myHuskStatsMetadata(husk_stats_metadata)
104  , myStatsDataPaths(statsdatapaths)
105  , myHuskVerboseScript(husk_verbose_script)
106  , myHuskVerboseInterval(husk_verbose_interval)
107  , myPreloadLibraries(preload_libraries)
108  , myNeedsNativeDepthPass(needsnativedepth)
109  , myNeedsNativeSelectionPass(needsnativeselection)
110  , myAllowBackgroundUpdate(allowbackgroundupdate)
111  , myDestroyIfDeactivated(destroyifdeactivated)
112  , myPauseOnUpdate(pauseonupdate)
113  , myAovSupport(aovsupport)
114  , myViewportRenderer(viewportrenderer)
115  , myDrawModeSupport(drawmodesupport)
116  , myHuskFastExit(husk_fastexit)
117  { }
118 
119  // The renderer plugin name as registered with HUSD. Something like
120  // HdStreamRendererPlugin.
121  const UT_StringHolder &name() const
122  { return myName; }
123  // The display name registered with USD for this plugin. This may not be
124  // the name we want to use in the menu.
126  { return myDisplayName; }
127  // The name we use in the menu to describe this plugin.
128  const UT_StringHolder &menuLabel() const
129  { return myMenuLabel; }
130  // Indicates the priority for this plugin to control its location in the
131  // renderer menu. Higher numbers show up higher in the menu.
132  int menuPriority() const
133  { return myMenuPriority; }
134  // Specifies a multiplier to use on the Hydra draw complexity calculated
135  // from the Display Options Level of Detail.
137  { return myDrawComplexityMultiplier; }
138  // Should be true for all plugins. Only false if the default constructor
139  // was used and none of the other data in this structure is valid.
140  bool isValid() const
141  { return myIsValid; }
142  // True for the Houdini GL native renderer plugin only.
143  bool isNativeRenderer() const
144  { return myIsNativeRenderer; }
145  // Describes the range used when returning depth information.
147  { return myDepthStyle; }
148  // An array of the render purposes that should be enabled by deafult for
149  // this render plugin.
151  { return myDefaultPurposes; }
152  // Names of render settings that should force the renderer to restart
153  // when they are changed.
155  { return myRestartRenderSettings; }
156  // Names of camera settings that should force the renderer to restart
157  // when they are changed.
159  { return myRestartCameraSettings; }
160  // Names of render statistics printed in the viewport when view stats is on
162  { return myRenderViewStats; }
163  // True if this plugin needs the native GL renderer to provide a depth
164  // map for the render.
165  bool needsNativeDepthPass() const
166  { return myNeedsNativeDepthPass; }
167  // True if this plugin needs the native GL renderer to provide an overlay
168  // to highlight selected primitives.
170  { return myNeedsNativeSelectionPass; }
171  // True if this plugin allows Houdini to run scene graph update processing
172  // on a background thread.
174  { return myAllowBackgroundUpdate; }
175  // True if this plugin requires Houdini to tear it down if the viewport
176  // switches to a different active renderer.
177  bool destroyIfDeactivated() const
178  { return myDestroyIfDeactivated; }
179  // True if this plugin should pause while processing update. Should be set
180  // if the renderer can read COP textures to avoid potential deadlocks.
181  bool pauseOnUpdate() const
182  { return myPauseOnUpdate; }
183  // True if this plugin is able to generate AOV buffers.
184  bool aovSupport() const
185  { return myAovSupport; }
186  // True if this plugin does its own viewport rendering.
187  bool viewportRenderer() const
188  { return myViewportRenderer; }
189  // True if this plugin supports USD draw modes.
190  bool drawModeSupport() const
191  { return myDrawModeSupport; }
192  // Return whether husk.fast-exit is set
193  bool huskFastExit() const
194  { return myHuskFastExit; }
195 
196  /// Return the husk.metadata map. This map is used by husk to add metadata
197  /// when saving images. The metadata keys are specific to the format (see
198  /// "iconvert --help"). When using the multi-part EXR writer, arbitrary
199  /// typed metadata can also be saved (see the HDK documentation for more
200  /// details), but examples might be "string OpenEXR:Software" or "mat4d
201  /// OpenEXR:custom_matrix".
202  ///
203  /// Husk provides a JSON dictionary of metadata values which can be
204  /// referenced in the value of the metadata map. The JSON dictionary will
205  /// look something like: @code
206  /// {
207  /// "frame" : 42,
208  /// "command_line" : "husk -f 42 foo.usd",
209  /// "render_stats" : { "render_time" : [3.42, 0.24, 1.32] },
210  /// ...
211  /// }
212  /// @endcode
213  /// A delegate can specify metadata as either verbatim text or by expanding
214  /// data referenced in the JSON dictionary (using the JSON Path syntax).
215  /// For example:
216  /// - "float OpenEXR:frame" : "${frame}"
217  /// - "float OpenEXR:load_time_cpu" : "${render_stats.render_time[0]}" @n
218  /// Extracts the first time from the render_time array
219  /// - "float OpenEXR:load_time_sys" : "${render_stats.render_time[1]}"
220  /// - "float OpenEXR:load_time_wall" : "${render_stats.render_time[2]}"
221  /// - "string OpenEXR:stats_json" : "${render_stats}"
222  /// Encodes all the render_stats as a string in JSON format
223  ///
224  /// @note that the render stats mapping is not used when performing render
225  /// stat lookup.
226  const HuskMetadata &huskMetadata() const
227  { return myHuskMetadata; }
228 
229  /// Some delegates prefer to pass metadata from GetRenderStats() directly
230  /// to image metadata. This option passes a string pattern (see
231  /// UT_String::multiMatch) for render stats which should be stored as
232  /// metadata directly. This defaults to `*` (meaning all the stats from
233  /// GetRenderStats will be stored as metadata). If you set
234  /// `husk.metadata`, you probably want to set this to an empty string.
236  { return myHuskStatsMetadata; }
237 
238  /// Similar to the husk metadata, this returns the statsdatapaths, which
239  /// gives the JSON path to the render stat required by the viewer or husk.
240  /// Currently thses are:
241  /// - int peakMemory: The peak memory usage
242  /// - float percentDone: The percent complete (0 to 100)
243  /// - float totalClockTime: The wall clock time taken to render
244  /// - float totalUTime: The CPU time taken to render
245  /// - float totalSTime: The system time taken to render
246  /// - string renderProgressAnnotation: multi-line renderer status
247  /// - string renderStatsAnnotation: multi-line renderer status
248  /// - string rendererStage: The current stage of rendering for the
249  /// delegate. This might be something like "displacing", "loading
250  /// textures", "rendering", etc.
251  /// - string rendererName: The name of the delegate (defaults to menuLabel())
252  ///
253  /// In addition, each delegate may also specify a list of custom labels in
254  /// the "viewstats" item.
255  ///
256  /// One major difference between this and the husk.metadata is that for
257  /// this setting, the value in the pair is a direct JSON Path (rather than
258  /// being a string that undergoes variable expansion.
260  { return myStatsDataPaths; }
261 
262  /// Get standard renderer info for a particular render delegate. Either
263  /// the internal renderer name or the display name can be provided. The
264  /// other parameter can be an empty string.
265  static HUSD_RendererInfo getRendererInfo(
266  const UT_StringHolder &name,
267  const UT_StringHolder &displayname);
268  /// Get renderer info for a particular render delegate, and also extract
269  /// custom data. The "custom" map on input should contain empty entries
270  /// for all extra data of interest. On output, the map will be filled with
271  /// the values associated with these keys extracted from the
272  /// UsdRenderers.json file.
273  static HUSD_RendererInfo getRendererInfo(
274  const UT_StringHolder &name,
275  const UT_StringHolder &displayname,
277 
278  /// Convenience method to fill out a UT_Options with all the stats data
279  /// required for the delegate
280  void extractStatsData(UT_Options &options,
281  const UT_JSONValue &stats_dictionary) const;
282 
283  /// Convenience method to find a JSON Value for a given key
284  const UT_JSONValue *findStatsData(const UT_JSONValue &stats_dict,
285  const char *key) const;
286 
287  /// Python script used by husk for verbose callbacks
289  { return myHuskVerboseScript; }
291  { return myHuskVerboseInterval; }
292 
293  /// Before doing anything that may cause this render delegate's library
294  /// to be loaded, call this method to make sure any required libraries
295  /// (most likely libpxr libraries) are already loaded. This saves third
296  /// party libraries from having to worry about LD_LIBRARY_PATH.
297  void preloadLibraries() const;
298 
299 private:
300  UT_StringHolder myName;
301  UT_StringHolder myDisplayName;
302  UT_StringHolder myMenuLabel;
303  int myMenuPriority;
304  fpreal myDrawComplexityMultiplier;
305  HUSD_DepthStyle myDepthStyle;
306  UT_StringArray myDefaultPurposes;
307  UT_StringArray myRestartRenderSettings;
308  UT_StringArray myRestartCameraSettings;
309  UT_StringArray myRenderViewStats;
310  StatsDataPaths myStatsDataPaths;
311  HuskMetadata myHuskMetadata;
312  UT_StringHolder myHuskStatsMetadata;
313  UT_StringHolder myHuskVerboseScript;
314  fpreal myHuskVerboseInterval;
315  UT_StringArray myPreloadLibraries;
316  bool myIsValid;
317  bool myIsNativeRenderer;
318  bool myNeedsNativeDepthPass;
319  bool myNeedsNativeSelectionPass;
320  bool myAllowBackgroundUpdate;
321  bool myDestroyIfDeactivated;
322  bool myPauseOnUpdate;
323  bool myAovSupport;
324  bool myViewportRenderer;
325  bool myDrawModeSupport;
326  bool myHuskFastExit;
327 };
328 
330 
331 #endif
332 
bool needsNativeDepthPass() const
Parse and provide information from UsdRenderers.json.
const UT_StringHolder & displayName() const
const UT_StringArray & defaultPurposes() const
const UT_StringHolder & name() const
#define HUSD_API
Definition: HUSD_API.h:32
UT_StringMap< HUSD_RendererInfo > HUSD_RendererInfoMap
bool isValid() const
bool destroyIfDeactivated() const
bool drawModeSupport() const
fpreal huskVerboseInterval() const
HUSD_DepthStyle depthStyle() const
bool allowBackgroundUpdate() const
bool isNativeRenderer() const
bool pauseOnUpdate() const
const UT_StringArray & restartRenderSettings() const
fpreal drawComplexityMultiplier() const
bool aovSupport() const
const UT_StringHolder & menuLabel() const
const UT_StringHolder & huskVerboseScript() const
Python script used by husk for verbose callbacks.
GLuint const GLchar * name
Definition: glcorearb.h:786
HUSD_RendererInfo(const UT_StringHolder &name, const UT_StringHolder &displayname, const UT_StringHolder &menulabel, int menupriority, fpreal complexitymultiplier, bool isnative, HUSD_DepthStyle depth_style, const UT_StringArray &defaultpurposes, const UT_StringArray &restartrendersettings, const UT_StringArray &restartcamerasettings, const UT_StringArray &renderstats, const HuskMetadata &husk_metadata, const UT_StringHolder &husk_stats_metadata, const StatsDataPaths &statsdatapaths, const UT_StringHolder &husk_verbose_script, fpreal husk_verbose_interval, const UT_StringArray &preload_libraries, bool needsnativedepth, bool needsnativeselection, bool allowbackgroundupdate, bool destroyifdeactivated, bool pauseonupdate, bool aovsupport, bool viewportrenderer, bool drawmodesupport, bool husk_fastexit)
A map of string to various well defined value types.
Definition: UT_Options.h:84
const UT_StringArray & renderViewStats() const
bool needsNativeSelectionPass() const
int menuPriority() const
fpreal64 fpreal
Definition: SYS_Types.h:277
const HuskMetadata & huskMetadata() const
bool huskFastExit() const
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
bool viewportRenderer() const
HUSD_DepthStyle
const StatsDataPaths & statsDataPaths() const
const UT_StringHolder & huskStatsMetadata() const
const UT_StringArray & restartCameraSettings() const