skip to content

How do vsync and double or triple swapchain buffering trade tearing and smooth frame pacing against input latency in a game loop?

level: middleimportance: should knowfreq 46%

answer

  1. presenting during scanout tears
  2. wait for the vertical blank
  3. missed deadline halves the rate
  4. queued images add delay
  5. even intervals beat a higher average

basics

~20 s

Vsync waits for the display's refresh boundary so images never tear, but a missed deadline costs a whole extra refresh. More swapchain buffers keep the rate up, but queued images add input latency and uneven pacing judders.

solid answer

~50 s

Without vsync a finished image replaces the one being scanned out mid-refresh, so the screen shows parts of two frames: tearing, but the lowest latency. With vsync and two buffers, a frame that misses a 16.7 ms deadline at 60 Hz waits for the next refresh, so a game that needs 17 ms per frame locks to 30 frames per second. A third buffer lets rendering continue while a finished image waits, so average rates between 30 and 60 become possible, but each image queued ahead of the display adds up to one refresh of input latency, and display intervals become uneven. Frame pacing is that evenness: 40 frames per second on a 60 Hz display alternates 16.7 and 33.3 ms and looks worse than a steady 30. Common answers are capping the rate to a divisor of the refresh, limiting queued images, a replace-latest present mode, or a variable refresh rate display.

go deeper

for a junior

Recall what tearing looks like, that vsync prevents it by waiting for the display's refresh boundary, and that waiting can lower the frame rate.

for a middle

Explain why double-buffered vsync snaps to divisors of the refresh rate, the two meanings of triple buffering, and why queued images add latency.

for a senior

Diagnose judder from uneven display intervals versus low average rate, and choose between frame caps, queue limits and late input sampling for a given game.

for a principal

Set the defaults a team ships per platform and genre, balancing latency for competitive play against even pacing, and decide which options players control.

## How an image reaches the screen A display **refreshes** at a fixed rate, for example 60 Hz, which means a new refresh every 16.7 ms. During each refresh it **scans out** the image line by line from top to bottom, then pauses briefly in the **vertical blank** before the next refresh. The game renders into images held in a **swapchain**, a small ring of images owned by the display system: one is being shown (the front buffer) while the game draws into another (a back buffer). **Presenting** hands a finished back buffer to the display. When that hand-over happens decides three things players notice: **tearing**, **smoothness** and **input latency** (the time from pressing a button to seeing its effect). ## Vsync off: lowest latency, tearing If the game presents the moment a frame is finished, the display switches images mid-scanout. The top of the screen shows the old frame and the bottom the new one, split by a visible horizontal **tear** that is most obvious during fast camera pans. Latency is as low as it gets, which is why some competitive players accept tearing. ## Vsync with two buffers: no tearing, quantised rates With **vsync**, a present waits for the vertical blank, so a whole image is always shown. With only two buffers, the game cannot start the next frame until the back buffer is free, so: - a frame finished within 16.7 ms is shown at the next refresh; - a frame that takes 17 ms misses that refresh and waits for the following one, so it is shown for 33.3 ms; - sustained frames just over budget lock the game to **30 frames per second**, and further misses give 20, then 15: whole divisors of the refresh rate. A 1 ms overrun costs half the frame rate, which is the classic complaint about double-buffered vsync. ## Triple buffering: two different meanings Adding a third image lets the game keep rendering while a finished image waits for the blank. Engines and display systems use the name for two different behaviours: | Mode | What happens to finished images | Effect | |---|---|---| | **Queued** | each waits its turn and is shown in order | no tearing, rates between divisors, but images wait in the queue, adding latency | | **Replace-latest** | a newer finished image replaces the one waiting | no tearing, lower latency than a queue, some rendered frames are never shown | | **Two buffers, vsync on** | only one image can wait | little queueing delay, but rates snap to divisors | In a queued mode, every image waiting ahead of the newest one delays it by up to one refresh, about 16.7 ms each at 60 Hz. When rendering is the bottleneck the queue stays full, so latency sits at its maximum all the time. ## Frame pacing **Frame pacing** is the evenness of the intervals at which new images reach the screen, which matters as much as the average rate. On a 60 Hz display: - a steady 30 frames per second shows every image for exactly two refreshes, 33.3 ms each; - 40 frames per second shows images for 16.7, 33.3, 16.7, 33.3 ms, and moving objects visibly **judder** even though the average is higher. Pacing also feeds back into the loop: if the delta time the simulation uses does not match how long each image is actually on screen, motion stutters even when every frame is delivered on time. Some engines therefore derive delta time from the presentation schedule rather than from raw frame-start timestamps. ## Levers a game loop has 1. **Cap the frame rate** to a divisor of the refresh rate (60 or 30 on a 60 Hz display) for even pacing. 2. **Limit the images queued** for display to keep latency bounded, accepting that the game may miss refreshes more often. 3. **Sample input as late as possible** in the frame, so the input is fresh when the image is built. 4. **Use a replace-latest mode** where available to drop stale images instead of queueing them. 5. **Support variable refresh rate displays**, which refresh when an image is ready within a range, removing the snap to divisors; capping a few frames below the display's maximum keeps the game inside that range so the queue never fills. No single setting wins everywhere: a fast competitive game favours latency, a cinematic one favours even pacing, which is why many games expose vsync and frame caps as player options.

  • Why does a game running at 40 frames per second on a 60 Hz display often look worse than one capped at 30?
    Sixty refreshes do not divide evenly into forty frames, so images stay on screen for alternating 16.7 and 33.3 ms. Objects moving at constant speed advance by uneven amounts per displayed image, which reads as judder. At a steady 30 every image lasts 33.3 ms, so motion is evenly spaced even though fewer images are shown.
  • Why can capping the frame rate a few frames below the display's maximum reduce latency on a variable refresh rate display?
    A variable refresh rate display refreshes when an image is ready, but only up to its maximum rate. If the game produces images faster than that, finished images start queuing as they would under ordinary vsync, and each one waits. Capping slightly below the maximum keeps every image presented as soon as it is done, so the queue stays empty.

  • Believing vsync never changes the frame rate, only removes tearing
  • Assuming triple buffering always lowers input latency
  • Judging smoothness by the average frame rate alone
  • Thinking tearing comes from the game simulating too fast
  • Adding buffers to fix latency instead of removing queued images