DXGI_SWAP_EFFECT enumeration

Options for handling pixels in a display surface after calling IDXGISwapChain1::Present1.


typedef enum DXGI_SWAP_EFFECT {
} ;


DXGI_SWAP_EFFECT_DISCARD Use this flag to specify the bit-block transfer (bitblt) model and to specify that DXGI discard the contents of the back buffer after you call IDXGISwapChain1::Present1.
This flag is valid for a swap chain with more than one back buffer, although, applications only have read and write access to buffer 0.
Use this flag to enable the display driver to select the most efficient presentation technique for the swap chain.

Note  There are differences between full screen exclusive and full screen UWP. If you are porting a Direct3D 11 application to UWP on a Windows PC, be aware that the use of DXGI_SWAP_EFFECT_DISCARD when creating swap chains does
not behave the same way in UWP as it does in Win32, and its use may be detrimental to GPU performance.

This is because UWP applications are forced into FLIP swap modes (even if other swap modes are set), because this reduces the computation
time used by the memory copies originally done by the older bitblt model.

The recommended approach is to manually convert DX11 Discard swap chains to use flip models within UWP, using DXGI_SWAP_EFFECT_FLIP_DISCARD instead of DXGI_SWAP_EFFECT_DISCARD where possible.
Refer to the Example below, and see this article for more information.

DXGI_SWAP_EFFECT_SEQUENTIAL Use this flag to specify the bitblt model and to specify that DXGI persist the contents of the back buffer after you call IDXGISwapChain1::Present1.
Use this option to present the contents of the swap chain in order, from the first buffer (buffer 0) to the last buffer.
This flag cannot be used with multisampling.

Note  For best performance, use DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL instead of DXGI_SWAP_EFFECT_SEQUENTIAL. See this article for more information.

DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL Use this flag to specify the flip presentation model and to specify that DXGI persist the contents of the back buffer after you call IDXGISwapChain1::Present1. This flag cannot be used with multisampling.

Direct3D 11:  This enumeration value is supported starting with Windows 8.
DXGI_SWAP_EFFECT_FLIP_DISCARD Use this flag to specify the flip presentation model and to specify that DXGI discard the contents of the back buffer after you call IDXGISwapChain1::Present1.
This flag cannot be used with multisampling and partial presentation.
See DXGI 1.4 Improvements.

Direct3D 11:  This enumeration value is supported starting with Windows 10.




This enumeration is used by the DXGI_SWAP_CHAIN_DESC and DXGI_SWAP_CHAIN_DESC1structures.

To use multisampling with DXGI_SWAP_EFFECT_SEQUENTIAL or DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, you must perform the multisampling in a separate render target. For example, create a multisampled texture by calling ID3D11Device::CreateTexture2D with a filled D3D11_TEXTURE2D_DESC structure (BindFlags member set to D3D11_BIND_RENDER_TARGET and SampleDesc member with multisampling parameters). Next call ID3D11Device::CreateRenderTargetView to create a render-target view for the texture, and render your scene into the texture. Finally call ID3D11DeviceContext::ResolveSubresource to resolve the multisampled texture into your non-multisampled swap chain.

The primary difference between presentation models is how back-buffer contents get to the Desktop Window Manager (DWM) for composition. In the bitblt model, which is used with the DXGI_SWAP_EFFECT_DISCARD and DXGI_SWAP_EFFECT_SEQUENTIAL values, contents of the back buffer get copied into the redirection surface on each call to IDXGISwapChain1::Present1. In the flip model, which is used with the DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL value, all back buffers are shared with the DWM. Therefore, the DWM can compose straight from those back buffers without any additional copy operations. In general, the flip model is the more efficient model. The flip model also provides more features, such as enhanced present statistics.

When you call IDXGISwapChain1::Present1 on a flip model swap chain (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) with 0 specified in the SyncInterval parameter, IDXGISwapChain1::Present1's behavior is the same as the behavior of Direct3D 9Ex's IDirect3DDevice9Ex::PresentEx with D3DSWAPEFFECT_FLIPEX and D3DPRESENT_FORCEIMMEDIATE. That is, the runtime not only presents the next frame instead of any previously queued frames, it also terminates any remaining time left on the previously queued frames.

Regardless of whether the flip model is more efficient, an application still might choose the bitblt model because the bitblt model is the only way to mix GDI and DirectX presentation. In the flip model, the application must create the swap chain with DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE, and then must use GetDC on the back buffer explicitly. After the first successful call to IDXGISwapChain1::Present1 on a flip-model swap chain, GDI no longer works with the HWND that is associated with that swap chain, even after the destruction of the swap chain. This restriction even extends to methods like ScrollWindowEx.

For more info about the flip-model swap chain and optimizing presentation, see Enhancing presentation with the flip model, dirty rectangles, and scrolled areas.


To create a swap chain in UWP, you just need to create a new instance of the DX11 template and look at the implementation of DeviceResources::CreateWindowSizeDependentResources in the D3D12 samples.

DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};

       swapChainDesc.Width = lround(m_d3dRenderTargetSize.Width);    // Match the size of the window.
       swapChainDesc.Height = lround(m_d3dRenderTargetSize.Height);
       swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;            // This is the most common swap chain format.
       swapChainDesc.Stereo = false;
       swapChainDesc.SampleDesc.Count = 1;                           // Don't use multi-sampling.
       swapChainDesc.SampleDesc.Quality = 0;
       swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
       swapChainDesc.BufferCount = 2;                                // Use double-buffering to minimize latency.
       swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;     // All Windows Store apps must use a flip effect.
       swapChainDesc.Flags = 2048;
       swapChainDesc.Scaling = scaling;
       swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;

       // This sequence obtains the DXGI factory that was used to create the Direct3D device above.
       ComPtr<IDXGIDevice3> dxgiDevice;

       ComPtr<IDXGIAdapter> dxgiAdapter;

       ComPtr<IDXGIFactory4> dxgiFactory;

       ComPtr<IDXGISwapChain1> swapChain;


Header dxgi.h

See also

DXGI Enumerations