OpenCL:内核从 INT_16 图像中读取插值

OpenCL : kernel read interpolated value from a INT_16 image

我正在使用一个以 INT_16 图像作为输入的内核。

我尝试使用用 CLK_FILTER_LINEAR.

声明的采样器从此图像读取插值

我使用 read_imagei 方法得到了正确的值:例如,如果我在“200”像素和“300”像素之间读取,我得到“ 220" 结果(取决于读取坐标)

现在我尝试使用 read_imagef 值进行阅读以获得更精确的值:

在这里,我可以读取与以前相同的值(使用 read_imagei)。

但我从来没有得到像“220.56”或“220.76”这样的值,我总是得到四舍五入的值。 就像使用 INT_16 寄存器而不是浮点寄存器计算 GPU 上的内部插值一样。

我在 OpenCL 规范中没有看到关于 INT_16 值之间的插值计算方式的任何内容。

问题:

使用 CL_SNORM_INT16[=46 中的 read_imagef 时,总是得到舍入值而不是浮点值是否正常=] 使用 CLK_FILTER_LINEAR 模式采样的图像?

(我需要使用INT_16图像来限制内存使用,但我希望插值结果具有浮点精度)

是的,此行为符合 OpenCL 规范,但在不同的实现中可能有所不同。规范的相关部分是 Addressing and Filter Modes 末尾的注释,其中还包括获得所需行为的解决方法:

For all other sampler combinations of normalized or unnormalized coordinates, filter and addressing modes, the relative error or precision of the addressing mode calculations and the image filter operation are not defined by this revision of the OpenCL specification. To ensure a minimum precision of image addressing and filter calculations across any OpenCL device, for these sampler combinations, developers should unnormalize the image coordinate in the kernel and implement the linear filter in the kernel with appropriate calls to read_image{f|i|ui} with a sampler that uses unnormalized coordinates, filter mode set to CLK_FILTER_NEAREST, addressing mode set to CLK_ADDRESS_NONE, CLK_ADDRESS_CLAMP_TO_EDGE or CLK_ADDRESS_CLAMP, and finally performing the interpolation of color values read from the image to generate the filtered color value.