Skip to content

drm/apple: m4: tag external frames with the primaries they are drawn in (stacked on #3259) - #3260

Open
themartiano wants to merge 4 commits into
aurora-silicon:mainfrom
themartiano:fix/m4-ext-colour
Open

themartiano wants to merge 4 commits into
aurora-silicon:mainfrom
themartiano:fix/m4-ext-colour

Conversation

@themartiano

@themartiano themartiano commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Every M4 surface is tagged Display P3, so the firmware converts an sRGB display's frames from P3 and oversaturates them; and the external link prefers an sRGB element, which makes a wide-gamut sink remap. Tag an external frame Display P3 only for a sink whose published EDID is Display P3 (untagged, which the firmware reads as sRGB, otherwise), and prefer Default RGB as the firmware 27 externals do.
Stacked on #3259 (the external EDID keeps its primaries; the tag reads them). Only the top two commits are new here; this PR shows that commit too until #3259 merges.
Tested: J713 (13-inch M4 MacBook Air, firmware 26.6.2) at 9038241871db, 2026-11-26, Apple Studio Display (Display P3) over Thunderbolt: PASS. 5120x2880, Hyprland 0.57.2 with cm = edid; a person judged the colours right (reds and greens neither neon nor washed out, whites neutral) and the picture sharp. The kernel (7.3.0-0.next2) was main ba29027e1580 merged with all our M4 display and other branches and #2814, #2797, #2807, #2672, not this branch alone. The trees of these commits are identical to the ones booted (353ad9d23504, 2b1bcec66174; only the Signed-off-by was added). Regression on that kernel: 0 failed units, no oops, crash or stall, 10/10 deep sleeps without kernel errors (no SELinux on this image). Host: KUnit, new parser_edid_color_space passes (566 run, 564 pass, 1 skip, 1 fail that main has too: apple-dcpaud-no-sio); apple-dcp host suite 95/95; W=1 build of each commit.
Rebased onto main 9177b2d474f8 on 2026-12-02, on top of #3259's new head; head 1644ede5163d, then 59006d52704d (a failed EDID update keeps the tag of the EDID that stays published; both touched objects compile without warnings (arm64 LLVM, -Wextra without unused-parameter, sign-compare and missing-field-initializers, against the headers of a newer main), host test tools/asahi/dcpext26-edid-tests.py passes; no hardware run yet). One conflict in dcp-m4-frame.h: #2814's dcp_m4_direct_frame() and this PR's DCP_M4_SURFACE_COLORSPACE were added at the same place; both are kept unchanged. Host checks re-run at the new head: W=1 arm64 build of drivers/gpu/drm/apple/, 0 warnings; checkpatch --strict clean; KUnit dcp-fabric, dcp-topology, dcp-display (the suites CI picks for these files) on arm64 QEMU: no failures (one case skips in each of two suites); apple-dcp host suite, no new failures (14 cases fail to compile with this container's newer compiler on main itself, and the same 14 here). The hardware rows above are from before the rebase.

Risk: two-way door · M4 (T8132) external outputs on firmware 26.6.2. Other Macs: only the M4 path calls the new dcp_edid_has_color_space() and uses the new link order; other DCPs are unchanged. Today's DTs enable the M4 external DCPs on J604, J713 and J715. On those, a Display P3 sink and the internal panel keep their tag; an sRGB sink should stop looking oversaturated (not yet seen at this head); a wide-gamut sink that is not Display P3 (Adobe RGB, BT.2020) is now converted as sRGB instead of as P3, so it can look less saturated than before. The link pick changes only for a sink that lists both a Default RGB and an sRGB element.
Not yet: an sRGB display (the change that matters most); a sink that is neither P3 nor sRGB; the tag across a deep sleep with a display attached.

Details
  • The tag follows the EDID the connector publishes (t8132_ext_get_modes()), not the DCP's cache, so it stays with what the compositor draws for over a relink or drm: apple: t8132: keep an external display across a deep sleep #2200's hold. Before an EDID is published, frames are untagged.
  • The Display P3 test uses the tree's own display-p3 table, tolerance 5/1024; KUnit in parser-test.c.
  • The link rank is the order dcp-color.h uses with default_rgb: Default RGB, then sRGB/BT.709, then full range. Nothing changes for a sink that lists one colorimetry only, such as the Studio Display.
  • Earlier evidence, older tree on the same J713 and display: untagged frames with cm = edid looked washed out next to the panel; tagged Display P3 they were judged right in a blind comparison. An earlier comparison found no visible difference between a BT.709 tag and none, which agrees with "untagged reads as sRGB".

Credit: Dylan Ironside first made the tag depend on the external sink (omarchy-j604).

Evidence

J713, Studio Display on DP-1 (Thunderbolt DP tunnel), test run of 2026-11-26 on 7.3.0-0.next2:

display   DP-1-sink            APP StudioDisplay
ext-edid  DP-1-chromaticities  r 0.6797,0.3203  g 0.2646,0.6904  b 0.1504,0.0596  w 0.3125,0.3291  (Display P3)
ext-edid  DP-1-hyprland-cm     preset edid
display   DP-1-last-enable     5120x2880@60 Hz, 936000 kHz; 0 enable failures
person    colours right: yes; picture sharp and steady: yes

The kernel does not log the chosen tag, so the Display P3 tag on this sink is inferred from the code and the result, not read back.

Host, at the old head 2b1bcec66174 (same tree): KUnit apple* on arm64 QEMU 566 run, 564 pass, 1 skip, 1 fail (apple-dcpaud-no-sio, fails on main too); apple-dcp host suite 95/95; both commits build with W=1; checkpatch --strict only asked for the Signed-off-by (now added).

The EDID an M4 external output publishes goes through dcp_edid_sdr(),
written for the native26 outputs and their sRGB output contract. Besides
the colour capabilities it zeroes the ten chromaticity bytes, so the
connector describes a sink whose red, green, blue and white are all 0,0:
no gamut at all. A compositor that maps into the EDID's gamut builds its
matrix from these bytes, and a zero set is singular.

The M4 path has no such contract. Its link uses a colour element of the
sink's own timing, which on an Apple Studio Display is Default RGB, the
sink's native gamut: its primaries are the ones frames are shown with.

Keep them, through dcp_edid_sdr_native(). Everything else dcp_edid_sdr()
removes still goes, and the native26 outputs keep the bytes zeroed.

Signed-off-by: Eduardo <git@martiano.me>
The external link prefers an sRGB/BT.709 colour element over a Default
RGB one. Told to show sRGB, a wide-gamut sink maps the values into sRGB
itself, while its EDID still describes its native gamut: a compositor
that maps into the EDID's gamut then has its colours converted twice.

Rank Default RGB first, then sRGB/BT.709, then full range, as
dcp-color.h does with default_rgb for SDR on the firmware 27 externals.
Nothing changes for a sink that lists one colorimetry only, such as an
Apple Studio Display (Default RGB).

Signed-off-by: Eduardo <git@martiano.me>
Every surface the M4 path presents is tagged Display P3, the panel's
primaries. The firmware converts a frame from its tag to the sink's
gamut, so on an external display that is not Display P3 it converts
values that were never P3: an sRGB sink's colours come out oversaturated.

A compositor draws for the EDID the connector publishes. Tag an external
output's frames Display P3 when that EDID has Display P3 primaries and a
D65 white, and leave them untagged otherwise, which the firmware reads
as sRGB. The tag follows the published EDID, so it stays with it over a
relink or a system sleep.

Nothing changes for a Display P3 sink or the panel. A sink that is
neither Display P3 nor sRGB is converted as if it were sRGB.

Dylan Ironside first found that the tag must depend on the external
sink (omarchy-j604, "drm/apple: m4: decide the EDID and SDR primaries of
an external sink").

Seen on a J713 with an Apple Studio Display (Display P3) and an earlier
tree: with its frames untagged a compositor drawing in the EDID's gamut
looked washed out next to the panel; tagged Display P3 it was judged
right in a blind comparison.

Signed-off-by: Eduardo <git@martiano.me>
@themartiano
themartiano marked this pull request as ready for review December 2, 2026 16:15
@themartiano
themartiano requested review from a team and DjDeveloperr as code owners December 2, 2026 16:15
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at 59006d52: not ready yet

Check Detail
CI at head ok 4 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at 59006d52
Conflicts ok none
PR text ok Risk: two-way · M4 (T8132) external outputs on firmware 26.6.2. Other Macs: only the M4 path calls the new dcpedidhascolorspace() and uses the new link order; other DCPs are unchanged. Today's DTs enable the M4 external DCPs on J604, J713 and J715. On those, a Display P3 sink and the internal panel keep their tag; an sRGB sink should stop looking oversaturated (not yet seen at this head); a wide-gamut sink that is not Display P3 (Adobe RGB, BT.2020) is now converted as sRGB instead of as P3, so it can look less saturated than before. The link pick changes only for a sink that lists both a Default RGB and an sRGB element.

Areas: area:display, area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@maralcbr maralcbr 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.

Verdict: FINISH, then merge at 1644ede5163d

Blockers:

  1. Hardware row at head: the 2026-11-26 J713 row ran at 9038241871db in a pre-rebase combined kernel; the rebase onto 9177b2d474f8 conflicted in dcp-m4-frame.h, and iomfb_m4.c has gained #3321 idle-off on main since. Please post a J713 + Studio Display row at 1644ede5163d (or a batched M4 candidate containing it unchanged on current main).
  2. sRGB external display check at head: fixing oversaturation on sRGB sinks is the main user-visible change here, and "untagged reads as sRGB" currently relies on an earlier indirect comparison. Please include an sRGB sink check at this head (or confirm if no sRGB external sink is available).

Once the hardware rows are posted (and #3259 merges first; #3259's commit ab7b87192d77 is an exact ancestor, so no rebase is needed), this is ready to approve and merge without a full re-review.

Checked: code is clean with no blockers; no Apple material, no chip/board/firmware gates, no new parameters, human DCO on all three commits; EDID chromaticity decoding, rounding/tolerance, surface colorspace tagging, link rank, concurrency, and current main (#3321) compatibility verified; hosted CI (Apple build and KUnit, Host tests, pr-text) is green at 1644ede5163d.

Evidence
  • drivers/gpu/drm/apple/dcp-display-metadata.c:201-219: dcp_edid_has_color_space() is the exact inverse of dcp_metadata_color() (:131-142, low-bit shifts 6/4/2/0, (lo >> s) & 3). DCP_CIE + DIV_ROUND_CLOSEST(named, 64) yields 696/328, 271/707, 154/61, 320/337, matching parser-test.c:1519 and the Studio Display chromaticities; ±5/1024 cleanly separates sRGB, DCI white, and D50 white.
  • drivers/gpu/drm/apple/dcp-m4-frame.h:112-113, 321-335 & iomfb_m4.c:2269-2272: dcp_m4_swap_set_colorspace() runs only after dcp_m4_swap_encode_on() succeeds (upper index validated 1..3), tags surface 0 only when primary && frame and upper only when upper && upper->frame, and touches external outputs (ext) only; internal panel and idle-cache swaps keep tag 12.
  • drivers/gpu/drm/apple/iomfb_m4.c:287, 3468-3477 & t8132_ext_drm.c:655-658: single-byte ext_colorspace under READ_ONCE/WRITE_ONCE persists in struct iomfb_m4 across relinks, sleep, and #3321 idle-off; updated strictly from the EDID published on the connector.
  • drivers/gpu/drm/apple/iomfb_m4.c:4002-4012: dcp_m4_ext_color_rank() ranks Default RGB (4) > sRGB/BT.709 (2) > other (0), plus full range (+1), matching fw27 (sdr_default_rgb_rank() / dcp-color.h).
  • 3-way merge against current main (6ee70d49c228): clean; dcp-m4-frame.h conflict with #2814 resolved cleanly.
  • Hosted CI at 1644ede5163d: Apple build and KUnit pass, Host tests pass, pr-text pass.
  • Non-blocking notes:
    • parser-test.c:1559-1584: low bits contribute at most 3 while tolerance is 5, so only red_x (701/702) exercises the low-bit shift; one boundary check in blue_white_lo (e.g. white_y) would pin the second low byte too.
    • iomfb_m4_ext_edid_published() is exported and could defensively guard drm_edid_raw(edid) == NULL and IS_ERR(dcp_color_space_lookup(...)) (neither can happen with today's callers).
    • Tag stays at the last published value if get_modes is skipped (disconnect / debugfs EDID override), and a keep cursor keeps its previous tag until updated; both are transient.
    • Note for future follow-up: Default RGB in limited range now outranks sRGB in full range (matching fw27), and explicit DCP_COLORSPACE_BT709 vs 0 (UNSPECIFIED) is worth keeping in mind if firmware behavior ever differs.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: REQUEST CHANGES at 1644ede

Failure: Start with a working Display P3 monitor and its EDID already published. On the next probe, drm_edid_connector_update() can fail when allocating the replacement EDID blob. drm_property_replace_global_blob() returns at IS_ERR(new_blob) before replacing connector->edid_blob_ptr, so the connector still exposes the previous Display P3 EDID. t8132_ext_get_modes() at lines 655–658 then calls iomfb_m4_ext_edid_published(owner, NULL), which writes DCP_COLORSPACE_UNSPECIFIED. The next swap sends the compositor's Display P3 frames with the firmware's sRGB interpretation even though the connector still advertises P3. Retain the current tag on an update error and clear it when an EDID removal succeeds.

Checked: Reviewed the EDID coefficient extraction and D65 tolerance, surface eligibility and bounds, and the Default RGB/SDR link ranking. Hosted build, host tests and DCP KUnit show success.

drm_edid_connector_update() can fail before it replaces the EDID blob. The
connector then still advertises the previous EDID, but the tag was cleared, so
a compositor's Display P3 frames were read as sRGB. Take the tag from the blob
the connector publishes, whatever the update returned.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Pushed 59006d52704d for the App review at 1644ede5163d: the tag now comes from the EDID blob the connector publishes, so a failed drm_edid_connector_update() keeps the previous tag and a removed EDID clears it. Both touched objects compile without warnings (arm64, LLVM, -Wextra without unused-parameter, sign-compare and missing-field-initializers, against the headers of a newer main, not a full W=1 build), tools/asahi/dcpext26-edid-tests.py passes, checkpatch --strict is clean. I did not inject the allocation failure.

Still owed: the J713 + Studio Display row and the sRGB sink check, now at 59006d52704d, after #3259; and an approval from someone other than me, since I pushed last.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 59006d5

Checked: The probe reads the connector's retained EDID blob while the DRM mode configuration mutex is held. A host fault-injection check using the exact probe and DRM blob replacement code passed all three cases: failed replacement retains the published Display P3 tag, successful replacement changes it to sRGB, and successful removal clears it. The previous probe failed the retained-tag assertion. The exact EDID suite also passed. Merge parent #3259 first.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants