Special K - The Official Wiki

SwapChain Science

It puts the Pacing in Frame Pacing

D3D11/12 swapchain science

          The secret to SK's unbeatable framepacing results

What is a swapchain?

SwapChains are how Direct3D sequences rendered images for display output.

You may have heard of double- or triple-buffering, V-Sync, and refresh rate. Those are all properties of a DXGI SwapChain, along with framebuffer resolution, format and colorspace (HDR), and legacy things like MSAA / Gamma. Not all properties of a DXGI SwapChain are appropriate for modern Direct3D rendering as you will find out in the section on tuning.

FSE, FSO, Independent Flip, etc? Sorry, but what?!

For the super interested, we have two Sankey diagrams over on the Presentation Model page that shows the path from the swap effect requsted by the game and the display mode used to the final presentation model used by Windows, summarizing the below info dump in a hopefully understandable diagram.

It is a bit convoluted, but basically there are different swap effects a game can configure a swapchain to use -- the swap effect controls how the rendered frame should be presented from the perspective of the game. The actual presentation model used, however, depends on various factors beyond just the swap effect used.

Multi-Plane Overlay (MPO)

Multi-Plane Overlay (MPO) refers to the use of additional dedicated hardware scanout planes in the GPU that frames can be presented to, which the GPU then takes care of scanning out to the display itself, thereby allowing the GPU to shoulder the work (again achieving lower latencies) that the DWM would otherwise do but in software (which would incur an additional latency). How many MPOs a graphic card has assigned to a display is shown in SKIF's Settings tab (introduced in April 2023). Typically NVIDIA assigns all of the planes it supports (usually upwards of 4 of them) to a single display while the rest of the displays goes without any.

Minimum Requirements:

Support depends on the GPU and display configuration. Unusual driver or display configurations might disable MPO support, such as by using 10bpc in SDR mode or custom GPU scaling (NIS/RSR/integer etc).

Tuning goals

Flip model

Special K's primary attack strategy for D3D11 frame pacing is to enable flip model presentation.

(DXGI) Flip model is a new mode introduced in Windows 8 that makes the swapchain work efficiently with the Desktop Window Manager (DWM) of Windows. Flip model eliminates performance penalties normally associated with windowed mode rendering and introduces new methods to measure and regulate render latency.

Flip model is required for all D3D12 software as well as all UWP games sold on the Microsoft Store. It is also useable in D3D10 and D3D11 software, but most developers shipping software on Windows are oblivious to this and your typical D3D11 game performs sub-par as a result.

Frame Dropping (Always Display Newest Frame)

Traditional swapchain behavior (with V-Sync enabled) requires that each buffer be displayed on screen for at least 1 screen refresh before the contents of the next buffer is displayed and that all buffers output in the same order they were input.

FIFO's inability to prioritize the newest frame is the reason triple-buffering has traditionally meant trading increased input latency for V-Sync stutter mitigation.

Special K is configured to drop old frames by default.

We see no reason to ever use the traditional FIFO queuing behavior on a desktop machine in any graphics API that has the ability to skip old frames (e.g. D3D10/11/12 and Vulkan).

Recommended settings

The sections below include various recommended swapchain management settings that can be used in Special K in some common scenarios. Note that there is often no need to change any of these values, as Special K already ships with and enables the most optimal settings for most use-cases out-of-the-box. However, if you want to experiment and test around with various settings in an attempt to improve the experience in any of the below scenarios, these are some good baselines to go by.

Not all games support overriding the Buffer Count value. If any issues occur, open the game-specific config and change the BufferCount parameter to -1 to restore the game's default, or try 1 below/above its current value and see if that works better.

Enabling the Waitable SwapChain paramater, which may lower latency in certain cases, makes it impossible to use fullscreen exclusive mode (in D3D11 games), and it is no longer recommended in any scenario due to the stutter it results in when DirectFlip optimizations are lost.

D3D12 is a low-level API; many graphics engines have hard-coded their frame queuing behavior and will crash if the number of buffers is changed.

  • What was a quick and easy way to mitigate stutter in D3D11 is potentially fatal in D3D12.

You may need to set AllowD3D12FootGuns=true in the the game-specific config to be able to adjust the Buffer Count and Maximum Device Latency settings in D3D12.

Fiddle with Buffer Count in D3D12 at your own peril... Expect most games to crash at startup, and be prepared to set it back to -1 😃

The remaining SwapChain settings are generally safe to change.

V-Sync/Black Frame Insertion

While using regular V-Sync or Black Frame Insertion (BFI):

In-Game Setting Value Config Parameter
Presentation Interval 1 PresentationInterval
Buffer Count 3 BufferCount
Maximum Device Latency 4 or -1 PreRenderLimit
Enable Tearing Enabled AllowTearingInDWM

Variable refresh rate

While using a variable refresh rate (VRR/G-Sync/FreeSync):

In-Game Setting Value Config Parameter
Presentation Interval 1 PresentationInterval
Buffer Count 3 BufferCount
Maximum Device Latency 2 or -1 PreRenderLimit
Enable Tearing Enabled AllowTearingInDWM

V-Sync OFF/Latent Sync

While using V-Sync off / Presentation Interval 0 in Special K, which also engages Special K's tear-free no-sync feature (See Latent Sync for more information on that feature):

In-Game Setting Value Config Parameter
Presentation Interval 0 PresentationInterval
Buffer Count 3 BufferCount
Maximum Device Latency -1 PreRenderLimit
Enable Tearing Enabled AllowTearingInDWM

Flip model compatibility (Developer-focused info)

     Why Flip Model Overrides Have Never Been Implemented In Other Projects (e.g. ReShade)
           ... and where these projects should focus their efforts 🤣

Technical restrictions Special K has to work-around to enable Flip Model in all games:

1. sRGB Formats are Unsupported in Flip Model

Special K handles sRGB <-> Linear gamma correction for games that request an sRGB SwapChain and would otherwise not be Flip Model compatible.

Prior versions ignored the issue completely, simply stripping the sRGB format from the SwapChain and letting the user deal with the dark image that produced--do not do that ❗

2. MSAA (using SwapChain resolve) is Unsupported in Flip Model

Special K disables SwapChain-level MSAA when you enable Flip Model.

There are multiple ways of doing MSAA; modern graphics engines handle MSAA Resolve manually and are unaffected by this restriction.

Only really bad ports / engines use the SwapChain for MSAA in D3D11.

Special K may eventually provide offscreen MSAA resolve services for these poorly designed D3D11 games, but it is not a high priority.

3. Flip Model only supports 1 SwapChain per-window

This is almost never an issue, except for stupendiously screwed up games (i.e. NieR: Automata)

Special K detects situations where a game has created multiple SwapChains for the same window and will try to consolidate them into a single SwapChain in order to support Flip Model.

This workaround is usually successful...

If a game mixes and matches graphics APIs based on GDI and DXGI to render to the same HWND, it will never be compatible with Flip Model via an override.

Such a game is in serious need of refactoring and not worth the effort of supporting.

4. Flip Model Unbinds the SwapChain buffer from the D3D11 Output Merger

After a frame is Presented, Flip Model SwapChains will unbind any RenderTarget that references one of their buffers from the D3D11 Immediate Context.

Applications that do not explicitly setup the OM state to output to the SwapChain each frame will tend to produce a black screen if you force Flip Model on without also resetting the Output Merger state after Present (...)

5. Fullscreen Exclusive Mode Switches Require Resizing the SwapChain

Whether the actual resolution changes or not, until a Flip Model SwapChain is Resized, all attempts to Present (...) will fail.