Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As mentioned here Effects should be avoided in DX11. If I understand correctly, that includes techniques and passes defined in *.FX files. So when doing a multipass shader (like the always-mentioned toon shader) I should create 2 separate shaders (for 2 passes), set the first one, render geometry, set the second one, render the geometry again. Correct so far?

But what I'm concerned about is that whether or not the technique/passes in Effects are just a syntactic sugar and offer no performance improvement whatsoever. Or the whole Effects in general. Do they?

GLSL version 4.20 or sth about that has subroutines which allow to switch the function in the shader and avoid changing the shader which does improve performance. Is there anything similar in DX?

Edit: Here [link] it says:

Since performance is crucial in shader programs, avoiding a conditional statement or a shader swap can be very valuable. With subroutines, we can implement the functionality of a conditional statement or shader swap without the computational overhead.

Also this post seems to confirm it.

share|improve this question
btw, changing the shader is a particularly cheap operation, especially when compared with making the draw call itself, which is a relatively expensive one. So I don't see why optimizing such a thing is that big of a deal unless you're switching it many many many times. But as always, profiling is helpful here.. – user148459 May 11 '13 at 20:37
I've read here and there (can't provide actual links now, sorry) that it is an expensive operation. Are you sure about that? (Of course, besides the fact that when it comes to GPU programming every optimization is precious.) – NPS May 11 '13 at 20:40
up vote 2 down vote accepted

Techniques and passes in an effect file are just syntactic sugar. Internally, the effect system is creating a separate shader for each pass of each technique. It also does things like managing constant buffers for you. The Effects 11 source is out there now, so you can look in there and see exactly how it works.

As for switching shaders, the common wisdom is that it's good practice to sort your draws by shader in order to reduce state changes to the minimum possible. I haven't seen any recent studies of just how much performance is at stake, though.

I'm not that familiar with GLSL subroutines, but they sound similar to D3D11 dynamic linking (which I'm pretty sure basically no one uses). Internally, I wouldn't be at all surprised if the graphics drivers are simply compiling a separate version of the shader for each GLSL subroutine or each D3D11 class interface, so I wouldn't take it for granted that these actually reduce the cost of state switching.

share|improve this answer
I google'd a lil' on the performance matter and it seems like subroutines actually might be improving performance. I've added my search results to my question (please see). I'd really like to hear more information on the performance matter (from anyone). – NPS Aug 25 '13 at 21:33
Also - do ifs actually decrease shader performance? Because that's something I neither would ever suspect nor have ever heard of. – NPS Aug 25 '13 at 21:38
@NPS If-statements in a shader can hurt performance because they cause divergence (see this presentation for more info; it's from 2010 but the same principles still apply). As for subroutines, the best advice I can offer at this point is to profile them and see what the performance impact is versus separate shaders. – Nathan Reed Aug 26 '13 at 0:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.