Skip to content

drm/apple: ask software-rendering clients for a shadow buffer - #2571

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
j615/appledrm-prefer-shadow
Nov 22, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
j615/appledrm-prefer-shadow

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem. appledrm's dumb buffers come from the DMA GEM helpers and are mapped write-combined to user space. A compositor that renders in software draws straight into them and reads back from uncached memory on every blend. Every compositor renders in software on a Mac whose GPU driver isn't up yet, e.g. the M3 MacBook Air on macOS 27.2 firmware tonight. GNOME on the J615 (2880x1800) used a whole core and presented about one frame a second, while the DCP finished each swap in 4-15 ms.

Change. Set mode_config.prefer_shadow. DRM_CAP_DUMB_PREFER_SHADOW then tells such clients to render into a cached shadow buffer and copy. Mutter logs the cap at start-up for every KMS device, but acts on it only when it renders in software: should_force_shadow_fb() (meta-renderer-native.c) returns before reading it when the renderer is hardware. With a hardware renderer nothing changes.

Testing. J615 (MacBook Air 15" M3), macOS 27.2 stub, lab kernel with the 27.2 internal-display series, appledrm.ko with and without this change, GNOME 51 (Mutter software path):

  • Mutter logs Device '/dev/dri/card1' prefers shadow buffer (not logged before).
  • With a fullscreen GTK client animating every frame, DCP iomfb_swap_complete events went from about 0.8/s to 5.4/s (44 in 8.1 s). gnome-shell is still CPU-bound (~98 % of one core), so this is a mitigation until the GPU driver exists, not a fix.
  • No change in the display path itself: pure-KMS atomic flips stay at 60.000 Hz.

Hardware renderer (M2, fleet76, GNOME on the GPU driver). The cap reads 1 with this change, gnome-shell stays on the GPU render node, and the appledrm framebuffer list is the same as with the stock module (gnome-shell's XR30 scanout imported from the GPU, plus fbcon; no dumb or shadow buffers). Idle gnome-shell CPU is unchanged (0.1-0.4 %). Row: #2571 (comment)

Method and evidence
  • Lane J615-DISP. Kit: kits/test/20261120-j615-disp/shadow/ (module dbac7cc1, built against the j615d1 tree, signed with its key). Rows: shadow-row.sh (gtkhz, a GTK4 fullscreen client queueing a redraw every frame, GSK_RENDERER=cairo, plus a private tracefs instance on dcp:iomfb_swap_complete, plus gnome-shell utime+stime over the window).
  • Before: boot 498501b3 (same kernel and Stage 2, stock appledrm.ko). After: step-6 boot (same kernel, updates/ module). Both with the session unlocked and the panel lit at 50 nits for the test only (lab night rules).
  • Lab traces: traces/display/20261120-j615-dcp272/ (batch1-pacing-dbg.txt, step6-shadow-row2.txt), our own measurements.

Assisted-by: LLM (Claude:Opus 5.5)

appledrm's dumb buffers come from the DMA GEM helpers and are mapped
write-combined to user space. A compositor that renders in software
into them, which is every compositor on a Mac whose GPU driver is not
up yet, reads back from uncached memory for every blend. On the M3
MacBook Air (J615) with no GPU driver, GNOME's gnome-shell spends a
whole CPU core and presents about one frame a second on the 2880x1800
panel while the DCP completes each swap in 4 to 15 ms.

Set mode_config.prefer_shadow, so DRM_CAP_DUMB_PREFER_SHADOW tells
those clients to render into a cached shadow buffer and copy the
damage. Mutter reads the cap and uses a shadow buffer only when it
renders in software; with a hardware renderer nothing changes.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Tested on an M2 MacBook Air (J413, T8112), kernel 7.3.0-aurora-fleet76, GNOME 50 / mutter 50.6, Aurora Mesa 26.3. Method: the same fleet76 tree built twice (stock appledrm.ko and appledrm.ko with this diff, W=1 with no warnings), one plain boot of each, with checks taken while the GNOME session was running.

Mutter prints Device '/dev/dri/card1' prefers shadow buffer from init_caps() (src/backends/native/meta-kms-impl-device.c:590 in 50.6) for every KMS device that reports the cap, whatever the renderer, so that line shows up with this PR and tells us nothing about which path is in use. The shadow framebuffer is chosen in should_force_shadow_fb() (src/backends/native/meta-renderer-native.c:1491-1506), and that function returns FALSE first when the renderer is hardware accelerated. gnome-shell renders on the aurora GPU in both builds, so its shadow path stays off. The framebuffer list on the display device confirms it: both builds have the same scanout buffers, and the only gnome-shell buffer is imported from the GPU. There are no extra dumb or shadow buffers.

check stock with this PR
DRM_CAP_DUMB_PREFER_SHADOW on card1 (apple) 0 1
DRM_CAP_DUMB_BUFFER on card1 1 1
gnome-shell render node renderD128 (aurora), GPU engine time > 0 renderD128 (aurora), GPU engine time > 0
Mutter "prefers shadow buffer" line absent present (logged at init for any device with the cap)
debugfs dri/1/framebuffer gnome-shell XR30 2560x1664 mod 0 imported=yes, fbcon XR24 same
gnome-shell CPU, idle, 30 s samples at 130-220 s uptime 7-12 ticks (0.2-0.4%) 3-12 ticks (0.1-0.4%)
eDP-1 connector connected, session up connected, enabled, session up
kernel errors / AVC / failed units 0 / 0 / 0 0 / 0 / 0

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train adversarial review (MERGETRAIN-LINUX2) at 81282b6: NO BLOCKERS.

Code read only, nothing built here. Before the merge it still needs Dj's verdict at this head; the missing rows are listed below.

Full review

#2571 drm/apple: ask software-rendering clients for a shadow buffer @81282b64

VERDICT: NO BLOCKERS

drivers/gpu/drm/apple/apple_drv.c:1721-1726 sets mode_config.prefer_shadow. In this tree that field is read only by the DRM_CAP_DUMB_PREFER_SHADOW ioctl (drivers/gpu/drm/drm_ioctl.c:273). The in-kernel fbdev (drm_fbdev_dma.c:306) chooses shadowing from fb->funcs->dirty, not from this field, so fbcon is unchanged. It is not a gate or a param, and it applies to every Mac with appledrm.

Nits:

  • The comment and commit message claim "with a hardware renderer nothing changes". That is verified for Mutter only (the M2 row). Other clients act on this cap too. Xorg modesetting reads it when glamor is off, and weston-pixman/wlroots-pixman read it for software paths. That's the intended effect, but KWin/Plasma and the Xorg path have no row.
  • A Mutter session that drives an external display through a separate KMS device or the secondary-GPU copy path was not tested with this cap set. Single-device M2 is the only hardware-renderer row.

Missing rows: J616s or Neo (other DCP generation, iomfb_is_m4 path) on the hardware renderer with an external display attached, checking that gnome-shell still imports GPU scanout buffers on every output. A KDE/KWin session on any Mac.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-PR checklist review at 81282b6451d121f9a1da7add0448d805d8d45292 (§1–§6): 0 blockers — APPROVE.

Code & Source Verification

  • drivers/gpu/drm/apple/apple_drv.c:1726 unconditionally sets apple->drm.mode_config.prefer_shadow = true during apple_drm_init(), matching the DMA GEM write-combined dumb-buffer mapping (apple_drm_gem_dumb_create -> drm_gem_dma_dumb_create_internal).
  • Verified across drivers/gpu/drm/ that the sole in-kernel reader of mode_config.prefer_shadow is drivers/gpu/drm/drm_ioctl.c:273 (DRM_CAP_DUMB_PREFER_SHADOW).
  • Verified drivers/gpu/drm/drm_fbdev_dma.c:306 selects shadowed fbdev strictly from fb->funcs->dirty, so in-kernel fbcon is unaffected.

Checklist Summary

  • §1 No model gating: Pass — unconditional across all appledrm devices; no chip/SoC/board/firmware gating.
  • §2 Production-ready: Pass — works on default command line with no parameters, delays, or workarounds.
  • §3 Safety: Pass — no hardware safety limits or protection paths touched.
  • §4 Clean-room & attribution: Pass — commit 81282b64 carries human author/committer and Signed-off-by: Ryan Murray <[email protected]> with no AI trailers; Assisted-by: is in the PR body.
  • §5 Evidence: Pass — covers both affected paths on this exact diff: software-renderer A/B on J615 (M3 Air, 0.8/s -> 5.4/s swaps, 60.000 Hz pure-KMS unchanged) and hardware-renderer A/B on J413 (M2 Air, 7.3.0-aurora-fleet76, GNOME 50 / Aurora Mesa 26.3: cap 0 -> 1, GPU-imported scanout unchanged, idle CPU unchanged, 0 kernel errors / 0 AVC / 0 failed units).
  • §6 Naming: Pass.
  • CI: host-tests SUCCESS on live head 81282b64.

Non-blocking note: hardware-renderer testing covers single-device Mutter (GNOME); KWin/Plasma, Xorg modesetting, and external-display copy paths were not sampled, though advertising DRM_CAP_DUMB_PREFER_SHADOW for write-combined dumb buffers is standard DRM behavior.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide
RyanTheTide merged commit f036989 into integration/aurora Nov 22, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the j615/appledrm-prefer-shadow branch November 27, 2026 13:21
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.

2 participants