OpenGL Compute Shader Invocations

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:38:15

You have your barriers on backwards. It's a common problem.

The bits you give to the barrier describe how you intend to use the data written, not how the data was written. GL_SHADER_STORAGE_BARRIER_BIT would only be appropriate if you had some process that wrote to a buffer object via image load/store (or a storage buffer/atomic counters), then used a storage buffer to read that buffer object data.

Since you're reading the buffer as a vertex attribute array buffer, you should use the cleverly titled, GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT.

I resolved the problem. The problem was just the number of work-groups I dispatched. numParticles/WORK_GROUP_SIZE will be round off because both variables are integers. That caused too little dispatched work-groups with different numbers of particles.

When I got 1000 particles, then only 1000/128 = 7 work-groups are dispatched. Every work-group has the size of 128. That means I get 7*128 = 896 threads and thus 104 particles won't move at all. Since numParticles%128 may range from 0...128 I just dispatched one more work-group:

glDispatchCompute((_numParticles/WORK_GROUP_SIZE)+1, 1, 1);

And every particle moves from now on. :)

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