Sign in to follow this  
suniu

A strange problem after called ' CreateDevice '

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

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