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  FLOAT,
47  FLOAT2,
48  FLOAT3,
49  FLOAT4,
50  FLOAT8,
51  FLOAT16,
52  FIELD_S,
53  FIELD_V,
54  FIELD_M,
55  RAMP,
56  ATTRIBUTE,
57  VOLUME,
58  VDB,
59  OPTION,
60  LAYER,
61  NUM_TYPES
62  };
64 
65  enum class BindingAttribClass
66  {
67  DETAIL,
68  PRIMITIVE,
69  POINT,
70  VERTEX,
71  };
73 
74  enum class BindingAttribType
75  {
76  FLOAT,
77  INT,
78  FLOATARRAY,
79  INTARRAY,
80  };
82 
83  enum class BindingVDBType
84  {
85  ANY,
86  FLOAT,
87  VECTOR,
88  };
90 
91  enum class BindingPrecision
92  {
93  NODE,
94  _16,
95  _32,
96  _64,
97  };
99 
100  enum class BindingTimescale
101  {
102  NONE,
103  MULT,
104  INVERT,
105  POW,
106  };
108 
109  enum class BindingRampType
110  {
111  FLOAT,
112  VECTOR,
113  };
115 
116  enum class BindingLayerType
117  {
118  INPUT,
119  FLOAT,
120  FLOAT2,
121  FLOAT3,
122  FLOAT4,
123  INT,
124  };
126 
127  enum class BindingLayerBorder // must be IMX_BorderType + 1!
128  {
129  INPUT,
130  CONSTANT,
131  CLAMP,
132  MIRROR,
133  WRAP,
134  };
136 
137  enum class BindingOptionType
138  {
139  FLOAT,
140  INT,
141  };
143 
144  struct Binding
145  {
149  mutable const fpreal32* rampdata = nullptr;
151  int64 rampsize = 1024;
155  bool fieldoffsets = true;
156  int input = 0;
160  bool forcealign = true;
161  bool resolution = false;
162  bool voxelsize = false;
163  bool xformtoworld = false;
164  bool xformtovoxel = false;
170  bool readable = true;
171  bool writeable = false;
172  bool optional = false;
173  bool defval = false;
176  UT_Vector2D v2val { 0, 0 };
177  UT_Vector3D v3val { 0, 0, 0 };
178  UT_Vector4D v4val { 0, 0, 0, 0 };
179  UT_Vector4D v4bval { 0, 0, 0, 0 };
180  UT_Matrix4D m4val { 0, 0, 0, 0,
181  0, 0, 0, 0,
182  0, 0, 0, 0,
183  0, 0, 0, 0 };
188  int optionsize = 1;
189  };
190 
191 
192  /// Protect @s that shouldn't be parsed because they are in comments
193  /// or in quotes with ATSAFESTRING
195 
196 
197  /// Process all @BIND commands appending to the provided Bindings
198  /// array. Returns the code with the @BIND elided
200  UT_Array<Binding> &bindings,
201  UT_ErrorManager *error);
202 
203  /// Returns the kernel code transformed by the bindings, ie, all
204  /// @ commands turned into accessors and the appropriate prequel
205  /// code generated.
206  /// Globals generate @KEY := _bound_VAL
208  RunOver runover,
209  UT_Options *opt,
211  UT_StringMap<UT_StringHolder> *missing_globals,
212  const UT_Array<Binding> &bindings,
213  const char *kernelsig, const char *writebacksig,
214  UT_ErrorManager *error);
215 
216  /// Restore protected @s to be @ again.
218 
219 
220  /// Given an opencl decorated typename break it into type, precision, and size.
221  /// TYPE#[]
222  /// TYPE: half, float, double, fpreal, short, int, long exint
223  /// #: missing means scalar, ? means -1.
224  /// [] optional to flag array.
225  CE_API bool parseType(const UT_StringRef &attribtypename,
226  BindingAttribType &attribtype,
228  int &tuplesize);
229 
230  constexpr const char *ATSAFESTRING = "!_safe_at_string_!";
231  constexpr const char *BOUNDPREFIX = "_bound_";
232  constexpr const char *AUTOPREFIX = "_auto_";
233  constexpr char SYNTAX_COMMENT = '/';
234  constexpr char SYNTAX_NORMAL = ' ';
235  constexpr char SYNTAX_QUOTE = '"';
236  constexpr char SYNTAX_REF = '#';
237 
238  /// Return a syntax string that is byte-for-byte with code
239  /// describing the state at that point.
240  CE_API UT_StringHolder computeSyntax(const char *code);
241 
242  /// Append into sign the argument signature for a binding
243  CE_API void buildArgumentSign(const Binding &binding,
244  int p, int maxparam,
246  UT_StringHolder &firstwriteable,
247  bool &firstwriteable_forced,
248  BindingVDBType &firstvdbtype,
249  bool prefixbound,
250  RunOver runover,
251  bool fieldsarealigned,
252  UT_WorkBuffer &paraminitcode);
253 
254  /// Append into signature the arguments required for the
255  /// runover mode.
257  RunOver runover, bool singleworkgroup,
258  bool filedsarealigned,
259  const char *bound);
260 
261  /// Append into sign the code to start the provided runover mode.
263  RunOver runover, BindingVDBType firstvdbtype,
264  bool singleworkgroup, bool fieldsarealigned,
265  bool firstname_forced,
266  const char *bound, UT_StringRef firstname);
267 
268 }
269 
270 #endif
#define CE_API
Definition: CE_API.h:10
UT_StringHolder attribute
Definition: CE_Snippet.h:165
UT_StringHolder fieldname
Definition: CE_Snippet.h:154
constexpr const char * BOUNDPREFIX
Definition: CE_Snippet.h:231
constexpr char SYNTAX_REF
Definition: CE_Snippet.h:236
CE_API UT_StringHolder computeSyntax(const char *code)
UT_Matrix4D m4val
Definition: CE_Snippet.h:180
CE_API const char * bindingLayerBorderToString(BindingLayerBorder type)
CE_API void buildKernelRunOverArguments(UT_WorkBuffer &signature, RunOver runover, bool singleworkgroup, bool filedsarealigned, const char *bound)
CE_API bool parseType(const UT_StringRef &attribtypename, BindingAttribType &attribtype, BindingPrecision &precision, int &tuplesize)
UT_StringHolder name
Definition: CE_Snippet.h:146
UT_Vector4D v4val
Definition: CE_Snippet.h:178
float fpreal32
Definition: SYS_Types.h:200
UT_Vector4D v4bval
Definition: CE_Snippet.h:179
CE_API const char * bindingAttribClassToString(BindingAttribClass type)
UT_StringHolder optionname
Definition: CE_Snippet.h:186
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:177
BindingOptionType optiontype
Definition: CE_Snippet.h:187
UT_StringHolder geometry
Definition: CE_Snippet.h:158
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
const fpreal32 * rampdata
Definition: CE_Snippet.h:149
CE_API const char * bindingAttribTypeToString(BindingAttribType type)
BindingLayerType layertype
Definition: CE_Snippet.h:152
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRef(const UT_StringRef &ref)
Convert a UT_StringRef into a UT_StringHolder that is a shallow reference.
constexpr const char * AUTOPREFIX
Definition: CE_Snippet.h:232
CE_API UT_StringHolder restoreAts(UT_StringHolder code)
Restore protected to be @ again.
constexpr const char * ATSAFESTRING
Definition: CE_Snippet.h:230
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.
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
Definition: ImathFun.h:33
UT_SharedPtr< UT_Ramp > ramp
Definition: CE_Snippet.h:148
BindingAttribClass attribclass
Definition: CE_Snippet.h:166
BindingLayerBorder layerborder
Definition: CE_Snippet.h:153
BindingRampType ramptype
Definition: CE_Snippet.h:150
GLenum GLint GLint * precision
Definition: glcorearb.h:1925
constexpr char SYNTAX_NORMAL
Definition: CE_Snippet.h:234
A map of string to various well defined value types.
Definition: UT_Options.h:84
CE_API const char * bindingOptionTypeToString(BindingOptionType type)
BindingAttribType attribtype
Definition: CE_Snippet.h:167
UT_StringHolder dataname
Definition: CE_Snippet.h:185
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)
constexpr char SYNTAX_QUOTE
Definition: CE_Snippet.h:235
A global error manager scope.
constexpr char SYNTAX_COMMENT
Definition: CE_Snippet.h:233
UT_Vector2D v2val
Definition: CE_Snippet.h:176
BindingAttribClass
Definition: CE_Snippet.h:65
CE_API const char * bindingTypeToString(BindingType type)
CE_API const char * bindingPrecisionToString(BindingPrecision type)
type
Definition: core.h:1059
CE_API void buildKernelRunOverCode(UT_WorkBuffer &signature, RunOver runover, BindingVDBType firstvdbtype, bool singleworkgroup, bool fieldsarealigned, bool firstname_forced, const char *bound, UT_StringRef firstname)
Append into sign the code to start the provided runover mode.
CE_API const char * bindingRampTypeToString(BindingRampType type)
UT_StringHolder volume
Definition: CE_Snippet.h:157
BindingVDBType vdbtype
Definition: CE_Snippet.h:159
CE_API const char * bindingLayerTypeToString(BindingLayerType type)
BindingTimescale timescale
Definition: CE_Snippet.h:184
CE_API const char * bindingTimescaleToString(BindingTimescale type)