Skip to content

wlroots0.20: reuse front buffer on same-resolution modeset - #40

Open
grierj wants to merge 1 commit into
OrchardLinux:mainfrom
grierj:wlroots-same-res-modeset
Open

grierj wants to merge 1 commit into
OrchardLinux:mainfrom
grierj:wlroots-same-res-modeset

Conversation

@grierj

@grierj grierj commented Dec 5, 2026

Copy link
Copy Markdown

Problem

When a compositor commits a refresh-rate-only mode change without attaching a buffer (e.g. labwc applying a wlr-output-management configuration via wlr-randr), output_ensure_buffer() in wlroots unconditionally attaches a newly cleared solid-black empty buffer for the modeset (Attaching empty buffer to output for modeset).

On simpledrm / ProMotion displays (such as J207 switching between 60 Hz and 24 Hz for OrchardLinux/omarchy-a#298), this blits a full black frame (~19 ms measured directly on the physical scanout framebuffer) before the compositor paints the next frame, causing a visible black flicker on every refresh-rate transition.

Change

Add 0004-output-reuse-front-buffer-on-same-resolution-modeset.patch to wlroots0.20 and bump pkgrel to 3 (1:0.20.2-3):

  • types/output/render.c (output_ensure_buffer()): On a WLR_OUTPUT_STATE_MODE commit without a buffer, when no other state change requires a fresh buffer (ENABLED, RENDER_FORMAT, initial reconfiguration, COLOR_TRANSFORM, or IMAGE_DESCRIPTION), skip attaching an empty buffer if the output is already enabled at the same width x height and output->impl->test(output, state) succeeds. Otherwise fall back to the existing empty-buffer path.
  • backend/drm/drm.c (drm_connector_commit_state()): Restrict per-output bufferless modeset reuse on renderer-backed outputs to single-GPU commits whose current primary framebuffer belongs to output->swapchain with swapchain->format.format == output->render_format (avoiding untested secondary-GPU probes, direct-scanout scaling/clock hazards, and 8-bit direct-scanout frames capping max_bpc on 10-bit outputs, without affecting device-wide wlr_backend_test/commit).
  • include/backend/drm/drm.h & backend/drm/drm.c: Track queued_fb_reused on struct wlr_drm_plane so explicit-sync release timelines on a reused framebuffer are preserved until a new buffer replaces it, while explicit same-buffer resubmissions still release normally.

Verification

  • ./tools/pkgrepo check and python3 -m unittest discover -s tests (37/37 OK).
  • Built cleanly for aarch64 via ci/build-package arch wlroots0.20 aarch64 1:0.20.2-3.
  • Installed wlroots0.20 1:0.20.2-3 on iPad Pro 10.5" (J207, simpledrm + labwc): cycled across 9 refresh-rate switches (24 / 30 / 48 / 60 / 120 Hz) plus 90° -> normal rotation with zero visible black flickers and zero compositor errors.

Assisted-by: LLM

When a compositor commits a refresh-rate-only mode change without attaching a buffer (such as labwc applying a wlr-output-management config), output_ensure_buffer() previously attached a freshly cleared solid-black empty buffer for the modeset. On simpledrm / ProMotion displays this blits a full black frame (~19 ms on J207) before the compositor repaints.

Add patch 0004 to skip the empty buffer when an already-enabled output changes mode at the same resolution (without color-transform or image-description changes) and the backend test accepts the bufferless state. On the DRM backend, keep reuse restricted to per-output commits using a primary framebuffer from the current render-format swapchain (avoiding secondary-GPU untested probes and direct-scanout format/scaling hazards) and preserve explicit-sync release points until a new buffer replaces the reused framebuffer.

Bump wlroots0.20 pkgrel to 3 (1:0.20.2-3).

Assisted-by: LLM
@grierj

grierj commented Dec 5, 2026

Copy link
Copy Markdown
Author

Before / After hardware verification (iPad Pro 10.5" J207, simpledrm + labwc)

Sampled the physical scanout framebuffer (0x8fa0a4000) via /dev/mem at ~1 ms intervals during wlr-randr --output Unknown-1 --mode ... switches:

Before (wlroots0.20 1:0.20.2-2):

t= 0.0 ms: 75f141067901820679018206  (desktop)
t= 6.5 ms: 000000000000000000000000  (solid black empty buffer blitted for 19.1 ms)
t=25.6 ms: 75f141067901820679018206  (desktop repainted)

After (wlroots0.20 1:0.20.2-3):
3 non-zero scanout offsets (0xa3ac0, 0x198020, 0x28c580) across 4 switches (0 / 1,220 samples black):

1668x2224@60Hz:  rc=0, samples=306, black_hits=0, changes=1
1668x2224@120Hz: rc=0, samples=305, black_hits=0, changes=1
1668x2224@24Hz:  rc=0, samples=304, black_hits=0, changes=1
1668x2224@60Hz:  rc=0, samples=305, black_hits=0, changes=1

drm.debug=0x16 atomic commit trace (60Hz -> 24Hz -> 60Hz):
Both modesets reuse the existing swapchain front buffer ([FB:44]) directly instead of allocating/attaching an empty black framebuffer, followed by normal double-buffered repaints ([FB:42], [FB:44]):

[ 3561.187996] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_fb_for_plane] Set [FB:44] for [PLANE:35:plane-0] state ...
[ 3561.188001] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_mode_prop_for_crtc] Set [MODE:1668x2224] for [CRTC:37:crtc-0] state ...
[ 3561.215747] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_fb_for_plane] Set [FB:42] for [PLANE:35:plane-0] state ...
[ 3561.237442] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_fb_for_plane] Set [FB:44] for [PLANE:35:plane-0] state ...
[ 3561.370913] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_fb_for_plane] Set [FB:44] for [PLANE:35:plane-0] state ...
[ 3561.370917] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_mode_prop_for_crtc] Set [MODE:1668x2224] for [CRTC:37:crtc-0] state ...
[ 3561.391822] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_fb_for_plane] Set [FB:42] for [PLANE:35:plane-0] state ...
[ 3561.411123] simple-framebuffer 8fa0a4000.framebuffer: [drm:drm_atomic_set_fb_for_plane] Set [FB:44] for [PLANE:35:plane-0] state ...

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