Skip to content

On Linux, a compressed scanout is captured correctly while no cursor shows - #11

Merged
adamshiervani merged 1 commit into
mainfrom
kms-compressed-scanout
Nov 25, 2026
Merged

adamshiervani merged 1 commit into
mainfrom
kms-compressed-scanout

Conversation

@adamshiervani

@adamshiervani adamshiervani commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On Linux computers with an Intel GPU, parts of the video show a pattern of dots and dark blocks in place of the desktop. Regions with fine detail, such as photos, look correct, and flat regions, such as a terminal background or a wallpaper, do not. The fault appears while the mouse pointer is hidden, and it goes away when the pointer shows again. The viewer reports no lost packets, no dropped frames and no keyframe requests during the fault, so the stream arrives complete and the encoded picture itself is wrong.

Cause

The fault is in the KMS capture pipeline, in the step that brings the scanout (the framebuffer that the display shows) to the encoder.

A compositor can scan out a framebuffer with a render-compression modifier. On the affected computers, GNOME's scanout has the format XR30 and the modifier I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC (0x100000000000008). Such a framebuffer has planes after the pixel plane that hold the compression state of the pixels, and the pixel plane alone is not the picture.

CursorVpp::compose in cursor_vaapi.h has two ways to the encoder:

cursor visible  -> EGL imports the scanout (modifier, all planes), draws it and the cursor -> VPP -> encoder
cursor hidden   -> FFmpeg hwmap imports the scanout into VAAPI                            -> VPP -> encoder

EGL imports the scanout with its modifier and all its planes, so the first way gives the correct picture. On the second way, Intel's VAAPI driver refuses the import, because SetSurfaceParameterFromModifier in intel-media-driver has no case for this modifier. FFmpeg (vaapi_map_from_drm) then imports the buffer again through the older PRIME interface, which carries no modifier. The driver reads the compressed pixel plane as plain pixels, so every compressed block shows as garbage, and the fault follows the visibility of the cursor.

Fix

CursorVpp::compose now takes the EGL way also without a cursor when the scanout has more planes than its pixel format: more than 2 for NV12, more than 1 for the other formats. The new function has_auxiliary_planes makes that decision from the PRIME descriptor of the frame. CursorGL::compose already draws a scanout without a cursor, so it needs no change.

The check is on the number of planes and not on a list of modifiers, because the extra planes are what the import without a modifier loses, for any vendor's modifier. A scanout without extra planes keeps the direct way, so computers that are not affected do not pay for the EGL step.

The limit on the cursor size (1024 pixels) still applies only to a visible cursor. The error text of a failed composition changes from "cursor EGL composition failed" to "scanout EGL composition failed", because the step now also runs without a cursor.

Testing

The test computer has an Intel N100, Ubuntu 26.04, Mesa 26.0.8 and intel-media-driver 26.1.2. On a spare virtual terminal, kmscube -m 0x100000000000008 -f XR30 shows a cube on a gray background on a scanout with the modifier above and without a cursor plane. --capture-test then records 3 seconds, and the last frame of the recording is compared with the screen.

Build Scanout Picture Frame rate
main compressed wrong: the gray background is black and the cube is a pattern of dots 118.3 fps
this change compressed correct 99.0 fps
main not compressed (GNOME, X_TILED) correct 117.0 fps
this change not compressed (GNOME, X_TILED) correct 117.0 fps

The capture runs at up to 120 fps on this display. On the compressed scanout the EGL step costs frame rate on this GPU, and it is the same step that every frame with a visible cursor already takes. On the scanout that is not compressed, the frame rate and the bitrate (4955 and 4956 kbit/s) do not change.

The fault was first seen with version 0.4.5 on two computers with Intel Iris Xe graphics (12th and 13th generation Core), Debian 13, GNOME 48 on Wayland, Mesa 25.0.7 and intel-media-driver 25.2.3, at 2560x1440. On both, the picture was wrong with the pointer hidden and correct with the pointer visible. On one of them, --capture-test of this change records the GNOME desktop correctly with the pointer visible, on a scanout with the modifier above, at 110.6 fps. The state with a hidden pointer was not available on that computer for this change, so the table above is the test of that state.

Not in this PR

There is no automated test: the fault needs an Intel GPU and a compositor that scans out a compressed framebuffer, and the unit tests have neither.

…shows

With an Intel GPU, the video showed a pattern of dots and dark blocks in
place of parts of the desktop while the mouse pointer was hidden, for
example while the user typed in a terminal. With the pointer visible, the
picture was correct.

A compositor can scan out a framebuffer with a render-compression
modifier, such as I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC. Such a
framebuffer has planes after the pixel plane that hold the compression
state. Intel's VAAPI driver refuses to import a buffer with that
modifier. FFmpeg then imports the buffer again through the older
interface, which carries no modifier, and the driver reads the
compressed pixels as plain ones.

The capture pipeline has two ways to the encoder. With a visible cursor,
EGL imports the scanout with its modifier and all its planes, and draws
it and the cursor into an RGB surface. Without a cursor, the VAAPI
import of the scanout went to the encoder directly, and that import is
the one that is wrong for a compressed buffer.

A scanout with more planes than its pixel format now takes the EGL way
also without a cursor. Other scanouts keep the direct way.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Scanout composition

Layer / File(s) Summary
Auxiliary-plane detection and composition
src/video/kms/native/cursor_vaapi.h
has_auxiliary_planes compares the scanout plane count with the expected pixel-plane count. compose runs EGL composition when the cursor is visible or auxiliary planes are present. A comment notes that compressed scanout also uses EGL without a cursor.

Change: Bug fix

Merge Risk: Minimal · up to 2f71b

This change routes compressed scanouts through EGL even when no cursor is visible, which should fix corrupted capture on some Intel GPU systems. No concrete merge-blocking risk was found. Validation needs Intel hardware, so owners may want to confirm on a real compressed-scanout setup.

Security architecture risk: Low · up to 2f71b

The fix uses an existing rendering path to capture compressed desktops correctly when the cursor is hidden. If that path rejects a frame using the layout the session opened with, capture can stop rather than skip the frame. The impact is limited to the affected capture session.

Retained concerns

  • Low · reliability · observed: A cursorless auxiliary-plane frame that previously skipped EGL can now stop live capture if EGL composition fails. When the frame uses the modifier the pipeline opened with and stalled recovery has not already triggered, the worker records a fault and drops the live pipeline rather than discarding only the frame or reopening. Failures on a different modifier still take the reopen path.
Security review details

Security Blast Radius

  • inferred — The newly reachable work is GPU import and rendering for additional frames from the same locally captured DRM output. The inspected route does not introduce a viewer-supplied descriptor or a new authority boundary.

Trust Boundaries and Controls

  • observed — The local caller wraps the captured DMA-BUF in a single-layer descriptor, bounds the plane count, and retains the descriptor until composition returns. The EGL importer checks layer and plane limits and plane object indexes. The existing visible-cursor size limit remains in force.

Resilience and Maintainability Implications

  • observed — The compositor synchronizes the destination before GL access and waits for drawing to finish before handoff. Scoped imports release temporary resources, and the caller returns before encoder submission if composition fails, preventing a failed compose from emitting stale or partial output.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6f726505-c345-4b8c-9734-7cdcec6b6abe
Commits

Reviewing files that changed from the base of the PR and between d5de2f9 and 2f71b88.

Files selected for processing: 1

  • src/video/kms/native/cursor_vaapi.h

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@adamshiervani
adamshiervani merged commit c7c44c9 into main Nov 25, 2026
5 checks passed
@adamshiervani
adamshiervani deleted the kms-compressed-scanout branch November 25, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant