PDA

View Full Version : AMD : glLinkProgram error with uniform Struct



MichalD
07-19-2011, 10:26 AM
Hey,

I think I've just encountered AMD driver bug.
Compiling following shaders is fine. However, when calling glLinkProgram on program with attached shaders I get unexpected error and linking fails.

On Nvidia everything works correctly.

Vertex :


// glslv

#version 150

struct VertParams {
vec4 _mPosition;
vec4 _mVertexColor;
};

struct InUniformParams {
vec4 _mModelViewProj[4];
};

vec4 _outHPosition1;
uniform InUniformParams _inVU1;
vec4 _r0003;
in vec4 POSITION;

// main procedure, the original name was main
void main()
{


_r0003 = POSITION.x*_inVU1._mModelViewProj[0];
_r0003 = _r0003 + POSITION.y*_inVU1._mModelViewProj[1];
_r0003 = _r0003 + POSITION.z*_inVU1._mModelViewProj[2];
_r0003 = _r0003 + POSITION.w*_inVU1._mModelViewProj[3];
_outHPosition1 = _r0003;
gl_Position = _r0003;
} // main end



Fragment :



// glslf

#version 150

struct InUniformParams {
vec4 _mColor;
};

uniform InUniformParams _inVU1;
out vec4 COL0;

// main procedure, the original name was main
void main()
{
COL0 = _inVU1._mColor;
} // main end

What is even more surprising is the fact that program links correctly on AMD if I remove uniform struct in fragment shader - just declare uniform vec4 _mColor; and use it directly.

AMD support? Anyone :) Any ideas?

btw. cheers everyone - first time posting here ;]

MichalD
07-20-2011, 01:24 AM
Didn't mention before : Catalyst 11.7, Win 7 64bit

Alfonse Reinheart
07-20-2011, 01:45 AM
However, when calling glLinkProgram on program with attached shaders I get unexpected error and linking fails.

What error do you get specifically.


On Nvidia everything works correctly.

That's not surprising, since this looks like something that NVIDIA's Cg-to-GLSL compiler coughed up. That's not to say that it is wrong, but it does do a lot of unusual things (structs with one member, pretending that a matrix is 4 vec4's for no particular reason, etc).

Have you considered writing the GLSL by hand? You'll be less likely to hit corner cases that drivers may not handle correctly.

MichalD
07-20-2011, 01:58 AM
Hi. Thx for reply.

The problem with glLinkProgram error is that it is actually a string : 'unexpected error' . Nothing more in the log.

And yeas actually this code is from cg to glsl compilation. Unfortunately we've got the whole shading node based workflow setup in cg including shader builder, therefore rewriting the whole thing to pure glsl is somewhat non preferable atm.

However, this code should actually still compile according to glsl specification.

MichalD
07-20-2011, 02:13 AM
I discovered what was wrong.

My uniform in Vertex shader was having the same name as the uniform in Fragment shader.
I thought that should be distinguished by shader domain. Apparently it is not.

I would assume that two uniforms with different struct types, but same names in two different domains should compile without a problem as they should have different resources and different actual names because of flattening of struct.
However, it is understandable that this is not the proper clear code. Lack of error code was a bit misleading.
I will rewrite the rules for our uniforms.

Thx for help. Topic closed.