Sign in to follow this  

Efficient use of shader uniforms [ANSWERED]

This topic is 3285 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this