Advisory: You Should Probably Use FpuPreserve

Published January 23, 2010
Advertisement
Late copy of a post from Ventspace. Full text today.

One of the create flags for D3D 9 devices is FpuPreserve. It tells the Direct3D runtime that you don't want it to mess with the FPU flags, which it does to improve performance. And you should probably be using it.

FPU computations are a really hideously messy area, one that makes my head spin when you get into the details. One of the cool things .NET does is to take away most of the complexity and make very simple, straightforward guarantees about how floating point code must behave. Operations are done at specifically defined precision, in a certain way, and the runtime must enforce these requirements during code generation. (Which creates some weird x86 code.)

When DirectX goes in and messes with FPU state, it apparently throws off what .NET expects, leading to weird bugs of various sorts. So unless you've got some problem with FPU performance that can be solved by switching to the faster FPU states (hint: you don't), it's probably a good idea to simply set FpuPreserve all the time.

[EDIT] I forgot to mention as an addendum that as part of the SlimDX 2.0 transition, it's very likely this flag will become the default.
0 likes 1 comments

Comments

Hodgman
Yep, I've actually worked on a huge blob of corporate software which would crash after ~1 day of uptime, *UNLESS* you specify that flag. The engine we used didn't.

Fun.

[edit]Definitely should be opt-in behaviour, not opt-out.
February 01, 2010 10:09 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement
Advertisement