Repository navigation
drm/apple: m4: tag external frames with the primaries they are drawn in (stacked on #3259) - #3260
themartiano wants to merge 4 commits into
Conversation
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>
9038241 to
f3e3c55
Compare
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>
f3e3c55 to
1644ede
Compare
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
maralcbr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 1644ede5163d
Blockers:
- Hardware row at head: the 2026-11-26 J713 row ran at
9038241871dbin a pre-rebase combined kernel; the rebase onto9177b2d474f8conflicted indcp-m4-frame.h, andiomfb_m4.chas gained #3321 idle-off onmainsince. Please post a J713 + Studio Display row at1644ede5163d(or a batched M4 candidate containing it unchanged on currentmain). - 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 ofdcp_metadata_color()(:131-142, low-bit shifts 6/4/2/0,(lo >> s) & 3).DCP_CIE+DIV_ROUND_CLOSEST(named, 64)yields696/328, 271/707, 154/61, 320/337, matchingparser-test.c:1519and the Studio Display chromaticities;±5/1024cleanly 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 afterdcp_m4_swap_encode_on()succeeds (upper index validated 1..3), tags surface 0 only whenprimary && frameand upper only whenupper && 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-byteext_colorspaceunderREAD_ONCE/WRITE_ONCEpersists instruct iomfb_m4across 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.hconflict with #2814 resolved cleanly. - Hosted CI at
1644ede5163d:Apple build and KUnitpass,Host testspass,pr-textpass. - Non-blocking notes:
parser-test.c:1559-1584: low bits contribute at most 3 while tolerance is 5, so onlyred_x(701/702) exercises the low-bit shift; one boundary check inblue_white_lo(e.g.white_y) would pin the second low byte too.iomfb_m4_ext_edid_published()is exported and could defensively guarddrm_edid_raw(edid) == NULLandIS_ERR(dcp_color_space_lookup(...))(neither can happen with today's callers).- Tag stays at the last published value if
get_modesis skipped (disconnect / debugfs EDID override), and akeepcursor 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_BT709vs0(UNSPECIFIED) is worth keeping in mind if firmware behavior ever differs.
There was a problem hiding this comment.
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>
|
Pushed Still owed: the J713 + Studio Display row and the sRGB sink check, now at |
There was a problem hiding this comment.
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.
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 withcm = 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 mainba29027e1580merged 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, newparser_edid_color_spacepasses (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
9177b2d474f8on 2026-12-02, on top of #3259's new head; head1644ede5163d, then59006d52704d(a failed EDID update keeps the tag of the EDID that stays published; both touched objects compile without warnings (arm64 LLVM,-Wextrawithoutunused-parameter,sign-compareandmissing-field-initializers, against the headers of a newer main), host testtools/asahi/dcpext26-edid-tests.pypasses; no hardware run yet). One conflict indcp-m4-frame.h: #2814'sdcp_m4_direct_frame()and this PR'sDCP_M4_SURFACE_COLORSPACEwere added at the same place; both are kept unchanged. Host checks re-run at the new head: W=1 arm64 build ofdrivers/gpu/drm/apple/, 0 warnings; checkpatch --strict clean; KUnitdcp-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
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.display-p3table, tolerance 5/1024; KUnit inparser-test.c.dcp-color.huses withdefault_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.cm = edidlooked 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:
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): KUnitapple*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--strictonly asked for the Signed-off-by (now added).