PDA

View Full Version : cost of glGetUniformLocation



km,
11-30-2006, 08:11 AM
Hi All,

Does anyone know what is the cost of failed uniform query?

I have 10-15 uniforms which I would like to set depending on whether that uniform is defined in the attached shader.

I understand that failed GL query is costly but I do not see any difference between 1) while checking for uniform and setting when valid location found or 2) checking only for valid uniforms and setting.

Does anyone have some more information or data regarding what is the cost of failed glGetUniformLocation call?

thanks
Ketan

Relic
11-30-2006, 08:29 AM
To find a uniform which is not active will have to run through the whole search algorithm, so it's expected to take greater or equal the time to find an active uniform (=> slowest option).
Since uniform locations don't change if you don't call LinkProgram you can gather the valid locations per program once, and either simply check the location for -1 (inactive) and not sent the value (=> fastest option), or just send the values anyway and if the location is -1, the OpenGL implementation will ignore it (=> medium fast).
Calling an OpenGL entry function is slower than the if-statement you need to check if the uniform location is > -1, which makes the fastest option the smartest choice. ;)

km,
11-30-2006, 08:41 AM
Hi Relic,

For me since I have distinction between global (for all shaders) and local uniforms, access and search is not a low cost.

Before switching the shaders; I disable and set it to fixed function pipeline (glUseProgram(0)) - does that invalidate a uniform location?

I will also check your fastest suggestion :)

thanks
Ketan

Overmind
11-30-2006, 09:14 AM
Uniform locations are only invalidated when you call glLinkProgram, so the fastest option is that you just determine all uniform locations when linking the program and store it somewhere.

The uniform location query is expensive because it has to deal with strings. It has to do at least a few string compares, opposed to a simple table lookup when using the uniform index.

I don't think there is any relevant performance difference between a successful and a failed query.

Relic
12-01-2006, 02:08 AM
What overmind said ^^^


Before switching the shaders; I disable and set it to fixed function pipeline (glUseProgram(0))You mean you use
glUseProgram(A)
glUseProgram(0)
// Nothing in between
glUseProgram(B)
glUseProgram(0)

That's not necessary, just switch from A to B.

Yay, celebrating my 2222's post. Cheers. :D

km,
12-01-2006, 08:17 AM
Yes, I had done that and could scrap few miliSecs.

thanks to all of you, I think I have found my optimal flow.

thx
Ketan