Skip to content

Conversation

@RT2Code
Copy link
Contributor

@RT2Code RT2Code commented Oct 23, 2025

This PR is a follow-up to #8979 (comment)
It is split into two commits:

Use DXGI_SWAP_EFFECT_FLIP_DISCARD instead of DXGI_SWAP_EFFECT_DISCARD

Switching to DXGI_SWAP_EFFECT_FLIP_DISCARD is straightforward and requires changing only three lines. The buffer count was increased from 1 to 2, as DXGI_SWAP_EFFECT_FLIP_DISCARD requires a minimum of two buffers. According to the documentation, this swap effect is supported starting with Windows 10, which implies requiring the Windows 10 SDK.

Enable swapchain tearing

This part is largely similar to #8965. Adding support for tearing is significantly more involved, and here are the key changes:

  • In the example file, D3D11CreateDeviceAndSwapChain was replaced by D3D11CreateDevice and CreateSwapChainForHwnd. This change is necessary because we must access the DXGI factory before creating the swapchain, in order to query tearing support and set the corresponding flag. This is not possible with D3D11CreateDeviceAndSwapChain, as the swapchain is created before the factory is accessible.
  • CreateSwapChainForHwnd returns an IDXGISwapChain1 instead of IDXGISwapChain, and requires a DXGI_SWAP_CHAIN_DESC1 instead of DXGI_SWAP_CHAIN_DESC. The according types have been updated.
  • In the backend, CreateSwapChain was also replaced by CreateSwapChainForHwnd. While not strictly required, the former is deprecated and Microsoft recommends transitioning away from it.
  • Flags are provided to swapchain ResizeBuffers to propagate the DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING flag (or else it will fail).

Regarding SDK requirements, this bumps the dxgi version to 1.5 (required for CheckFeatureSupport). Dxgi 1.5 was introduced in the Windows 10 Anniversary SDK. According to Microsoft’s documentation, the tearing feature is nearly ubiquitous on recent versions of Windows 10 and on modern hardware.

If you’re considering whether this is too much of a change, note that tearing support is highly recommended by Microsoft when using flip-model swap effects with VSync disabled:

For an application using sync interval 0, we do not recommend switching to flip model unless the IDXGIFactory5::CheckFeatureSupport API is available, and reports support for DXGI_FEATURE_PRESENT_ALLOW_TEARING.

One aspect not yet addressed is how the user can provide the desired swap effect to the backend. It isn't strictly required, main and secondary viewports can happily operate with different swap effects. However, if we want to allow users to configure this behavior, it would likely require introducing an init info structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants