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