Jump to content
  • Advertisement
Sign in to follow this  
suniu

A strange problem after called ' CreateDevice '

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

{ pD3d = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; double var = 16.485429763793945; var += 7.6520182201692704e-007; //here after '+=', 'var' has changed pD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, this->GetSafeHwnd(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pD3dDevice); var = 16.485429763793945; var += 5.6520182201692704e-007; //when got here, 'var' ingore the //small number, remain unchanged. } It is seemed that after called 'CreateDevice', the precision of 'double' type was reduced!! I'm using VC7.net, nothing else is special. Can someone point out what happens???

Share this post


Link to post
Share on other sites
Advertisement
Pass the D3DCREATE_FPU_PRESERVE flag to CreateDevice(), that should fix it (Although you'll lose a bit of performance - I don't know exactly how much).
The problem is that D3D alters the FPU precision. From the docs:
Quote:
Indicates that the application needs either double-precision floating-point unit (FPU) or FPU exceptions enabled. Direct3D sets the FPU state each time it is called.
By default, the pipeline uses single precision. Be sure to use this flag to get double precision. Setting the flag will reduce Direct3D performance.

Share this post


Link to post
Share on other sites
From the docs on CreateDevice:

D3DCREATE_FPU_PRESERVE - Forces Direct3D to not change the floating-point unit (FPU) control word, running the pipeline using the precision of the calling thread. Without this flag, Direct3D defaults to setting the FPU to single-precision round-to-nearest mode. Using this flag with the FPU in double-precision mode will reduce Direct3D performance

Share this post


Link to post
Share on other sites
By default, D3D will put the floating point unit into a reduced precision mode. Simply create the device with the D3DCREATE_FPU_PRESERVE flag to preserve your floating point precision. It may come at a bit of a cost speed wise though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!