Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2003

Tip: Looking for answers? Try searching our database.

Strange behavior with DirectX

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Emmanuel Stapf - 10 Oct 2003 20:06 GMT
Hi,

I have this small program using Direct 9.0b. The computation of `d1' and `d2' in
`launch' does not give the same results after I've initialized some stuff of
DirectX. Is this normal? A bug somewhere?

Thanks,
Manu

using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.DirectX.Direct3D;
namespace ConsoleApplication1

{

public class Manu {
public static void Main (){
   Manu app = new Manu();
   app.launch();
}

public double pi = 3.14159265358979323846;

public void launch () {
   double d1, d2;
   float f1;

   d1 = calc_double (180.0) - pi;
   call_directx();

   d2 = calc_double (180.0) - pi;
}

public double calc_double (double angle) {
   return angle / 180.0 * pi;
}

public void call_directx (){
   PresentParameters parameters;
   Device render_device;
   System.Windows.Forms.Form window;

   window = new System.Windows.Forms.Form();
   parameters = new PresentParameters();
   parameters.Windowed = true;
   parameters.SwapEffect = SwapEffect.Discard;
   parameters.EnableAutoDepthStencil = true;
   parameters.AutoDepthStencilFormat = DepthFormat.D16;
   render_device = new Device (0, DeviceType.Hardware, window.Handle,
   CreateFlags.SoftwareVertexProcessing, parameters);
}

}

}
Peter Koen - 11 Oct 2003 01:11 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> Thanks,
> Manu

DirectX also initializes some stuff on the fpu, that means the fpu will
perform slightly different rounding and will show different effects on
extrem values. although with normal calculations you shouldn't notice the
difference.

but always remember: "We are pentium of borg, division is futile, you will
be approximated" *g* ;)

Signature

best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at

Phil Taylor [ATI] - 11 Oct 2003 01:43 GMT
graphics hw works in float. not double.

the DX runtime inits the FPU to what works with graphics hw.

if you require double, then init DX with the FPU_PRESERVE flag.

its a perf hit, but unless you want to manually reset the FPU its the
easiest thing to do.

> Hi,
>
[quoted text clipped - 55 lines]
>
> }
Emmanuel Stapf - 11 Oct 2003 06:30 GMT
> if you require double, then init DX with the FPU_PRESERVE flag.
>
> its a perf hit, but unless you want to manually reset the FPU its the
> easiest thing to do.

How do you do this in managed DirectX?

Thanks,
Manu
Fabian Schmied - 12 Oct 2003 17:47 GMT
> How do you do this in managed DirectX?

Use a Direct3D.Device constructor that takes a CreateFlags value and specify
CreateFlags.FpuPreserve.

Fabian
David Notario [MSFT] - 19 Oct 2003 18:53 GMT
This behavior is bad enough already in C++. In managed code it's a bug to
change any FPU flags. I'll open a bug against the DX guys so that at least
the default is  FpuPreserve. How much does this matter nowadays anyways? In
the past the burden of the math computations was done in the CPU in x87
mode. Today, the computations are done in the GPU and/or software vertex
shaders, which are probably done in SSEized code.

Signature

David Notario
Software Design Engineer, CLR JIT Compiler
http://devdiary.xplsv.com

> > How do you do this in managed DirectX?
>
> Use a Direct3D.Device constructor that takes a CreateFlags value and specify
> CreateFlags.FpuPreserve.
>
> Fabian

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.