Search code examples
directx-11direct3ddirect3d11

Does the backbuffer that a RenderTargetView points to automagically change after Present?


I've created a ID3D11RenderTargetView by specifying the ID3D11Texture2D* of back buffer 0 in the swap chain. But I'm unclear on what happens after _pSwapChain->Present(0, 0) is called.

Presumably what the ID3D11RenderTargetView had been pointing to is now the front buffer. Does Present somehow change the ID3D11RenderTargetView object to point to the new back buffer or does the application have to keep requesting the new 0 back buffer from the swap chain? I haven't found an explanation of exactly how the ID3D11RenderTargetView is supposed to always point to the new back buffer. I'm also unclear on how many buffers make sense to be in the swap chain.


Solution

  • Basically it is 'automagically' done in DirectX 11.

    See Anatomy of Direct3D 11 Create Device and DX11 DeviceResources

    This is not true in DirectX 12 where you have to explicitly bind to each back-buffer, as well as ensure all video memory that is 'in flight' for the frame is left in place until after the GPU is done with that frame. That's why DXGI 1.4 added IDXGISwapChain3::GetCurrentBackBufferIndex.

    See Anatomy of Direct3D 12 Create Device and DX12 DeviceResources

    There are a few other swapchain 'evolution' changes between DX11 & DX12 style. See The Care and Feeding of Modern Swap Chains.