4

I've read up on the theory/reasoning behind a swap chain in Graphics. Everywhere I've read, they talk about pointers to the front and backbuffer(s) which are swapped instead of actual data exchange. My question is, where exactly can we see this swapping? is it in some function? is it automatic? if it's automatic, where do we get the pointer to the other buffer?

If we look at this code from Rastertek for instance, m_renderTargetView always seems to point to the same buffer throughout the execution of the code :

result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
if(FAILED(result))
{
    return false;
}

// Create the render target view with the back buffer pointer.
result = m_device->CreateRenderTargetView(backBufferPtr, NULL, &m_renderTargetView);
if(FAILED(result))
{
    return false;
}
backBufferPtr->Release();
backBufferPtr = 0;
Amit
  • 43
  • 1
  • 3
  • 1
    This question may be more on-topic on gamedev.stackexchange.com . – Lars Viklund Oct 20 '15 at 13:24
  • The buffer swapping happens inside the driver, most likely in some other thread. When you issue a `Present`/`SwapBuffers` call or the like, that's just pushing a command into the driver queue, to be executed at some point by the driver back-end. Modern graphics drivers are quite complex and run in parallel with your application. – glampert Oct 20 '15 at 18:08

1 Answers1

4

When swapping with a Direct3D 11 device, the API presents the contents of the current buffer and internally maps in the next buffer as the same slot, making it seem like you're always working with the same buffer.

From what I've seen of Direct3D 12, they appear to remove this shadowing and instead forces the developer to manually keep track of which resource is used to present and which one is the render target.

Direct3D 12 forbids usage of the usual DXGI_SWAP_EFFECT_DISCARD and DXGI_SWAP_EFFECT_SEQUENTIAL, instead mandating DXGI_SWAP_EFFECT_FLIP_DISCARD or DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL. Generally you are forced to use DXGI flip model introduced in DXGI 1.2 improvements.

Citing MSDN's page titled DXGI 1.4 Improvements:

Invariant Backbuffer Identity

In Direct3D 11, applications could call GetBuffer( 0, … ) only once. Every call to Present implicitly changed the resource identity of the returned interface. Direct3D 12 no longer supports that implicit resource identity change, due to the CPU overhead required and the flexible resource descriptor design. As a result, the application must manually call GetBuffer for every each buffer created with the swapchain. The application must manually render to the next buffer in the sequence after calling Present. Applications are encouraged to create a cache of descriptors for each buffer, instead of re-creating many objects each Present.

Lars Viklund
  • 2,106
  • 1
  • 17
  • 14
  • That makes sense, thanks both of you. Also, if it's not too much trouble, could you point me to the documentation that gives this detail, I'd like to learn more about it. – Amit Oct 21 '15 at 05:18