A strange problem after called ' CreateDevice '

Started by
3 comments, last by suniu 18 years, 10 months ago
{ 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???
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.
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
Stay Casual,KenDrunken Hyena
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.
.
Oh, I see.

Thanks!

This topic is closed to new replies.

Advertisement