Skip to content

drm: apple: let external displays prefer an sRGB link colorimetry - #157

Open
briantoll wants to merge 1 commit into
omacom:integration/aurorafrom
briantoll:dcp-external-colour
Open

briantoll wants to merge 1 commit into
omacom:integration/aurorafrom
briantoll:dcp-external-colour

Conversation

@briantoll

@briantoll briantoll commented Oct 19, 2026 •

Copy link
Copy Markdown

drm: apple: let external displays prefer an sRGB link colorimetry

Target: omacom/linux-aurora, branch integration/aurora. One commit, rebased on 8eddf5a.

This PR is now just the link colorimetry change. The other two patches that used to ride along are their own PRs: the XRGB2101010 10-bit scanout fix is #411 and the sRGB surface tag is #412. Each can be reviewed and merged on its own.

Problem

For the SDR RGB link to an external display, parser.c keeps whichever colour mode the firmware scores highest. On a Studio Display XDR at 5120x2880@60 that is colour mode 68: 10-bit RGB, colorimetry 9 (BT.2020 RGB). The desktop renders sRGB, so its pixels travel on a BT.2020 link and the display stretches them to its full gamut. Every saturated colour comes out far more vivid than on macOS, reds most visibly. The internal panel runs colorimetry 16 (default RGB). The H17P path already refuses wide-gamut modes by score alone (external_sdr_rank); the other externals get nothing.

Decoded ColorElements for the XDR's 5K60 timing (non-virtual RGB modes; the sRGB 8-bit entries 1 and 2 are virtual and skipped):

ID depth EOTF colorimetry score
66 8 SDR Default RGB (16) 240999
69 10 SDR Default RGB (16) 440999
68 10 SDR BT.2020 RGB (9) 447999, picked by score
72 / 73 10 PQ BT.2020 / Default RGB 447999 / 440999
76 / 77 12 PQ BT.2020 / Default RGB needs DSC

No sRGB, BT.709 or P3 entry exists for this timing, so the best available is "default RGB", the same colorimetry the internal panel uses.

This matters for compositors too. Omarchy 4.5 now sets cm = "edid" on every Apple Silicon monitor rule (omacom/omarchy#17640) so Hyprland maps sRGB into the display's EDID gamut. That mapping assumes the link carries the display's native colorimetry. On a BT.2020 link the display stretches the already-mapped pixels a second time, and no compositor setting can undo that.

Fix

New module parameter appledrm.external_colorimetry (default 10, sRGB). Among SDR RGB modes for an external display an exact match wins, then sRGB/BT.709, then default RGB, then anything else, with the firmware score deciding inside a tier. -1 keeps the old behaviour. Read at mode-parse time, so a change needs a replug or reboot. Internal panels and the H17P external path are untouched.

v2 (after Toni Bergholm's review, comment): a higher-tier candidate is now validated into a copy of the slot and committed, with its rank, only once fill_color_mode() accepts it. The earlier version reset the slot's score before validating, so a malformed higher-tier record (depth 7, a missing depth or range) erased a valid lower-tier mode and advanced the rank past it; the fallback then picked a wide-gamut mode over the valid BT.709 one. Reported-by and Suggested-by are in the commit. A host test of the selection logic (not part of the tree) covers the three-record case and the malformed-record variants on either side of a valid record: the old code lost the slot in all of them, the new code keeps the valid mode, and the all-valid preference, same-tier score and no-valid cases are unchanged.

Tested

MacBook Pro 14" M1 Max (j314c), DCP firmware 13.5, Studio Display XDR at 5120x2880@60 over a Thunderbolt DP tunnel, Omarchy with Hyprland 0.56.2 for the side-by-side tests, 0.57.1 in daily use since. In daily use since 2026-10-19 (local kernel releases 12 through 16), including hotplug cycles.

  • dmesg | grep 'set_digital_out_mode() color mode' goes from depth:10 format:0 colorimetry:9 to colorimetry:16 for the XDR. The internal panel still picks mode 1. A replug on 2026-10-23 logged the same mode 69 selection through the normal hotplug path.
  • With the default-RGB link, compositor-side mapping behaves as expected: cm = "dp3" with sdr_eotf = "gamma22" lands close to the internal panel, and a per-monitor ICC profile gets to a match. On the BT.2020 link the same settings overshoot.
  • The 3840x2160@120 timing decodes to the same colour-mode set.

drivers/gpu/drm/apple/ builds on integration/aurora 8eddf5a with the Omarchy config (W=1, clang); checkpatch --strict reports only the Co-Authored-By trailer spelling.

🤖 Generated with Claude Code

@tonibergholm

tonibergholm commented Oct 20, 2026 •

Copy link
Copy Markdown

Found a selection regression while preparing a J613/.20 backport of this PR. This is an offline source test against head 9d3aeb24cb864d5f99a7172e9004884bf3c1a9a0, not a native colour/HDR test.

In the new rank >= best_sdr_rank block, a higher-tier entry resets sdr_rgb.score before fill_color_mode() validates it. The rank then advances even if validation fails. That can erase a valid slot and prevent later lower-tier valid modes from replacing it.

One synthetic decoded-record sequence, all non-virtual SDR RGB:

ID Colourimetry Depth Range Score
71 BT.709 8 full 100
68 BT.2020 RGB 10 full 447999
99 sRGB 7 (invalid) full 500000

The invalid third record leaves sdr_rgb.score=-1; the final slot fallback picks 68 rather than retaining valid BT.709 mode 71. An omitted depth (-1) or range also reproduces the slot loss, with the malformed entry both before and after the valid one. I have not observed these malformed records on the ARZOPA itself.

A small fix is to copy the current RGB slot, reset the temporary score for a higher tier, validate into the temporary, and commit both the slot and best_sdr_rank only on success. Patch against this head.

Reproducer extracts the actual fill/rank/selection code and final slot-priority block from pinned source blobs. With ASan/UBSan: the PR fails seven of nine checks, the fixed version passes nine of nine; the .20 reference passes its existing-behaviour checks. Valid preference and disabled-preference checks pass with the fix. This does not exercise serialized record decoding, the H17P-specific branch or firmware output. The fixed .20 parser object also compiles for ARM64; a broader reference build hit the unchanged temperature guard, so no complete module-build/native claim follows. Nothing installed or loaded.

Selected results and scope. Tests, patch and report prepared with Codex on Toni's J613.

Serialized-record follow-up

The wrong final colour selection also reproduces through the actual parse() / parse_mode() path, using synthetic serialized dictionaries and userspace kernel/DRM stubs. The three-record fixture above returns mode 68 on this PR and mode 71 with the fix. The six simpler malformed-plus-valid fixtures keep the same final ID via fallback: their earlier failures are RGB-slot corruption, not six additional wrong-output observations.

The fixed parser passes all 15 serialized checks, including valid and disabled preference, internal-panel score behaviour, one H17P rank case, same-tier scores, invalid-colour rejection, bad header and truncation. The reference for this comparison is the exact PR parent 44d5afc79; an initial hosted run with .20 as reference exposed an older unaligned integer read under Clang UBSan, already fixed in that parent. The failed run is retained; no sanitizer check was disabled.

GitHub GCC and Clang jobs both pass the nine fixed slot-selection checks and 15 fixed serialized checks, reproduce the expected upstream failures, and independently apply the published patch and compare its complete output with the tested fixed source. All four downloaded JSON result artifacts were checked, with no compiler or sanitizer diagnostics.

Serialized reproducer, selected results and artifact hashes. This is still a host harness, not a full kernel/KUnit, firmware, scanout or native colour/HDR qualification. No installation or runtime colour change made.

briantoll added a commit to briantoll/linux-aurora that referenced this pull request Nov 3, 2026
For an SDR RGB link the parser keeps whichever colour mode the firmware
scores highest. On a Studio Display XDR at 5120x2880@60 that is colour
mode 68: 10-bit RGB, colorimetry 9 (BT.2020 RGB). The desktop renders
sRGB, so its pixels travel on a BT.2020 link and the display stretches
them to its full gamut. The H17P path already refuses wide-gamut modes
by score alone (external_sdr_rank); this gives the other externals a
similar preference.

appledrm.external_colorimetry (default 10, sRGB) names the colorimetry
to prefer. Exact match wins, then sRGB/BT.709, then default RGB, then
anything else, with the firmware score deciding within a tier. -1 keeps
the old behaviour. The parser reads it when a display's modes are
parsed, so a change needs a replug or reboot.

Validate a higher-tier candidate into a copy of the slot and commit the
copy and its rank only once fill_color_mode() has accepted it. An earlier
version reset the slot's score before validating, so a malformed
higher-tier record (depth 7, a missing depth or range) erased a valid
lower-tier mode and advanced the rank past it; the final fallback then
picked a wide-gamut mode over the valid BT.709 one.

Reported-by: Toni Bergholm <[email protected]>
Link: omacom#157 (comment)
Suggested-by: Toni Bergholm <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Brian Toll <[email protected]>
@briantoll
briantoll force-pushed the dcp-external-colour branch from 9d3aeb2 to a7ae084 Compare November 3, 2026 19:24
@briantoll

Copy link
Copy Markdown
Author

Thanks, that is a real bug and your reproducer nails it. A higher-tier record reset the slot's score before fill_color_mode() had validated the replacement, so a malformed record both erased the valid lower-tier mode and advanced best_sdr_rank past it; your three-record case then fell back to BT.2020 mode 68 instead of keeping BT.709 mode 71.

Pushed a new version of the series, rebased onto the current integration/aurora:

  • drm: apple: let external displays prefer an sRGB link colorimetry now validates into a copy of the slot and commits the copy and its rank only on success, as you proposed. Credited with Reported-by/Suggested-by and a link to your comment. I kept my own host test of the branch logic beside it: the previous code lost the slot in the three-record case and in the depth-7 / missing-depth / missing-range variants on either side of a valid record; the new code keeps the valid mode in all of them, and the all-valid preference, same-tier score and no-valid cases are unchanged.
  • drm: apple: tag RGB surfaces on external displays as sRGB only needed its extern moved below the include block that grew upstream.
  • The XRGB2101010 commit is unchanged.

drivers/gpu/drm/apple/ builds on the new base with the Omarchy config; checkpatch --strict is clean on all three. No native colour re-test since the rebase yet; the previous runtime testing was on the Studio Display XDR at 5K60 as described in the PR body.

For an SDR RGB link the parser keeps whichever colour mode the firmware
scores highest. On a Studio Display XDR at 5120x2880@60 that is colour
mode 68: 10-bit RGB, colorimetry 9 (BT.2020 RGB). The desktop renders
sRGB, so its pixels travel on a BT.2020 link and the display stretches
them to its full gamut. The H17P path already refuses wide-gamut modes
by score alone (external_sdr_rank); this gives the other externals a
similar preference.

appledrm.external_colorimetry (default 10, sRGB) names the colorimetry
to prefer. Exact match wins, then sRGB/BT.709, then default RGB, then
anything else, with the firmware score deciding within a tier. -1 keeps
the old behaviour. The parser reads it when a display's modes are
parsed, so a change needs a replug or reboot.

Validate a higher-tier candidate into a copy of the slot and commit the
copy and its rank only once fill_color_mode() has accepted it. An earlier
version reset the slot's score before validating, so a malformed
higher-tier record (depth 7, a missing depth or range) erased a valid
lower-tier mode and advanced the rank past it; the final fallback then
picked a wide-gamut mode over the valid BT.709 one.

Reported-by: Toni Bergholm <[email protected]>
Link: omacom#157 (comment)
Suggested-by: Toni Bergholm <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Brian Toll <[email protected]>
@briantoll

Copy link
Copy Markdown
Author

Split: this PR is now only the link colorimetry change (v2 with the validation fix from the review above). The XRGB2101010 fix is #411 and the sRGB surface tag, now default off, is #412. Rebased on integration/aurora 8eddf5a.

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