SPV: Implement short circuiting of && and || when emitting SPIR-V.

This commit is contained in:
John Kessenich
2015-10-15 13:29:11 -06:00
parent da581a2b95
commit 7c1aa1026e
9 changed files with 1942 additions and 1429 deletions

50
Test/spv.shortCircuit.frag Executable file
View File

@@ -0,0 +1,50 @@
#version 400
uniform ivec4 uiv4;
uniform vec4 uv4;
uniform bool ub;
uniform bool uba;
uniform bvec4 ub41, ub42;
uniform float uf;
uniform int ui;
out float of1;
out vec4 of4;
bool foo() { ++of1; return of1 > 10.0; }
void main()
{
of1 = 0.0;
of4 = vec4(0.0);
if (ub || ui > 2) // not worth short circuiting
++of1;
if (ub && !uba) // not worth short circuiting
++of1;
if (ub || foo()) // must short circuit
++of1;
if (ub && foo()) // must short circuit
++of1;
if (foo() || ub) // not worth short circuiting
++of1;
if (foo() && ub) // not worth short circuiting
++of1;
if (ub || ++of1 > 1.0) // must short circuit
++of4;
if (++of1 > 1.0 || ub) // not worth short circuiting
++of4;
if (ub || sin(uf) * 4.0 > of1) // worth short circuiting
++of1;
if (ub && sin(uf) * 4.0 > of1) // worth short circuiting
++of1;
}