GLpeon

05-12-2011, 12:33 PM

On nvidia cards, these GLSL fragment shaders work OK, but on AMD, it is getting some extreme performance hiccups, and I thought maybe it was something I was doing wrong in the conversion process, since I was getting tons of errors with the shaders.

This is with 11.5 drivers, Radeon 6870

I changed

normal_final_view += bumpmapping_factor*(2.0 * texture2D(texNormalMap, gl_TexCoord[0].st) - 1.0);

to

normal_final_view += bumpmapping_factor*(2.0 * vec3(texture2D(texNormalMap, gl_TexCoord[0].st) - 1.0));

vec4 LevelOfGrey(vec4 colorIn)

{

return colorIn.r * 0.299 + colorIn.g * 0.587 + colorIn.b * 0.114;

}

to

vec4 LevelOfGrey(vec4 colorIn)

{

return vec4(colorIn.r * 0.299 + colorIn.g * 0.587 + colorIn.b * 0.114);

}

for(int i=-kernel_size; i<=kernel_size; i++)

{

vec4 value = texture2D(texScreen, uv + vec2(pas.x*i, 0.0));

int factor = kernel_size+1 - abs((float)i);

to

for(int i=-kernel_size; i<=kernel_size; i++)

{

vec4 value = texture2D(texScreen, uv + vec2(pas.x*i, 0.0));

int factor = kernel_size+1 - abs(i);

and finally

float mask5_2[] = { 1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0};

float mask3_2[] = { 1.0/3.0, 1.0/3.0, 1.0/3.0};

...

vec4 convolH(float tab[], int size)

{

float stepX = 1.0/screenWidth;

vec4 color = 0;

int k = (size/2);

int ind = 0;

for(int i=-k; i<=k; i++)

color += tab[ind++] * texture2D(texScreen, gl_TexCoord[0].st + vec2(i*stepX, 0));

return color;

}

...

color = convolH(mask5_2,5);

...

color = convolH(mask3_2,3);

to

float mask5_2[5] = float[5](1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0);

float mask3_2[3] = float[3](1.0/3.0, 1.0/3.0, 1.0/3.0);

...

...

vec4 convolV(int size)

{

float stepY = 1.0/screenHeight;

vec4 color = vec4(0);

int k = (size/2);

int ind = 0;

if (size == 5)

{

float tab[5] = mask5_2;

for(int i=-k; i<=k; i++)

color += tab[ind++] * texture2D(texScreen, gl_TexCoord[0].st + vec2(0, i*stepY));

return color;

}

else if (size ==3)

{

float tab[3] = mask3_2;

for(int i=-k; i<=k; i++)

color += tab[ind++] * texture2D(texScreen, gl_TexCoord[0].st + vec2(0, i*stepY));

return color;

}

...

color = convolH(5);

...

color = convolH(3);

Once those were all fixed, the shaders now compile in AMD land, but the FPS is going from a smooth 60 to 1, then back up to 60.. then 1.

On Nvidia hardware, it is solid 60 all the way through.

Did I screw something up trying to convert the shaders ?

This is my first jump into GLSL, in case you haven't guessed. :)

Thanks for any info on this.

BTW, I thought GLSL is a standard, so why in the world is nvidia breaking the standard with their own mix of GLSL ? From what I read in the specs, you aren't supposed to use arrays like : vec4 convolH(float tab[], int size) [unless I read the specs wrong, which is always possible ;)]

This is with 11.5 drivers, Radeon 6870

I changed

normal_final_view += bumpmapping_factor*(2.0 * texture2D(texNormalMap, gl_TexCoord[0].st) - 1.0);

to

normal_final_view += bumpmapping_factor*(2.0 * vec3(texture2D(texNormalMap, gl_TexCoord[0].st) - 1.0));

vec4 LevelOfGrey(vec4 colorIn)

{

return colorIn.r * 0.299 + colorIn.g * 0.587 + colorIn.b * 0.114;

}

to

vec4 LevelOfGrey(vec4 colorIn)

{

return vec4(colorIn.r * 0.299 + colorIn.g * 0.587 + colorIn.b * 0.114);

}

for(int i=-kernel_size; i<=kernel_size; i++)

{

vec4 value = texture2D(texScreen, uv + vec2(pas.x*i, 0.0));

int factor = kernel_size+1 - abs((float)i);

to

for(int i=-kernel_size; i<=kernel_size; i++)

{

vec4 value = texture2D(texScreen, uv + vec2(pas.x*i, 0.0));

int factor = kernel_size+1 - abs(i);

and finally

float mask5_2[] = { 1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0};

float mask3_2[] = { 1.0/3.0, 1.0/3.0, 1.0/3.0};

...

vec4 convolH(float tab[], int size)

{

float stepX = 1.0/screenWidth;

vec4 color = 0;

int k = (size/2);

int ind = 0;

for(int i=-k; i<=k; i++)

color += tab[ind++] * texture2D(texScreen, gl_TexCoord[0].st + vec2(i*stepX, 0));

return color;

}

...

color = convolH(mask5_2,5);

...

color = convolH(mask3_2,3);

to

float mask5_2[5] = float[5](1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0, 1.0/5.0);

float mask3_2[3] = float[3](1.0/3.0, 1.0/3.0, 1.0/3.0);

...

...

vec4 convolV(int size)

{

float stepY = 1.0/screenHeight;

vec4 color = vec4(0);

int k = (size/2);

int ind = 0;

if (size == 5)

{

float tab[5] = mask5_2;

for(int i=-k; i<=k; i++)

color += tab[ind++] * texture2D(texScreen, gl_TexCoord[0].st + vec2(0, i*stepY));

return color;

}

else if (size ==3)

{

float tab[3] = mask3_2;

for(int i=-k; i<=k; i++)

color += tab[ind++] * texture2D(texScreen, gl_TexCoord[0].st + vec2(0, i*stepY));

return color;

}

...

color = convolH(5);

...

color = convolH(3);

Once those were all fixed, the shaders now compile in AMD land, but the FPS is going from a smooth 60 to 1, then back up to 60.. then 1.

On Nvidia hardware, it is solid 60 all the way through.

Did I screw something up trying to convert the shaders ?

This is my first jump into GLSL, in case you haven't guessed. :)

Thanks for any info on this.

BTW, I thought GLSL is a standard, so why in the world is nvidia breaking the standard with their own mix of GLSL ? From what I read in the specs, you aren't supposed to use arrays like : vec4 convolH(float tab[], int size) [unless I read the specs wrong, which is always possible ;)]