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  CONTEXT,
68  NUM_TYPES
69  };
71 
72  enum class BindingAttribClass
73  {
74  DETAIL,
75  PRIMITIVE,
76  POINT,
77  VERTEX,
78  DETACHED
79  };
81 
82  enum class BindingAttribType
83  {
84  FLOAT,
85  INT,
86  FLOATARRAY,
87  INTARRAY,
88  STRING,
90  };
92 
93  enum class BindingVDBType
94  {
95  ANY,
96  FLOAT,
97  VECTOR,
98  INT,
99  FLOATN,
100  };
102 
103  enum class BindingPrecision
104  {
105  NODE,
106  _16,
107  _32,
108  _64,
109  };
111 
112  enum class BindingTimescale
113  {
114  NONE,
115  MULT,
116  INVERT,
117  POW,
118  };
120 
121  enum class BindingRampType
122  {
123  FLOAT,
124  VECTOR,
125  };
127 
128  enum class BindingLayerType
129  {
130  INT,
131  FLOAT,
132  FLOAT2,
133  FLOAT3,
134  FLOAT4,
135  FLOATN,
136  };
138 
139  enum class BindingLayerBorder // must be IMX_BorderType + 1!
140  {
141  INPUT,
142  CONSTANT,
143  CLAMP,
144  MIRROR,
145  WRAP,
146  };
148 
149  enum class BindingOptionType
150  {
151  FLOAT,
152  INT,
153  };
155 
157  {
158  FLOAT,
159  INT,
160  };
162 
163  struct Binding
164  {
170  int64 rampsize = 1024;
175  bool fieldoffsets = true;
176  int input = 0;
181  bool forcealign = true;
182  bool resolution = false;
183  bool voxelsize = false;
184  bool xformtoworld = false;
185  bool xformtovoxel = false;
190  bool attribbvh = false;
191  bool attribpointbvh = false;
193  bool attribosd = false;
195  bool readable = true;
196  bool writeable = false;
197  bool optional = false;
198  bool defval = false;
199  bool uipromote = true;
203  UT_Vector2D v2val { 0, 0 };
204  UT_Vector3D v3val { 0, 0, 0 };
205  UT_Vector4D v4val { 0, 0, 0, 0 };
206  UT_Vector4D v4bval { 0, 0, 0, 0 };
207  UT_Matrix4D m4val { 0, 0, 0, 0,
208  0, 0, 0, 0,
209  0, 0, 0, 0,
210  0, 0, 0, 0 };
215  int optionsize = 1;
218  };
219 
220 
221  /// Protect @s that shouldn't be parsed because they are in comments
222  /// or in quotes with ATSAFESTRING
224 
225  /// Expands a path into the matching include file on the search
226  /// path
228  bool searchcwd,
229  UT_ErrorManager *error);
230 
231  /// Loads an import, searching the include path to locate it.
232  CE_API UT_StringHolder loadImport(const char *path, bool searchcwd,
233  UT_ErrorManager *error);
234  /// Expands all #import directives.
236  UT_ErrorManager *error);
237 
238  /// Process all #bind/#runover commands appending to the provided Bindings
239  /// array. Returns the code with the #bind/#runover elided
241  UT_Array<Binding> &bindings,
242  RunOver &runover,
243  UT_ErrorManager *error);
244 
245  /// Returns the kernel code transformed by the bindings, ie, all
246  /// @ commands turned into accessors and the appropriate prequel
247  /// code generated.
248  /// Globals generate @KEY := _bound_VAL
250  RunOver runover,
251  UT_Options *opt,
253  UT_StringMap<UT_StringHolder> *missing_globals,
254  const UT_Array<Binding> &bindings,
255  const char *kernelsig, const char *writebacksig,
256  UT_ErrorManager *error);
257 
258  /// Restore protected @s to be @ again.
260 
261 
262  /// Given an opencl decorated typename break it into type, precision, and size.
263  /// TYPE#[]
264  /// TYPE: half, float, double, fpreal, short, int, long exint
265  /// #: missing means scalar, ? means -1.
266  /// [] optional to flag array.
267  CE_API bool parseType(const UT_StringRef &attribtypename,
268  BindingAttribType &attribtype,
270  int &tuplesize);
271 
272  /// Return a syntax string that is byte-for-byte with code
273  /// describing the state at that point.
274  CE_API UT_StringHolder computeSyntax(const char *code);
275 
276  /// Append into sign the argument signature for a binding
277  CE_API void buildArgumentSign(const Binding &binding,
278  int p, int maxparam,
279  UT_WorkBuffer &sign,
280  UT_StringHolder &firstwriteable,
281  bool &firstwriteable_forced,
282  BindingVDBType &firstvdbtype,
283  bool prefixbound,
284  RunOver runover,
285  bool fieldsarealigned,
286  UT_WorkBuffer &paraminitcode);
287 
288  /// Append into signature the arguments required for the
289  /// runover mode.
291  RunOver runover, bool singleworkgroup,
292  bool filedsarealigned, bool prefixbound);
293 
294  CE_API void addKernelArgument(UT_WorkBuffer &signature,
295  const char * type,
296  const char * name,
297  bool prefixbound);
298 
299  /// Append into sign the code to start the provided runover mode.
301  RunOver runover, BindingVDBType firstvdbtype,
302  bool singleworkgroup, bool fieldsarealigned,
303  bool firstname_forced, bool prefixbound,
304  UT_StringRef firstname);
305 
306 }
307 
308 #endif
#define CE_API
Definition: CE_API.h:13
UT_StringHolder attribute
Definition: CE_Snippet.h:186
UT_StringHolder attribpointbvhmask
Definition: CE_Snippet.h:192
UT_StringHolder fieldname
Definition: CE_Snippet.h:174
UT_StringHolder portname
Definition: CE_Snippet.h:177
CE_API UT_StringHolder computeSyntax(const char *code)
UT_Matrix4D m4val
Definition: CE_Snippet.h:207
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:165
CE_API RunOver stringToRunOver(const char *token)
UT_Vector4D v4val
Definition: CE_Snippet.h:205
UT_StringHolder sval
Definition: CE_Snippet.h:200
UT_Vector4D v4bval
Definition: CE_Snippet.h:206
CE_API const char * bindingAttribClassToString(BindingAttribClass type)
UT_StringHolder optionname
Definition: CE_Snippet.h:213
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:204
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
BindingOptionType optiontype
Definition: CE_Snippet.h:214
UT_StringHolder geometry
Definition: CE_Snippet.h:179
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:172
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.
BindingContextType contexttype
Definition: CE_Snippet.h:217
CE_API const char * bindingContextTypeToString(BindingContextType type)
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:167
BindingAttribClass attribclass
Definition: CE_Snippet.h:187
CE_API void addKernelArgument(UT_WorkBuffer &signature, const char *type, const char *name, bool prefixbound)
BindingLayerBorder layerborder
Definition: CE_Snippet.h:173
BindingRampType ramptype
Definition: CE_Snippet.h:169
GLenum GLint GLint * precision
Definition: glcorearb.h:1925
A map of string to various well defined value types.
Definition: UT_Options.h:87
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:188
UT_StringHolder dataname
Definition: CE_Snippet.h:212
UT_Array< int > intarray
Definition: CE_Snippet.h:171
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:203
BindingAttribClass
Definition: CE_Snippet.h:72
UT_Array< float > rampdata
Definition: CE_Snippet.h:168
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:178
BindingVDBType vdbtype
Definition: CE_Snippet.h:180
CE_API const char * bindingLayerTypeToString(BindingLayerType type)
BindingTimescale timescale
Definition: CE_Snippet.h:211
UT_StringHolder contextname
Definition: CE_Snippet.h:216
CE_API const char * runoverToString(RunOver runover)
CE_API const char * bindingTimescaleToString(BindingTimescale type)