11 #ifndef __CE_SnippetKernelBind__
12 #define __CE_SnippetKernelBind__
22 template <CE_Precision PREC,
typename OP>
38 template <
typename OP>
50 for (
auto && binding : bindings)
58 UT_ASSERT(!
"This should have been handled");
61 ok &= setKernelArgument<CE_16, OP>(binding, p, kernel, argidx,
buffers, timestep, error, missingseverity, op);
64 ok &= setKernelArgument<CE_32, OP>(binding, p, kernel, argidx,
buffers, timestep, error, missingseverity, op);
67 ok &= setKernelArgument<CE_64, OP>(binding, p, kernel, argidx,
buffers, timestep, error, missingseverity, op);
80 int pidx,
const char *
type,
83 template <
typename TYPE>
86 const char *
name,
const char *
type,
int pidx,
88 const char *extra = 0)
92 kernel.
setArg( argidx, tuplesize *
sizeof(TYPE), val);
106 const char *extra = 0)
107 {
bindKernelArgRaw(&val, 1, kernel, argidx, name,
"int", pidx, error, extra); }
110 const char *extra = 0)
111 {
bindKernelArgRaw(val, 2, kernel, argidx, name,
"int2", pidx, error, extra); }
114 const char *extra = 0)
115 {
bindKernelArgRaw(&val, 1, kernel, argidx, name,
"float", pidx, error, extra); }
118 const char *extra = 0)
119 {
bindKernelArgRaw(val, 2, kernel, argidx, name,
"float2", pidx, error, extra); }
123 const char *extra = 0)
124 {
bindKernelArgRaw(val, 4, kernel, argidx, name,
"float3", pidx, error, extra); }
127 const char *extra = 0)
128 {
bindKernelArgRaw(val, 4, kernel, argidx, name,
"float4", pidx, error, extra); }
131 const char *extra = 0)
132 {
bindKernelArgRaw(val, 16, kernel, argidx, name,
"float16", pidx, error, extra); }
134 const char *
name,
int pidx,
const char *
type,
136 const char *extra = 0)
140 kernel.
setArg( argidx, val);
151 template <CE_Precision PREC,
typename OP>
176 paramtype = binding.
type;
183 param_int = binding.
intval;
185 kernel, argidx, binding.
name,
"int", p, error);
191 const int tuplesize = 1;
194 array.
entries(array_size * tuplesize);
197 for (
int i = 0; i <
n; i++)
200 const size_t array_data_size = array_size * tuplesize *
sizeof(
CEintH<PREC> );
204 array_buffer = clcontext->
allocBuffer(array_data_size);
208 buffers.
append(array_buffer);
219 param_float = binding.
fval;
227 param_float *= timestep;
230 param_float /= timestep;
233 param_float = SYSexp( param_float * timestep );
240 kernel, argidx, binding.
name,
"float", p, error);
246 param_float2 = binding.
v2val;
247 param_fpreal_array[0] = param_float2(0);
248 param_fpreal_array[1] = param_float2(1);
251 kernel, argidx, binding.
name,
"float2", p, error);
256 param_float3 = binding.
v3val;
257 param_fpreal_array[0] = param_float3(0);
258 param_fpreal_array[1] = param_float3(1);
259 param_fpreal_array[2] = param_float3(2);
260 param_fpreal_array[3] = 0;
263 kernel, argidx, binding.
name,
"float3", p, error);
268 param_float4 = binding.
v4val;
269 param_fpreal_array[0] = param_float4(0);
270 param_fpreal_array[1] = param_float4(1);
271 param_fpreal_array[2] = param_float4(2);
272 param_fpreal_array[3] = param_float4(3);
274 kernel, argidx, binding.
name,
"float4", p, error);
279 param_float4 = binding.
v4val;
280 param_fpreal_array[0] = param_float4(0);
281 param_fpreal_array[1] = param_float4(1);
282 param_fpreal_array[2] = param_float4(2);
283 param_fpreal_array[3] = param_float4(3);
284 param_float4 = binding.
v4bval;
285 param_fpreal_array[4+0] = param_float4(0);
286 param_fpreal_array[4+1] = param_float4(1);
287 param_fpreal_array[4+2] = param_float4(2);
288 param_fpreal_array[4+3] = param_float4(3);
290 kernel, argidx, binding.
name,
"float8", p, error);
296 for (
int r = 0;
r < 4;
r++)
297 for (
int c = 0;
c < 4;
c++)
298 param_fpreal_array[
r*4+
c] = binding.
m4val(
r,
c);
300 kernel, argidx, binding.
name,
"float8", p, error);
313 ramp_array.
entries(ramp_size * tuplesize);
318 for (
int i = 0; i < ramp_size; i++)
322 binding.
ramp->rampLookup( pos, values );
323 for (
int j = 0;
j < tuplesize;
j++)
324 ramp_array(writepos++) = values[
j];
331 for (
int i = 0; i <
n; i++)
332 ramp_array(i) = binding.
rampdata(i);
333 for (
int i = n; i < ramp_array.
entries(); i++)
341 const size_t ramp_data_size = ramp_size * tuplesize *
sizeof(
CEfloatH<PREC> );
345 buffers.
append(ramp_buffer);
357 if (!op(binding, p, kernel, argidx, error, PREC))
376 if (!op(binding, p, kernel, argidx, error, PREC))
389 if (!isarray && binding.
defval)
394 param_int = binding.
intval;
396 kernel, argidx, binding.
name,
"int", p, error);
398 else if (tuplesize == 2)
400 param_float2 = binding.
v2val;
401 param_fpreal_array[0] = param_float2(0);
402 param_fpreal_array[1] = param_float2(1);
405 kernel, argidx, binding.
name,
"float2", p, error);
407 else if (tuplesize == 3)
410 param_float3 = binding.
v3val;
411 param_fpreal_array[0] = param_float3(0);
412 param_fpreal_array[1] = param_float3(1);
413 param_fpreal_array[2] = param_float3(2);
414 param_fpreal_array[3] = 0;
417 kernel, argidx, binding.
name,
"float3", p, error);
419 else if (tuplesize == 4)
422 param_float4 = binding.
v4val;
423 param_fpreal_array[0] = param_float4(0);
424 param_fpreal_array[1] = param_float4(1);
425 param_fpreal_array[2] = param_float4(2);
426 param_fpreal_array[3] = param_float4(3);
428 kernel, argidx, binding.
name,
"float4", p, error);
433 param_float = binding.
fval;
435 kernel, argidx, binding.
name,
"float", p, error);
451 if (!op(binding, p, kernel, argidx, error, PREC))
458 param_float = binding.
fval;
460 kernel, argidx, binding.
name,
"float", p, error);
467 msg.
sprintf(
"Invalid volume '%s'", (
const char *) binding.
volume);
482 if (!op(binding, p, kernel, argidx, error, PREC))
487 msg.
sprintf(
"Invalid vdb '%s'", (
const char *) binding.
volume);
497 param_float = binding.
fval;
499 kernel, argidx, binding.
name,
"float", p, error);
510 bool defval = binding.
defval;
515 if (!op(binding, p, kernel, argidx, error, PREC))
533 param_int = binding.
intval;
535 kernel, argidx, binding.
name,
"int", p, error);
537 else if (tuplesize == 2)
539 param_float2 = binding.
v2val;
540 param_fpreal_array[0] = param_float2(0);
541 param_fpreal_array[1] = param_float2(1);
544 kernel, argidx, binding.
name,
"float2", p, error);
546 else if (tuplesize == 3)
549 param_float3 = binding.
v3val;
550 param_fpreal_array[0] = param_float3(0);
551 param_fpreal_array[1] = param_float3(1);
552 param_fpreal_array[2] = param_float3(2);
553 param_fpreal_array[3] = 0;
556 kernel, argidx, binding.
name,
"float3", p, error);
558 else if (tuplesize == 4)
561 param_float4 = binding.
v4val;
562 param_fpreal_array[0] = param_float4(0);
563 param_fpreal_array[1] = param_float4(1);
564 param_fpreal_array[2] = param_float4(2);
565 param_fpreal_array[3] = param_float4(3);
567 kernel, argidx, binding.
name,
"float4", p, error);
572 param_float = binding.
fval;
574 kernel, argidx, binding.
name,
"float", p, error);
586 bool defval = binding.
defval;
589 if (!op(binding, p, kernel, argidx, error, PREC))
594 msg.
sprintf(
"Invalid image '%s'", (
const char *) binding.
name);
606 param_int = binding.
intval;
608 kernel, argidx, binding.
name,
"int", p, error);
611 param_float = binding.
fval;
613 kernel, argidx, binding.
name,
"float", p, error);
616 param_fpreal_array[0] = binding.
v2val(0);
617 param_fpreal_array[1] = binding.
v2val(1);
619 kernel, argidx, binding.
name,
"float2", p, error);
622 param_fpreal_array[0] = binding.
v3val(0);
623 param_fpreal_array[1] = binding.
v3val(1);
624 param_fpreal_array[2] = binding.
v3val(2);
625 param_fpreal_array[3] = 0;
627 kernel, argidx, binding.
name,
"float3", p, error);
630 param_fpreal_array[0] = binding.
v4val(0);
631 param_fpreal_array[1] = binding.
v4val(1);
632 param_fpreal_array[2] = binding.
v4val(2);
633 param_fpreal_array[3] = binding.
v4val(3);
635 kernel, argidx, binding.
name,
"float4", p, error);
UT_StringHolder attribute
UT_StringHolder fieldname
void bindKernelArgB(cl::Buffer val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, const char *type, UT_ErrorManager *error, const char *extra=0)
typename CE_PrecisionResolver< P >::host_int_type CEintH
SYS_FORCE_INLINE const char * buffer() const
CE_API void reportSetArgError(const char *name, int argidx, int pidx, const char *type, const char *extra, UT_ErrorManager *error)
Adds an error to the error manager for mis-binding an argument.
void bindKernelArgF(cl_float val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
typename CE_PrecisionResolver< P >::host_float_type CEfloatH
void writeBuffer(const cl::Buffer &buf, size_t size, const void *p, bool blocking=true, size_t offset=0)
Write the specified number of bytes to the buffer.
UT_StringHolder optionname
void bindKernelArgV2(cl_float *val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
bool setKernelArguments(const UT_Array< Binding > &bindings, BindingPrecision nodeprecision, cl::Kernel &kernel, int &argidx, UT_Array< cl::Buffer > &buffers, fpreal timestep, UT_ErrorManager *error, UT_ErrorSeverity missingseverity, const OP &op)
UT_Vector2D UT_Vector3D v3val
bool setKernelArgument(const Binding &binding, int p, cl::Kernel &kernel, int &argidx, UT_Array< cl::Buffer > &buffers, fpreal timestep, UT_ErrorManager *error, UT_ErrorSeverity missingseverity, const OP &op)
}
void bindKernelArgV3(cl_float *val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
NOTE: This binds float4 due to vagaries of cl!
static CE_Context * getContext(bool gl_shared=true, bool shared_fallback=true)
BindingOptionType optiontype
BindingLayerType layertype
GLuint const GLchar * name
UT_SharedPtr< UT_Ramp > ramp
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
GLenum GLint GLint * precision
exint entries() const
Alias of size(). size() is preferred.
void bindKernelArgI(cl_int val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
void bindKernelArgI2(cl_int *val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
BindingAttribType attribtype
GLenum GLsizei GLsizei GLint * values
void bindKernelArgV4(cl_float *val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
A global error manager scope.
void constant(const T &v)
Quickly set the array to a single value.
void bindKernelArgV16(cl_float *val, cl::Kernel &kernel, int &argidx, const char *name, int pidx, UT_ErrorManager *error, const char *extra=0)
cl_int setArg(cl_uint index, T value)
UT_Array< float > rampdata
Kernel interface that implements cl_kernel.
void bindKernelArgRaw(TYPE *val, int tuplesize, cl::Kernel &kernel, int &argidx, const char *name, const char *type, int pidx, UT_ErrorManager *error, const char *extra=0)
cl::Buffer allocBuffer(int64 size, bool usePool=true, bool read=true, bool write=true, uint32 ogl_bind=SYS_UINT32_MAX)
UT_ErrorSeverity addGeneric(const char *type, int code, const char *msg, UT_ErrorSeverity sev, const UT_SourceLocation *loc=0)
BindingTimescale timescale