(转)Direct3D的浮点精度问题
2009-08-26 10:01
141 查看
(http://software.intel.com/zh-cn/blogs/2009/06/08/direct3d/?cid=sw:prccsdn695)
最近编写一个Firefox的小插件,里面利用D3D进行Render,结果导致Firefox的UI渲染错误(插件后面的主窗口背景变成黑色),检查了好几天发现程序逻辑并没有问题,窗口函数和消息处理都正常。后来偶然发现同样用OpenGL渲染没有问题,再三查找发现问题出在D3D的浮点精度上面。从D3D的文档D3DCREATE条目中查到的:
D3DCREATE_FPU_PRESERVE Set the precision for Direct3D floating-point calculations to the precision used by the calling thread. If you do not specify this flag, Direct3D defaults to single-precision round-to-nearest mode for two reasons:
- Double-precision mode will reduce Direct3D performance.
- Portions of Direct3D assume floating-point unit exceptions are masked; unmasking these exceptions may result in undefined behavior
在调用IDirect3D9::CreateDevice的时候,D3D默认改变了程序的浮点精度(出于性能的考虑),导致Firefox的UI出错,加上了这个选项就正常了,而实际上性能并没有比原来低多少。
在开发实践中,很多不起眼的细节都能影响程序的结果!而很多不相关的事情其实都是有千丝万缕的联系,编码的时候总有在设计时想不到的事情发生,这就是理论和实践的区别所在!印证了一句名言:
In theory, there is no difference between theory and practice. In practice, there is。
我们平时对整数比较熟悉,但是对浮点数比较陌生,这里有篇文章比较深入地探讨了FPU:Know Your FPU http://www.stereopsis.com/FPU.html,和它的更新版.http://www.stereopsis.com/sree/fpu2006.html
Direct3D的浮点精度问题
作者: Wu Xiaochang 吴晓昶 (Intel) (6 篇文章) 日期: 六月 8, 2009 在 11:49 上午
Direct3D的浮点精度问题最近编写一个Firefox的小插件,里面利用D3D进行Render,结果导致Firefox的UI渲染错误(插件后面的主窗口背景变成黑色),检查了好几天发现程序逻辑并没有问题,窗口函数和消息处理都正常。后来偶然发现同样用OpenGL渲染没有问题,再三查找发现问题出在D3D的浮点精度上面。从D3D的文档D3DCREATE条目中查到的:
D3DCREATE_FPU_PRESERVE Set the precision for Direct3D floating-point calculations to the precision used by the calling thread. If you do not specify this flag, Direct3D defaults to single-precision round-to-nearest mode for two reasons:
- Double-precision mode will reduce Direct3D performance.
- Portions of Direct3D assume floating-point unit exceptions are masked; unmasking these exceptions may result in undefined behavior
在调用IDirect3D9::CreateDevice的时候,D3D默认改变了程序的浮点精度(出于性能的考虑),导致Firefox的UI出错,加上了这个选项就正常了,而实际上性能并没有比原来低多少。
在开发实践中,很多不起眼的细节都能影响程序的结果!而很多不相关的事情其实都是有千丝万缕的联系,编码的时候总有在设计时想不到的事情发生,这就是理论和实践的区别所在!印证了一句名言:
In theory, there is no difference between theory and practice. In practice, there is。
我们平时对整数比较熟悉,但是对浮点数比较陌生,这里有篇文章比较深入地探讨了FPU:Know Your FPU http://www.stereopsis.com/FPU.html,和它的更新版.http://www.stereopsis.com/sree/fpu2006.html
相关文章推荐
- 浮点数精度问题处理
- 深入浅出iOS浮点数精度问题 (下)
- 浮点数中的精度问题与所谓的"double a=0"
- Java中浮点类型的精度问题 double float
- JS浮点类型运算精度丢失问题解决办法
- javascript(js)浮点数字精度问题的一个解决办法。
- java浮点计算精度丢失问题
- 【解码】浮点数精度问题 | 为什么(int)(32.3 x 100) = 3229?
- Python的浮点数损失精度问题
- java float double精度为什么会丢失?浅谈java的浮点数精度问题 【转】
- 又见浮点数精度问题
- <2011 11 7> 编程中数据处理的问题(一)浮点数与精度理解
- JqGrid 框架自带sum合计浮点数精度问题处理
- JS浮点类型运算精度丢失问题解决办法
- 解决excel解析浮点类型数据精度问题
- js小数运算精度问题,js浮点数运算时出现精度问题
- 浮点数输入精度问题
- JAVA 浮点精度问题
- JavaScript浮点数及运算精度问题
- 有关浮点数的精度问题