SPIRV-Cross/shaders/comp/cfg.comp
2016-11-18 16:45:11 +01:00

92 lines
1.2 KiB
Plaintext

#version 310 es
layout(local_size_x = 1) in;
layout(std430, binding = 0) buffer SSBO
{
float data;
};
void test()
{
// Test that variables local to a scope stay local.
if (data != 0.0)
{
float tmp = 10.0;
data = tmp;
}
else
{
float tmp = 15.0;
data = tmp;
}
// Test that variable access propagates up to dominator
if (data != 0.0)
{
float e;
if (data != 5.0)
{
if (data != 6.0)
e = 10.0;
}
else
e = 20.0;
}
// Test that variables local to a switch block stay local.
switch (int(data))
{
case 0:
{
float tmp = 20.0;
data = tmp;
break;
}
case 1:
{
float tmp = 30.0;
data = tmp;
break;
}
}
// Check that multibranches propagate up to dominator.
float f;
switch (int(data))
{
case 0:
{
f = 30.0;
break;
}
case 1:
{
f = 40.0;
break;
}
}
// Check that loops work.
// Interesting case here is propagating variable access from the continue block.
float h;
for (int i = 0; i < 20; i++, h += 10.0)
;
data = h;
// Do the same with do-while, gotta test all the hard cases.
float m;
do
{
} while (m != 20.0);
data = m;
}
void main()
{
// Test that we do the CFG analysis for all functions.
test();
}