ARB_precision_hint_fastest,ARB_precision_hint_nicest 的意义,作用

来源:互联网 发布:在淘宝代运营公司工作 编辑:程序博客网 时间:2024/06/06 08:52

首先必须吐槽一下,百度搜任何跟技术相关的东西,简直是辣鸡的不行,还是vpn翻墙google王道,分分钟找到想要的内容。。。
其实之前知道这2个命令是干什么的,但是总是会忘记,鉴于这个情况,所以决定还是做一下笔记了~

首先,这2命令最权威解释的地方,肯定就是openGl官网了,以下是链接:
https://www.opengl.org/registry/specs/NV/fragment_program4.txt

这里有这么一段:

+ Precision Hints (ARB_precision_hint_fastest, ARB_precision_hint_nicest)

Fragment program computations are carried out at an implementation-dependent precision.  However, some implementations may be able to performfragment program computations at more than one precision, and may be ableto trade off computation precision for performance.If a fragment program specifies the "ARB_precision_hint_fastest" programoption, implementations should select precision to minimize programexecution time, with possibly reduced precision.  If a fragment programspecifies the "ARB_precision_hint_nicest" program option, implementationsshould maximize the precision, with possibly increased execution time.Only one precision control option may be specified by any given fragmentprogram.  A fragment program that specifies both the"ARB_precision_hint_fastest" and "ARB_precision_hint_nicest" programoptions will fail to load.

看标题也知道了,也就是精度提示。

ARB_precision_hint_fastest 最快的,意思就是会用低精度(一般是指fp16),以提升片段着色器的运行速度,减少时间。

ARB_precision_hint_nicest 最佳的,意思就是会用高精度(一般是指fp32),可能会降低运行速度,增加时间。

注意:这2个命令不可以同时使用

unity里的写法是 #pragma fragmentoption ARB_precision_hint_fastest

具体说fp16,fp32是什么的话,就涉及到GPU的知识了,我也不是太懂。
大概说说的话,fp16在gpu里一般被称为半精度计算

图形计算中使用的精度是:

FP16,16bit,半精度
FX10,10bit,都不是浮点,而是定点数了
FP32,32bit,单精度(最常见的)
FP64,64bit,双精度(不常见的,图像处理一般用不到)

虽然在实际应用中,这2种精度在表现上区别并不大,但是还是建议使用fp16精度的更好。

因为像在 ARM Mali, Imagination PowerVR 这种移动GPU上,都有独立的fp16单元,也就是说,fp16是从硬件电路级别上被支持的,我们知道,这就意味着一个字,那就是“快!”,所以你懂的!

不过据说NVIDIA的gpu里,都是用fp32 CUDA核心去处理fp16的。(这其实是比单独的fp16单元要慢的)

总结一下就是在写shader时可以顺手把这个命令给加上,但是如果你忘记了,或者懒,其实问题也不是太大,以上!

0 0
原创粉丝点击