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  INVALID = -1,
35  ATTRIBUTE = 0,
36  VOLUME,
37  WORKSETS,
38  FIELDS,
39  VDB,
40  LAYER
41  };
42  CE_API const char *runoverToString(RunOver runover);
43  CE_API RunOver stringToRunOver(const char *token);
44 
45  enum class BindingType
46  {
47  INVALID = -1,
48  INT,
49  INTARRAY,
50  FLOAT,
51  FLOAT2,
52  FLOAT3,
53  FLOAT4,
54  FLOAT8,
55  FLOAT16,
56  STRING,
57  FIELD_S,
58  FIELD_V,
59  FIELD_M,
60  RAMP,
61  ATTRIBUTE,
62  VOLUME,
63  VDB,
64  OPTION,
65  LAYER,
66  GEO,
67  NUM_TYPES
68  };
70 
71  enum class BindingAttribClass
72  {
73  DETAIL,
74  PRIMITIVE,
75  POINT,
76  VERTEX,
77  };
79 
80  enum class BindingAttribType
81  {
82  FLOAT,
83  INT,
84  FLOATARRAY,
85  INTARRAY,
86  STRING,
88  };
90 
91  enum class BindingVDBType
92  {
93  ANY,
94  FLOAT,
95  VECTOR,
96  INT,
97  FLOATN,
98  };
100 
101  enum class BindingPrecision
102  {
103  NODE,
104  _16,
105  _32,
106  _64,
107  };
109 
110  enum class BindingTimescale
111  {
112  NONE,
113  MULT,
114  INVERT,
115  POW,
116  };
118 
119  enum class BindingRampType
120  {
121  FLOAT,
122  VECTOR,
123  };
125 
126  enum class BindingLayerType
127  {
128  INT,
129  FLOAT,
130  FLOAT2,
131  FLOAT3,
132  FLOAT4,
133  FLOATN,
134  };
136 
137  enum class BindingLayerBorder // must be IMX_BorderType + 1!
138  {
139  INPUT,
140  CONSTANT,
141  CLAMP,
142  MIRROR,
143  WRAP,
144  };
146 
147  enum class BindingOptionType
148  {
149  FLOAT,
150  INT,
151  };
153 
154  struct Binding
155  {
161  int64 rampsize = 1024;
166  bool fieldoffsets = true;
167  int input = 0;
172  bool forcealign = true;
173  bool resolution = false;
174  bool voxelsize = false;
175  bool xformtoworld = false;
176  bool xformtovoxel = false;
182  bool readable = true;
183  bool writeable = false;
184  bool optional = false;
185  bool defval = false;
189  UT_Vector2D v2val { 0, 0 };
190  UT_Vector3D v3val { 0, 0, 0 };
191  UT_Vector4D v4val { 0, 0, 0, 0 };
192  UT_Vector4D v4bval { 0, 0, 0, 0 };
193  UT_Matrix4D m4val { 0, 0, 0, 0,
194  0, 0, 0, 0,
195  0, 0, 0, 0,
196  0, 0, 0, 0 };
201  int optionsize = 1;
202  };
203 
204 
205  /// Protect @s that shouldn't be parsed because they are in comments
206  /// or in quotes with ATSAFESTRING
208 
209  /// Expands a path into the matching include file on the search
210  /// path
212  bool searchcwd,
213  UT_ErrorManager *error);
214 
215  /// Loads an import, searching the include path to locate it.
216  CE_API UT_StringHolder loadImport(const char *path, bool searchcwd,
217  UT_ErrorManager *error);
218  /// Expands all #import directives.
220  UT_ErrorManager *error);
221 
222  /// Process all #bind/#runover commands appending to the provided Bindings
223  /// array. Returns the code with the #bind/#runover elided
225  UT_Array<Binding> &bindings,
226  RunOver &runover,
227  UT_ErrorManager *error);
228 
229  /// Returns the kernel code transformed by the bindings, ie, all
230  /// @ commands turned into accessors and the appropriate prequel
231  /// code generated.
232  /// Globals generate @KEY := _bound_VAL
234  RunOver runover,
235  UT_Options *opt,
237  UT_StringMap<UT_StringHolder> *missing_globals,
238  const UT_Array<Binding> &bindings,
239  const char *kernelsig, const char *writebacksig,
240  UT_ErrorManager *error);
241 
242  /// Restore protected @s to be @ again.
244 
245 
246  /// Given an opencl decorated typename break it into type, precision, and size.
247  /// TYPE#[]
248  /// TYPE: half, float, double, fpreal, short, int, long exint
249  /// #: missing means scalar, ? means -1.
250  /// [] optional to flag array.
251  CE_API bool parseType(const UT_StringRef &attribtypename,
252  BindingAttribType &attribtype,
254  int &tuplesize);
255 
256  /// Return a syntax string that is byte-for-byte with code
257  /// describing the state at that point.
258  CE_API UT_StringHolder computeSyntax(const char *code);
259 
260  /// Append into sign the argument signature for a binding
261  CE_API void buildArgumentSign(const Binding &binding,
262  int p, int maxparam,
263  UT_WorkBuffer &sign,
264  UT_StringHolder &firstwriteable,
265  bool &firstwriteable_forced,
266  BindingVDBType &firstvdbtype,
267  bool prefixbound,
268  RunOver runover,
269  bool fieldsarealigned,
270  UT_WorkBuffer &paraminitcode);
271 
272  /// Append into signature the arguments required for the
273  /// runover mode.
275  RunOver runover, bool singleworkgroup,
276  bool filedsarealigned, bool prefixbound);
277 
278  CE_API void addKernelArgument(UT_WorkBuffer &signature,
279  const char * type,
280  const char * name,
281  bool prefixbound);
282 
283  /// Append into sign the code to start the provided runover mode.
285  RunOver runover, BindingVDBType firstvdbtype,
286  bool singleworkgroup, bool fieldsarealigned,
287  bool firstname_forced, bool prefixbound,
288  UT_StringRef firstname);
289 
290 }
291 
292 #endif
#define CE_API
Definition: CE_API.h:13
UT_StringHolder attribute
Definition: CE_Snippet.h:177
UT_StringHolder fieldname
Definition: CE_Snippet.h:165
UT_StringHolder portname
Definition: CE_Snippet.h:168
CE_API UT_StringHolder computeSyntax(const char *code)
UT_Matrix4D m4val
Definition: CE_Snippet.h:193
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:156
CE_API RunOver stringToRunOver(const char *token)
UT_Vector4D v4val
Definition: CE_Snippet.h:191
UT_StringHolder sval
Definition: CE_Snippet.h:186
UT_Vector4D v4bval
Definition: CE_Snippet.h:192
CE_API const char * bindingAttribClassToString(BindingAttribClass type)
UT_StringHolder optionname
Definition: CE_Snippet.h:199
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:190
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
BindingOptionType optiontype
Definition: CE_Snippet.h:200
UT_StringHolder geometry
Definition: CE_Snippet.h:170
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:163
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.
CE_API UT_StringHolder extractBindings(UT_StringHolder code, UT_Array< Binding > &bindings, RunOver &runover, UT_ErrorManager *error)
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_SharedPtr< UT_Ramp > ramp
Definition: CE_Snippet.h:158
BindingAttribClass attribclass
Definition: CE_Snippet.h:178
CE_API void addKernelArgument(UT_WorkBuffer &signature, const char *type, const char *name, bool prefixbound)
BindingLayerBorder layerborder
Definition: CE_Snippet.h:164
BindingRampType ramptype
Definition: CE_Snippet.h:160
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:179
UT_StringHolder dataname
Definition: CE_Snippet.h:198
UT_Array< int > intarray
Definition: CE_Snippet.h:162
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:189
BindingAttribClass
Definition: CE_Snippet.h:71
UT_Array< float > rampdata
Definition: CE_Snippet.h:159
CE_API const char * bindingTypeToString(BindingType type)
CE_API const char * bindingPrecisionToString(BindingPrecision type)
CE_API const char * bindingRampTypeToString(BindingRampType type)
UT_StringHolder volume
Definition: CE_Snippet.h:169
BindingVDBType vdbtype
Definition: CE_Snippet.h:171
CE_API const char * bindingLayerTypeToString(BindingLayerType type)
BindingTimescale timescale
Definition: CE_Snippet.h:197
CE_API const char * runoverToString(RunOver runover)
CE_API const char * bindingTimescaleToString(BindingTimescale type)