kwes
kwes

Reputation: 71

OpenCL - Pass image2d_t twice to get both read and write from kernel?

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

Answers (1)

Roman Arzumanyan
Roman Arzumanyan

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

Related Questions