Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

particle_sort_local

A sprite emitter's whole back-to-front sort in one dispatch, for a population of up to 2048 live particles. One workgroup of 256 threads, once per frame the emitter sorts and its live particles fit.

The threads walk every slot, give each live particle its depth key (particle_sort_depth) and gather it into workgroup memory as one word: the key in the high bits and the slot in the low sortlocal[0] bits. A bitonic network sorts those words, sized to the next power of two at or above the live count, so the population comes out ordered by key and, inside one key, by slot: the same total order the radix path (particle_sort_key, three gpuSort passes per eight bits of key, particle_sort_indices) produces.

The sorted words are written out as the emitter's index buffer. Run n takes the two triangles of the n-th particle, and every run past the live count is six copies of index 0, so the buffer holds exactly what the radix path leaves. Only the runs between this write's live count and sortlocal[1] (the runs the previous write may have left holding triangles) are cleared, so the write costs the live population rather than the emitter's capacity.

An emitter takes this path when the slot and the key fit one 32-bit word together and its live count is at most 2048; past that, the radix path orders it.

Bindings

SlotAccessContents
particlesreadThe emitter's particle state, 16 f32 per slot.
paramsreadThe emitter's parameter block: the camera position.
out_indicesread_writeThe emitter's index buffer, six indices per slot.
sortviewread[0] slot count, [1] bucket count, [2] near, [3] far.
sortlocalread_write[0] slot bits, [1] runs that may hold triangles, [2] live particles found.

Dispatch exactly one workgroup.