Skip to content

drm/apple: fall back to safe SDR when auto SDR BT2020_RGB has no match - #3872

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/dcp-sdr-bt2020-fallback
Dec 2, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/dcp-sdr-bt2020-fallback

Conversation

@maralcbr

@maralcbr maralcbr commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Stock compositors such as Hyprland 0.57 (default cm=edid, no custom monitor color config) set Colorspace=BT2020_RGB in SDR mode (EOTF=SDR, color_format=AUTO, Broadcast RGB=Automatic) whenever a sink EDID advertises BT2020RGB and the connector exposes Colorspace.

On bandwidth-limited HDMI 2.0 timings such as 3840x2160@60 on an LG 4K UHD TV behind T6040 external DCP (m4pro, J616S, Timing ID=72), the firmware ColorModes catalogue exposes:

  • 0 BT2020_RGB entries
  • 23 UNSAFE entries (including all 10/12-bit BT2020_YCC entries)
  • only 3 safe entries (ID=5, 123, 125), all 8-bit DownstreamFormat YCbCr 4:2:0 SDR sRGB/BT.601

Since #3052, dcp_crtc_check_hdr() -> dcp_select_color_mode() rejected every atomic modeset with -EINVAL, trapping aquamarine/Hyprland in an unpaced retry loop (~1,000 atomic commits/s) that left HDMI-A-1 unable to complete modeset and drove idle power to 59–64 W (~2,800 GPU mailbox IRQs/s, ~23,600 timer IRQs/s, 25–43% Hyprland CPU) vs ~7.8 W baseline.

Fix

  1. drivers/gpu/drm/apple/dcp-color.h (dcp_color_space_matches): allow DRM_MODE_COLORIMETRY_BT2020_RGB with DRM_CONNECTOR_COLOR_FORMAT_AUTO to match safe DCP_COLORIMETRY_BT2020_YCC entries in SDR as well as HDR (RGB on the wire still outranks all YCbCr formats when both exist; explicit color_format != AUTO still rejects the alias).
  2. drivers/gpu/drm/apple/dcp-color.h (dcp_scan_color_modes, dcp_select_color_mode): extract the filtered catalogue scan into dcp_scan_color_modes(). When an automatic SDR BT2020_RGB request (color_format == AUTO, broadcast_rgb == AUTO) has no matching BT.2020 entry, retry once directly through dcp_scan_color_modes() with DRM_MODE_COLORIMETRY_DEFAULT (never entering the legacy dcp_default_sdr_color() cache fast path). This preserves DCP_COLOR_FLAG_UNSAFE/sdr_usable/allow_unsafe_sdr filtering, EOTF checks, and max_bpc, and works even when cached default slots are unpopulated. Explicit format, explicit range, non-BT2020_RGB colorspaces, low max_bpc, and HDR/PQ requests continue to return -EINVAL when unsupported.
  3. drivers/gpu/drm/apple/iomfb.c (dcp_crtc_check_hdr): accept DRM_MODE_COLORIMETRY_BT2020_RGB alongside DRM_MODE_COLORIMETRY_DEFAULT for fixed 8-bit SDR pipes (!iomfb_template_pq || dcp_is_ext26) under the same AUTO/AUTO and (!max_bpc || max_bpc >= 8) guards.
  4. tools/testing/selftests/drivers/gpu/apple-dcp/display.py: add unit test coverage for SDR BT2020_RGB + AUTO -> BT2020_YCC, explicit wire format alias rejection (YCBCR420 + BT2020_RGB), 4K60 HDMI 2.0 safe SDR fallback with unsafe cached default (max_bpc=0/12/8, unpopulated caches, max_bpc=6), uncapped unsafe-only timing (allow_unsafe_sdr=false vs true), PQ-only timing rejection, and explicit format/range/colorspace/HDR rejections.

Note: consistent with existing DCP output-based surface tagging, falling back to an sRGB/BT.601 link leaves the plane's base surface tag in place (it avoids a stale BT.2020 tag rather than converting BT.2020-encoded pixels); ext26's unchanged fixed-pipe fast path still validates sdr_rgb at modeset time just as it does for DRM_MODE_COLORIMETRY_DEFAULT.

Before / After on M4 Pro (J616S + LG SMART UHD 4K60 TV on HDMI-A-1)

Metric (settled idle desktop) aurora-silicon/main (6c83a2a64539) With c97b9dbff5b2 (j1202-144240-c43d)
aquamarine failed to commit errors infinite (~1,000/s) 0
HDMI-A-1 active mode stuck retrying 3840x2160@60, timing_id=72, color_id=125 (8-bit YCbCr 4:2:0 SDR Limited)
GPU mailbox IRQs/s 2,798/s 0/s
Timer IRQs/s 23,648/s 851/s (415/s on v1)
Idle CPU (top) Hyprland 25–43% 100.0% id
Total System Power (Performance) 59.0–64.0 W 6.96 W (Heatpipe 1.99 W)
Total System Power (Balanced) — 6.36 W (Heatpipe 1.39 W)

Tested: MacBook Pro 16-inch (M4 Pro, J616S, T6040) with LG SMART UHD 4K60 TV on HDMI-A-1 at c97b9dbff5b2 (maclab b1202-144026-fde7 / j1202-144240-c43d): failed_to_commit=0, HDMI-A-1 active at 3840x2160@60 (timing_id=72, color_id=125), GPU mailbox IRQs 2,798/s -> 0/s, idle power 64.01 W -> 6.96 W (performance) / 6.36 W (balanced); checkpatch.pl --strict 0 errors / 0 warnings / 0 checks; Codex round 2 review VERIFIED (01a234ff-9a90-7112-9100-bd8925627971) including checked-in display.py and production-parser probes under LLVM with UBSan.
Risk: two-way · drivers/gpu/drm/apple/dcp-color.h and iomfb.c automatic SDR BT2020_RGB fallback

Compositors such as Hyprland 0.57 (default cm=edid) set
Colorspace=BT2020_RGB in SDR mode whenever the sink EDID advertises
BT.2020 and the connector exposes the Colorspace property.

On bandwidth-limited HDMI 2.0 timings (such as 3840x2160@60 on an LG
4K UHD TV behind T6040 external DCP), the firmware ColorModes catalogue
exposes no BT2020_RGB entries and marks all 10/12-bit BT2020_YCC
entries as unsafe, leaving only 8-bit YCbCr 4:2:0 sRGB/BT.601 safe.
dcp_crtc_check_hdr() -> dcp_select_color_mode() rejected every atomic
modeset with -EINVAL, trapping aquamarine/Hyprland in an unpaced retry
loop (~1,000 commits/s, ~2,800 GPU mailbox IRQs/s, ~64 W idle power vs
~7.8 W baseline) with the external HDMI display never completing
modeset.

Fix both gaps without weakening explicit colour requests or HDR checks:
1. In dcp_color_space_matches(), allow DRM_MODE_COLORIMETRY_BT2020_RGB
   with DRM_CONNECTOR_COLOR_FORMAT_AUTO to match safe
   DCP_COLORIMETRY_BT2020_YCC entries for SDR as well as HDR (RGB still
   outranks YCbCr when both exist).
2. Extract dcp_scan_color_modes() and, in dcp_select_color_mode(), if
   an automatic SDR BT2020_RGB request (color_format == AUTO and
   broadcast_rgb == AUTO) finds no matching BT.2020 entry, fall back
   directly through dcp_scan_color_modes() with
   DRM_MODE_COLORIMETRY_DEFAULT rather than dcp_default_sdr_color().
   This preserves unsafe/sdr_usable filtering, EOTF checks, max_bpc,
   and works even when cached default slots are unpopulated.
3. In dcp_crtc_check_hdr(), accept DRM_MODE_COLORIMETRY_BT2020_RGB
   alongside DRM_MODE_COLORIMETRY_DEFAULT for fixed 8-bit SDR pipes
   (!iomfb_template_pq || dcp_is_ext26) under the same AUTO/AUTO and
   max_bpc >= 8 guards.

Explicit format, range, non-BT2020_RGB colorspace, low max_bpc, and
HDR/PQ requests continue to return -EINVAL when unsupported.

Add unit test coverage in the apple-dcp display.py selftest.

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
@maralcbr
maralcbr requested review from a team as code owners December 2, 2026 04:47
@maralcbr
maralcbr requested review from LiamRay11 and malik-na and a balanced review from Copilot December 2, 2026 04:47

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

This PR addresses Apple DCP modeset failures and compositor retry loops when SDR requests use Colorspace=BT2020_RGB with color_format=AUTO, by introducing safe fallback selection logic and widening BT.2020 matching behavior.

Changes:

  • Allow SDR BT2020_RGB + AUTO requests to match safe BT2020_YCC catalog entries when appropriate.
  • Refactor color-mode selection by extracting a filtered catalog scan helper and adding a one-shot fallback to DRM_MODE_COLORIMETRY_DEFAULT for the problematic SDR auto case.
  • Expand selftest coverage for SDR BT2020_RGB aliasing and safe SDR fallback behavior across multiple edge cases.
File Description
tools/​testing/​selftests/​drivers/​gpu/​apple-dcp/​display.py Adds selftests that exercise the new SDR BT2020_RGB aliasing and safe fallback behavior, including rejection cases.
drivers/​gpu/​drm/​apple/​iomfb.c Permits BT2020_RGB requests (under AUTO/AUTO constraints) on fixed 8-bit SDR pipes to avoid erroneous rejection.
drivers/​gpu/​drm/​apple/​dcp-color.h Refactors selection logic into dcp_scan_color_modes() and adds SDR fallback from BT2020_RGB to DEFAULT scan; expands BT2020_RGB matching to include SDR.

Review effort: Lite

Comment on lines +285 to 290
static inline const struct dcp_color_entry *
dcp_scan_color_modes(const struct dcp_display_mode *mode,
const struct dcp_color_request *req)
{
u8 max_bpc = req->max_bpc ? req->max_bpc : 12;
bool hdr = req->eotf != HDMI_EOTF_TRADITIONAL_GAMMA_SDR;
Comment on lines +364 to +370
* Compositors (e.g. Hyprland's default cm=edid) set
* Colorspace=BT2020_RGB in SDR when the sink EDID advertises
* BT.2020, even on bandwidth-limited timings (such as 4K60
* HDMI 2.0) where only 8-bit sRGB/BT.601 YCbCr 4:2:0 is safe.
* Rejecting that commit with -EINVAL traps compositors in an
* unpaced modeset retry loop; fall back through the filtered
* catalogue so unsafe, EOTF, and max_bpc rules still apply.
Comment on lines +3781 to 3787
/* Fixed 8-bit SDR pipes satisfy default or auto BT.2020 SDR with max_bpc >= 8. */
if (req.eotf == HDMI_EOTF_TRADITIONAL_GAMMA_SDR &&
req.colorspace == DRM_MODE_COLORIMETRY_DEFAULT &&
(req.colorspace == DRM_MODE_COLORIMETRY_DEFAULT ||
req.colorspace == DRM_MODE_COLORIMETRY_BT2020_RGB) &&
req.color_format == DRM_CONNECTOR_COLOR_FORMAT_AUTO &&
req.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_AUTO &&
(!req.max_bpc || req.max_bpc >= 8))

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

Reviewed c97b9db. The SDR retry still uses the catalogue filters for link safety, depth and EOTF. An explicit format or range prevents the default-colorspace retry, and HDR retains its existing permission and selection paths. The exact-head color-mode fixture passed with Clang ASan/UBSan, including the 4K60 fallback and rejection controls. The J616s HDMI result exercises the reported failure. The shared fixed-pipe path still needs its cross-generation HDMI control before merge.

@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at c97b9dbf: ready to merge

Check Detail
CI at head ok 9 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at c97b9dbf
Conflicts ok none
PR text ok Risk: two-way · drivers/gpu/drm/apple/dcp-color.h and iomfb.c automatic SDR BT2020RGB fallback

Areas: area:display
Merge: gh pr merge 3872 --merge (Owners and Core through the bypass: add --admin).

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

@github-actions github-actions Bot added the ready-to-merge Meets the merge policy: merge it (bot) label Dec 2, 2026
@maralcbr

maralcbr commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Cross-generation HDMI + DP control at exact PR head c97b9dbff5b2 (b1202-144026-fde7 / j1202-184628-aa42) on MacBook Pro 14-inch (M1 Pro, J314S, T6000, v13.5 DCP):

  • Displays attached (3 active simultaneously):
    • HDMI-A-1: LG ULTRAWIDE (3840x2160@60, EDID advertises BT2020YCC, BT2020RGB, YCbCr 4:2:0, HDR Static Metadata)
    • DP-2: LG ULTRAWIDE (3440x1440@60 over USB-C DP)
    • eDP-1: internal panel (3024x1964@120 VRR)
  • Live DRM atomic state & DCP color_state:
    • HDMI-A-1: Hyprland requested colorspace=BT2020_RGB, max_requested_bpc=8, broadcast_rgb=Automatic → cleanly selected safe 8-bit YCbCr 4:2:0 SDR (timing_id: 56, color_id: 102, depth: 8, format: YCbCr420 (1), colorimetry: BT709 (1), eotf: SDR (0), range: Limited (1)).
    • DP-2: Hyprland requested colorspace=BT2020_RGB, max_requested_bpc=8 → cleanly selected safe 8-bit Full-range RGB sRGB SDR (timing_id: 42, color_id: 62, depth: 8, format: RGB (0), colorimetry: sRGB (10), eotf: SDR (0), range: Full (0)).
    • eDP-1: timing_id: 2, color_id: 1, 8-bit RGB Default_RGB Full (colorspace=Default).
  • Result: failed_to_commit=0 across all displays, 99.5% id CPU, 0/s GPU mailbox IRQs, 10.59 W total system power across all 3 active displays, and zero apple-dcp / apple-drm warnings or errors in dmesg.

@DjDeveloperr
DjDeveloperr merged commit b8c3c45 into main Dec 2, 2026
10 of 12 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/dcp-sdr-bt2020-fallback branch December 2, 2026 08:52
maralcbr added a commit to omacom/linux-aurora that referenced this pull request Dec 2, 2026
omarchy-pkgs-merge Bot pushed a commit to omacom/omarchy-pkgs that referenced this pull request Dec 2, 2026
…DCP SDR fallback (#558) (#4508)

Pin linux-aurora and aurora-userpages to immutable tag aurora-7.3.0-5
(omacom/linux-aurora c731018151b1 on carry/aurora-7.3.0-5), built from
integration/aurora-7.3 (omacom/linux-aurora 87005e7e5393):
- Re-pins aurora-silicon/linux#3490 to 8ba26a7e7edc (omacom/linux-aurora#557):
  single-consumer G15 stats ring drain, PM suspend/resume ring drain, and
  M3 receive-ring load/store ordering (resolving the #3490 caveat tracked in #4397)
- Adds aurora-silicon/linux#3872 (omacom/linux-aurora#558): DCP auto SDR
  BT2020_RGB fallback to safe SDR on bandwidth-limited HDMI 2.0 timings
- Preserves intake 4a42f3105002 and all 23 carries from 7.3.0.aurora4-1

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
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) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants