问题
According to the GLSL ES reference, support for highp
in fragment shaders is optional. So I have been using precision mediump float;
in all my fragment shaders so I don't have device compatibility issues. In some cases it's quite difficult to produce good-looking output with only 10 bits of relative precision, and I would love to be able to switch to highp
when necessary.
How safe is it in practice to require highp
support in a fragment shader? I've tried it on a variety of devices, and it works on every device I've tried. I'm only looking to target, say, Android 4.1+ and iOS 8+, so if it's only crusty old devices that don't support it then I'm fine with that.
I know there are runtime checks etc. I should be doing, but first I'd just like to get an approximate feel for what percentage of devices in the wild we're talking about. I haven't been able to find this information anywhere. If only 75% of devices support highp
, then I'll stick with mediump
. If 99.9% of devices support it, highp
here we come.
回答1:
There's a database, where you can lookup GL_OES_fragment_precision_high which suggests that just under 50% of Android devices support highp in the fragment shader. You can inspect which ones have and do not have this extension. link
However, that might be misleading because that GLES extension has been withdrawn, so maybe some devices don't report it anymore even though they do support highp, so you can consider that 50% a minimum - it could be a lot higher. The extension is replaced by GetShaderPrecisionFormat, and I can't find a good database for that.
With a much smaller dataset, I have tested my game on 28 devices, 8 of which do not support highp in fragment shader, including a Nexus 7 and a Samsung Galaxy Note II running Android 4.4 and a Samsung Galaxy S3 running 4.3 (the other devices I had which didn't support highp in fragment shader were pretty obscure brands)
I'm pretty sure all your target iOS devices do support highp in fragment shader but can't find any evidence right now to back that up.
Finally, as you mention "precision mediump float;", IMO you should be picking a precision on a case-by-case basis and not picking a level for the entire shader. You'd be wasting a lot of performance on some GPUs if you used highp on everything (particularly colour based operations which can easily be lowp). Of course, you can set a default precision, then override wherever necessary, and perhaps that's what you're doing, but personally I prefer not to set a default precision in fragment shaders, then the compiler forces me to be explicit.
Edit: Also, it's allowed to use highp in a fragment shader even for devices that don't support it, you'll just get mediump. In a lot of cases that fallback behaviour is fine - high end devices get better precision lighting or whatever, lower end devices fallback to something less perfect but still acceptable.
来源:https://stackoverflow.com/questions/40856861/is-it-ok-to-use-highp-in-fragment-shaders-for-ios-android