Sign in to follow this  
feal87

StopWatch returns Integer after DirectX Device creation

Recommended Posts

The question is pretty "simple". I have an engine that can work with both DirectX9 and DirectX10 with SlimDX in C#. I use the Stopwatch class to time the game and test speed of some routine. Strangely exactly after the creation of the DirectX9 the floating point of the StopWatch go crazy and the GetTimeStamp()/Frequency division returns only integer values (single with .000000). Why this? Please note that with DirectX10, this problem isn't present. (if I do the check just before opening the device in DirectX9 it works, just after don't.) This is the code i use for both version (DirectX10 and DirectX9) (Double)Stopwatch.GetTimestamp() * 1000d / (Double)Stopwatch.Frequency Any clues? I tested using QueryPerformanceCounter, but the result is the same. Perfect calculation before creating the DirectX9 device, only integer after. EDIT: After some testing i managed to make it show some floating point values but they are pretty different from the DirectX10 one in precision. Here's some example : DirectX10 Form creation : 110.09241 LoadContent Full : 738.64486 LoadContent ContentManager : 593.57572 DirectX9 Form creation : 112.45000 LoadContent Full : 489.50000 LoadContent ContentManager : 355.50000 EDIT2: Tested on another machine and the result is the same...before the creating of the device all ok, after only integer... [Edited by - feal87 on December 28, 2009 4:11:37 AM]

Share this post


Link to post
Share on other sites
Creating a D3D9 device will issue a command that sets the CPU into half-precision mode for floating points...I suppose this is what's screwing you up. You can try creating your Stopwatch after you create the device, or if you want you can tell Direct3D not to do that by passing "D3DCREATE_FPU_PRESERVE" to CreateDevice. However according to the documentation this can result in performance issues and undefined behavior.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this