Reputation: 71
In my OpenCL kernel I would like to both read and write to an image2d_t object. According to OpenCL standard I can only specify either __read_only or __write_only. However, I figured if I send the same cl_mem as two separate kernel arguments (one with __read_only and one with __write_only) I can do both.
Probably when I do a write followed by a read, I might get the old value(?) but in my case I would like the old value first, update it and write it back to the image. A simple example would be "increment each pixel by 1". It looks like it works in 99.9% but gives me artifacts sometimes.
Does anybody know if this is possible at all or if I have to expect undefined behaviour?
Upvotes: 4
Views: 2391
Reputation: 1814
According to OpenCL standard, one Image can be used either for reading, or for writing within one kernel. So, if you need to read-write into same memory object, you have to use 2 Images, or switch to regular Buffer. No guarantee can be made that your kernel will work fine.
Upvotes: 4