在我的OpenCL代码中(不是我自己编写的,这只是来自Internet的示例代码),下面的句子使用了钳位功能。

return clamp(color,0,1);

但是,这似乎在编译过程中产生了错误,因此我通过使用clGetProgramBuildInfo中的CL_PROGRAM_BUILD_LOG得到了错误信息消息。
Error during compilation! (-11)
4483
build log
:211:9: error: call to 'clamp' is ambiguous
        return clamp(color,0,1);
               ^~~~~
<built-in>:3558:26: note: candidate function
float4  __OVERLOADABLE__ clamp(float4 x, float min, float max)   ;
                         ^
<built-in>:3577:25: note: candidate function
float4 __OVERLOADABLE__ clamp(float4, float4, float4);
                        ^
<built-in>:3556:26: note: candidate function
float3  __OVERLOADABLE__ clamp(float3 x, float min, float max)   ;
                         ^
<built-in>:3575:25: note: candidate function
float3 __OVERLOADABLE__ clamp(float3, float3, float3);
                        ^
:296:52: error: address expression must be an lvalue or a function designator
                                r.origin = matrixVectorMultiply(viewTransform, &(float3)(0, 0, -1));
                                                                               ^~~~~~~~~~~~~~~~~~
:297:62: error: address expression must be an lvalue or a function designator
                                r.dir    = normalize(matrixVectorMultiply(viewTransform, &(float3)(x, y, 0)) - r.origin);
                                                                                         ^~~~~~~~~~~~~~~~~

在OpenCL代码中使用钳位功能是否有必要的关键字?顺便说一句,我正在使用Linux Ubuntu 10.04 64bit的环境。

最佳答案

尝试以下

return clamp(color,0.0f,1.0f);

这样,我们可以确定第二和第三参数不是模棱两可的,并且您正在尝试调用该函数:
clamp(float4 color, float min, float max);

如果这不起作用,请查看您的颜色参数,但是现在第二和第三参数应该可以了。

关于c++ - 在OpenCL代码中使用钳位功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11985173/

10-12 00:24
查看更多