Efficient use of shader uniforms [ANSWERED]

Started by
4 comments, last by zedz 15 years, 3 months ago
It is my understanding that updating a shader's uniforms is costly to perform. But there has to be some kind of value associated with each uniform, even if dynamic branching is employed to avoid the section of the shader where it is used. So this leads to my questions about efficiency. Is updating all of a shader's uniforms per-object really expensive? Would I gain much from not updating uniforms that aren't used for that material? Any comments or examples would be most helpful. ;) [Edited by - n00body on January 17, 2009 10:12:07 PM]

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

Advertisement
My understanding is that it is better to use Attributes for things that get updated often.

In practice I have not noticed much difference.

Again, in practice I have found that you can get away with leaving Uniforms defined and re-using them without altering them. But I don't think it is "best practice".
Feel free to 'rate me down', especially when I prove you wrong, because it will make you feel better for a second....
dont use attributes for per object infomation, use uniforms (true the overhead is higher) but u only need to set it once for the whole object.

theyre not that expensive to change changing ~1000 a frame shouldnt occur any 'real' performance loss

btw aware eg nvidia do some tomfollery with certain uniforms eg 1.0 or 0.0 which can cause shader recompilation

as another performance saver with int/floats of 4 or less elements I first check if the current uniform values are the same as the new ones (on the cpu) if they are I dont reset them
I figured it was something like that. I didn't think they would be too expensive to switch, or it would be hard to have much variation between objects.

So it would be a performance win to check if the uniforms are the same? I thought this might be the case, but wasn't sure. I was planning to implement a similar trick for state-switching (blend, raster, etc).

Thanks for the tips, guys.

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

Quote:Original post by zedz
as another performance saver with int/floats of 4 or less elements I first check if the current uniform values are the same as the new ones (on the cpu) if they are I dont reset them


Have you done some benchmarks about this ? Is there really some performance gain ?

Y.

yeah I tested back in the days of the geforceFX ~4 years ago,
Logically thinking Ill say it still holds true today.

the only ones its not worth checking IMO are the mat44 cause
A/ theyre big thus a few dotproducts to see if the result is different
B/ they most likely change with each object,
- the only case this is not true I believe would be a shader used on a single object onscreen that is 100% stationary

This topic is closed to new replies.

Advertisement