HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_VexResolver.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VEX_VexResolver.h ( VEX Library, C++)
7  *
8  * COMMENTS: A class with virtual functions for getting VEX code from
9  * Vop networks. See VOPNET_VexResolver for the real
10  * implementation.
11  */
12 
13 #ifndef __VEX_VexResolver__
14 #define __VEX_VexResolver__
15 
16 #include "VEX_API.h"
17 #include "VEX_VexTypes.h"
18 
19 #include <UT/UT_String.h>
20 #include <UT/UT_StringArray.h>
21 #include <UT/UT_ValArray.h>
22 
23 #include <iosfwd>
24 #include <time.h>
25 
26 class VEX_VexResolver;
27 class VEX_ErrorLog;
28 class DEP_MicroNode;
30 
31 
33 
34 /// @{
35 /// Check whether this line marks the beginning of a compiled VEX shader
40 /// @}
41 
42 /// Check whether this line marks the end of a compiled VEX shader
43 bool VEX_API VEXisVexCodeEndMarker(const UT_String &str);
45 
47 {
48 public:
49  static bool needsVexResolver(const char *shader);
50  static bool needsVexResolverForMantraOutput(const char *shader);
51  static bool getVflCode(const char *shader, std::ostream &os,
52  VEX_CodeGenFlags code_flags = VEX_CG_DEFAULT,
53  int context_type = 0,
54  VEX_ErrorLog *errors = nullptr);
55 
56  /// Obtains an object (vex) shader code in os for the given shader name
57  /// and for the given context type.
58  /// If provided, pure_compiled_out will be true for shaders from
59  /// fully compiled code-only operators or HDAs.
60  /// If provided, warnings_or_errors will be filled with messages; if
61  /// no issues were encountered it will be empty; if there are warnings
62  /// it will contain them (but the method will return true); if there are
63  /// errors it will contain them and the method will return false.
64  /// Returns true if a valid vex code has been obtained (though, note
65  /// there may still be some warnings in the outgoing argument).
66  /// Returns false if vex could not be obtained.
67  static bool getVexCode(const char *shader, std::ostream &os,
68  VEX_CodeGenFlags code_flags = VEX_CG_DEFAULT,
69  int context_type = 0,
70  bool *is_pure_compiled_out = nullptr,
71  VEX_ErrorLog *errors = nullptr);
72 
73  /// Returns a list of shaders that the given shader depends on. This is
74  /// usually a list of encapsulated shaders that can be shared among multiple
75  /// shader instances.
76  static bool getDependencies(const char *shader,
77  UT_StringArray &shader_dependencies,
78  int context_type = 0);
79 
80  /// Marks a given micronode as dependent on our code. It will be
81  /// dirtied whenever the generating VOPs change.
82  static bool addDependency(const char *shader,
83  DEP_MicroNode *depmicronode);
84 
85  // Returns an integer that can be used to check whether code has
86  // changed since it was last resolved, without fetching the code. If
87  // an identical value is returned, the code is unchanged. If the code
88  // does not exist, a value of -1 is returned.
89  static time_t getCodeTimeStamp(const char *shader,
90  int context_type = 0);
91 
92  static void getEmptyVexCode(const char *shader, std::ostream &os);
93  static bool getVexContext(const char *shader, UT_String &ctx,
94  int requested_context_type = 0,
95  VEX_ErrorLog *errors = nullptr);
96 
97  /// Resolvers may support relative paths in the shader string. Sometimes,
98  /// however, you'll want to use the shader string as an identifier. For
99  /// example, you might want to cache the resolved result. To safely do so
100  /// you'll need a canonical string with the relative paths resolved. This
101  /// method performs this conversion, returning true and setting the output
102  /// string only when some resolution had to be performed.
103  static bool convertToCanonicalPath(const char *shader,
104  UT_String &canonical_shader);
105 
106  /// Resolves the alias to a proper shader name.
107  /// Sometimes, a shader may be referred to using its function name as alias
108  /// rather than operator name as is the convention for resolving code.
109  static bool convertAlias(const char *alias, UT_String &shader);
110 
111  /// Resolves the shader & adds it to the cache, returning true
112  /// if successfully cached.
113  static bool cacheVexCode(const char *shader, int context_type = 0,
114  VEX_ErrorLog *errors = nullptr);
115 
116 protected:
117  VEX_VexResolver();
118  virtual ~VEX_VexResolver();
119 
120  virtual bool canResolveCode(const char *shader) const = 0;
121 
122  /// Returns true when mantra is able to independently retrieve the VEX
123  /// shader code without requiring it to be embedded in the ifd.
124  virtual bool supportedByMantra(const char *shader) const = 0;
125 
126  virtual bool resolveVflCode(const char *shader,
127  std::ostream &os,
128  VEX_CodeGenFlags code_flags,
129  int context_type) const = 0;
130 
131  /// See comments for getVexCode().
132  virtual bool resolveVexCode(const char *shader,
133  std::ostream &os,
134  VEX_CodeGenFlags code_flags,
135  int context_type,
136  bool& is_pure_compiled_out,
137  VEX_ErrorLog &errors) const = 0;
138  virtual bool resolveCacheVexCode(const char *shader,
139  int context_type,
140  VEX_ErrorLog &errors) const = 0;
141  virtual bool resolveDependencies(const char *shader,
142  UT_StringArray &shader_deps,
143  int context_type) const = 0;
144  /// Marks a given micronode as dependent on our code. It will be
145  /// dirtied whenever the generating VOPs change.
146  virtual bool resolveAddDependency(const char *shader,
147  DEP_MicroNode *depmicronode) const = 0;
148 
149 
150  virtual time_t resolveCodeTimeStamp(const char *shader,
151  int context_type) const = 0;
152  virtual bool resolveVexContext(const char *shader,
153  UT_String &ctx,
154  int requested_context_type) const = 0;
155  virtual bool resolveCanonicalPath(const char *shader,
156  UT_String &canonical_shader) const = 0;
157  virtual bool resolveAlias(const char *alias,
158  UT_String &shader) const = 0;
159 
160 private:
161  static void addVexResolver(VEX_VexResolver *resolver);
162  static void removeVexResolver(VEX_VexResolver *resolver);
163  static VEX_VexResolverArray &getVexResolvers();
164  static VEX_VexResolver *getVexResolver(const char *shader);
165 };
166 
167 #endif
168 
169 
bool VEX_API VEXisVexCodeBeginMarker(const UT_String &str)
#define VEX_API
Definition: VEX_API.h:14
bool VEX_API VEXstartsWithVexCodeBeginMarker(const UT_String &str)
A utility class to do read-only operations on a subset of an existing string.
Definition: UT_StringView.h:40
UT_ValArray< VEX_VexResolver * > VEX_VexResolverArray
bool VEX_API VEXisVexCodeEndMarker(const UT_String &str)
Check whether this line marks the end of a compiled VEX shader.
GLuint shader
Definition: glcorearb.h:785
VEX_CodeGenFlags
VEX code generation flags when calling VEX_VexResolver::getVflCode.
Definition: VEX_VexTypes.h:138