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

有些话、适合烂在心里 提交于 2019-12-07 15:26:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25114580/opencl-pass-image2d-t-twice-to-get-both-read-and-write-from-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!