将支持的图像/纹理内存格式信息转换为opencl中的可读字符串

时间:2014-05-29 17:29:22

标签: textures opencl gpu amd-processor

我想获得设备支持的图像格式。 但是opencl函数在cl_image_format中返回结果。 我想知道字符串中的结果。

目前我正在使用以下代码:

cl_uint uiNumSupportedFormats = 0;

// 2D
clGetSupportedImageFormats((cl_context)image.clCxt->oclContext(),
                           CL_MEM_WRITE_ONLY,
                           CL_MEM_OBJECT_IMAGE2D,
                           NULL, NULL, &uiNumSupportedFormats);

cl_image_format* ImageFormats = new cl_image_format[uiNumSupportedFormats];
clGetSupportedImageFormats((cl_context)image.clCxt->oclContext(),
                           CL_MEM_WRITE_ONLY,
                           CL_MEM_OBJECT_IMAGE2D,
                           uiNumSupportedFormats, ImageFormats, NULL);

for(unsigned int i = 0; i < uiNumSupportedFormats; i++)
{

    cout<<ImageFormats[i].image_channel_order<<endl;

    cout<<ImageFormats[i].image_channel_data_type<<endl;

}

delete [] ImageFormats;

现在我只获得整数值。如何获得相应的字符串值?例如:CL_RA CL_UNORM_INT8

我正在使用AMD GPU设备。

1 个答案:

答案 0 :(得分:3)

没有OpenCL标准方法来获取这些常量(或任何其他常量)的字符串表示形式,因此您必须自己编写或使用一些为您执行此操作的实用程序。你可以写下自己的“人类可读”字样,这是非常好的。图像格式的打印方法。你可以这样做:

void printImageFormat(cl_image_format format)
{
#define CASE(order) case order: cout << #order; break;
  switch (format.image_channel_order)
  {
    CASE(CL_R);
    CASE(CL_A);
    CASE(CL_RG);
    CASE(CL_RA);
    CASE(CL_RGB);
    CASE(CL_RGBA);
    CASE(CL_BGRA);
    CASE(CL_ARGB);
    CASE(CL_INTENSITY);
    CASE(CL_LUMINANCE);
    CASE(CL_Rx);
    CASE(CL_RGx);
    CASE(CL_RGBx);
    CASE(CL_DEPTH);
    CASE(CL_DEPTH_STENCIL);
  }
#undef CASE

  cout << " - ";

#define CASE(type) case type: cout << #type; break;
  switch (format.image_channel_data_type)
  {
    CASE(CL_SNORM_INT8);
    CASE(CL_SNORM_INT16);
    CASE(CL_UNORM_INT8);
    CASE(CL_UNORM_INT16);
    CASE(CL_UNORM_SHORT_565);
    CASE(CL_UNORM_SHORT_555);
    CASE(CL_UNORM_INT_101010);
    CASE(CL_SIGNED_INT8);
    CASE(CL_SIGNED_INT16);
    CASE(CL_SIGNED_INT32);
    CASE(CL_UNSIGNED_INT8);
    CASE(CL_UNSIGNED_INT16);
    CASE(CL_UNSIGNED_INT32);
    CASE(CL_HALF_FLOAT);
    CASE(CL_FLOAT);
    CASE(CL_UNORM_INT24);
  }
#undef CASE

  cout << endl;
}

然后在现有循环中调用printImageFormat(ImageFormats[i]);