FS performance question

I’m working on a Fragment Shader and I get a strange result about the execution times.

I have this line of code:

float var =  (inc / 2.0) + (cos(disp * 3.14) *  inc / 2.0);

now, if I pass inc as uniform variable, the FS takes 681 ms. to complete 1000 iterations (the shader is executed 1000 times), instead, if I replace inc with a numeric value (0.1 for example) it takes 699 ms.

I think that a code that uses a constant numeric value should be faster than the same code with an uniform variable, so why does this happen?

You are aware that such things completely depend on the shader compiler; with other words, on the driver? Son the behaviour will differ based on your graphics card and driver version. The values you are measuring are very close to each other (they are practically equal), I suppose the shader compiler just inlines the uniform variable as a constant (Nvidia drivers do that onolder cards, since uniforms have to be hard-coded n the shader anyway).

699 ms for 1000 shader executions? That doesn’t sound like you’re measuring shader execution time.

Why not?

You don’t know what my GL/GLSL code does nor the screen/texture size, how can you say that? :confused:

You don’t know what my GL/GLSL code does nor the screen/texture size, how can you say that?

If you are talking about the execution of a shader, then “screen/texture size” is entirely irrelevant. However, if you’re measuring the time it takes to execute a particular rendering command, then it is entirely relevant.

So the question stands: what are you measuring here?

I’m working on a GPGPU program, so I use 2 textures to read/write data, this is the reason why I talked about texture size in my previous post.

I forgot to thank Zengar for his reply :wink:

Well, you wrote the shader is executed 1000 times, but obviously you’re rendering far more than 1000 fragments… :wink:

You still haven’t mentioned what and how exactly you’re measuring.

A better way to determine the shader performance, is to use a occlusion and a timer (Nvidia only) query. With both values it’s easy to calculate the fillrate or averange shader run time.

I know, so I’m asking how did u say that :slight_smile:

However my timing code is something like this:

t1 = SDL_GetTicks();

for(int i = 0; i < num_it; i++)

t2 = SDL_GetTicks();

The time I wrote is the time needed by 1000 iterations on a 800x800 RGB texture.

I didn’t give you more details because I’m not complaining about the execution time, I was just wondering why a shader that uses a uniform variable is faster than the same one that uses a numerical value.

Are you talking about EXT_timer_query ?

yes, unfortunately it doesn’t work with ATI cards…

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