OpenGL Compute shader sync different work groups

时光毁灭记忆、已成空白 提交于 2019-12-24 01:19:52

问题


If you have a compute shader where different work groups in the same dispatch are put in a continuous loop and you want to signal them all to exit said loop by any of them setting a flag. Is this actually possible?

I've tried using a flag in an SSBO marked both coherent and volatile to trigger their exit. Which sometimes doesn't work on AMD it seems. When one of the work groups wants to trigger all of them to exit I simply set the flag from zero to one directly (as it doesn't matter as long as someone sets it) with no use of atomics and call a memoryBarrier() afterwards.

From the documentation of memoryBarrier() it seems to me like it will guarantee the eventual visibility of the set to other work groups within the same dispatch?


回答1:


From the documentation of memoryBarrier() it seems to me like it will guarantee the eventual visibility of the set to other work groups within the same dispatch?

Visibility, yes. But what about the execution of them?

Do you have any guarantees that the work group that will trigger this shutdown will be executed alongside the looping work groups? No.

There are no ordering guarantees at all between invocations from different work groups. So it is entirely possible that the GPU will fill all of its execution time with the looping work groups. Which means that they will wait for a signal that will never come.

Compute shaders offer no guarantees that all threads will progress. And therefore, you cannot write code that assumes they will. The only tool to control the execution of compute shaders is barrier, and that only controls the execution of invocations within a work group.



来源:https://stackoverflow.com/questions/39139989/opengl-compute-shader-sync-different-work-groups

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