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