PDA

View Full Version : moody ATI shader compiler



nurbz
08-19-2005, 12:55 AM
Hi guys,

I am developing some shader programs, and I encountered some problems when I try to run them on an ATI graphic card, although the same version on nVidia does compile without any errors.

Here is the bit incriminated:

void calDiffuseSpecular(Light light, vec4 pos, vec3 norm, vec4 camPos, float shininess,
* * * * * * * * * * * * out vec4 diffuseOut, out vec4 specularOut)
{
** // some code .....

** vec4 lightVec = normalize(light.position - pos);
** float diffuseLight = max(dot(norm, lightVec), 0);

##### error on previous line
##### ERROR: 0:129: 'dot' : no matching overloaded function found
##### ERROR: 0:129: 'max' : no matching overloaded function found

I tried to cast both lightVec and norm to vec4, but it was still not working. Any ideas of what is wrong?

Some more info about the graphic card:
Version: 1.5.4517 WinXP Release
Vendor: ATI Technologies Inc.
Renderer: RADEON 9550 x86/SSE2

Many thank

Alexis

mrbill
08-19-2005, 02:21 AM
Sorry to sound so snippy.
What you call "moody" I call "conformant."

// ( ... , const in vec3 norm, ... )
// ...
vec4 lightVec = normalize(light.position - pos);
float diffuseLight = max(dot(norm, lightVec), 0);

##### error on previous line
##### ERROR: 0:129: 'dot' : no matching overloaded function found
##### ERROR: 0:129: 'max' : no matching overloaded function found

Three issues.

One, overloaded built-in functions in GLSL are matched exactly. There is no:

float dot( const in vec3 a, const in vec4 b );

I have an idea what function NVIDIA's implementation decided to match for you.

It probably matched:

float dot( const in vec3 a, const in vec3 b ); // valid implied cast of b exists

It also probably warned you on this.

You should double check their documentation.
(Cg appendix A may or may not help you here.)
Or you could look at their NV_fragment_programN
output from their compiler to find out for sure.

Two, there are no casts in GLSL.
In GLSL you should construct.

Three, there is no overloaded built-in function in GLSL for:

float max( const in float x, const in int y);

General solutions:

Recommend that you at least add GLSLvalidate
(http://developer.3dlabs.com/downloads/glslvalidate/index.htm)
to your shader development tool chain.
This will give you a way to continue to develop on NVIDIA hardware,
but you'll have a conformant front end to catch your errors.

Recommend that you continue your cross implementation development.
But understand that the "moody" ATI shader compiler is the more correct one.

Recommend the Orange Book.

On this specific problem, you probably want:

vec3 lightVec = normalize(light.position.xyz - pos.xyz); // normalize a vec3
float diffuseLight = max(dot(norm, lightVec), 0.0); // float literal const 0.0 insted of int literal const 0

-mr. bill

nurbz
08-19-2005, 03:51 AM
Brilliant! That's the kind of answer I usually only dream of.

Many thanks.

Alex

nurbz
08-19-2005, 06:27 AM
[Note: I had to replace/delete some brackets, as the cgi script complained]

And what about that one:
- I declared a struct Light{...};
- and an array containing instances of this structure: uniform Light* ** light[LIGHT_NB];

In the code, I was iterating through the array to compute the contribution from each light:

"* for int i=0; i<LIGHT_NB ; ++i
* {
* * calDiffuseSpecular [light[i], vertexPosition, normal, cameraPosition, phongExp,
** * * * * * * * * * * diffuseLight, specularLight ] ;
"

But the ATI compiler complained that it couldnt find a proper overload for the function calDiffuseSpecular;

If I create a temporary variable to store the current light, as follow, it does not generate any compiling errors

"* for int i=0; i<LIGHT_NB ; ++i
* {
Light tmp = light[i];
* * calDiffuseSpecular[ tmp, vertexPosition, normal, cameraPosition, phongExp,
** * * * * * * * * * * diffuseLight, specularLight ] ;
"

A bit pedantic, dont you think?

Jan
08-19-2005, 08:02 AM
You didn't actually copy this out of your shader-file, did you?
Else there would be so many stupid syntax-errors, i can hardly believe ANY compiler would take that.

So, please, before you let us analyse your shader, post the real shader, that you actually use.

Just to point out, what i mean:
-Your for-loop is missing round braces
-Your function gets called with []-braces (how do you call them in english???)

Jan.

Overmind
08-20-2005, 01:08 AM
You can use [ CODE ] ... [ /CODE ] (without the spaces) to produce this:

...Inside code tags you can post your shader without the forum messing up your code ;)

mrbill
08-20-2005, 03:21 AM
Originally posted by nurbz:
A bit pedantic, dont you think?I don't think it's a bit pedantic at all.

I think it's a bit of a bug. (Sorry.)

-mr. bill

nurbz
08-22-2005, 02:31 AM
Thanks again for the answer. A bug from the ATI compiler right? No clever way to work around it?

Alex


Originally posted by mrbill:

Originally posted by nurbz:
A bit pedantic, dont you think?I don't think it's a bit pedantic at all.

I think it's a bit of a bug. (Sorry.)

-mr. bill