[Mesa-dev] GLSL compiler bug

Vadim Girlin vadimgirlin at gmail.com
Wed Apr 10 12:20:10 PDT 2013


Hi,

It seems there is a bug in the compiler. The problem may be reproduced 
with the following shader (complete shader_test file attached):

	void main()
	{
		float f = 0.0;
		while (true) {
			f = 1.0;
			break;
			f = 0.5;
		}
		gl_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
	}

The result of compilation is equal to:

	while (true) {
		break;
	}
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);

In other words, GLSL compiler eliminates both assignments to "f" in the 
loop body and the resulting value of the "f" variable is 0.

Vadim

-------------- next part --------------
[require]
GLSL >= 1.20

[vertex shader]
void main()
{
	gl_Position = gl_Vertex;
}

[fragment shader]
void main()
{
	float f = 0.0;
	while (true) {
		f = 1.0;
		break;
		f = 0.5;
	}
	gl_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}

[test]
clear color 0.0 0.0 0.0 0.0
clear

draw rect -1 -1 2 2
probe all rgba 0.0 1.0 0.0 1.0


More information about the mesa-dev mailing list