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