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