A GLSL compiler problem?

Hello everybody,

I’ve been experiencing some problems with the code compilation when I added a geometry shader.

For example, in the following code in every shader(vertex, geom and fragment):

for(int i=0;i<a;i++)
for(int j=0;j<i;j++)

(“a” can be everything from 0 to infinity)
do_something is never executed.I’ve tried transforming it in a while, a do while, a recursion function. I just can’t make it worked when I have a loop that depends on other loop’s variant. But, like I said, this only happens when I add a geometry shader.

Why is this happening?Is something wrong with the GLSL compiler or optimizer?I’ve tried with #pragma optimize(off) but still the same.The shaders are compiled and executed without errors.

a recursion function.

Recursion is not allowed in GLSL, period.

But, like I said, this only happens when I add a geometry shader.

This sounds like a compiler bug, but your geometry shader may be screwing other things up. So it’s hard to say without seeing code.

Thanks for the reply!
Here is the code where shaders are compiled(typical):


	m_hProgramObject = glCreateProgramObjectARB();

	glAttachObjectARB(m_hProgramObject, m_hVertexShader);
	glAttachObjectARB(m_hProgramObject, m_hGeometryShader);
	glAttachObjectARB(m_hProgramObject, m_hFragmentShader);

	glProgramParameteriEXT( m_hProgramObject, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES );
	glProgramParameteriEXT( m_hProgramObject, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP );
	glProgramParameteriEXT( m_hProgramObject, GL_GEOMETRY_VERTICES_OUT_EXT, 120 );


the CompileShader function

void CompileShader(GLhandleARB &hShader, string strSource, GLuint type)
	const char *szShader = strSource.c_str();

	hShader = glCreateShaderObjectARB(type);
	glShaderSourceARB(hShader, 1, &szShader, NULL);


I’m posting some basic shaders:
vertex shader:

varying vec2 iUV0;

void main()
	iUV0 = gl_MultiTexCoord0.xy;
	gl_Position = gl_Vertex;


varying in vec2 iUV0[3];
varying out vec2 oUV0;

void main(void)
	int i;

	for(i=0; i< 3; i++){
		gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_PositionIn[i].xyz,1.);
		oUV0 = iUV0[i];
		//oNormal = gl_ModelViewMatrix * vec4(normal[i],0);

and fragment:

varying vec2 oUV0;
uniform sampler2D ColorMap;
//varying out vec4 color;

void main()
	vec4 color;
	for(int i=0;i<2;i++)
	for(int j=0;j<i;j++)	
	color = vec4(1,0,0,1);

	gl_FragColor = color;

In fragment shader I put those two fors for testing.The color is undefined not red.If instead of i in the second for is a constant it works.
Is it a general problem with glsl compiler or there is something I’m doing that messes it up?

Loops with variable loop termination conditions
were not supported in early versions of GLSL.
Because you are not supplying a #version pragma
to the compiler, you are implicitly asking for
version 1.10, which is about as early as it gets.
The fact that this works unless you add a geometry
shader is strange, but try adding an explicit
#version pragma. That might help the compiler
to understand what it is supposed to do.
Geometry shaders were not supported in GLSL 1.10.

I see that my openGL version is 4.0. The glsl version is the same?I’ve put #version 400(in all shaders or only in geometry shader) but still the same results.


This is not a valid geometry shader according to the OpenGL Specification Version 4.0. That may be how ARB_geometry_shader4 or EXT_geometry_shader4 works, but that’s not how the core geometry shader works. And since you don’t define ARB_geometry_shader4 or EXT_geometry_shader4 as extensions in the shaders, they won’t work.

I’m amazed that even compiled. Well, maybe not if it’s on NVIDIA, which tends to be rather loose on these things.

I’ve put:
#version 400
#extension GL_EXT_geometry_shader4 : enable

but with no effect.
It’s a general problem, or is just something I’m doing?I mean, did you experienced it with those two fors?
With ARB_geometry_shader4 doesn’t compile.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.