How DirectX Manages V-Sync Synchronization
Vertical synchronization (V-Sync) in DirectX is managed primarily through the DirectX Graphics Infrastructure (DXGI), which coordinates frame timing between the graphics processing unit (GPU) and the display monitor. By synchronizing the swapping of rendered frame buffers with the display's vertical blanking interval (VBlank), DirectX prevents screen tearing and ensures that new image data is presented only when the monitor is ready to draw a complete new scan.
The Swap Chain Architecture
DirectX implements V-Sync through an abstraction known as a swap chain. A swap chain consists of at least two frame buffers:
- Front Buffer: The memory buffer currently being read by the display hardware to output the image on the screen.
- Back Buffer: The off-screen buffer where the GPU renders the next frame.
Without synchronization, the GPU might write new data to the visible buffer mid-scan, causing the top half of the screen to show one frame while the bottom half shows the next—an artifact known as screen tearing.
The Presentation
Mechanism and SyncInterval
Synchronization occurs when an application calls the
IDXGISwapChain::Present method. This method accepts a
parameter called SyncInterval, which explicitly dictates
how the frame presentation aligns with the display's vertical refresh
cycle:
SyncInterval = 0(V-Sync Disabled): The runtime presents the frame immediately without waiting for a VBlank signal. The front and back buffers swap as soon as rendering completes, which maximizes frame rates and minimizes input latency, but allows screen tearing.SyncInterval = 1(Standard V-Sync): DirectX queues the rendered frame and waits for the hardware VBlank signal. Once the monitor finishes drawing the current scanline pass and enters the blanking interval, the runtime executes the buffer flip. The frame rate is capped to match the display’s native refresh rate (e.g., 60 Hz, 144 Hz).SyncInterval = n(Fractional Sync): Specifying a value higher than 1 instructs DirectX to synchronize the presentation with every n-th vertical blank. For example, aSyncIntervalof2on a 120 Hz monitor caps the presentation to 60 FPS.
Flip Model vs. BitBlt Model
Modern DirectX versions (DirectX 11.3 and DirectX 12) prioritize the
Flip Model
(DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and
DXGI_SWAP_EFFECT_FLIP_DISCARD) over the legacy
BitBlt Model.
In the legacy BitBlt model, the back buffer was physically copied to the front buffer, consuming memory bandwidth and adding latency. The modern Flip model bypasses this copy operation by simply exchanging the memory addresses of the front and back buffers.
When running in windowed or borderless modes, the modern Flip model allows DirectX to coordinate directly with the Desktop Window Manager (DWM). This ensures that windowed applications receive the same low-latency, tear-free V-Sync performance traditionally reserved for exclusive fullscreen mode.
Variable Refresh Rate (VRR) Integration
For displays supporting Variable Refresh Rate technologies, such as
NVIDIA G-Sync or AMD FreeSync, the fixed VBlank paradigm is modified.
Under DirectX 11 and 12, developers can pass the
DXGI_PRESENT_ALLOW_TEARING flag alongside a
SyncInterval of 0. This enables the graphics
driver and display hardware to adapt dynamically: the monitor delays its
refresh cycle until the GPU has finished rendering the next frame,
providing tearing-free presentation without enforcing a rigid, fixed
refresh interval.