I took my first stab at using deferred contexts in DirectX 11 today. Basically, I created my deferred context using CreateDeferredContext() and then drew a simple triangle strip with it.

Early on in my test application, I call OMSetRenderTargets() on the immediate context in order to render to the swap chain's back buffer. Now, after having read the documentation on MSDN about deferred contexts, I assumed that calling ExecuteCommandList() on the immediate context would execute all of the deferred commands as "an extension" to the commands that had already been executed on the immediate context, i.e. the triangle strip I rendered in the deferred context would be rendered to the swap chain's back buffer.

That didn't seem to be the case, however. Instead, I had to manually pull out the immediate context's render target (using OMGetRenderTargets()) and then set it on the deferred context with OMSetRenderTargets().

Am I doing something wrong or is that the way deferred contexts work?


Turns out the answer was staring me in the face on MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476424%28v=vs.85%29.aspx

Immediate context state is cleared before and after a command list is executed. A command list has no concept of inheritance. Each call to FinishCommandList will record only the state set since any previous call to FinishCommandList.

I don't know why it's mentioned on the page for ID3D11DeviceContext::FinishCommandList when it's even more relevant for ID3D11DeviceContext::ExecuteCommandList.


I think a good solution would be to record the state of the immediate context after the initialization code and then execute the list on each deferred context when you create it and then call FinishCommandList on the deferred contexts just to prevent the initialization operations from being merged into the actual command lists later on. But I'm not sure if that's what they intended.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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