简体   繁体   English

OpenCL - 两次传递image2d_t以获取内核的读写权限?

[英]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. 在我的OpenCL内核中,我想读写一个image2d_t对象。 According to OpenCL standard I can only specify either __read_only or __write_only. 根据OpenCL标准,我只能指定__read_only或__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. 但是,我想如果我发送相同的cl_mem作为两个单独的内核参数(一个用__read_only,一个用__write_only)我可以做两个。

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". 一个简单的例子是“将每个像素增加1”。 It looks like it works in 99.9% but gives me artifacts sometimes. 它看起来像99.9%,但有时给我文物。

Does anybody know if this is possible at all or if I have to expect undefined behaviour? 有人知道这是否可行或者我是否需要预期未定义的行为?

According to OpenCL standard, one Image can be used either for reading, or for writing within one kernel. 根据OpenCL标准,一个Image可用于读取或在一个内核中写入。 So, if you need to read-write into same memory object, you have to use 2 Images, or switch to regular Buffer. 因此,如果需要读写同一个内存对象,则必须使用2个图像,或切换到常规缓冲区。 No guarantee can be made that your kernel will work fine. 不能保证你的内核能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM