Pow 函数与着色器中的查找纹理
我正在为 XBOX 360 进行开发,并在一些照明计算中使用 pow() 内在函数。
6-8 年前,曾经很常见使用一维查找纹理来近似 pow()。现在还有人这样做吗?
对于已有 6 年历史的 XBOX 360 是否值得尝试这一点,或者它不太可能提高性能?
I'm developing for the XBOX 360, and I use the pow() intrinsic in some lighting calculations.
6-8 years ago it used to be common to use a 1D lookup texture to approximate pow(). Does anyone still do that?
Is it worth trying this for the 6 year old XBOX 360, or is it unlikely to improve performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
pow
指令(或等效的 HLSL 中的固有 函数)。 它需要 3 个指令槽,这表明它相当快。我还没有坐下来计算出查找表的确切成本。但是您将很难在更少的指令槽中找到有用的实现。显然它需要纹理读取(这本身不是免费的,并且很有可能它将是依赖纹理读取,因此速度相当慢)。
(此外:如果查找纹理是更好的选择,那么 GPU 可以像它本身一样实现
pow
指令。)过去普遍使用纹理的原因是
pow
指令rel="nofollow">顶点 或 着色器模型 1.x 中的像素着色器。在 2.x 和所有更新版本中,它都可用(更多指令集)。Use the
pow
instruction (or the equivalent intrinsic function in HLSL). It takes 3 instruction slots, which indicates that it is reasonably quick.I haven't sat down and figured out the exact cost of doing a lookup table. But you would struggle to find a useful implementation in fewer instruction slots. And obviously it requires a texture read (which is itself not free, and there's a good chance it will be a dependent texture read and so quite slow).
(Additionally: if a lookup texture were a better choice, then the GPU could just implement the
pow
instruction like that itself.)The reason that it used to be common to use a texture is that the
pow
instruction did not exist for either vertex or pixel shaders in shader model 1.x. In 2.x and everything newer it is available (more instruction sets).