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_NonCopyable.h>
20 #include <UT/UT_String.h>
21 #include <UT/UT_StringArray.h>
22 #include <UT/UT_ValArray.h>
23 
24 #include <iosfwd>
25 #include <time.h>
26 
27 class VEX_VexResolver;
28 class VEX_ErrorLog;
29 class DEP_MicroNode;
31 
32 
34 
35 /// @{
36 /// Check whether this line marks the beginning of a compiled VEX shader
41 /// @}
42 
43 /// Check whether this line marks the end of a compiled VEX shader
44 bool VEX_API VEXisVexCodeEndMarker(const UT_String &str);
46 
48 {
49 public:
50  static bool needsVexResolver(const char *shader);
51  static bool needsVexResolverForMantraOutput(const char *shader);
52  static bool getVflCode(const char *shader, std::ostream &os,
53  VEX_CodeGenFlags code_flags = VEX_CG_DEFAULT,
54  int context_type = 0,
55  VEX_ErrorLog *errors = nullptr);
56 
57  /// Obtains an object (vex) shader code in os for the given shader name
58  /// and for the given context type.
59  /// If provided, pure_compiled_out will be true for shaders from
60  /// fully compiled code-only operators or HDAs.
61  /// If provided, warnings_or_errors will be filled with messages; if
62  /// no issues were encountered it will be empty; if there are warnings
63  /// it will contain them (but the method will return true); if there are
64  /// errors it will contain them and the method will return false.
65  /// Returns true if a valid vex code has been obtained (though, note
66  /// there may still be some warnings in the outgoing argument).
67  /// Returns false if vex could not be obtained.
68  static bool getVexCode(const char *shader, std::ostream &os,
69  VEX_CodeGenFlags code_flags = VEX_CG_DEFAULT,
70  int context_type = 0,
71  bool *is_pure_compiled_out = nullptr,
72  VEX_ErrorLog *errors = nullptr);
73 
74  /// Returns a list of shaders that the given shader depends on. This is
75  /// usually a list of encapsulated shaders that can be shared among multiple
76  /// shader instances.
77  static bool getDependencies(const char *shader,
78  UT_StringArray &shader_dependencies,
79  int context_type = 0);
80 
81  /// Marks a given micronode as dependent on our code. It will be
82  /// dirtied whenever the generating VOPs change.
83  static bool addDependency(const char *shader,
84  DEP_MicroNode *depmicronode);
85 
86  // Returns an integer that can be used to check whether code has
87  // changed since it was last resolved, without fetching the code. If
88  // an identical value is returned, the code is unchanged. If the code
89  // does not exist, a value of -1 is returned.
90  static time_t getCodeTimeStamp(const char *shader,
91  int context_type = 0);
92 
93  static void getEmptyVexCode(const char *shader, std::ostream &os);
94  static bool getVexContext(const char *shader, UT_String &ctx,
95  int requested_context_type = 0,
96  VEX_ErrorLog *errors = nullptr);
97 
98  /// Resolvers may support relative paths in the shader string. Sometimes,
99  /// however, you'll want to use the shader string as an identifier. For
100  /// example, you might want to cache the resolved result. To safely do so
101  /// you'll need a canonical string with the relative paths resolved. This
102  /// method performs this conversion, returning true and setting the output
103  /// string only when some resolution had to be performed.
104  static bool convertToCanonicalPath(const char *shader,
105  UT_String &canonical_shader);
106 
107  /// Resolves the alias to a proper shader name.
108  /// Sometimes, a shader may be referred to using its function name as alias
109  /// rather than operator name as is the convention for resolving code.
110  static bool convertAlias(const char *alias, UT_String &shader);
111 
112  /// Resolves the shader & adds it to the cache, returning true
113  /// if successfully cached.
114  static bool cacheVexCode(const char *shader, int context_type = 0,
115  VEX_ErrorLog *errors = nullptr);
116 
117 protected:
118  VEX_VexResolver();
119  virtual ~VEX_VexResolver();
120 
122 
123  virtual bool canResolveCode(const char *shader) const = 0;
124 
125  /// Returns true when mantra is able to independently retrieve the VEX
126  /// shader code without requiring it to be embedded in the ifd.
127  virtual bool supportedByMantra(const char *shader) const = 0;
128 
129  virtual bool resolveVflCode(const char *shader,
130  std::ostream &os,
131  VEX_CodeGenFlags code_flags,
132  int context_type) const = 0;
133 
134  /// See comments for getVexCode().
135  virtual bool resolveVexCode(const char *shader,
136  std::ostream &os,
137  VEX_CodeGenFlags code_flags,
138  int context_type,
139  bool& is_pure_compiled_out,
140  VEX_ErrorLog &errors) const = 0;
141  virtual bool resolveCacheVexCode(const char *shader,
142  int context_type,
143  VEX_ErrorLog &errors) const = 0;
144  virtual bool resolveDependencies(const char *shader,
145  UT_StringArray &shader_deps,
146  int context_type) const = 0;
147  /// Marks a given micronode as dependent on our code. It will be
148  /// dirtied whenever the generating VOPs change.
149  virtual bool resolveAddDependency(const char *shader,
150  DEP_MicroNode *depmicronode) const = 0;
151 
152 
153  virtual time_t resolveCodeTimeStamp(const char *shader,
154  int context_type) const = 0;
155  virtual bool resolveVexContext(const char *shader,
156  UT_String &ctx,
157  int requested_context_type) const = 0;
158  virtual bool resolveCanonicalPath(const char *shader,
159  UT_String &canonical_shader) const = 0;
160  virtual bool resolveAlias(const char *alias,
161  UT_String &shader) const = 0;
162 
163 private:
164  static void addVexResolver(VEX_VexResolver *resolver);
165  static void removeVexResolver(VEX_VexResolver *resolver);
166  static VEX_VexResolverArray &getVexResolvers();
167  static VEX_VexResolver *getVexResolver(const char *shader);
168 };
169 
170 #endif
171 
172 
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:39
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
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