Skip to main content

Swapchain & Presentation Policy

Kanvas keeps swapchain selection policy in a small platform-neutral C unit: swapchain_policy.c.

That code chooses:

  • surface format
  • color space
  • present mode
  • image count
  • drawable extent

before backend-specific creation code consumes the result.

Preferred format​

When available, Kanvas prefers:

BGRA8 sRGB
+
sRGB nonlinear color space

If a Vulkan-style surface reports a single undefined format, Kanvas selects that sRGB format explicitly.

Color-space policy is observable

UI colors are authored and interpreted as display-referred colors. Treating the presentation surface as an arbitrary linear UNORM target can produce visibly wrong output when the source content and swapchain disagree about transfer functions. This is why the sRGB preference is part of presentation policy rather than a cosmetic choice.

Present mode​

The policy prefers mailbox presentation when available and falls back to FIFO.

MAILBOX → preferred
FIFO → required fallback

FIFO is treated as the baseline because it is the portable, guaranteed presentation mode in the Vulkan model.

Image count​

Kanvas requests:

minImages + 1

and clamps that value to the surface maximum when a maximum exists.

The extra image gives the renderer room to work without immediately reusing the minimum set of presentation images.

Extent selection​

When the platform supplies a fixed current extent, Kanvas uses it.

When the extent is application-selected, the requested width/height is clamped to the surface's supported minimum and maximum.

This policy is tested separately from the Vulkan implementation so swapchain decision bugs can be reproduced without needing a live GPU surface.

Source: