How many shader programs is too many?

Started by
3 comments, last by RobinsonUK 12 years ago
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.
Advertisement

At what point should I start thinking about ways to consolidate shader programs?

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 name='metsfan' timestamp='1333414361' post='4927722']
At what point should I start thinking about ways to consolidate shader programs?

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 need 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.
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.
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.

This topic is closed to new replies.

Advertisement