HLSL编译器优化奇怪? [英] HLSL compiler optimizes strange?

查看:324
本文介绍了HLSL编译器优化奇怪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是HLSL编译器的专家,他们如何与分支机构合作,但我已经阅读了关于这个问题的不同意见。所以具体来说:在C / C ++中,实现像下面这样非常有意义:

I am not an expert in HLSL compilers and how they work with branches but I have read different opinions about this issue. So to be concrete: In C/C++ it would make perfect sense to implement something like:

if (factor == 0)
{
// Simple calculation in special case of factor=0
}
else if (factor == 1)
{
// Simple calculation in special case of factor=1
}
else
{
// Much more complex calculation in general case of arbitrary factor
}

在大多数时间因子为0或1的情况下。HLSL是否相同?我已经读了多次,HLSL编译器工作不同,在生成的机器代码中,无论如何都会计算所有分支。在这种情况下,上面的结构是没有意义的,只能用else语句替换。

in situations where most of the time factor is 0 or 1. Is the same true for HLSL? I have read multiple times that HLSL compilers work differently and e.g. in the resulting machine code all branches are computed anyway. In this case the above construction would not make sense and could be replaced by only the else case.

推荐答案

a href =http://msdn.microsoft.com/en-us/library/windows/desktop/bb509610%28v=vs.85%29.aspx =nofollow>文档编译器,无论这两种情况是否都应该执行(标签 [flatten] )或只有一侧(标签 [branch] )。如果你使用像 tex2D 这样的渐变函数,你不能使用分支,除非你用 tex2Dlod

As stated in the documentation you can tell the compiler, whether both cases should be executed (tag [flatten]) or only one side (tag [branch]). If you're using gradient functions like tex2D you can't use branch, except you replace them with something like tex2Dlod.

这篇关于HLSL编译器优化奇怪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆