我想在多个计算着色器 中使用imageStore
和imageLoad
。
这与屏幕或帧缓冲区的“正常”渲染命令 (glDraw) 混合,但这些不使用 imageStore
或 imageLoad
(仅 texture
或 texelFetch
)。
我只有一个 OpenGL 上下文和线程。
我的假设如下:
- 在执行
imageStore
时,我需要在稍后的计算着色器或texture
中执行imageLoad
之前执行glMemoryBarrier
code> 或texelFetch
在后面的片段着色器中。 - 我根本不需要使用
coherent
。 - 我根本不需要使用
glSync
。 - 在使用帧缓冲区写入纹理然后使用
imageLoad
读取它之后,我不需要使用glMemoryBarrier
- OpenGL 将按照请求的顺序运行计算着色器和“正常”绘制操作。假设我在调用之间使用
glMemoryBarrier
,则没有“线程问题”。
它们正确吗?
最佳答案
除了一个“可能”的异常(exception):
I don't need to use
coherent
at all.
您可能需要 coherent
,这取决于您的计算着色器正在做什么。如果您的计算着色器写入图像,然后从另一个写入的数据中读取 invocation within the same dispatch ,那么你需要 coherent
。因此,如果您执行 imageStore
,发出计算着色器 barrier()
调用,然后执行 imageLoad
以读取其他 invocation的值,那么您需要 coherent
限定词。
coherent
是为了确保 visibility within a rendering command (CS 分派(dispatch)在 OpenGL 中被视为“渲染命令”)。如果您不需要内部可见性,那么您就不需要 coherent
。
我想详细说明一下,因为这是一个常见的混淆来源:
I don't need to use
glMemoryBarrier
after writing to a texture using a framebuffer and then reading it withimageLoad
这是绝对正确的。内存屏障是关于确保不连贯写入内存的可见性(和同步)。渲染到帧缓冲区不是不连贯的写入。因此,您可以对此类数据使用 imageLoad
,而无需显式同步。
当然假设你不是rendering to that framebuffer in the same operation you're imageLoad
ing from it .该规则仍然适用。
关于c++ - 与计算着色器和 imageStore 的内存一致性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34069961/