Precision

A bunch of questions that I couldn’t find precise answers to:

  • IIRC there is a precision conversion overhead, does it occur both ways (float->half and half->float)?

  • Does mesh data (normals/UVs) always come into vertex program as floats?

  • If it does, when is it reasonable to use half for unit vectors (normals, tangents), despite the conversion overhead? (how complex should subsequent operations on the vector be for half to be viable in such cases?)

  • half h = .00000001, will there be a conversion overhead, or different shader variants will be generated for GPUs that do and do not support half?

  • How do unity macros get along with half? Looking at the source code, some macros use float, some use half, constants are float, does it all get optimized in compile time to prevent conversions?

  • What percentage of current mobile devices supports half precision? When do you think half will become obsolete like fixed currently is?

Yes, both ways.

UVs should be floats, otherwise you don’t have enough precision.
Not sure about the normals part.

This is a compile time constant, no conversion overhead here.

No, there is no automatic precision optimisation.

All of them

Probably, never. Half offers a good performance and memory footprint improvement over float.

2 Likes

The one caveat is the above answers are all in the context of mobile. The answers for desktop would be:

No, because half is always treated as a float.

Yes, because it’s always a float.

No, because it’s always a float.

No, because it’s a compile time constant. Also, it’s always a float even if you write it as a half precision value.

Yes, because it’s always a float.

All of them.

Never, and half precision has been re-implemented into desktop and consoles GPUs as well because it can offer a not insignificant performance improvement if used properly. However it’s only available when using Vulkan or Direct3D 12 when using the DXC shader compiler and when running on those GPUs that support it, or at least will be once that works.

2 Likes