Pages

Friday, September 23, 2011

Direct3D as precision killer

Recently I have spent much time trying to find an algorithm for precise computing of roots of cubic equation, I was nearly to go crazy and blamed all the inventors of all known computational methods for their “bad” work – no one method gave me precise results.

But as it turned out, Cardano, Netwon and other guys have done their job quite well, and my real problem and precision killer was revealed, that was IDirect3D9::CreateDevice, which checnges FPU precision by default from 53 bits to 24, unless you add D3DCREATE_FPU_PRESERVE to the Behavior flags.

But the solution is not that smooth and will require you to make a big trade-off between precision, or performance and reliability. Check out what D3DCREATE_FPU_PRESERVE actually means (source http://msdn.microsoft.com/en-us/library/windows/desktop/bb172527(v=vs.85).aspx):

Set the precision for Direct3D floating-point calculations to the precision used by the calling thread. If you do not specify this flag, Direct3D defaults to single-precision round-to-nearest mode for two reasons:

  • Double-precision mode will reduce Direct3D performance.
  • Portions of Direct3D assume floating-point unit exceptions are masked; unmasking these exceptions may result in undefined behavior.

Brrr…

No comments:

Post a Comment