Reputation: 1268
I am trying to do OpenCL/OpenGL interop using an OpenGL texture as described at this Intel tutorial. I want to keep my host code as simple as possible, so I wanted to go with "Method 1", thus creating an OpenCL image from an OpenGL texture with clCreateFromGLTexture
. The tutorial also states the following:
Note the CL_MEM_WRITE_ONLY flag that allows fast discarding of the data. Use CL_MEM_READ_WRITE if your kernel requires reading the current texture context. Also, remove the _write_only qualifier for the image access in the kernel in that case.
However, this does not seem to work. As soon as I remove __write_only
from the kernel, I get a compile error, using platform Nvidia OpenCL 1.2 CUDA 10.0.132 (driver 417.71):
Error: Invalid image type in sust.
Whatever that means. Using the platform Intel OpenCL 2.1 UHD Graphics 620 (driver 24.20.100.6286) I get the following:
CTHeader.h:1333:38: note: candidate function not viable: no known conversion from 'read_only image2d_t' to '__write_only image1d_array_t' for 1st argument void __attribute((overloadable)) write_imagef(write_only image1d_array_t image_array, int2 coord, float4 color);
Seems like image2D_t defaults to __read_only
?
Anyways, I found that the specification clearly states that what is proposed in the tutorial is not supported, at least not using image objects:
read_image and write_image calls to the same image memory object in a kernel are not supported
So I am wondering, since the tutorial does not go into detail in how to set up the kernel argument, maybe using image2d_t
is wrong in the first place. Since the argument is of type cu_mem
at host side, I tried around with float*
, but without success so far.
I realize I could do double buffering or go with other methods like using a PBO for interop, but as I said, I want to keep things as simple as possible, plus I'm just wondering why that is. Any ideas?
Upvotes: 1
Views: 581
Reputation: 6343
A kernel image parameter must be qualified with __write_only
or __read_only
, up to OpenCL 2.0, which allows images to be __read_write
but special rules must be followed (such as barriers) to get correct results. Note that an image also has qualifier which indicate how the host may access it (read only, write only, or read/write). A given image may be __write_only
in one kernel and then __read_only
in the next, which allows for the results of one kernel to feed into the next.
Upvotes: 2