Sign in to follow this  
metsfan

How many shader programs is too many?

Recommended Posts

metsfan    679
Hey all, I've been experimenting with a lot of different techniques and I'd just like to get an opinion from people with experience, how many shader programs is too many? Hundreds? Thousands? At what point should I start thinking about ways to consolidate shader programs? What are the performance implications of creating, say, 1000 shader programs for a single application?

Any advice would be much appreciated, thank you.

Share this post


Link to post
Share on other sites
tanzanite7    1410
[quote name='metsfan' timestamp='1333414361' post='4927722']
At what point should I start thinking about ways to consolidate shader programs?
[/quote]
When compilation time becomes an issue.

Ways to prevent it becoming an issue:
* don't load everything at once - stream it as much as possible. (ex: load immediately what is needed for the first scene and load the rest later. ex2: load the ones you expect will be needed while the user is navigating your menus to load/start a game).
* use binary blobs to cache already compiled programs.
* don't use so darn many shaders if you do not actually have to ;p.

Share this post


Link to post
Share on other sites
metsfan    679
[quote name='tanzanite7' timestamp='1333420682' post='4927740']
[quote name='metsfan' timestamp='1333414361' post='4927722']
At what point should I start thinking about ways to consolidate shader programs?
[/quote]
When compilation time becomes an issue.

Ways to prevent it becoming an issue:
* don't load everything at once - stream it as much as possible. (ex: load immediately what is needed for the first scene and load the rest later. ex2: load the ones you expect will be needed while the user is navigating your menus to load/start a game).
* use binary blobs to cache already compiled programs.
* don't use so darn many shaders if you do not actually have to ;p.
[/quote]

I wouldn't say I [i]need [/i]that many shaders but it would make my life much easier. I'm just trying to get an idea of if there is some sort of hard or soft limit I should be aware of for shader programs where it starts to have a very negative adverse effect. This is helpful though, thank you.

Share this post


Link to post
Share on other sites
Ashaman73    13715
The only real problem I could see is compilation time. But, to be honest, when you use around 1000 different shaders, you will most likely have more than a few thousand batches, which will be a real problem (number of batches is still a bottleneck at current gen).

Beside shader compilation time I would not invest too much time thinking about the number of shaders, to be honest. There will be other, more important issues.

Share this post


Link to post
Share on other sites
RobinsonUK    108
As this is on the topic of multiple shaders and that's something I've been thinking about recently, can I add a question? Is it common practice to generate one uber-shader that can deal with all combinations of parameters, including maps, or to use conditional compilation to make one shader that you can associate with each material type? For example, I might have one model with diffuse, gloss, normal map, emissivity map and one model with only diffuse. I can make set of bit flags and use that to index an appropriate shader to draw the object, binding the correct number of targets. So, would you have one shader for all combinations, or one for each combination of different map types? With 8 maps types in my model, there are a possible 256 different combinations.

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