4
$\begingroup$

Open GL and other graphics APIs support floating point formats smaller than 32 bits (e.g. see https://www.opengl.org/wiki/Small_Float_Formats). While GPUs seem to handle these formats natively, CPUs have limited support (x86 architecture chips can convert to/from 16 bit floats using the AVX instructions). It is sometimes convenient to pack/unpack these formats on the CPU , but it is not obvious how to do so efficiently.

What are the fastest techniques to convert between 32 bit floating point and the small float formats on the CPU? Are libraries or sample implementations available?

$\endgroup$
6
$\begingroup$

You definitely want to check out meticulous half to float and float to half implementations by Fabian Giesen. I don't think there is anything faster than those: https://gist.github.com/rygorous/2144712 https://gist.github.com/rygorous/2156668

For other formats you will find an implementation in DirectXMath (part of WindowsSDK), Mesa and similar libraries. For example, R11G11B10_Float conversions are implemented by DirectXMath in XMFLOAT3PK and by Mesa in u_format_other.c.

$\endgroup$
  • $\begingroup$ Cool - it's nice to have an alternative to AVX. f11_f11_f10 is my priority right now, as I use it for all my linear space/HDR rendering. $\endgroup$ – Daniel M Gessel Feb 14 '16 at 22:52
  • 1
    $\begingroup$ I've added some links to R11G11B10_Float conversion implementations. $\endgroup$ – Krzysztof Narkowicz Feb 15 '16 at 8:29
  • $\begingroup$ Your link to Mesa implementation is now dead. $\endgroup$ – Ruslan Apr 27 '18 at 10:01
  • $\begingroup$ Why do we need directx when there is an opengl? $\endgroup$ – Zich May 3 '18 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.