Skip to content

drm/apple: colour matrix fixes (two's complement, refused warning, tag names, brightness correction) - #790

Merged
RyanTheTide merged 4 commits into
integration/aurorafrom
colour/ctm-fixes
Nov 5, 2026
Merged

RyanTheTide merged 4 commits into
integration/aurorafrom
colour/ctm-fixes

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Colour matrix (CTM) fixes, found while checking GNOME night light and an ambient white point on the J616s, M1 Pro and M2.

  • Two's complement CTM. set_matrix takes S31.32 values with negatives in two's complement. The driver sent DRM's sign-magnitude form, so any negative coefficient came out as a large positive one. On the J616s panel a white field through B' = B - R stayed white before this and turns yellow with it (Ryan checked both by eye). macOS 27 on the same machine sends exactly this encoding for Night Shift and True Tone (traced with dtrace, values like 0xffffffffff2ae435 for small negatives).
  • Refused matrix warning. The set_matrix reply was ignored. A refused matrix now logs a rate-limited warning and the per-family sequence carries on.
  • Surface colour tag names. The enum names now say what the values mean (linear 8, sRGB 13, PQ 16, HLG 18; BT.2020 9, P3-D65 12). Values sent are unchanged.
  • Identity brightness correction after every matrix. macOS follows every set_matrix with setBrightnessCorrection(1.0) on each display (seen on all three J616s displays). Linux only did so on the Neo; this sends it on the 12.3 and 13.5 firmwares too, which is the likely reason the CTM had no visible effect on the M1 Pro and M2.

Tested: J616s on fleet14d with these commits (yellow/white check, kernel -p3 0). The M1 Pro/M2 effect of the brightness correction is not measured yet (the M2's light sensor needs room light; planned for the morning), so please hold the merge for that. Host selftests 85/85, W=1 clean.

🤖 Generated with Claude Code

DRM carries CTM coefficients as S31.32 sign-magnitude. The firmware's
set_matrix takes signed two's complement Q31.32, the same encoding the
display stack uses for its own conversion matrices. The template copied
the DRM matrix unchanged, so any negative coefficient (a saturation
change, a gamut conversion) reached the firmware as a huge negative value
instead. Positive coefficients have the same bits in both encodings, which
is why diagonal CTMs such as night light worked.

Convert each coefficient with drm_color_ctm_s31_32_to_qm_n(), which also
folds DRM's negative zero to zero, in one helper shared by the template
and the J613 backend, which had its own open-coded conversion. Add a host
selftest for the identity default, positive pass-through and negative
values.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The set_matrix reply was ignored on every firmware family, so a refused
CTM left the previous matrix on screen with nothing in the log. Check the
reply status in one callback that then continues with the per-family
sequence (A428 on H17P, the gamma table on desktop 26.x, else the swap).

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The surface colour primaries and transfer function are the IOSurface
indices the firmware takes unchanged. Several names said something else:
primaries 12 is P3-D65, not a native space; 0 is unspecified rather than
sRGB; 9 is plain BT.2020; transfer 13 is sRGB rather than generic SDR and
16 is SMPTE ST 2084 (PQ) rather than generic HDR. Rename them, add the
linear (8) and HLG (18) transfer functions and DCI-P3 primaries (11) used
by extended-range and video surfaces, and say in the header what each
value is. The values sent are unchanged.

The YCbCr mapping in plane.c still sends primaries 1 for BT.601 and 2 for
BT.709, although 1 is BT.709 in the IOSurface naming; that is left for a
change that can be tested with video.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
On the M2 (13.5 firmware) a CTM sent with set_matrix location 9 is
accepted, status 0, but the panel output does not change: a white field
with a 0.5 diagonal CTM measures the same as plain white. The status only
says the firmware cached the matrix. Every known working sequence follows
set_matrix with brightness correction set to identity, 0x10000 (1.0 in
16.16): the H17P path already does so with A428, macOS sends A428 after
each Night Shift and True Tone matrix, and the M1 bring-up sequence sends
A427 after A422.

Send A427 identity after set_matrix on 12.3 and 13.5 too, through one
method entry shared with H17P's A428 and one callback for every firmware
family that has the method. Desktop 26.x keeps its current sequence.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware evidence from tonight. The merge itself waits for the retarget to integration/aurora, with Ryan.

J616s one-shot of 7.3.0-aurora-prr1103c = integration/aurora f153499 + this PR + linux PRs 837 and 731, boot 6a127964. The boot is k -p3 0 with 0 AVCs, and its warning set is identical to fleet14p's. With GNOME Night Light forced on at 3500 K for 10 s, the kernel logged nothing: no refused-matrix warning and no DCP errors. The settings were put back afterwards. The panel was blanked for night rules, so this doesn't show the colour itself, and the M1 Pro/M2 brightness-correction measurement you asked to hold for is still outstanding. On the host, the apple-dcp selftests including the new colorimetry group pass in the aurora-wip test merge.

@RyanTheTide
RyanTheTide changed the base branch from aurora-wip to integration/aurora November 2, 2026 23:15
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge train (MTL, 06/11), gates passed on test tree 0412501 (integration/aurora 2661d71 + the train):

  • Signed-off-by present on every commit; adversarial review done (MERGE-WITH-NOTES, notes below).
  • W=1 on the touched objects: 0 new warnings. drm/apple KUnit 112/113 (1 skip), apple-dcp host selftests 86/86, run-host-tests at base parity.
  • Regression boots of 7.3.0-aurora-mtl1106a, compared with fleet16/fleet17 rows: M2, M1 Pro and J700 all clean (0 err-level lines, 0 AVCs, display, Wi-Fi, BT, Touch ID, camera, speakers at minimal volume with speakerguardd 0.1, s2idle x2, perf at parity).
  • drm/apple: colour matrix fixes (two's complement, refused warning, tag names, brightness correction) #790 specifically: GNOME night light on/off/on on the M2 (firmware 12.x/13.x path, eDP + DP-1 connected) gave 0 new dmesg lines, so no "colour matrix not applied" and no DCP errors. Review notes: the comment says Q32.32 while the commit says Q31.32 (same S31.32 layout), and the 14.7 template has no brightness-correction entry, so it isn't sent there.

@RyanTheTide
RyanTheTide merged commit 12047d7 into integration/aurora Nov 5, 2026
@RyanTheTide
RyanTheTide deleted the colour/ctm-fixes branch November 5, 2026 16:20
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