OpenCL 中的 image2d_t 和 image2d_array_t 有什么区别?

What is the difference between image2d_t and image2d_array_t in OpenCL?

OpenCL 中的 image2d_t 和 image2d_array_t 数据类型有什么区别? 我在规范中找不到太多信息。

image2d_t 是特定格式和大小的平面二维图像。如果 cl_khr_mipmap_image 扩展可用 (https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_khr_mipmap_image.html),它也可能包含 mipmap 级别。

image2d_array_t 是一组大小和类型都相同的图像。查看 https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_image_desc.html 以了解如何创建此类图像数组。从这个页面:

Note that reading and writing 2D image arrays from a kernel with image_array_size = 1 may be lower performance than 2D images.

所以你应该只在需要的时候使用图像数组。

请参阅 https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/read_imagef2d.html 了解如何从内核访问 image2d_timage2d_array_t。对于图像数组,所需图像的索引将位于 z 纹理坐标中。对于 image2d_timage2d_array_t,mipmap 级别被指定为 read_image()lod 参数。

如果您需要将可变数量的图像传递给内核,图像数组很有用,即在 run-time 处决定,因为在您的内核中,您可以查询 [=12= 中有多少图像] 和 get_image_array_size(),例如假设您想对图像数组中的所有图像进行平均。

它们对于从内核中索引图像也很有用,例如根据内核中计算的局部图像统计信息选择边缘锐化蒙版(存储在图像数组中)。

在硬件方面,image2d_array_t 通常比 image3d_t 更快并且得到更广泛的支持。但是,image2d_array_t 无法(自动)在 之间 阵列图像进行采样,而 image3d_t 可以在部分 z 位置进行采样。