HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CE_Snippet.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: CE_Snippet.h ( CE Library, C++)
7  *
8  * COMMENTS: Snippet manipulation for OpenCL
9  */
10 
11 #ifndef __CE_Snippet__
12 #define __CE_Snippet__
13 
14 #include "CE_API.h"
15 #include "CE_Precision.h"
16 
17 #include <UT/UT_String.h>
18 #include <UT/UT_StringHolder.h>
19 #include <UT/UT_Vector3.h>
20 #include <UT/UT_Vector4.h>
21 #include <UT/UT_Array.h>
22 #include <UT/UT_SharedPtr.h>
23 #include <UT/UT_StringMap.h>
24 #include <UT/UT_Ramp.h>
25 #include <UT/UT_Error.h>
26 
27 class UT_ErrorManager;
28 class UT_Options;
29 
30 namespace CE_Snippet
31 {
32  enum class RunOver
33  {
34  ATTRIBUTE = 0,
35  VOLUME,
36  WORKSETS,
37  FIELDS,
38  VDB,
39  LAYER
40  };
41 
42  enum class BindingType
43  {
44  INVALID = -1,
45  INT,
46  INTARRAY,
47  FLOAT,
48  FLOAT2,
49  FLOAT3,
50  FLOAT4,
51  FLOAT8,
52  FLOAT16,
53  FIELD_S,
54  FIELD_V,
55  FIELD_M,
56  RAMP,
57  ATTRIBUTE,
58  VOLUME,
59  VDB,
60  OPTION,
61  LAYER,
62  NUM_TYPES
63  };
65 
66  enum class BindingAttribClass
67  {
68  DETAIL,
69  PRIMITIVE,
70  POINT,
71  VERTEX,
72  };
74 
75  enum class BindingAttribType
76  {
77  FLOAT,
78  INT,
79  FLOATARRAY,
80  INTARRAY,
81  };
83 
84  enum class BindingVDBType
85  {
86  ANY,
87  FLOAT,
88  VECTOR,
89  };
91 
92  enum class BindingPrecision
93  {
94  NODE,
95  _16,
96  _32,
97  _64,
98  };
100 
101  enum class BindingTimescale
102  {
103  NONE,
104  MULT,
105  INVERT,
106  POW,
107  };
109 
110  enum class BindingRampType
111  {
112  FLOAT,
113  VECTOR,
114  };
116 
117  enum class BindingLayerType
118  {
119  INT,
120  FLOAT,
121  FLOAT2,
122  FLOAT3,
123  FLOAT4,
124  FLOATN,
125  };
127 
128  enum class BindingLayerBorder // must be IMX_BorderType + 1!
129  {
130  INPUT,
131  CONSTANT,
132  CLAMP,
133  MIRROR,
134  WRAP,
135  };
137 
138  enum class BindingOptionType
139  {
140  FLOAT,
141  INT,
142  };
144 
145  struct Binding
146  {
152  int64 rampsize = 1024;
157  bool fieldoffsets = true;
158  int input = 0;
163  bool forcealign = true;
164  bool resolution = false;
165  bool voxelsize = false;
166  bool xformtoworld = false;
167  bool xformtovoxel = false;
173  bool readable = true;
174  bool writeable = false;
175  bool optional = false;
176  bool defval = false;
179  UT_Vector2D v2val { 0, 0 };
180  UT_Vector3D v3val { 0, 0, 0 };
181  UT_Vector4D v4val { 0, 0, 0, 0 };
182  UT_Vector4D v4bval { 0, 0, 0, 0 };
183  UT_Matrix4D m4val { 0, 0, 0, 0,
184  0, 0, 0, 0,
185  0, 0, 0, 0,
186  0, 0, 0, 0 };
191  int optionsize = 1;
192  };
193 
194 
195  /// Protect @s that shouldn't be parsed because they are in comments
196  /// or in quotes with ATSAFESTRING
198 
199  /// Expands a path into the matching include file on the search
200  /// path
202  bool searchcwd,
203  UT_ErrorManager *error);
204 
205  /// Loads an import, searching the include path to locate it.
206  CE_API UT_StringHolder loadImport(const char *path, bool searchcwd,
207  UT_ErrorManager *error);
208  /// Expands all #import directives.
210  UT_ErrorManager *error);
211 
212  /// Process all @BIND commands appending to the provided Bindings
213  /// array. Returns the code with the @BIND elided
215  UT_Array<Binding> &bindings,
216  UT_ErrorManager *error);
217 
218  /// Returns the kernel code transformed by the bindings, ie, all
219  /// @ commands turned into accessors and the appropriate prequel
220  /// code generated.
221  /// Globals generate @KEY := _bound_VAL
223  RunOver runover,
224  UT_Options *opt,
226  UT_StringMap<UT_StringHolder> *missing_globals,
227  const UT_Array<Binding> &bindings,
228  const char *kernelsig, const char *writebacksig,
229  UT_ErrorManager *error);
230 
231  /// Restore protected @s to be @ again.
233 
234 
235  /// Given an opencl decorated typename break it into type, precision, and size.
236  /// TYPE#[]
237  /// TYPE: half, float, double, fpreal, short, int, long exint
238  /// #: missing means scalar, ? means -1.
239  /// [] optional to flag array.
240  CE_API bool parseType(const UT_StringRef &attribtypename,
241  BindingAttribType &attribtype,
243  int &tuplesize);
244 
245  /// Return a syntax string that is byte-for-byte with code
246  /// describing the state at that point.
247  CE_API UT_StringHolder computeSyntax(const char *code);
248 
249  /// Append into sign the argument signature for a binding
250  CE_API void buildArgumentSign(const Binding &binding,
251  int p, int maxparam,
253  UT_StringHolder &firstwriteable,
254  bool &firstwriteable_forced,
255  BindingVDBType &firstvdbtype,
256  bool prefixbound,
257  RunOver runover,
258  bool fieldsarealigned,
259  UT_WorkBuffer &paraminitcode);
260 
261  /// Append into signature the arguments required for the
262  /// runover mode.
264  RunOver runover, bool singleworkgroup,
265  bool filedsarealigned, bool prefixbound);
266 
267  CE_API void addKernelArgument(UT_WorkBuffer &signature,
268  const char * type,
269  const char * name,
270  bool prefixbound);
271 
272  /// Append into sign the code to start the provided runover mode.
274  RunOver runover, BindingVDBType firstvdbtype,
275  bool singleworkgroup, bool fieldsarealigned,
276  bool firstname_forced, bool prefixbound,
277  UT_StringRef firstname);
278 
279 }
280 
281 #endif
#define CE_API
Definition: CE_API.h:11
UT_StringHolder attribute
Definition: CE_Snippet.h:168
UT_StringHolder fieldname
Definition: CE_Snippet.h:156
UT_StringHolder portname
Definition: CE_Snippet.h:159
CE_API UT_StringHolder computeSyntax(const char *code)
UT_Matrix4D m4val
Definition: CE_Snippet.h:183
CE_API UT_StringHolder loadImport(const char *path, bool searchcwd, UT_ErrorManager *error)
Loads an import, searching the include path to locate it.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
CE_API const char * bindingLayerBorderToString(BindingLayerBorder type)
CE_API UT_StringHolder findIncludeFile(const char *path, bool searchcwd, UT_ErrorManager *error)
CE_API bool parseType(const UT_StringRef &attribtypename, BindingAttribType &attribtype, BindingPrecision &precision, int &tuplesize)
UT_StringHolder name
Definition: CE_Snippet.h:147
UT_Vector4D v4val
Definition: CE_Snippet.h:181
UT_Vector4D v4bval
Definition: CE_Snippet.h:182
CE_API const char * bindingAttribClassToString(BindingAttribClass type)
UT_StringHolder optionname
Definition: CE_Snippet.h:189
CE_API UT_StringHolder expandImportDirectives(UT_StringHolder code, UT_ErrorManager *error)
Expands all #import directives.
CE_API UT_StringHolder protectAts(UT_StringHolder code)
double fpreal64
Definition: SYS_Types.h:201
CE_API const char * bindingVDBTypeToString(BindingVDBType type)
UT_Vector2D UT_Vector3D v3val
Definition: CE_Snippet.h:180
BindingOptionType optiontype
Definition: CE_Snippet.h:190
UT_StringHolder geometry
Definition: CE_Snippet.h:161
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
CE_API const char * bindingAttribTypeToString(BindingAttribType type)
BindingLayerType layertype
Definition: CE_Snippet.h:154
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRef(const UT_StringRef &ref)
Convert a UT_StringRef into a UT_StringHolder that is a shallow reference.
CE_API UT_StringHolder restoreAts(UT_StringHolder code)
Restore protected to be @ again.
long long int64
Definition: SYS_Types.h:116
CE_API void buildArgumentSign(const Binding &binding, int p, int maxparam, UT_WorkBuffer &sign, UT_StringHolder &firstwriteable, bool &firstwriteable_forced, BindingVDBType &firstvdbtype, bool prefixbound, RunOver runover, bool fieldsarealigned, UT_WorkBuffer &paraminitcode)
Append into sign the argument signature for a binding.
GLuint const GLchar * name
Definition: glcorearb.h:786
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
Definition: ImathFun.h:33
UT_SharedPtr< UT_Ramp > ramp
Definition: CE_Snippet.h:149
BindingAttribClass attribclass
Definition: CE_Snippet.h:169
CE_API void addKernelArgument(UT_WorkBuffer &signature, const char *type, const char *name, bool prefixbound)
BindingLayerBorder layerborder
Definition: CE_Snippet.h:155
BindingRampType ramptype
Definition: CE_Snippet.h:151
GLenum GLint GLint * precision
Definition: glcorearb.h:1925
A map of string to various well defined value types.
Definition: UT_Options.h:84
CE_API const char * bindingOptionTypeToString(BindingOptionType type)
CE_API void buildKernelRunOverCode(UT_WorkBuffer &signature, RunOver runover, BindingVDBType firstvdbtype, bool singleworkgroup, bool fieldsarealigned, bool firstname_forced, bool prefixbound, UT_StringRef firstname)
Append into sign the code to start the provided runover mode.
BindingAttribType attribtype
Definition: CE_Snippet.h:170
UT_StringHolder dataname
Definition: CE_Snippet.h:188
UT_Array< int > intarray
Definition: CE_Snippet.h:153
CE_API UT_StringHolder extractBindings(UT_StringHolder code, UT_Array< Binding > &bindings, UT_ErrorManager *error)
CE_API UT_StringHolder generateAtCode(UT_StringHolder code, RunOver runover, UT_Options *opt, UT_StringMap< UT_StringHolder > *globals, UT_StringMap< UT_StringHolder > *missing_globals, const UT_Array< Binding > &bindings, const char *kernelsig, const char *writebacksig, UT_ErrorManager *error)
A global error manager scope.
CE_API void buildKernelRunOverArguments(UT_WorkBuffer &signature, RunOver runover, bool singleworkgroup, bool filedsarealigned, bool prefixbound)
UT_Vector2D v2val
Definition: CE_Snippet.h:179
BindingAttribClass
Definition: CE_Snippet.h:66
UT_Array< float > rampdata
Definition: CE_Snippet.h:150
CE_API const char * bindingTypeToString(BindingType type)
CE_API const char * bindingPrecisionToString(BindingPrecision type)
type
Definition: core.h:1059
CE_API const char * bindingRampTypeToString(BindingRampType type)
UT_StringHolder volume
Definition: CE_Snippet.h:160
BindingVDBType vdbtype
Definition: CE_Snippet.h:162
CE_API const char * bindingLayerTypeToString(BindingLayerType type)
BindingTimescale timescale
Definition: CE_Snippet.h:187
CE_API const char * bindingTimescaleToString(BindingTimescale type)