Porting (!?!) GLSL shader from GeForce to Radeon

I have shader developed on GeForce 6600 and can’t even get 1/3 of it’s original code to run on Radeon x850. I’ve commented-out entire code and added the following lines at the end of the fragment shader:

  vec3 color;
  color.r = gl_FragCoord.x / 1280.0 + 0.5;
  color.g = gl_FragCoord.y / 1024.0 + 0.5;
  color.b = 0.5;
  gl_FragColor.rgb = color;

Alpha blending is disabled.

I run this in 1280x1024 and I get some sort of test - whenever I draw polygon it has color depending on it’s location on the screen.

When I uncomment some lines at the beginning it still works, but when I uncomment more I just get a gray surfaces. Note that the fragment shader still works, because if not the color would be different.
It doesn’t matter wchich lines I uncomment - at some piont I always get this - gl_FragCoord is simply (0.0, 0.0) on entire screen.
Ain’t that weird?

This happened on Radeon x850, bot the same shader works fine on GeForce 7800.
Out of registers? Too many instructions?

At the point when problems begin I still have 2/3 of the fragment shader commented-out. When I try to run entire shader (as it runs on GeForce) my application stops responding when rendering polygons.

At the moment I can’t post the shader code since it’s on another machine, but I can post it tomorrow on demand.
However, I’m convinced there is nothing wrong with the shader, so my question is:

Is there anything wrong with ATI’s GLSL support that I should know about in the first place?

Thanks in advance for any hints.

Any messages in the infolog?

And yes, the entire shader would help to debug.

Here is the fragment shader:

 
uniform sampler2D testTexture1;
uniform sampler2D testTexture2;
uniform sampler2D testTexture3;
uniform sampler2D testTexture4;
varying vec2 v_texCoord0;
varying vec2 v_texCoord1;
varying vec2 v_texCoord2;
varying vec2 v_texCoord3;

varying vec3 v_eye;
varying vec3 v_up;
varying vec4 v_pos;
varying float dynamicWaveScale;

void main( void )
{
/* */

  vec3 v_normal =   texture2D( testTexture1, v_texCoord0).rgb
                  + 2.0 * texture2D( testTexture1, v_texCoord1).rgb
                  + (1.0 - dynamicWaveScale) * 8.0 * texture2D( testTexture1, v_texCoord2).rgb
                  + texture2D( testTexture1, v_texCoord3).rgb;

/* */

  float wave1 = dot(normalize(reflect(v_eye, v_normal)), v_up);
/*  wave1 = -smoothstep(0.3, 1.0, wave1) + 0.4 - v_pos.y * 0.1; */

/* */

  vec3 color;
  color.r = gl_FragCoord.x / 1024.0 + 0.5;
  color.g = gl_FragCoord.y / 768.0 + 0.5;
  color.b = 0.5;
  gl_FragColor.rgb = color;
}

I skipped lines that are comented-out since entire shader is a bit complex and I’m only trying to run what you see here.
This fragment shader runs fine - i get surface that has different colors over the screen.

There is one line commented-out. When I uncomment it I get a gray color all over polygons that use this shader.

Infolog says:
Link successful. The GLSL vertex shader will run in hardware. The GLSL fragment shader will run in hardware.

And the shader is active - when I change:
color.b = 0.5;
to
color.b = 0.0;
I get a brown surface.

It look like built-in uniform value gl_FragCoord doesn’t work. Maybe it gets hidden by another register when I add too much instructions/registers to shader?
I’ll send this post and try to decrease number of used registers (first of all I will remove the v_texCoord varying variables).


I’ve changed v_texCoord to gl_TexCoord[] - no effect.

Ok, I’ve changed another thing in the line that causes problems:
I’ve replaced v_pos with v_eye, so now the line is:
wave1 = -smoothstep(0.3, 1.0, wave1) + 0.4 - v_eye.y * 0.1;
Now the shader is working again.
I really get the feeling that ATI’s compiler or linker is messed up. :confused:

Any hints?

Ok, the shader works now on Radeon x850. It was caused by passing too many (?) varying variables from vertex shader to fragment shader. Old code has the following set of uniforms and varying variables:

uniform sampler2D testTexture1;
uniform sampler2D testTexture2;
uniform sampler2D testTexture3;
uniform sampler2D testTexture4;
varying vec3 v_eye;
varying vec3 v_up;
varying vec4 v_pos;
varying float dynamicWaveScale;

New code looks like this:

uniform sampler2D testTexture1;
uniform sampler2D testTexture2;
uniform sampler2D testTexture3;
uniform sampler2D testTexture4;
varying vec3 v_eye;
varying vec4 v_up;
varying vec4 v_pos;

dynamicWaveScale is now the 4’th component of v_up.

Latest ATI drivers simply failed to allocate registers for me and did not report any error.

Yeah, welcome to the real world.

gl_FragCoord will take up one interpolator, so if you’re already using 8 this will be a problem. Normally this would mean you drop into software mode, but apparently in this case the shader just got miscompiled, so it executed fine in hardware but did the wrong thing. I’ll file a bug report on it.

I found another strange stuff on my ATI 9600. When I commented out usage of texture2D () in fragment shader and let the usage of gl_TexCoord varying in pixel shader, the shader produced strange results. The solution was to comment out also usage of gl_TexCoord built-in varying. Maybe caused by some kind of shader optimalization.

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