0
votes

Using DirectX 11 & Effect 11, I'm trying to understand how to draw efficiently two objects with different shaders. So first I set all the states and set the constant buffers up once for all. And while iterating through all of first object's meshes, all the previously set constant buffers stay available which is fine as you can see here.

And then I'm applying another pass (Pass.Apply() from Effect 11) to draw the second object. And at this point, all my constant buffers are destroyed as shown there.

So now I'm starting to wonder if the constant buffers cannot be set once for all on app startup and then be used/shared at anytime, across any shader. Or does it belong to the active shader only?

Thanks!

1
What makes you think the CBs are being 'destroyed'? They are being updated per draw as one would expect. Take a look at this classic presentation for some good insights into Constant Buffers.Chuck Walbourn
Even if it's about a previous version of DirectX, it's a very interesting document, thanks for sharing Chuck, but I don't see any information about the CBs "life cycle" that could explain my situation.PontErable30

1 Answers

0
votes

If I remember, if you execute a different effect then you will have to reassociate the constant buffer to the stage (this is also possible dependent on the driver also). The only time you should get to reuse the same constant buffer is if you are not changing the state of shaders.

To be safe, a different Pass is basically binding a new set of shaders (if they differ). Best practice is that you bind your resource (buffer), each time you do a different effects pass.

I personally have moved away from Effects as it is deprecated, I've also found that explicitly understanding what I am binding to the pipeline has helped my understanding on usage of constant buffers.

The buffer shouldn't be destroyed, it should be just unbound on the 2nd call - otherwise you have something more nefarious going on.