假设我有这样的内容:
float foo;
float bar = baz / foo;
float qux = quux / foo;
当我执行以下操作时会发生什么:
foo = 1./foo;
float bar = baz * foo; //can i expect roughly the same number as with division?
floar qux = quux * foo; //is it always going to be faster?
鉴于WebGL可在各种硬件上运行,我是否可以期望在编译时会发生类似这样的情况,或者总是更安全地像这样编写代码?
同时也对此很好奇。
uniform float invFoo;
...
bar = baz * invFoo;
//instead of:
uniform float foo;
...
bar = baz / foo;
我不太理解这个:
// A stupid compiler might use these as written: a divide, then add.
vec4 result1 = (value / 2.0) + 1.0;
vec4 result2 = (value / 2.0) - 1.0;
vec4 result3 = (value / -2.0) + 1.0;
// There are most likely converted to a single MAD operation (per line).
vec4 result1 = (value * 0.5) + 1.0;
vec4 result2 = (value * 0.5) - 1.0;
vec4 result3 = (value * -0.5) + 1.0;
在这种情况下,我不明白一个愚蠢的编译器要做什么。它是否遗漏了可以通过单个MAD指令完成此操作,或者它是否遗漏了可以将除法表达为乘法(同时遗漏了MAD)。
另外,如果移动一些内容并进行分组,会怎样:
vec2 foo,bar;
float baz;
baz = 1./baz;
vec2 temp = vec2( foo.x , bar.x ) * baz; //move but do one mult?
foo.x = temp.x;
bar.x = temp.y;
EXT_disjoint_timer_query
。 - Kirill Dmitrenko