State machine vs shader uniforms; does performance really matter?

K.I.L.E.R

Retarded moron
Veteran
I have a typical habit of coding directly to my shaders, meaning I avoid using the GL state machine as much as possible(I cannot wait until Longs Peak is out).

One of the things I do is parse my matrices directly into the vertex program via uniforms instead of using glLoadMatrix. I control all my state inside my program.
My biggest concern is whether performance will suffer during rendering ops. Shaders may need to be recompiled internally when uniforms change.

I believe it comes down to a question of "What is the driver mostly optimised for?".
Given that games have been using shaders for a long time now, I figured that things such as updating uniforms would be faster than the more traditional fixed function state updates.

Maybe I'm wrong?
 
In theory it's better to not use any built-in state. In practice it doesn't matter.
 
or perhaps fixed-function state is implemented in terms of uniforms and there isn't a good reason for a performance difference.
 
Direct3D shaders don't have to the fixed function state, so in effect all the state info in Direct3D shaders such as matrices need to be passed as 'uniforms'. Chances are there would be little if any performance difference for you in OpenGL if you use uniforms. Of course using the GL State might provide the shade compiler some hints wrt optimizations... but don't ask me what.

If you want to find out just write a benchmark yourself. :)
 
Generally there should be no difference in performance. Even though the built-in variables are global across shaders doesn't mean that they don't cause constant uploads to the hardware since they most likely won't end up in the same constant registers across shaders anyway. I'd just stick to plain uniforms for best readability.
 
Thanks.

Just to clear up one more thing:
95% of OpenGL are shaders, the other 5% are buffer objects?

I've written a small library and found that I encompass everything I've ever needed or wanted with shaders and Buffer Objects. The recent addition to buffer objects(pixels) has been a god send.

Thanks Humus and Ati. :)
 
Using the recommended way offers the best possibility for automatic improvements with driver updates. But, due to the vast amount of different ways all the developers do their stuff, it shouldn't matter. It might run a bit better or worse on different versions, depending.
 
Back
Top