// Rotate left operation on 64bit integers. // Rotates `x` by `k` positions to the left. uint64_t rotl64(const uint64_t x, const uint64_t k) { return (x << k) | (x >> (64 - k)); } // Implementation of the xoroshiro128+ PRNG. // For reference see: http://xoroshiro.di.unimi.it/xoroshiro128plus.c uint64_t xoroshiro128plus(void) { // xoroshiro128+ has a state consisting of 2 64bit integers. const uint id = 2 * invocation_uid; const uint64_t s0 = prng[id]; uint64_t s1 = prng[id + 1]; const uint64_t result = s0 + s1; s1 ^= s0; prng[id] = rotl64(s0, 55) ^ s1 ^ (s1 << 14); prng[id + 1] = rotl64(s1, 36); return result; } void main(void) { // This shader generates random numbers using the xoroshiro128+ PRNG. // It modifies the seed. The seed of the invocation (x,y,1) is located // `2.0 * (y * work_group_size.x * work_group_count.x + x)`. result[invocation_uid] = xoroshiro128plus(); }