Major breakthrough!
For years I was unable to run my BVH path tracers on mobile - they wouldn’t even compile, or would just crash after a few seconds, even on my Samsung Galaxy S21.
A recent Twitter post by Garrett Johnson caught my eye because he was having similar problems when developing his BVH system. We got into a discussion about it, chalked it up to lack of precision, and I was ready to give up. Not Garrett however, he is a robotics expert at NASA and he knows all about low level stuff and machine precision. He couldn’t let this go, because mobile devices should have as much floating point precision as desktops, as reported. Yet there was still a discrepancy.
Many posts later and a multiple-expert discussion later (Ken Russell, Romain Guy from Google, someone who knows mobile chips, etc…) it was discovered that for some reason (which I can’t quite fathom), the designers of Adreno mobile chips treat all members of structs{} as mediump or lowp precision, even if I specifically put highp precision at the beginning of my shaders! I have structs all over the place, stuff like Ray{vec3 origin; vec3 direction;} Intersection{ vec3 hitPos, etc.}, BVHNode{vec4 data, etc.}.
So the problem was that when traversing the very precise BVH, my mobile devices were unable to even start because floating point round-off errors were flying all over the place! All this was happening unbeknownst to me because I thought everything was in highp precision, like I had instructed on every shader - not so!
As soon as I got rid of all my structs, and unpacked them into seperate variables, like vec3 rayOrigin instead of ray.origin, everything magically started to work! It was such a joy to be able to see the Stanford Bunny (30,000+ triangles) path traced at 60 fps,… on my phone!
So I just wanted to pass this gold nugget on to you all for all your future GPU projects that might have to be run on mobile. Use individual vec2, vec3, vec4 variables, instead of grouping them together into structs in your shaders. It will be an inconvenience for me (and you possibly) to go back and change all my code now, but the result is well worth it!