mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-11-06 13:28:17 +00:00
The bitonic sort needed a 64 KiB shared buffer, more than some devices have, and for larger slices sorted in place in an unqualified buffer with a memoryBarrierBuffer() after the barrier, which under the Vulkan memory model does not make the writes visible to other invocations. It also takes log2(N)^2/2 barriers, 91 for the UHD slices, and a slice of millions of pixels times out the GPU. Replace it with an LSD radix sort, 4 bits per pass, between the pairs region of a plane and a scratch region. Each subgroup owns a block of rows of elements, one per lane, and ranks them with ballots from the digit counts of the blocks, which take up to 16 KiB of shared memory. The bitmaps of the planes now follow the pairs of all planes, as the setup shader only fills them once the sort is done, so their region serves as the scratch and the buffer keeps its size. At UHD with the default slicing on an RX 6900 XT, the sort of a frame goes from 14 ms to 3.4 ms.