Accessing binding in functions in OpenCL

   496   3   2
User Avatar
Member
11 posts
Joined: 1月 2023
Offline
I have noticed that you cannot access bindings from your parms or @Time, for example, inside a function you write outside for an OpenCL kernel. Does anyone know why? Is there a way to pass binding to functions in OpenCL

For example
#bind layer src? val=0
#bind layer !&dst
#bind parm someParm float val=0

void returnMyParm()
{
    return @someParm;
}

@KERNEL
{
returnMyParm();    
@dst.set(@src);
}


the resulting error
1 error generated.
OpenCL Exception: <kernel>:3020:12: error: use of undeclared identifier '_bound_someParm'
    return AT_someParm;
           ^
<kernel>:3009:21: note: expanded from macro 'AT_someParm'
#define AT_someParm     _bound_someParm
                        ^
clBuildProgram (-11)
User Avatar
Member
193 posts
Joined: 2月 2016
Offline
You'll need to pass the parm in as a function argument.
Either by making it a float function:
float returnMyParm(float parm)
{
    return parm;
}

@KERNEL
{
    float foo = returnMyParm(@someParm);
    @dst.set(foo);
}

Or modifying a variable "inplace": (no idea if this is efficient)
void modifyVar(float* in, float parm)
{
    *in = parm;
}

@KERNEL
{
    float foo = 0.0f;
    modifyVar(&foo, @someParm);
    @dst.set(foo);
}
Edited by AslakKS - 2025年2月7日 15:36:18
User Avatar
Member
9078 posts
Joined: 7月 2007
Online
While I'm not that familiar with OpenCL snippets, I'd assume it's the same as in VEX, where you need to pass those values as function arguments from the main body of the shader

since the snippet syntax is not part of the language
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
11 posts
Joined: 1月 2023
Offline
Thank you both very much. I think my example was a bit misleading. I guess what I am referring to is that in Openl CL, global and parameter bindings are only accessible within the scope of the Kernal. And functions have to be defined outside of the kernel, so you cannot access binding in the scope of the function. For example, I cannot pass @Time to a function I write, not as a function argument. It does make sense in the end.
  • Quick Links