Skip to content

drm: apple: t8132: a cursor plane on external outputs (KWin on the M4 mini's HDMI) - #2296

Open
DjDeveloperr wants to merge 3 commits into
integration/aurorafrom
djdev/t8132-ext-cursor-plane
Open

DjDeveloperr wants to merge 3 commits into
integration/aurorafrom
djdev/t8132-ext-cursor-plane

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

The T8132 (M4) external outputs (t8132_ext_drm.c: the J713's USB-C displays, and the J773g Mac mini's HDMI with #1192) offer only a primary plane. KWin 6.8 then puts its cursor on that plane and every modeset fails with EINVAL (Plane must cover entire CRTC), so the desktop never lights the output unless KWIN_FORCE_SW_CURSOR=1 is set. This series adds a cursor plane and stops frames from being dropped while swaps are in flight.

Commits

  1. iommu: apple-dart: room for more external display host windows. The SID0 arena goes from 10 to 16 slices (6 to 12 host windows). With a cursor plane, KWin's frame buffers plus its cursor buffers ran the 6 windows out.
  2. drm: apple: t8132: a cursor plane on external outputs.
    • The plane is presented as the swap's upper surface 1, the way the swap record already describes upper surfaces (dcp_m4_upper): ARGB8888, pre-multiplied, surface ID 2.
    • The atomic check accepts only what the DCP takes as an upper surface: unscaled, 32x32 to 256x256 on screen, from the buffer's first byte.
      • A cursor partly off the right or bottom edge is shown as its on-screen part.
      • One off the top or left edge, or with under 32 px left on screen, is refused, so the compositor draws it itself.
    • Every swap carries the cursor with the frame, copied frames included.
    • The cursor framebuffer gets a SID0 window of its own. It is tracked like the frame's window, so a window is never unmapped while a swap may still show it.
  3. drm: apple: t8132: let a frame wait for the swaps in flight.
    • When both direct slots were in flight, a direct frame got -EBUSY and was dropped. The same happened to a copied frame while any direct swap was in flight.
    • On the J773g this showed as frame not shown: -16 after every 120 Hz modeset.
    • Frames now wait, at most 1 s, with the session lock dropped.

Testing

On a J773g (Mac mini M4) with a G81SF on HDMI, kernel 7.3.0 = this series + #1192 + #2166 on the M4 mini GPU stack:

  • Atomic test client, 1920x1080 at 60 and 120 Hz:
    • Accepted and committed: a 64x64 cursor with the modeset, mid screen, in the bottom-right corner, with 40 px visible at the right/bottom edges, and a 32x32 crop.
    • Refused at TEST_ONLY: 20 px visible at the right, off the left or top edge, and a 16x16 crop.
    • 240 cursor-only commits in a row, 0 failed (16.6 ms each at 60 Hz). The firmware took every upper-surface swap; no swap errors.
  • KWin 6.8:
    • It lights HDMI with its cursor on the cursor plane, which follows a uinput pointer.
    • It still logs a few Modeset failed: Invalid argument at start: its own trial of the cursor on the primary plane, before it settles. Harmless.
  • Dropped frames: no frame not shown in boots or across five suspend-to-idle cycles. The only cursor misses are ~0.3 s while KWin starts, when every window is busy.
  • Host tests: tools/asahi/run-host-tests.py --only apple-dcp (m4-wire-golden included) gives the same 15 failures on this branch as on integration/aurora 0abc2f3. All 15 are new-clang -Werror warnings in other units.

The J713 external path is the same code; it is untested there.

🤖 Generated with Claude Code

An external display DART's SID0 arena holds the two retained copy surfaces
(four slices) and the host windows of directly scanned-out framebuffers, one
32 MiB slice each. Ten slices leave six windows. A compositor that also
puts its cursor on a plane of its own (the next commit) uses three windows
for its frames and up to three for its cursor buffers, besides the
console's, and the windows ran out: the frame fell back to the copy path and
the cursor was not shown.

Take sixteen slices, which leaves twelve windows. The arena is fixed at
admission from the slices nothing else uses; generic DMA keeps the rest of
the 2048.

Signed-off-by: Diljit Singh <hey@djdev.me>
The T8132 external outputs (the J713's USB-C displays, and the J773g Mac
mini's HDMI with the main DCP) offered one plane, the primary. KWin 6.8 then
puts its cursor on that plane and every modeset fails with EINVAL ("Plane
must cover entire CRTC", a 64x64 buffer as a 32x32 destination), so the
desktop never lights the output unless KWIN_FORCE_SW_CURSOR=1 is set.

Add a cursor plane to each output and present it as the swap's upper surface
1, the way the swap record already describes upper surfaces:
- ARGB8888, linear, pre-multiplied (is_premultiplied set), zpos 1, under
  surface ID 2;
- the check takes what the DCP takes as an upper surface: unscaled, 32x32 to
  256x256 on screen, from the buffer's first byte, the pitch a multiple of
  64 bytes. A cursor partly off the right or bottom edge is shown as its
  on-screen part; one off the top or left edge, or with less than 32 pixels
  left on screen, is refused, so that the compositor draws it itself;
- every swap carries the cursor with the frame, the copied frames included:
  a commit of the cursor alone presents the frame on screen again with it;
- the cursor's framebuffer is mapped in a SID0 window of its own, tracked
  as the frame's is (the swap going out, the swaps in flight, given-up
  swaps, what a confirmed swap put on screen), so that a window is never
  unmapped while a swap may still show it. Twelve windows instead of eight.

Tested on a J773g (Mac mini M4) with a G81SF monitor on HDMI at 1920x1080,
60 and 120 Hz (kernel 7.3.0 with #1192):
- a raw atomic client: a 64x64 cursor with the modeset, then mid screen, in
  the bottom-right corner, 40 px visible at the right and bottom edges and a
  32x32 crop are accepted and committed; 20 px visible at the right, off the
  left or top edge, and a 16x16 crop are refused; 240 cursor-only commits in
  a row, none failed (16.6 ms each at 60 Hz);
- KWin 6.8 drives the output with the cursor on the cursor plane, which
  follows a uinput pointer; no swap errors.

Signed-off-by: Diljit Singh <hey@djdev.me>
With both slots for direct swaps in flight, iomfb_m4_ext_present_direct()
returned -EBUSY and the frame was dropped; and a frame that fell back to the
copy path while a direct swap was in flight was refused with -EBUSY too.
On the J773g Mac mini this showed as "frame not shown: -16", about ten in
a row after every 120 Hz modeset (fbcon, then KWin) while the display took
its first frames, and more whenever the host windows ran out. A dropped
frame's flip event is still sent, so a compositor that then goes idle leaves
the screen on the frame before.

Let the frame wait instead, with the session lock dropped: a direct one for
the oldest swap in flight to complete or be given up, a copied one for all
of them, 1 s at most each, then go out (-EBUSY only after that).

Tested on a J773g with KWin at 1920x1080@120 over HDMI: no "frame not
shown" in the boot or across three suspend-to-idle cycles (with the
previous commits).

Signed-off-by: Diljit Singh <hey@djdev.me>
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