set image format

Hi forum,

i have defined and allocated memory for a float2 data type as follows:


    typedef cl_float2 cData;

    hvfield = (cData*)malloc(sizeof(cData) * DS);

    memset(hvfield,0,sizeof(cData) * DS);

    dvfield = clCreateBuffer(cxGPUContext,CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,sizeof(cData) * DS,hvfield, &ciErrNum);
    oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);


    vxfield = clCreateBuffer(cxGPUContext,CL_MEM_READ_WRITE,sizeof(cData) * PDS,NULL,&ciErrNum);
    oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);

    vyfield = clCreateBuffer(cxGPUContext,CL_MEM_READ_WRITE,sizeof(cData) * PDS,NULL,&ciErrNum);
    oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);

Then i want to create a image buffer that that points to the linear device memory by dvfield. But i do not understand how to define the image format for the 2D texture(the code with ???) :


cl_mem initTexture(int width,int height)
{
   cl_int ciErrNum;

   cl_image_format image_format;
   image_format.image_channel_order = CL_RGBA;
   image_format.image_channel_data_type = ?????;

   cl_mem imageTexture = clCreateImage2D(cxGPUContext,CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
					 &image_format,width,height,width * sizeof(cData),dvfield,
					 &ciErrNum);
   oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);

   return imageTexture;
}

Any idea?

Regards
Sajjad

Unextended OpenCL doesn’t have a mechanism to share device memory between a buffer and an image. You need to refer to the cl_khr_image2d_from_buffer extension in the OpenCL 1.2 extensions specification.

Hi

Will it be possible to create an empty image object where host ptr is null and then later copy the contents of the linear buffer to the image object ?

In case of empty image object what should be the data type for the image format?

Regards
Sajjad