【发布时间】:2013-05-18 00:20:00
【问题描述】:
我不是 HLSL 编译器以及它们如何与分支一起工作的专家,但我已经阅读了有关此问题的不同意见。所以具体来说:在 C/C++ 中,实现类似这样的东西是非常有意义的:
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 情况替换。
【问题讨论】:
标签: optimization compiler-construction compilation hlsl