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