GLSL编译器是否得到了很好的优化?
Are GLSL compilers well optimized
最近的GLSL编译器是否智能/优化良好?
换句话说,如果我没有脑子,写了下面这样的东西,最近的编译器会节省我的时间并优化掉不必要的代码吗,还是我应该总是小心我写的东西?
// All of the values are constants
if (3.7 == 3.7) // Will the condition be executed or removed at build time?
x++;
// Will this whole block be entirely removed? (or should I use macros)
if (1 == 2)
x++;
for (i = 0; i < 0; ++i) // Remove this
x++;
for (i = 0; i < varA * varB; ++i) // Compute varA * varB once, outside the loop
x++;
vec3 v = vec3(0);
if (length(v) > 0) // Remove
x++;
float p = mix(varA, varB, 1); // p = varB
float p = 5;
p *= uniform * 0; // Just set a = 0 from the start
float p = 5;
p *= 1; // Remove that
现在还有很多事情我说不出来,但你应该明白这一点。
同样,最近的编译器可以自动检测不太明显的优化吗?http://www.opengl.org/wiki/GLSL_Optimizations
在"编译时间"answers"优化时间"之间是否存在已知的权衡,由实现者或规范设置?
GLSL编译器在浮点优化方面非常保守。您无法确定任何特定的优化。经验法则是:尽你所能优化,不要指望GLSL编译器的任何帮助。
阅读Emil Persson在高级着色语言中的低级思维,了解有趣的细节和案例研究。
p。S:这个答案可能听起来很悲观。然而,GLSL编译器仍然在优化代码方面做了很多出色的工作。别指望了,尽力而为吧。
相关文章:
- 我编写了代码将十进制分数转换为其二进制等效数.它编译得很好,但在执行时挂起
- 很好的语法来获取对向量/数组数据的大小引用?
- 我认为我的代码很好,但它在 cin a 之后停止并且没有进一步?
- 尽管一切看起来都很好,但值不会交换
- 为什么不同类型层次结构的指针之间的dynamic_cast定义得很好?
- 在 C++11 中利用 int*_t、int_fast*_t 和 int_least*_t 之间的差异的一个很好的例子是
- 对于短字符串来说,这是一个很好的哈希函数吗?
- 为什么指标有时效果很好,有时效果不佳?写下霍夫曼代码
- Red Hat:使用<atomic>编译很好,但链接器找不到__atomic_store_16;什么库?
- 使用移位的无符号数字作为数组的索引号是一种很好的做法
- 是否很好地使用状态模式来维护当前选定的对象?
- C++|以一种很好的方式将树(不一定是二进制的)打印到stdout
- 静态库单独使用很好,但在引用时会抛出错误
- 如果验证容器的大小并在同一条件语句下访问元素,这是很好的做法吗?
- 可变参数函数模板不能很好地使用 std::function 作为参数
- 有没有办法关闭文件? fclose 不能很好地工作
- ICC 中的 -O2 搞砸了汇编程序,ICC 中的 -O1 和 GCC / Clang 中的所有优化都很好
- 一个很好的例子说明了如何使函数primitve param const导致编译器优化
- 有一个很好的测试c++优化编译器
- GLSL编译器是否得到了很好的优化?