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