directxdirectx-11compute-shaderdeferred-shading

Defered shading using compute shader, multiple swapchains?


Hy again. I'm up to add deferred shading in my dx11 engine, but I have a architecture question. I was thinking on first render the gbuffer using MRT, pass it to the compute shader, dispatch, and then output the result. My question is, shall I create two swap chains, one to render the gbuffer, and one uav, to render the compute shader to the backbuffer and present or there's another way to do that?. What I'm trying to avoid here is have to use a fullscren quad and render on it the output of the cs. Is too much overhead. Thanks in advance.


Solution

  • EDIT: I need to add that you get some states warnings doing this, so use with care.

    At the end, two swapchains are not needed. You first create your backbuffer with the DXGI_USAGE_UNORDERED_ACCESS flag. Then create a render target. Render your scene to that target, pass it to the compute shader as a Texture2D, and pass the backbuffer as a RWTexture2D to the compute shader. Then just dispatch the cs, present and done! You got the cs output in the screen.