SPIRV-Cross/shaders/frag/inside-loop-dominated-variable-preservation.frag
Hans-Kristian Arntzen 03d93abc1a Deal with case where a variable is dominated by inner part of a loop.
There is a risk that we try to preserve a loop variable through multiple
iterations, even though the dominating block is inside a loop.

Fix this by analyzing if a block starts off by writing to a variable. In
that case, there cannot be any preservation going on. If we don't, pretend the
loop header is reading the variable, which moves the variable to an
appropriate scope.
2019-06-06 11:11:44 +02:00

22 lines
290 B
GLSL

#version 310 es
precision mediump float;
layout(location = 0) out vec4 FragColor;
void main()
{
float v;
bool written = false;
for (int i = 0; i < 4; i++)
{
float w = 0.0;
if (written)
w += v;
else
v = 20.0;
v += float(i);
written = true;
}
FragColor = vec4(1.0);
}