Vulkan icon indicating copy to clipboard operation
Vulkan copied to clipboard

Compute cull and lod: `idx == 0` may not ensures that uboOut.drawCount will be cleared as the first invocation?

Open wumo opened this issue 3 years ago • 1 comments

In the example of compute cull and lod, the uboOut.drawCount is initialized to 0 by the shader of idx == 0 as the code shows:

https://github.com/SaschaWillems/Vulkan/blob/9c029b36fa9e2504af9e978c888193e6e59c82f0/data/shaders/glsl/computecullandlod/cull.comp#L81-L91

But I think there are maybe other invocations of the shader running in parallel and are scheduled a little bit faster so that atomicAdd(uboOut.drawCount, 1) is executed before atomicExchange(uboOut.drawCount, 0). So as to ensure uboOut.drawCount is initialized to 0 before increment, we may need to call vkCmdFillBuffer in the commandbuffer.

wumo avatar Jul 31 '20 10:07 wumo

That may be right. I'll check and add a vkCmdFillBuffer.

SaschaWillems avatar Aug 23 '20 16:08 SaschaWillems

I have removed the shader code and the buffer is now cleared using vkCmdFillBuffer.

SaschaWillems avatar Dec 31 '22 15:12 SaschaWillems