Sign in to follow this  
Mercenarey

Vertex Shader constant data upload: Overhead?

Recommended Posts

Mercenarey    103
What is the overhead of uploading constant data to the shader? The reason I ask this, is because I am atm considering whether to make my shaders globally accessible through a kind of rendermanager, or let each renderobject manage its own private shader. The benefit of a rendermanager is obviously that it takes alot less memory to have only one instance of a certain shader, instead of one per renderobject. However, it got me thinking: What if every single renderobject (for instance with animations) have to upload all bone matrices every single frame? Not only when the bone matrices have been updated (I have made it so a animationFPS can be specified - for instance that the animation will only update 30 times a second, or even lower if I need to free up resources), but every single time? That would be necessary if there is one central shader, that all renderobjects uses, since other renderobjects would have overwritten the data with their bone matrices. What do you guys do? Do you give a renderobject its own personal shader? Or do you make them use a global one? What is the overhead of uploading all the time?

Share this post


Link to post
Share on other sites
999999999    162
I'm using global shaders. The data I need to upload is not so much in most cases. About the animation I have tried with 2 animations but I don't know how the performance will be when I have about 20 models to update.

Share this post


Link to post
Share on other sites
mattnewport    1038
You will have to reupload the constants either way - there's only one set of constant registers in the hardware and they will have to be updated with every draw call to hold the required values for that draw. If you use the effects system in D3D and create multiple effects then the effects runtime will handle the uploads behind the scenes for you but the same number of D3D Set*ShaderConst calls will be happening. You don't want to create multiple effect objects for a given shader - you'll get no efficiency benefit uploading constants and you'll lose performance because you'll probably have multiple copies of the vertex and pixel shader code around which the system won't recognise as the same so you'll end up with unneccessary SetVertexShader/SetPixelShader calls (in theory the runtime or driver could spot that the shaders are the same and optimize it away but you shouldn't rely on that).

Under D3D setting shader constants is relatively expensive - there's a fair bit of driver overhead involved in most cases - so you should try and minimize the number of shader constants you set (by not resetting the same value redundantly) but generally you have to do it for every draw.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this