Vulkan icon indicating copy to clipboard operation
Vulkan copied to clipboard

nbody: Control barrier in non-uniform control flow

Open msiglreith opened this issue 7 years ago • 2 comments

The N-body example uses a control barrier which might not be reached by all executed: https://github.com/SaschaWillems/Vulkan/blob/master/data/shaders/computenbody/particle_calculate.comp#L60

The early return here will result in possible divergence further on with potential stalls.

msiglreith avatar Feb 23 '18 17:02 msiglreith

might be worth examining SPIR-V glslang generated code versus disassembled DXBC in case the shader compiles fine to DXBC(blob) with D3DCompiler API.. anyway just a question: do you know if D3D12 spec more strict in that regard vs Vulkan spec regarding control barriers in non unif. control flow? I mean this sample works ok on a lot of Vulkan drivers (implementations)..

oscarbg avatar Mar 07 '18 06:03 oscarbg

d3d compiler is more strict here compared to SPIR-V which allows it. In practice, no divergence will occur as the example is crafted in such a way that the number of particles is a multiple of the group size. Therefore, it's soley a restriction by my d3d12 wrapper. A possible workaround would be to move the discard statement down after the control barrier.

msiglreith avatar Mar 07 '18 13:03 msiglreith