Rether / docs
engine/Swapchain
referenceA queue of rendered images waiting for the screen

Swapchain

updated 2026.08.31created 2026.08.31~2 min

The concept

A GPU cannot draw straight into the pixels a monitor is currently scanning out — doing so would show half-finished frames. Instead it renders into off-screen images held in memory, and only swaps a finished one onto the screen once it is ready.

The swapchain is the queue that manages those images: it hands the renderer an image to draw into, and later presents the completed image to the display, coordinating the timing between the GPU producing frames and the screen consuming them.

Why more than one image

With a single image the GPU and the display would fight over the same memory: the screen would read a frame while the GPU is still drawing it. Keeping a small set of images lets the two work in parallel.

  • Double buffering — one image is shown while the next is drawn. The GPU waits for the swap.
  • Triple buffering — a third image lets the GPU keep working ahead instead of stalling, at the cost of more memory and power.

Present modes

The present mode is the rule for when a finished image replaces the one on screen. It trades three things off against each other — tearing, latency, and power / frame rate:

  • VSync — swaps only at the monitor's refresh boundary. No tearing, but the frame rate is capped and latency can rise if the GPU falls behind.
  • Triple-buffered / mailbox — swaps at the boundary too, but always shows the newest finished frame and discards stale ones. No tearing, lowest latency, higher power draw.
  • Immediate — swaps the instant a frame is ready. Highest frame rate, but the image can change mid-scan, producing visible tearing.

The presentation cycle

Every frame follows the same three beats:

// text
acquire  -> the swapchain hands out the next free image
render   -> the GPU draws the frame into that image
present  -> the finished image is queued for the display

Because the CPU, the GPU, and the display all run at once, this cycle needs synchronization so an image is never drawn into while it is still being shown, and never shown while it is still being drawn.

Recreation

The swapchain is tied to the surface it presents to. If that surface changes — most commonly a Window & Native surface resize — the images no longer match and the swapchain must be torn down and rebuilt at the new resolution before rendering can continue.

Relation with other engine concepts

  • Window & Native surface: The swapchain presents to the window's surface; its image size follows the window's framebuffer, and a resize forces recreation.
  • Graphics context: The device and queues that own and drive the swapchain come from the graphics context.
  • Vulkan Swapchain: How this concept is actually built and driven on the Vulkan backend.

Keyboard

search this vault⌘K / /
step the sidebarjk
open selected↵
switch browse mode123
switch vaultgv
toggle themet
close / clearesc
this help?
esc to close