Ruben Osorio @osor.io · Jan 1

Oh! Also worth mentioning. In this sort of system you'll see a lot of contention when writing to shared counters. It's a good idea to minimize this by doing the global write once per wave or group. A neat trick is to also scalarize on the shader/draw for when a wave sees different values there 🙃

1 likes 1 replies

?

Replies

Ruben Osorio · Jan 1

If you need the correct index per-thread, as you do when you're going to write the samples to the buffer, there's some more wave-ops involved, since you also need to calculate the local offset for each thread on the wave. WaveReadLaneFirst/WavePrefixCountBits sorts you out, here is how it'd look: