Sign in to follow this  

What is a uber shader?

This topic is 1271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm wondering what a uber shader is. My first impression about a uber shader is putting everything in one shader and choosing the path dynamically. Does the shaders in Unreal Engine count as uber shader? They have plenty of branches in their shader code, however most of them are based on static conditions which are defined by macros during shader compiling, not run time. Do these kind of shader fall into the cateogry of uber shader? Thanks

Share this post


Link to post
Share on other sites

I'm wondering what a uber shader is. My first impression about a uber shader is putting everything in one shader and choosing the path dynamically. Does the shaders in Unreal Engine count as uber shader? They have plenty of branches in their shader code, however most of them are based on static conditions which are defined by macros during shader compiling, not run time. Do these kind of shader fall into the cateogry of uber shader? Thanks

 

I think it's a slightly fuzzy term without a strict definition.

 

I'd say that if your shader code is handling lots of different rendering scenarios, then it's an uber-shader . Whether those different scenarios are implemented with run-time or compile time switches doesn't matter IMO, it's still an uber shader.

 

I think that sometimes when people talk about uber-shaders, they mean just the scenario where there is pretty much just one shader used by the entire title (maybe with the exception that 2D/post-processing might use something different). Other times it's broader, and a title might be said to have a skinning uber shader and an environment uber shader, etc.

Share this post


Link to post
Share on other sites

Uber shaders were originally meant to reduce program state changes issued to GPU , thus it was being an idea of putting shader instructions into one shader and by branching over a uniform variable issue the desired ones, without the need of a program state change over GPU. Compile macros does not really target this usage, as they create separate compiled program objects in just a particular way. You need to check further whether those shaders in unreal engine are the "uber shaders"

 

But it is rather rare to have a performance benefit in using uber shaders in a well-managed rendering set since many branches in many draw calls will likely underperform a few program state changes. One should rather think of sorting draw calls by shader programs primarily. Generally, branching by uniform value is cheaper than branching by vertex attribute value, and cheaper than branching by interpolated or sampled value.

Share this post


Link to post
Share on other sites

Yeah in my experience, both of those different concepts get referred to as uber-shaders -- a complex shader with lots of runtime branches, or a complex shader-source-file that uses compile-time branching to generate many permutations / similar programs.

Also, back in the previous generation (D3D9 era), many GPUs allowed shaders to have 32 uniform boolean values. Doing a runtime branch on one of these was called "static branching", and branching on anything else was "dynamic branching". They both occur at runtime, but "static branching" was cheaper.
So there are actually 3 kinds:
1) compile-time selection of options, using different shaders at runtime.
2) runtime selection of options by branching on uniform Boolean values.
3) runtime selection of options by branching on other data (uniform floats, texels from a gbuffer, etc).

I don't think modern GPUs treat options #2/#3 differently anymore though!

Share this post


Link to post
Share on other sites
Sign in to follow this