Vertex Shader constant data upload: Overhead?

Started by
2 comments, last by Mercenarey 18 years, 8 months ago
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?
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Advertisement
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.
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.

Game Programming Blog: www.mattnewport.com/blog

Thanx Matt, that was VERY helpful! I understand shaders and how they interact/stores on the graphics card alot better now.
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.

This topic is closed to new replies.

Advertisement