views:

155

answers:

1

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?

EDIT : I tested using QueryPerformanceCounter, but the result is the same. Perfect calculation before creating the DirectX9 device, only integer after.

EDIT2: 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

EDIT3: Tested on another machine and the result is the same...before the creating of the device all ok, after only integer...

+2  A: 

By default, Direct3D 9 reduces the floating point precision to 32-bit. You can prevent this using the D3DCREATE_FPU_PRESERVE flag. In SlimDX, You would use the SlimDX.Direct3D9.CreateFlags.FpuPreserve flag when creating the device.

interjay
Sorry, but i doubt that's the problem. Cause if I use the StopWatch class (instanced) with Start() and Stop() method, all works fine. Only if i use TimeStamps everything goes awry.Anyway here's its not the talk about precision (32 bit precision would be fantastic XD), it returns plains integer or .50000.
feal87
Why don't you try it and see? Since timestamps have very large values, 32-bit precision could very well be the cause.
interjay
I'll give it a try right know :)
feal87
Yep, that was it. Pretty strange that the StopWatch class works thought...it should internally use the same QueryPerformanceCounter...
feal87