Skip to content

Conversation

@ben-clayton
Copy link
Collaborator

The trig / fract approach for PRNG is not portable and can produce remarkably non-random results on IMG GPUs.

Replace this with a bit-xor & shift function, adapted from the cornell sample.

Fixes the particles sample on Pixel 10.

The trig / fract approach for PRNG is not portable and can produce remarkably non-random results on IMG GPUs.

Replace this with a bit-xor & shift function, adapted from the cornell sample.

Fixes the particles sample on Pixel 10.
@ben-clayton ben-clayton requested review from Kangz and toji December 27, 2025 11:36
Copy link
Contributor

@Kangz Kangz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎅

@ben-clayton ben-clayton merged commit d97946e into webgpu:main Dec 27, 2025
1 check passed
@toji
Copy link
Contributor

toji commented Dec 28, 2025

Thank you! This has been on my list of things to look at for a bit but it's never been a high priority.

For posterity, do you have a brief explanation as to why the previous approach wasn't portable?

@ben-clayton
Copy link
Collaborator Author

For posterity, do you have a brief explanation as to why the previous approach wasn't portable?

TL;DR: my theory is bad trig precision resulted in a terrible hash function.

I haven't done any deep digging, but I would suspect it's about the precision of the trig functions. IIRC (it's been a while since my head has been in this space) the trig functions have quite a lot of leniency WRT the precision of their outputs, and I wouldn't be surprised if some GPUs used crude approximations (LUTs and the like) which scrape-by the API specification minimum thresholds.
If the trig functions end up quantizing nearby input values to the same output value, then pseudo-hashing via rounds of trig -> fract are likely going to quantize to discrete points and likely miss entire output value ranges. This is what was exactly observed with the particle probability map - spatial gaps where no particles were spawned, and instead thousands of particles spawning at the same discrete points on the plane.

@ben-clayton ben-clayton deleted the fix-particles-prng branch December 29, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants