PDA

View Full Version : shader performance



kewuwsi
10-29-2007, 01:26 PM
Hi, all
I had a fragment shader like this:
void main(void)
{
if(A)
{

}
}

Trenki
10-29-2007, 02:39 PM
So what? What is the question? Normally you should write to gl_FragColor!

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

Jan
10-29-2007, 03:40 PM
Nice one. Maybe you should submit it to nVidia, they might want to include it in their shader-library.

Jan.

kewuwsi
10-30-2007, 06:20 AM
looks something is wrong when I post!
Hi, all
I had a fragment shader like this:
.....
void main(void)
{
vec4 color(0.0);
if(A)
{
// convolution to texture_0
......
color = ..
}
else
{
// convolution to texture_1 & texture_0
........
color =...
}
gl_FragColor = color;
}

It works OK.
the interesting thing is: the performance is decreased a lot( at least half) with above if /else branch. following are my testing results (for else part):
1) comment out the code in if branch( just have color = vec4(1.0, 0.0, 0.0, 1.0)
the performance is improved
2) separate the if /else into two functions, then call these two function in main() like "
void main(void)
{
vec4 color = vec4(0.0);
if(A)
color = caltexture_0(texture_0);
else
color = caltexture_1(texture_1);
}
"
the performance is improved too.

3) separate the if/else into two shaders. the performance is improved even better.

this only happens for complicated convolution, for simple convolution, there are no noticeable difference between above testing.

------------------thought it is related to the compiler ( I am working on linux, NV Quadro graphic card)-------------- anybody has a proven explanation for it?

many many thanks